I'm trying to use the NMI on a SAM4S (Cortex M4), but I'm finding some hard time to make it work. The main objective is to jump to the NMI handler whenever the power is about to go down, so that I can perform a clean shutdown, saving data that could be lost otherwise.

At the moment, I'm using a PIO controller to jump to an interrupt when a power fail is detected. The code is something like this:

pio_set_debounce_filter(PIOA,POWERFAIL_PORT, 100);
pio_handler_set(PIOA, ID_PIOA,POWERFAIL_PORT , PIO_IT_FALL_EDGE, Powerfail_Interrupt_Handle);
pio_enable_interrupt(PIOA, POWERFAIL_PORT);

I'd like to set this interruption with maximum priority using the NMI. That way, this interruption would be active all the time, even after calling __disable_irq() in some parts of the code. Until now, I searched the SAM4S datasheet and ASF sources/examples, but I was unable to find any obvious way to do it, or simply realize if it's possible.


1 Answer 1


Atmel SAM4S MPUs feature NVIC interrupt controller that supports only external interrupts to be linked with NMI. You can also trigger it manually, but this won't be of much use to you.

Solution is to have external circuitry that will trigger the NMI using external interrupt on power failures.

Note: If I understand your current solution you try to detect falling edges on power line. I am not sure that this will be reliable, or even fast enough (since you have debouncing filter on the input).


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.