cancel
Showing results for 
Search instead for 
Did you mean: 

Early waking Up from STOP mode

JAN R
Associate III

Dear,

I use SM32L152, I go to STOP mode regularly and as the possible source of waking up is either RTC or External interrupt. It works Fine until I change the System clocks from MSI 4 MHz to for example HSI on 16 MHz. If I change it, then MY MCU is woken up even if RTC alarm has not expire yet and no external interrupt happened.

I am really desperate. I will appreciate every advice.

Thank you very much, Jan.

8 REPLIES 8
turboscrew
Senior III

How do you change he clock? Could it be that some other interrupt becomes enabled in the process?

JAN R
Associate III

To avoid misunderstanding: I change the clock only in CUBE_MX - not in running program.

But now it looks that it works. I dissabled LSI before reading from RTC calendar. I do not understand why it is needed because I have set BYPSHAD bit to1 - and I read the registers twice for getting correct values.

Th result is that if I have clock 2 or 4 MHz I do not have to dissable the LSI before reading reg form RTC. But for example if I change it to 16 MHz - then it does not work without the dissabling the LSI. It works as well when I dissable RTC before reading instead of LSI.

Mohamed Aymen HZAMI
ST Employee

Hello,

To do a test-case, I need to know more information :

  • What is the initial clock before entering STOP mode ( which type of oscillator you use ? )

Best Regards,

Mohamed Aymen.

JAN R
Associate III

Hi,

I always run from internal oscilators. MSI (2 and 4 MHz) *** HSI or PLL for higher freq. I use STM32L152VBTxA.

Now I use MSI@4 MHz and it works even without RTC_Disable or LSI_Pause. But when I increase clocksto 16 MHz or higher so it does nt work reliably.

My reading from RTC looks like

 HAL_RTC_GetTime( &RtcHandle, RTC_TimeStruct, RTC_FORMAT_BIN );
 
  __HAL_RCC_RTC_DISABLE();
 // __HAL_RCC_LSI_DISABLE();
  do
  {
	  firstRead = RTC_TimeStruct->SubSeconds;
	  HAL_RTC_GetDate( &RtcHandle, RTC_DateStruct, RTC_FORMAT_BIN );
	  HAL_RTC_GetTime( &RtcHandle, RTC_TimeStruct, RTC_FORMAT_BIN );
 
  } while (firstRead != RTC_TimeStruct->SubSeconds);
 
 // __HAL_RCC_LSI_ENABLE();
 //while(( __HAL_RCC_GET_FLAG(RCC_FLAG_LSIRDY) == RESET));
 
  __HAL_RCC_RTC_ENABLE();

Thanks, Jan.

Mohamed Aymen HZAMI
ST Employee

Hello JAN,

If I understand correctly, you are unable to read the RTC registers ?

  • You must call HAL_RTC_GetDate() function after HAL_RTC_GetTime() to ensure consistency between the time and date values.
  • If you do not set the BYPSHAD bit, you will need 2 cycles of RTCCLK to display the updated values.
  • Reading RTC current time locks the values in calendar shadow registers until Current date is read.

Best Regards,

Mohamed Aymen.

JAN R
Associate III

Hello Mohamed,

I have debugged it and have some findings:

1) I added HAL_RTC_GetDate() function after HAL_RTC_GetTime() 

2) I have set the BYPSHAD bit to 1 and from Reference manual RM0038 section 20.3.6 I have the reading correct:

The software must read all the registers twice, and then

compare the results to confirm that the data is coherent and correct. Alternatively, the

software can just compare the two results of the least-significant calendar register.

3) When I debug it, it looks like I can read the time from RTC calendar correctly, BUT When I set up the WKUP alarm A to specific time for example now + 100 ms so the alarm A expire after 1/PRREDIV_S cycles.

4) When I add the mentioned __HAL_RCC_RTC_DISABLE() and Enable when I read the Time and Date - then the alarm A expire and wakeup exactly in right time (in my case after 100 ms).

That is all what I have discovered so far 😊

Thank you for any help.

Jan.

Mohamed Aymen HZAMI
ST Employee

Hello JAN,

does that solve your problem ?

Best Regards,

Mohamed Aymen.

JAN R
Associate III

Hello,

basically yes, but I do not think that is the best way to solve it. There is probably any other problem and my solution is only crutch for it 🙂

Best Regards, Jan,