Can't set baud rate!

Hi. I’m trying to write a program to make an LED turn on by pressing 1 and turn off again by pressing 0. I’m using the STM32 Discovery Kit by ST Electronics (B-L475E-IOT01A).

I think the problem is that setting the baud rate does not work.

Here is my code so far:

#include "mbed.h"

DigitalOut led1(PC_5);

BufferedSerial pc(USBTX, USBRX);    

int main(){
    int toggle;


    printf("This is the bare metal blinky example running on Mbed OS %d.%d.%d.\n", MBED_MAJOR_VERSION, MBED_MINOR_VERSION, MBED_PATCH_VERSION);

    while (true)
        printf("Please type 1 or 0:");
        scanf("%i", &toggle);
        printf("%i \n", toggle);

Any ideas? It does not work!


when you set baud rate of your aplication to 9600, then does it work? Or what do you see in your terminal as output?

BR, Jan

It just printed rubbish then. However, we solved it by simply using .read() and .write() functions from the BufferedSerial class :slight_smile:

Easiest way is to remove all reference to “pc”,;
and use a mbed_app.json file to override default baud rate.
Example there: