cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L452 RTC wakeup timer works, but just once

WPuch
Associate II

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.

10 REPLIES 10
turboscrew
Senior III

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.

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:

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.

Replacing dmb with dsb doesn't change anything.
checked RTC_ISR just before return. It is 0x00170101. Even if i set it to 0 when initializing.
Which means that bits 20,18,17,16,8 and 0 are set.
According to documentation (page 1106 - it's STM32L452RE).
bit 20 - not documented
bit 18 - not documented
bit 17 - time stamp (never used this and enabled this)
bit 16 - recalibration pending. I never user recalibration
bit 8 - alarm A flag - never set ALARM
bit 0 - alarm A can be changed. too i never set an alarm.
Seems like everything is screwed up.
RTC_ISR is defined at 0x4000280C
After initialization before interrupt RTC_ISR is 0x17 which seems fine
RTC_CR is set to 0x4420 which seems fine too.
any more ideas?
On 2019.06.06 20:11, ST Community wrote:
Liu0155
Associate II

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?

WPuch
Associate II

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.

jrgert
Associate III

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();

RLind.3
Associate III

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;

Hi, @RLind.3​ ,

In which STM32?

JW