AnsweredAssumed Answered

STM32L051 enter Stop mode on return from ISR

Question asked by korhal.korhal on Sep 19, 2015
Latest reply on Sep 22, 2015 by Clive One

Hello!

I have a simple program. It has software IRQ to enter Stop mode on return from ISR, and RTC IRQ to wake up and leave Stop mode. RTC IRQ toggles the red LED. On return from Stop mode (return from SW IRQ) the blue LED must be turned off, which never happen. What I see is: the red LED is toggled and the blue LED is always on.
What is wrong ?

Source code:

void EXTI0_1_IRQHandler(void)
{
    EXTI->PR = 1;
    SCB->SCR = 6; // deepsleep + sleeponexit
}

void RTC_IRQHandler(void)
{
    EXTI->PR = EXTI_PR_PR20;
    RTC->ISR &= ~RTC_ISR_WUTF;
    LED_RED_TGL;
}

int main(void)
{
    RCC->IOPENR = 3; // GPIO A,B clock
    RCC->APB1ENR |= (1 << 28); // PWR
    RCC->APB2ENR |= 1; // SYSCFG

    PWR->CR |= (1 << 8); // DBP
    RCC->CSR |= (1 << 8); // LSE on
    while(!(RCC->CSR & (1 << 9))); // wait for LSE ready
    RCC->CSR |= (1 << 16) | (1 << 18); // RTC LSE src clk, RTC ena
    RTC->WPR = 0xCA; RTC->WPR = 0x53;
    while(!(RTC->ISR & 4)); // WUTWF
    RTC->WUTR = 0; // 1 second period
    EXTI->RTSR |= EXTI_RTSR_TR20;
    EXTI->IMR |= EXTI_IMR_IM20;
    NVIC_SetPriority (RTC_IRQn, 2);
    NVIC_EnableIRQ(RTC_IRQn);
    RTC->CR = RTC_CR_WUTE | RTC_CR_WUTIE | 4; // WUTE + WUTIE + ck_spre
    RTC->WPR = 0xFE; RTC->WPR = 0x64;

    EXTI->IMR |= EXTI_IMR_IM0;
    NVIC_SetPriority (EXTI0_1_IRQn, 0);
    NVIC_EnableIRQ(EXTI0_1_IRQn);

    LED_RED_ON;
    LED_BLUE_ON;
    while(1)
    {
        EXTI->SWIER = EXTI_SWIER_SWIER0; // software IRQ
        LED_BLUE_OFF; // turn off blue LED
    }
}

Outcomes