2018-06-04 12:21 AM
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-stm2018-06-04 01:20 AM
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.
2018-06-04 03:58 AM
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.
2018-06-04 06:02 AM
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.
2018-06-04 06:05 AM
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
2018-06-04 10:44 AM
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 initializationUpdated 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.