Skip to main content
caleb
Associate III
May 10, 2019
Question

ANSWER: Why SWD stopped working after re-programming

  • May 10, 2019
  • 7 replies
  • 4335 views

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.

    This topic has been closed for replies.

    7 replies

    Rogers.Gary
    Senior II
    May 10, 2019

    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.

    caleb
    calebAuthor
    Associate III
    May 12, 2019

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

    Rogers.Gary
    Senior II
    May 12, 2019

    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.

    Piranha
    Principal III
    May 11, 2019

    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.

    caleb
    calebAuthor
    Associate III
    May 12, 2019

    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
    Principal III
    May 12, 2019

    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.

    caleb
    calebAuthor
    Associate III
    May 12, 2019

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