This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Is it safe to use USB dp/dm pins for SWD interface?

We are building a new version of a small device with the new nRF52832. Its only external connection is a micro USB plug that we use for charging - we do not need it as USB data interface. But would like to (mis-)use the two data pins for Serial Wire Debug (SWCLK/SWDIO) for flashing, debugging, and RTT. As long as charging is done with our standard charger, everything is fine, because we do not connect the USB data lines.

Is it safe, if the device is connected/charged via a USB host, e.g. a PC, or is it possible that an USB host causes mal-functioning of the nRF52832, i.e. stops/crashes the application code?

EDIT: Assume that signals are clipped to protect the SWD-pins electrically from over-voltage.

Has anyone experience with a similar setting?

  • It's not a brilliant idea unless you can ensure absolutely that if someone DOES plug your device into a normal USB port it won't suffer damage. Because it's absolutely 100% going to happen, USB is so ubiquitous that people expect (and the standards demand) that you can plug anything with a USB connector into a USB hub and even if it doesn't work, it won't break.

    And I don't think you can do that with SWDCLK and SWDIO without extra circuitry. A USB port holds D+ and D- low with 15kΩ resistors. If they stay like that (I believe) the port assumes nothing is connected and doesn't try to use D+/D-. If however one of them is pulled up, the port assumes it's active and starts sending 5v pulses down it, which would be rather bad news.

    on the NRF51822 the SWDIO line has an internal pullup and I can find at least 3 different suggestions as to what the value of that is. If that pullup is strong enough against the pulldown on the USB side, the hub will think something is connected and start destroying the chip.

    So unless you've read all the USB specs, completely understand the pullups and pulldowns on the data lines in every current mode, understand the internal pullups and downs on the SWDxx pins on the nrf51822 and have convinced yourself the USB hub will never try to activate the port, I wouldn't do it.

  • Thx for your fast answer. I just edited my question to focus on protocol problems. We must protect the SWD-pins electrically from over-voltage. (USB1: up to 3.6V, USB2: 440mV max.)

  • I have been reading a while about this and I found out that USB uses 3.3V signals on D+ and D- pins. Having a maximum allowed of 3.6V. This is rare because the Vbus of USB is 5V. Reference: electronics.stackexchange.com/.../why-does-usb-have-vcc-5v-and-high-3-3v

    So assuming you are powering the nRF with 3.3V or higher (datasheet says maximum V at pins vdd+0.3V), AND that you don't connect the USB Vbus to Vdd, that should be safe I believe.

    I like the idea of having USB connector for programming, what do you think about this?

  • What you say is correct. The problem when connecting SWD over USB is something RK mentioned. If any of the data lines of the USB is pulled up, 3.3V pulses will be sent down the data lines. Even though that won't destroy the nRF it might put it into debug mode and increase power consumption significantly.

Related