4 years, 3 months ago.

mbed UART clcok speed.

Hello All.

I am running a project on a Nucleo-F411RE dev board. I understand that although the system is nominally 100Mhz, this board actually runs at 96Mhz, in order for ensuring correct USB operation. If one runs the CPU at various speeds, it must surely be necessary to adjust the UART clock speed, or inform the system of the actual clock speed. How do we do this?

I ask this because at 57,600 baud, my output looks slightly stretched compared to a standard FTDI usb to serial output.

Hello Mark,

I got similar problem related to USART few months ago. I hope following link can give you an idea, even though may be it is not a direct answer to your question.

https://developer.mbed.org/questions/54029/USART-Problem-with-NucleoF401RE/

Regards...

posted by Kamil M 05 Oct 2015

1 Answer

4 years, 3 months ago.

The init code for peripherals is called at instantiation time and it will derive clock settings by checking the SystemCoreClock variable. That variable should always reflect the basic systemclock. When you use own code to change the clock of the processor by manipulating the clocksource or the PLL or some other means it will result in incorrect peripheral clocks and thus wrong baudrates for UART, SPI, I2C and possibly tickers etc. So be careful when touching the clock in your own main code. Best way to do this is by using the mbed-src instead of the mbed lib and modify the system init files for the clock. In case you want to use the lib and still change the clock in your own main you can correct the baudrates by explicitly calling the serial.baud() method again after changing the clock. That should result in a recalculation using the new SystemCoreClock value.

Note that by default the nucleos use the internal high speed RC clocksource. That clock is not as accurate as a crystal and this could explain some discrepancy with the exact baudrate. There are also some baudrates which can not be generated accurately (or even at all) at specific SystemCoreClock values. The difference should stay within the tolerance range of most UART receivers/transmitters.

Accepted Answer