LOSnel
LOSnel

Reputation: 171

Disturbing irq waking me up from sleep mode

I have an issue with my system in sleep mode.

Currently my MCU is driving a radio chip which send periodically messages over radio, I set the MCU in sleep mode when the radio chip is sending a message.

But sometimes I get an interrupt when the radio chip is sending data and that wake up my MCU and abort data sending. I don't know how to find which irq is waking me up because my system is currently running with lots of tasks that can run irq "randomly" BUT none of the "random" irq is supposed to trig when the radio chip is sending a message.

When I try to break after __WFI() used in my sleep mode, the call stack is already refreshed with new data and I can't see what was the last instructions executed.

Do you know a method to determine which irq is waking me a sleeping system ?

Thanks for your help.

Upvotes: 0

Views: 234

Answers (1)

Examine the NVIC->ISPR[x] and the SCB->ICSR registers right after wakeup. If you can't break before the handler runs, replace __WFI() with this macro (or something equivalent if you are not using gcc)

uint32_t ispr0, ispr1, ispr2, icsr;
#define __WFI() ({ \
    uint32_t primask = __get_PRIMASK(); \
    __disable_irq(); \
    asm volatile("wfi");    \
    ispr0 = NVIC->ISPR[0];  \
    ispr1 = NVIC->ISPR[1];  \
    ispr2 = NVIC->ISPR[2];  \
    icsr = SCB->ICSR;       \
    __set_PRIMASK(primask); \
})

to be able to comfortably examine the contents afterwards. I have taken the register names from the ST Cortex-M3 Programming Manual, the process should be similar for other cores.

Upvotes: 2

Related Questions