AnsweredAssumed Answered

STM32F427 Missed Interrupt

Question asked by mex1 on Sep 25, 2014
Latest reply on Sep 29, 2014 by waclawek.jan
Greetings,

I'm using an STM32F427VI MCU to generate a 1 Hz pulse (50% duty cycle) with its RTC controller. For the most part, it seems like it works just fine, however during testing, the code will occasionally fail to toggle the GPIO pin. 

Here is the code for configuring the RTC:
void rtc_config(void)
{
    NVIC_InitTypeDef    nvic;
    RTC_InitTypeDef     rtc;
    EXTI_InitTypeDef    exti;
 
    /* Enable PWR Domain */
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
    PWR_BackupAccessCmd(ENABLE);
 
    /* Explicitly reset the domain to reset the RTC registers */
    RCC_BackupResetCmd(ENABLE);
    RCC_BackupResetCmd(DISABLE);
 
    /* Using custom board with 19.2 MHz oscillator */
    RCC_RTCCLKConfig(RCC_RTCCLKSource_HSE_Div30);
     
    /* Enable RTC Clock */
    RCC_RTCCLKCmd(ENABLE);
 
    /* Wait for RTC APB registers synchronisation */
    RTC_WaitForSynchro();
 
    /*
     * Assuming 19.2 MHz HSE with prescaler dividing at 30
     *
     * RTC_CLK = 19.2 / 30 = 640 KHz
     *
     * 640 KHz / ((127 + 1) * (2499 + 1))
     */
    rtc.RTC_HourFormat = RTC_HourFormat_24;
    rtc.RTC_AsynchPrediv = 127;
    rtc.RTC_SynchPrediv = 2499;
    RTC_Init(&rtc);
 
    /* RTC must go through EXTI line */
    EXTI_ClearITPendingBit(EXTI_Line22);
    exti.EXTI_Line = EXTI_Line22;
    exti.EXTI_Mode = EXTI_Mode_Interrupt;
    exti.EXTI_Trigger = EXTI_Trigger_Rising;
    exti.EXTI_LineCmd = ENABLE;
    EXTI_Init(&exti);
 
    /* Configure NVIC */
    nvic.NVIC_IRQChannel = RTC_WKUP_IRQn;
    nvic.NVIC_IRQChannelPreemptionPriority = 0;
    nvic.NVIC_IRQChannelSubPriority = 0;
    nvic.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&nvic);
 
    /* Configure source */
    RTC_WakeUpClockConfig(RTC_WakeUpClock_CK_SPRE_16bits);
    RTC_SetWakeUpCounter(0x0);
 
    RTC_ITConfig(RTC_IT_WUT, ENABLE);
 
    RTC_WakeUpCmd(ENABLE);
}
 
void RTC_WKUP_IRQHandler(void)
{
    if (RTC->ISR & 0x400)
    {
        /* Clear WUTF flag */
        RTC->ISR &= ~(0x400);
        EXTI->PR = EXTI_Line22;
        GPIOC->ODR ^= GPIO_Pin_13;      // Toggle pin here
    }
}

The code works 99% of the time. Using an oscilloscope, I can see a 1 Hz 50% duty cycle pulse coming out of pin PC13. However, the interrupt will randomly fail to be called (at least it seems), so the pin fails to toggle.

Reproducing this error is difficult, because I can't seem to figure out a way to trigger it, and it happens at random intervals (sometimes 2 min, sometimes 40 min). I've checked all the other possible interrupt sources in my code to make sure the RTC_WKUP interrupt is given the absolute highest priority, but that doesn't seem to fix the issue. I've also browsed the STM32F427 errata sheets, but nothing stood out to me as possibly causing this. I don't know how to debug this, has anyone seen something similar or know what might be causing it? 

Outcomes