STM32L476: Code runs into Reset Handler if Interrupts get activated although no Interrupts are triggered
Hi,
I have some code running on a Nucleo-STM32L476 which keeps running into the Reset Handler. But this does not cause a boot loop, instead the code just gets stuck there (the PC register points to the first line of assembler of the reset handler).
I modified the Systick to read a hardware-based timer so it works without interrupts. But the Code shows the same behaviour when using the default Systick implementation.
The conditions under which the reset handler gets called are really weird:
- If interrupts are enabled, the code gets stuck after switching on the LED (which gets called directly after initializing the hardware). The LED then stays on until I reset the board. It seems like it gets stuck at the beginning of the HAL_Delay function because If i call HAL_Delay(0) the LED gets disabled before it gets stuck, but at HAL_Delay(1) it gets stuck before the LED is disabled.
- If I debug this code, the code instead gets stuck earlier - usually somewhere in SystemClock_Config.
- If I disable interrupts before executing the initialization functions everything works fine. But if i enable them again, the Code gets stuck again immediately (the next line of code does not get executed).
- It I disable interrupts after executing the initialization, but before the LED is turned on, then it works fine if I just execute it, but if I debug it then it gets stuck at the initialization functions.
- My code jumps into a second firmware layer at its end. Vector Table and Stack pointer are redirected before jumping. If I have interrupts disabled in the first layer and enable them in the second layer, then the code immediately enters the reset handler of the first layer after the interrupts get activated.
- If I check for pending Interrupts before switching on the interrupts (both in the first and the second firmware layer) there are no pending interrupts.
Does anyone have an idea why this happens? I essentially want to have interrupts disabled in the first firmware layer and have them enabled in the second layer. This works if I execute them individually, but if i execute them after another I cannot enable interrupts at any point.
Thank you.