2022-10-01 07:23 AM
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
2022-10-01 10:13 AM
>>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.
2022-10-01 11:53 AM
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.
2022-10-01 02:17 PM
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.
2022-10-01 03:08 PM
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.
2022-10-02 06:14 AM
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.