2019-05-10 02:52 PM
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:
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.
2019-05-10 03:06 PM
One way is to hold the RESET line while the SWD connects. If you put a reset button/circuit on your target, hold that momentarily when you soft connect the debugger, and then release it, the debugger will take it from there. I tie the same line from the reset to the REST of the JTAG interface, and this line will do the same thing. When I build a target translator board from JTAG pod to SWD, I always have a reset button on that board too.
2019-05-11 12:30 AM
The method is generally called "connect under reset" and is supported at least by ST-LINK and J-Link, but MCU's NRST pin needs to be connected to the debuggers reset pin.
2019-05-11 11:07 PM
Thanks for the tip! I assumed that the ST-Link would pull the NRST line low and do this by itself. I'll stick a reset button on my translator cable..
2019-05-11 11:13 PM
Yeah, the NRST line is connected, but for some reason it still wasn't able to connect until I pulled the boot0 line.
It's connected like this:
Sys jtag
1.8V -> VTref
SWDIO -> SWDIO
SWCLK -> SWCLK
NRST -> RESET
GND -> GND
Am I missing something?
thanks,
-Caleb
2019-05-12 03:00 AM
By default "connect under reset" isn't enabled. You need to enable it in debugger/programmer settings and it depends on a software You are using to program MCU. Usually it's under "Mode", "Connect", "Reset type" or something like that.
2019-05-12 07:50 AM
Ah! Thanks, I'll look for that when I get back to it.
2019-05-12 07:55 AM
As piranha mentioned, also set your debugger up so the JTAG knows to pull the reset. When you implement your hardware solution, try to use the typical configuration of a 10k pull up, with a 100n to ground, and use the point between them to go to NRST. see attached screen clip. having that reset button is quite useful, because if you have a controller that's "beamed up", you can hold that button down until the link grabs it when you click the download button. I've had to do that in cases where no matter how the pod is set up in software, it will not grab it.