cancel
Showing results for 
Search instead for 
Did you mean: 

RTC Wakeup interrupt not triggering on STM32L100

juho
Associate II
Posted on November 17, 2015 at 15:09

Hello,

It seems that the IRQ handler for the wakeup does not trigger even the RTC is running correctly, WUTIE is set in CR register and the ISR flag WUTF is set as expected. What could be the issue? The FW is build with GCC. What could be the issue? Thanks in advance.

Here is the code:

void v_Rtc_Initialise(void)

{

    EXTI_InitTypeDef t_wut_interrupt;

    // Allow access to RTC

    RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);

    PWR_RTCAccessCmd(ENABLE);

    RTC_WriteProtectionCmd(DISABLE);

    // Enable the LSE OSC

    RCC_LSEConfig(RCC_LSE_ON);

    // Wait for LSE to settle.

    while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)

    {

        __NOP();

    }

    /* Select the RTC Clock Source */

    RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);

    // Disable all interrupt sources and clear flags.

    RTC_ITConfig(RTC_IT_TS | RTC_IT_WUT | RTC_IT_ALRA | RTC_IT_ALRB | RTC_IT_TAMP, DISABLE);

    RTC_ClearFlag(RTC_FLAG_TAMP1F | RTC_FLAG_TSOVF | RTC_FLAG_TSF | RTC_FLAG_WUTF | RTC_FLAG_ALRBF | RTC_FLAG_ALRAF | RTC_FLAG_RSF);

    /* EXTI configuration */

    EXTI_ClearITPendingBit(EXTI_Line20);

    t_wut_interrupt.EXTI_Line = EXTI_Line20;

    t_wut_interrupt.EXTI_Mode = EXTI_Mode_Interrupt;

    t_wut_interrupt.EXTI_Trigger = EXTI_Trigger_Rising;

    t_wut_interrupt.EXTI_LineCmd = ENABLE;

    EXTI_Init(&t_wut_interrupt);

    /* Enable the RTC Clock */

    RCC_RTCCLKCmd(ENABLE);

    /* Wait for RTC APB registers synchronisation */

    if (RTC_WaitForSynchro() == ERROR)

    {

        DEBUG_PRINT(1, ''RTC: Synchronisation failed.'');

    }

    /* RTC time base = LSE / ((AsynchPrediv+1) * (SynchPrediv+1))

           = 1 Hz

    */

    t_rtc_init.RTC_AsynchPrediv = 127;

    t_rtc_init.RTC_SynchPrediv =  255;

    t_rtc_init.RTC_HourFormat = RTC_HourFormat_24;

    if (RTC_Init(&t_rtc_init) == ERROR)

    {

        DEBUG_PRINT(1, ''RTC: Initialisation failed.'');

    }

    /* Set the Time */

    t_rtc_time.RTC_Hours   = 0x08;

    t_rtc_time.RTC_Minutes = 0x00;

    t_rtc_time.RTC_Seconds = 0x00;

    RTC_SetTime(RTC_Format_BCD, &t_rtc_time);

    /* Set the Date */

    t_rtc_date.RTC_Month = RTC_Month_November;

    t_rtc_date.RTC_WeekDay = RTC_Weekday_Sunday;

    t_rtc_date.RTC_Date = 0x01;

    t_rtc_date.RTC_Year = 0x15;

    RTC_SetDate(RTC_Format_BCD, &t_rtc_date);

    if (RTC_WakeUpCmd(DISABLE) == ERROR)

    {

        DEBUG_PRINT(1, ''RTC: Wake up disable failed.'');

    }

    RTC_ClearFlag(RTC_FLAG_WUTF);

    RTC_WakeUpClockConfig(RTC_WakeUpClock_CK_SPRE_16bits);//(RTC_WakeUpClock_RTCCLK_Div4);

    PWR_RTCAccessCmd(DISABLE);

    return;

}

void v_Rtc_Set_Wakeup(uint32_t u32_wakeup_in_minutes)

{

    PWR_RTCAccessCmd(ENABLE);

    RTC_WakeUpCmd(DISABLE);

    RTC_ITConfig(RTC_IT_WUT, DISABLE);

    DEBUG_PRINT(1, ''Debug: %u'', gu8_rtc_wut_debug);

    gu8_rtc_wut_debug = 0;

    if (u32_wakeup_in_minutes > 0)

    {

        if (u32_wakeup_in_minutes > WAKEUP_LIMIT)

        {

            DEBUG_PRINT(1, ''RTC: Wake up time too long, forced to 4369 minutes.'');

            u32_wakeup_in_minutes = WAKEUP_LIMIT;

        }

        //u32_wakeup_in_minutes *= 15;

        RTC_SetWakeUpCounter(u32_wakeup_in_minutes);

        RTC_ITConfig(RTC_IT_WUT, ENABLE);

        if (RTC_WakeUpCmd(ENABLE) == ERROR)

        {

            DEBUG_PRINT(1, ''RTC: Wake up enable failed.'');

        }

    }

    PWR_RTCAccessCmd(DISABLE);

    return;

}

void RTC_WKUP_IRQHandler(void)

{

    gu8_rtc_wut_debug = 1;

    PWR_RTCAccessCmd(ENABLE);

    RTC_ClearFlag(RTC_FLAG_WUTF);

    EXTI_ClearITPendingBit(EXTI_Line20);

    RTC_ClearITPendingBit(RTC_IT_WUT);

    PWR_RTCAccessCmd(DISABLE);

    return;

}

#irqhandler #wakeup #rtc
2 REPLIES 2
juho
Associate II
Posted on November 18, 2015 at 09:32

I made a test FW where I start a five second WUT and then print out the current register states to the serial. Here is short log:

DBG:Start WUT...

DBG:Time        Count   RTC-CR  RTC-ISR IMR     SWIER   EXTIPR  IRQ

DBG:08:00:00    5       4404    0033    102000  000000  000000  0

DBG:08:00:01    5       4404    0033    102000  000000  000000  0

DBG:08:00:02    5       4404    0033    102000  000000  000000  0

DBG:08:00:03    5       4404    0033    102000  000000  000000  0

DBG:08:00:04    5       4404    0033    102000  000000  000000  0

DBG:08:00:05    5       4404    0033    102000  000000  000000  0

DBG:08:00:06    5       4404    0433    102000  000000  100000  0

DBG:08:00:07    5       4404    0433    102000  000000  100000  0

DBG:08:00:08    5       4404    0433    102000  000000  100000  0

DBG:08:00:09    5       4404    0433    102000  000000  100000  0

DBG:08:00:10    5       4404    0433    102000  000000  100000  0

DBG:08:00:11    5       4404    0433    102000  000000  100000  0

DBG:08:00:12    5       4404    0433    102000  000000  100000  0

DBG:08:00:13    5       4404    0433    102000  000000  100000  0

DBG:08:00:14    5       4404    0433    102000  000000  100000  0

The logs show that the WUTF is set correctly after five seconds and the EXTI20 is set as pending, but no IRQHandler call (IRQ on the log). This is frustrating.

juho
Associate II
Posted on November 18, 2015 at 10:05

Problem solved! The code was missing configuration for NVIC vector. Now it works.