Skip to main content
MPrud.1
Associate
August 5, 2022
Solved

STM32L071 - RTC ISR flags clearing

  • August 5, 2022
  • 2 replies
  • 1470 views

In the following HAL function, RTC ISR register is cleared by "Read/Modify/Write" instruction.

Couldn't this cause eventual clearing of the ISR flags which may be raised by RTC periphery between "load" AND "store" ?

If somebody can confirm that such situation may happen, wouldn't be safer solution to rather write all other bits to "1", since ISR register has only of read-only or clear-only bits or reserved bits?

AL_StatusTypeDef HAL_RTC_WaitForSynchro(RTC_HandleTypeDef *hrtc)
{
 uint32_t tickstart;
 
 /* Clear RSF flag */
 hrtc->Instance->ISR &= (uint32_t)RTC_RSF_MASK;

AL_StatusTypeDef HAL_RTC_WaitForSynchro(RTC_HandleTypeDef *hrtc)

{

 uint32_t tickstart;

 /* Clear RSF flag */

 hrtc->Instance->ISR &= (uint32_t)RTC_RSF_MASK;

This topic has been closed for replies.
Best answer by Michael GLATZEL

Hello MPrud.1,

I agree with you. Due to the Read-Modify-Write (RMW) sequence in HAL_RTC_WaitForSynchro function, it can also clear accidentally flags which arrive after the READ.

I will internally suggest to remove the AND combination:

 hrtc->Instance->ISR = (uint32_t)RTC_RSF_MASK;

Thanks for raising this point.

Best regards

Michael

2 replies

Michael GLATZELBest answer
ST Employee
August 5, 2022

Hello MPrud.1,

I agree with you. Due to the Read-Modify-Write (RMW) sequence in HAL_RTC_WaitForSynchro function, it can also clear accidentally flags which arrive after the READ.

I will internally suggest to remove the AND combination:

 hrtc->Instance->ISR = (uint32_t)RTC_RSF_MASK;

Thanks for raising this point.

Best regards

Michael

MPrud.1
MPrud.1Author
Associate
August 5, 2022

Thx for very quick answer.

Regards,

Mirek