Electronic – STM32L0 Low power UART-receiver reads the wrong data at high baudrate after MCU waking up

baudratemicrocontrollerstm32stm32f0uart

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

Wakeup from Stop mode using LPUART

The LPUART is able to wake up the MCU from Stop modewhen the UESM bit is set and the LPUART clock is set to HSI or LSE (refer to the Reset and clock control (RCC) section.

  • LPUART source clock is HSI
    If during stop mode the HSI clock is switched OFF, when a falling edge on the LPUART receive line is detected, the LPUART interface requests the HSI clock to be switched ON. The HSI clock is then used for the frame reception.

    • If the wakeup event is verified, the MCU wakes up from low-power mode and data reception goes on normally.
    • If the wakeup event is not verified, the HSI clock is switched OFF again, the MCU is not waken up and stays in low-power mode and the clock request is released.

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)