cancel
Showing results for 
Search instead for 
Did you mean: 

Garbage Printing after wake up from STOP 2 mode - stm32l476rg

H UQ
Associate II
Posted on June 04, 2018 at 09:21

Hi, 

We are working on STM32L476_NUCLEO board. We successfully entered and exit from STOP 2 mode upon RTC timer expiry. However, when we print a message after wake up, garbage is printed. Here is the code. 

print ('Going to STOP 2 mode'); // Printed on console 

USART2 -> CR1 |= 2;

/* Enter into STOP 2 Mode */

WRITE(0xE000ED10,

READ(0xE000ED10) | 1<<2

);

temp32 = READ32(PWR_CR1);

WRITE32(PWR_CR1, temp32 | PWR_CR1_LPMS_STOP2);

WFI_EXECUTE();

WRITE(

0xE000ED10,

0

);

WRITE(PWR_CR1, temp32);

/* Successfully returned from STOP 2 mode */

USART2 -> CR1 &=  ~2;

print ('\r\nBack'); // Funny characters are printed. 

Regards

#stm32l476 #stop-mode-2 #nucleo-stm
5 REPLIES 5
Uwe Bonnes
Principal III
Posted on June 04, 2018 at 10:20

Probably UART TX has no external pull-up. When in sleep, internal pull-up is switched off, TX goes ow and when woken up TX goes to 1 again, indication a start condition, resulting in a nonsens character received.

Posted on June 04, 2018 at 12:58

That, or the part is operating with a different clocking regime when it comes back, and you either need to restore the original clocking, or adjust the UART->BRR to reflect new divisors for the baud rate.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on June 04, 2018 at 13:02

I checked my RCC settings before and after STOP Mode 2. It is same. We are using HSI clcok. Probably, some bit not in RCC is slipped after exiting from STOP mode. 

Posted on June 04, 2018 at 13:05

Suggest you output 'U' character stream and scope it to confirm bit timing if you see incorrect data. Check the clock source selected for the USART

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on June 04, 2018 at 17:44

Found the issue. After wake up from STOP 2 mode, USART->CR1->OVER8 bit is cleared (initially it was set) due to which, baud rate calculation is out of sync. Hence we get funny characters. 

There are two solutions

Solution 1: 

USART2->CR1 &= 

(~0x8000);

// During initialization 

Updated the baud rate calculation formula base upon OVER8 = 0. 

Solution 2: 

USART2->CR1 |= 

(0x8000);

// During initialization 

U

pdated the baud rate calculation formula base upon OVER8 = 1. 

After wake up from STOP2 mode, 

USART2->CR1 &= (~1); // 

USART2->CR1 |= 

(0x8000); // Set break point here and step over this line 

USART2->CR1 |= 

(1); // Step over this line 

print('We are Back'); // Go 

Unfortunately, Solution 2 is working in debug environment only. It does not work in non debug environment. Nothing is printed on screen. System got stuck after wake up from STOP 2 mode.