Skip to main content
Visitor II
June 4, 2019
Question

STM32L452 RTC wakeup timer works, but just once

  • June 4, 2019
  • 5 replies
  • 2824 views

I initialize RTC timer by first clearing RTC_CR register,then waiting until WUTWF bit is on, then setting RTC WUTR register to 100, and RTC_CR to 0x4420 (wakeup timer enable, wakeup interrupt enable, bypass shadow). Bypass shadow register is set for other things.

This setting should generate interrupt 2048/100=about 20 times per second

NVIC is enabled for RTC wakeup interrupt, EXTI is properly set to rising edge for line 20.

The interrupt handler clears bit in EXTI_PR1 by writing 1 and clear bit 10 in RTC_ISR.

NET EFFECT: one interrupt is generated. that's all.

What i am doing wrong.

    This topic has been closed for replies.

    5 replies

    Visitor II
    June 4, 2019

    Clear the RTC ISR first. Maybe add a barrier (DSB), then clear the pending IRQ from EXTI.

    Otherwise, the EXTI-flag may set again, before you get the RTC IRQ cleared.

    That _might_ be the problem.

    WPuchAuthor
    Visitor II
    June 5, 2019
    Tried.
    this is my IRQ handler
    void rtc_wkup_irq() {
     RTC_ISR&=~(1<<10); FLUSH; EXTI_PR1=(1<<20); FLUSH; //clear wakeup
    interrupt
    //my other code follows
    }
    FLUSH is a macro - actually asm("dmb");
    as described in page 1107 in manual bit 10 of RTC_ISR is WUTF bit set to
    1 when auto reload counter reaches 0.
    flag is cleared by writing 0 and i do this.
    is it something more needed so the counter will actually autoreload?
    Maybe it doesn't so interrupt works just once.
    initialization sequence is as follows
     RTC_WPR=0xCA; RTC_WPR=0x53; FLUSH;
     RTC_CR=0x20; while(!(RTC_ISR&4)); //czekamy aż WUTWF==1
     RTC_WUTR=100; RTC_CR=0x20; FLUSH;
     RTC_CR=0x4420; FLUSH; //bypass shadow registers, wakeup interrupt
    enable, wakeup timer enable
     RTC_WPR=0; FLUSH;
    and i've checked following this WUTR is 100 and CR is 0x4420.
    what more can i check?
    On 2019.06.04 18:53, ST Community wrote:
    Visitor II
    June 6, 2019

    Memory barrier (dmb) may not be enough, you may need barrier over the AMBA-bus - system barrier (dsb).

    I'd check whether the interrupt pending bit is really reset before return, or maybe after return (breakpoint after sleep).

    And I'd check that also just before second attempt to sleep.

    Visitor II
    March 15, 2020

    I have same problem but I use STM32F205RCT6. Wake up only happen once, the WUTF bit in RTC_ISR register can not be cleared. WPuch, did you sort the problem?

    WPuchAuthor
    Visitor II
    March 17, 2020

    For now all works. don't remember exactly what was wrong but now works. contact me directly (wojtek@puchar.net) if you need more info.

    Visitor II
    April 29, 2021

    I have same RTC Alarm Only Once bug in my STM32L496RG project as of 4/29/2021 using HAL 1.16.0 from CubeMX 6.1.1.

    Root cause: ALMAF not cleared in ISR.

    My solution was to add the following to the HAL callback routine in my code;

     /* Clear the RTC Alarm-A Flag */
     HAL_PWR_EnableBkUpAccess();
     __HAL_RTC_ALARM_CLEAR_FLAG(hrtc, RTC_FLAG_ALRAF);
     HAL_PWR_DisableBkUpAccess();

    Graduate
    January 8, 2025

    Had the exact same problem and your solution fixed it.
    In my code i wrote something in the RTC backup register:

    HAL_PWR_EnableBkUpAccess();
    HAL_RTCEx_BKUPWrite(&hrtc, RTC_BKP_DR1, 0);
    HAL_PWR_DisableBkUpAccess();

    If i uncommet HAL_PWR_DisableBkUpAccess(); it works like a charm also without your fix.

     

    My solution was to add your clear flag code in the AlarmA Event Callback:

    void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc) {
    	// *** 
    	// custom code
    	// ***
    
    	// Clear the RTC Alarm-A Flag
    	HAL_PWR_EnableBkUpAccess();
    	__HAL_RTC_ALARM_CLEAR_FLAG(hrtc, RTC_FLAG_ALRAF);
    	HAL_PWR_DisableBkUpAccess();
    }

     

    Now it triggers an Alarm as expected, thank you!

    Visitor II
    May 4, 2021

    I was having a similar problem with the RTC wakeup timer interrupt only firing once even though I was clearing the RTC_ISR_WUTF flag. The solution: I had to disable write protection before I could clear the RTC_ISR_WUTF flag.

    // Disable RTC write protection
    RTC->WPR = 0xCA;
    RTC->WPR = 0x53;
     
    // Clear WUT pending flags
    RTC->ISR &= ~RTC_ISR_WUTF;
     
    // Enable write protection
    RTC->WPR = 0xFFU;

    Super User
    May 4, 2021

    Hi, @RLind.3​ ,

    In which STM32?

    JW

    Visitor II
    May 4, 2021

    STM32L010RB (Nucleo-L010RB)