I have a battery-constrained device with STM32L011. Right now I am using Nucleo-32 development board. In the end I want to use suspend mode with RTC to wake up every couple of minutes. First I want the RTC to generate an interrupt using the wakeup function.
I can see in my UART log, that the RTC is running (RTC_TR is incremented), I can also see that RTC_ISR is initially 0x23 and in the next second it is 0x423, which means that WUTF flag has been set. However no interrupt occurs.
My ISR just turns a LED on and clears EXTI flag. When I do EXTI_SWIER |= BIT17;
the interrupt fires correctly (so I guess that EXTI and NVIC are set correctly). My problem is that even though the interrupt is enabled, RTC is running, WUTF flag is set - the interrupt does not occur. I have no hard faults, nor resets.
This is my RTC code:
RCC_APB1ENR |= BIT28; //turn on power control circuit clock
PWR_CR |= BIT8; //unlock the RTC domain, set DBP in PWR_CR
RCC_CSR |= BIT0; //rurn on LSI
while ( (RCC_CSR & BIT1) == 0); //wait for LSI to be ready
RCC_CSR |= BIT19; //put RTC into reset
RCC_CSR &= ~BIT19; //take it back out of reset
//RTC on, use LSI
RCC_CSR |= BIT17;
RCC_CSR &= ~BIT16;
RCC_CSR |= BIT18; //RTC enable
RTC_WPR = 0xca; //RTC unlock
RTC_WPR = 0x53;
// RTC Initialization procedure (see reference manual)
RTC_ISR |= BIT7; //set INIT bit, request RTC stop
while ((RTC_ISR & BIT6)==0); //wait for RTC to stop
ISER |= BIT2; // enable RTC IRQ in NVIC (via EXTI line)
//wakeup configuration
RTC_CR &= ~BIT10; //clear WUTE bit
while( !(RTC_ISR & BIT2 /*WUTWF*/) ){} //wait for the bit to be set
uart_puts("RTC_ISR=");
uart_puthex(RTC_ISR);
RTC_ISR |= BIT10/*WUTWF*/; //has to be set before writing to WUTR (manual 22.7.6)
RTC_WUTR = 0x9C0; //very short wakeup period
RTC_CR = BIT14 /*WUTIE*/ | BIT10 /*WUTE*/ | BIT0|BIT1 /*WUCKSEL - RTC/2 wakeup clock*/ ; //enable wakeup function and interrupt, RTC/2 clock
RTC_ISR &= ~BIT7; //start the RTC (clear INIT bit)
EXTI_IMR |= BIT17; //enable RTC alarm going through EXTI 17 line to NVIC
EXTI_EMR |= BIT17;
EXTI_RTSR |= BIT17;
This is my UART log (repeats approximately every second):
------
Hello
RTC_ISR=c7
wutr=2496
RTC_ISR=23
RTC_TR=0
RTC_CR=4403
EXTI_PR=0
wutr=2496
RTC_ISR=423
RTC_TR=1
RTC_CR=4403
EXTI_PR=0
wutr=2496
RTC_ISR=423
RTC_TR=1
RTC_CR=4403
EXTI_PR=0
wutr=2496
RTC_ISR=423
RTC_TR=2
RTC_CR=4403
EXTI_PR=0
wutr=2496
RTC_ISR=423
RTC_TR=3
RTC_CR=4403
EXTI_PR=0
wutr=2496
RTC_ISR=423
RTC_TR=4