cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L4 HAL RTC Clear Alarm flags

confalonieri
Associate II
Posted on November 30, 2016 at 16:21

Hi,

The latest release of RTC HAL library (1.6.0) for STM32L4 does not clear the RTC  ALARM interrupt flag.

The following code from the function

''void HAL_RTC_AlarmIRQHandler(RTC_HandleTypeDef* hrtc)''

    /* Clear the AlarmA interrupt pending bit */

      __HAL_RTC_ALARM_CLEAR_FLAG(hrtc, RTC_FLAG_ALRAF);

Does nothing !

the only way to clear the ALARMA flag is add a custom instruction like

hrtc->Instance->ISR = hrtc->Instance->ISR & 0xFFFFFEFF; // Clear Alarm A flag

Any idea ?

Is that problem affecting other peripherals ?

Kind regards

F.c

5 REPLIES 5
slimen
Senior
Posted on November 30, 2016 at 17:00

Hello,

Have you try this with an exist example? 

You can start with a working RTC_alarm example within STM32cubeL4 in order to deduce what is going wrong in your case.

This may helps you: STM32Cube_FW_L4_V1.6.0\Projects\STM32L476G_EVAL\Examples\RTC\RTC_Alarm

Regards

confalonieri
Associate II
Posted on November 30, 2016 at 17:28

Hi,

Thank you for the suggestion. I forgot to tell that it was a perfect running firmware created with CUBEMX 4.17 and using the HAL library version 1.5.2 !

I just update it using CUBEMX 4.18 and new library version 1.6.0

So the problem is somewhere else not in my code.

By debugging the code when an alarm is raised by the RTC I saw that the execution is blocked in the function Void HAL_RTC_AlarmIRQHandler(RTC_HandleTypeDef* hrtc) indefinitely

In this function there is WHILE that has been added in the new Library 1.6.0.

Not clearing the ALARM flag it enter in an infinite loop !

Maybe the problem was present even in old library but as there was not the WHILE !...

Kind Regards

f.c.

Posted on October 20, 2017 at 08:43

Did you manage to solve this? I am having this problem and I don't know what else I can try... I tried removing the while loop but then I just get the first ALARM A to work. Nor the alarm b, neither second alarm a.

Clonimus74
Senior II
Posted on October 29, 2017 at 11:18

I see the same problem, the code:

__HAL_RTC_ALARM_CLEAR_FLAG(hrtc, RTC_FLAG_ALRAF);

does not clear the interrupt flag.

I found a solution that works for me, though it makes no sense, I use the call back (I override the weak function as to not interfere with the generated code from Cube):

void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc)

{

  HAL_PWR_EnableBkUpAccess();

  LL_RTC_ClearFlag_ALRA(hrtc->Instance);

  HAL_PWR_DisableBkUpAccess();

}

Posted on October 30, 2017 at 08:01

As I have seen, when you block backup access, you cannot modify flag values. So In the end I did something like you. Enable backup access, operate and then disable it again.

Thank you for your response Clonimus74.