cancel
Showing results for 
Search instead for 
Did you mean: 

ANSWER: Why SWD stopped working after re-programming

caleb
Associate III

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.

7 REPLIES 7
Rogers.Gary
Senior II

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.

Piranha
Chief II

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.

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..

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

Piranha
Chief II

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.

Ah! Thanks, I'll look for that when I get back to it.

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.