2021-09-16 05:28 AM
Hi, I know there are other posts on this forum about this issue, but have not been able to solve my problem even when implementing the fixes those posts suggest. I am a total newbie to STMCubeMX etc - this is my first project on any ST MCU. Here are some details about my situation:
MCU: STM32F405RGT6
Programmer: ST-LINK V2 (blue USB) - GDB server
I try running HAL_Delay(500) and I step into the function using the debugging mode. My understanding is that this function relies on a periodic interrupt of the CPU (every 1 ms), at which point the HAL_IncTick() function is called, eventually increasing the number of ticks until the delay is complete. I took a look at the NVIC configuration as others suggested in posts - I set all the interrupts that I had control over to 1 (lower priority than the systick interrupt, which I left at priority 0). Still didn't stop the problem.
I also found that for some reason (can anyone elaborate as to why?), the NMI interrupt handler and the HardFault interrupt handler both have while(1){} loops inside them. Given that these two interrupts take 0 priority (which I can't seem to change from CubeMX), I wonder if one of these interrupts are being triggered and then the whole processor is stuck in this while(1) loop? I added break statements within the while(1) loops - didn't help.
It seems like the code just gets stuck in the HAL_GetTick() function in stm32f4xx_hal.c (image attached).
At this point, I'm out of ideas. Does anyone have some suggestions on what else to try? As I'm a newbie, I don't know the ins and outs of HAL and don't have the skills to troubleshoot any deep-rooted problem.
2021-09-16 06:27 AM
You can't change the priority of the NMI / Hard Fault. You should instrument Hard Fault and Error Handlers so they output actionable data. They have while(1) loops because it's the lazy way the examples deal with fatal errors.
2021-09-16 06:47 AM
> It seems like the code just gets stuck
How can you tell? Debug the code, run it and hit pause and look at where the code is stopping. Ensure you're not disabling interrupts.
If either HardFault or NMI handlers are hit, there is a critical flaw that you need to fix. Trying to disable those is futile. The while loop exists so that you can stop the debugger and examine the issue.
Including your code would he helpful along with showing where in particular it's getting stuck with the relevant stack trace.