cancel
Showing results for 
Search instead for 
Did you mean: 

How to clear all pending interrupts?

IJoe.1
Associate II

I want to clear all pending interrupts in my bootloader before jumping to the user application, otherwise an interrupt will remain pending and therefore other interrupts wouldn't be triggered in the user application.

After reading the Cortex-M datasheet, I found out about the NVIC->ICPR[0] to NVIC->ICPR[2] registers which let you clean the pending interrupts. I set those three registers to 0xFFFFFFFF in order to clear all interrupts, but it didn't work.

I am aware about bits in individual registers and macros such as __HAL_GPIO_EXTI_CLEAR_IT() which let you clear one specific interrupt, but what if I want to clear all of them? Is there any singular command that lets me achieve that? Thanks

5 REPLIES 5

>>Is there any singular command that lets me achieve that?

No

They will still pend/trigger from the source peripheral.

You really should tear-down all interrupt sources, or you don't just dump that on the code that takes over, generating interrupts it might not use/need, and into structures that haven't yet been properly initialized.

The QND approach is to use the NVIC System Reset,and quickly vector to the application code, rather than the loader.

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

You need to disable the interrupts, not clear them.

When you clear the interrupt flag, if the interrupt cause is still present, the interrupt flag will set again immediately.

Using NVIC->ISER you can disable the interrupt: if the interrupt flag is present il will not trigger the interrupt vector.

Then, when you want to enable a peripheral interrupt you must first clear the device interrupt flag, then enable the interrupt at the NVIC, then enable the interrupt at the device.

PHolt.1
Senior II

How about setting a "enter user app" flag (in RAM or in FLASH somewhere) and doing a software RESET. That will clear all pending interrupts and disable all interrupts too.

Nikita91
Lead II

This is ok if your bootloader check this flag before initrializing anything else.

You can use one of the backup registers to set the "enter user app" flag.

PHolt.1
Senior II

Yes. A reset does not affect the main RAM; it is startup code which clears BSS etc but unless you specially did so it won't clear the main RAM. So you can put that flag anywhere you like, after BSS, DATA, etc areas.

Nothing beats a hardware (or software; it's the same because it drives the NRST pin from the inside) reset. There are many features of these chips which cannot be "reset" by writing registers.