ANSWER: Why SWD stopped working after re-programming
I had a board that I was debugging, and all was going swimmingly. Then I started getting an 'unable to connect' message while debugging. I didn't touch the hardware, nothing had changed. So I thought.
To make a long story short, I had enabled the following option in STM32CubeMX:
Project Manager->Code Generator->HAL Settings->Set all free pins as analog
This was combined with the fact that I DIDN'T enable
Pinout & Configuration -> Trace and Debug -> DEBUG -> Serial Wire.
Without having that enabled, STM32CubeMX went ahead and put the SWD pins (PA13, PA14) into analog mode, and thus broke the debug session.
I could never get it back, because BOOT0 was pulled low on the board (luckily through a resistor). And every time power was applied to the board, it immediately stuck the pins back to analog mode, so I couldn't reprogram.
The solution:
- PULL BOOT0 HIGH
- Set DEBUG = Serial Wire
- power down (and wait a bit)
- Regenerate and reprogram code.
- Release BOOT0 back to low
All should be back to normal, and you have a brick no longer.
I'd love to hear any method of recovery that doesn't require pulling BOOT0 since it was a little hairy soldering on 0402 components. Not my forte.
