2025-07-07 3:10 AM
My project is using a GPIO to enable/disable a buzzer on a software timer. This boils down to a call to HAL_GPIO_WritePin(), which does GPIOx->BSRR = pinmask (0x80 in this case) to enable the buzzer. This works as expected most of the time. There are multiple calls to this function on the same pin on the same port which work correctly. And then... Boom! I have a very repeatable situation in which the register assignment immediately causes the device MCU to reset. I have implementations for hard faults, bus faults, and so on, but the code doesn't seem to go there (breakpoint instructions in place).
It turns out that this fault does not happen unless the debugger is connected. The reset does not disconnect from the debugger. I'm not stepping the code to make this happen.
What are possible causes for this error? I previously had an unrelated fault which only happened while stepping the code (a race condition tripped by a missed interrupt). While it was not an issue for the application, it was good to fix it anyway. My guess is that this issue might be somewhat like that.
Thanks
Solved! Go to Solution.
2025-07-07 5:54 AM
I'm such an ***. The PSU current max was a shade too low.
2025-07-07 3:40 AM - edited 2025-07-07 3:41 AM
Hello,
If you disconnect the buzzer from the GPIO, do you get the same behavior?
If you are not able to disconnect the buzzer and if you don't set the GPIO buzzer, do you get the same behavior?
2025-07-07 5:54 AM
I'm such an ***. The PSU current max was a shade too low.
2025-07-07 6:14 AM
Did you change a suitable power supply and it worked?
2025-07-07 6:17 AM
Yeah. In fact I just turned the dial a bit. It seems there is a short spike we weren't expecting. Oh well. Thanks for playing.