cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L071 - RTC ISR flags clearing

MPrud.1
Associate

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Michael GLATZEL
ST Employee

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

View solution in original post

2 REPLIES 2
Michael GLATZEL
ST Employee

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
Associate

Thx for very quick answer.

Regards,

Mirek