cancel
Showing results for 
Search instead for 
Did you mean: 

UART corrupted after wake from stop mode

ISeed
Senior

Hello, all!

I'm using STM32F100RBT.

I have the following code:

printf("hello\n");
while(1)
{
   HAL_PWR_EnterSTOPMode(PWR_MAINREGULATOR_ON, PWR_STOPENTRY_WFI);
   HAL_Delay(100);
   printf("***\n");
   HAL_Delay(100);
}

The first print before the loop is printed onto UART ok,

But those inside the loop are corrupted. That is, the print occurs but it's gibberish.

If I change the stop line to sleep:

HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);

Everything works fine. The problem is specific for STOP mode.

Searching the forum, I don't find a fix..

I tried de-initializing and initializing the UART after each wake, but it doesn't help, it keeps printing gibberish. It also happens whether it's baud rate of 9600 or 921600.

Any way to fix this?

Thanks!

2 REPLIES 2
ISeed
Senior

Anyone?

Tilen MAJERLE
ST Employee

Hello @ISeed​ 

after the wakeup from STOP mode, CPU runs at internal clock and not anymore at [most probably] PLL as it was configured before hence UART baudrate is not matching original settings.

When you enter to sleep mode only, then clocks are NOT stopped and after wakeup, CPU continues from same clock as before entering stop mode.

Solution is to reinitialize system clock after waking-up from STOP mode.

Tilen