AnsweredAssumed Answered

RTC Wakeup interrupt not triggering on STM32L100

Question asked by lepisto.juho on Nov 17, 2015
Latest reply on Nov 18, 2015 by lepisto.juho
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;
}

Outcomes