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;

    pc.set_baud(115200);

    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);
        led1.write(toggle);
        
    }
}

Any ideas? It does not work!

Hello,

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:

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