cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L051 enter Stop mode on return from ISR

korhal
Associate II
Posted on September 19, 2015 at 11:29

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

    }

}
2 REPLIES 2
korhal
Associate II
Posted on September 22, 2015 at 20:39

UP

Posted on September 22, 2015 at 21:26

NORTH, EAST, and DOWN?

Ok, so consider why your initial post is not getting any responses.

There appears to be code missing, it runs on a board you're not specifying, with LEDs you're not configuring and you're using a coding technique that's going to take 20-30 minutes of energy do anything productive with. Get that down to 2-3 minutes, and you might piques some interest.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..