Skip to main content
Graduate
July 7, 2025
Solved

STM32U575: GPIOx->BSRR assignment causes reset - but only when debugging

  • July 7, 2025
  • 3 replies
  • 388 views

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

    This topic has been closed for replies.
    Best answer by unicyclebloke

    I'm such an ***. The PSU current max was a shade too low. 

    3 replies

    Technical Moderator
    July 7, 2025

    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?

    unicycleblokeAuthorAnswer
    Graduate
    July 7, 2025

    I'm such an ***. The PSU current max was a shade too low. 

    Technical Moderator
    July 7, 2025

    Did you change a suitable power supply and it worked?

    Graduate
    July 7, 2025

    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.