I'm using a STM32L0 MCU for my project. The MCU has a Low-power Timer (LPTIM) for waking the MCU up from Stop-Mode, and a Low-power UART (LPUART) for both waking up the MCU from stop mode and receive/transmit data.
My problem is:
– When I let the MCU staying in running mode, LPUART working fine at baudrate over 256000.
– When I set MCU to go to Stop-mode, then when the MCU receives something from LPUART-Rx, it's woken up and keep reading the received sequence data. For this set up, when UART baudrate is lower than 56000 it works fine. However when the baudrate is higher than this (e.g at 115200), LPUART read the wrong data. I'm aware that in this set-up, the first transmitted byte will be lost but the others should be read correctly.
I tried with several different transmitted data with different lengths, however the received data is always wrong. (work fine when baudrate is 56000 though).
Best Answer
When the LPUART starts to receive data, the clocks won't be active immediately. HSI16 (high speed internal 16 MHz RC oscillator) typically takes 3.7 μs to start.*
You can eliminate the HSI16 startup time by leaving it running during stop mode, if you really need to do so. Once the HSI16 is available, the LPUART itself has to activate, which takes up to 12 μs* as well:
*The reference manual doesn't mention any startup times as they are specific to each individual part. You can find the actual values in the datasheet, the value here is for the STM32L051x6/8 and listed here only for illustrative purposes.
At 56 kbaud, the transmission period of one bit is 17.86 μs, which is barely long enough (still probably out of spec) for the LPUART to wake up before the next bit arrives and everything goes out of sync. This is why you can't increase the baud rate.
See "Determining the maximum LPUART baudrate allowing to wakeup correctly from Stop mode when the LPUART clock source is the HSI clock" (page 734, reference manual)