SWD USB connection

Thread Starter

AzizulHaque

Joined Jul 25, 2020
4
I will be building my own board STM32 for my projects, I've noticed people always put breakout sockets for SWD. My question is why?
why not make it connected to the usb port for simpler debugging/uploading code
 

MrChips

Joined Oct 2, 2009
21,666
You are using a DISCOVERY board such as this:

1595706021919.png

or this:

1595706220327.png

The board connects to the PC via a USB cable. On the board is an small auxiliary chip that interfaces with the IDE via the USB. This chip translates the information then uses SWD to connect with your target MCU.

If you want to create an embedded system using an STM32, you may not want all the baggage that comes with a DISCOVERY board.
 

Thread Starter

AzizulHaque

Joined Jul 25, 2020
4
Ah I see makes sense, I originally thought it was a direct connection to the usb from the mcu. I am looking for upload code via usb, how shall I implement this on my pcb. shall I try adding an FTDI circuit on board, or is there an alternative solution that is better?
 

MrChips

Joined Oct 2, 2009
21,666
If you are building your own PCB for STM32 then install SWD connection.
You only need four wires, SWCLK, SWDIO, GND, VDD.
I can show you the absolute minimum to build an STM32F407 board.
 

Thread Starter

AzizulHaque

Joined Jul 25, 2020
4
I've been following this tutorial -


but what I am trying to change is that instead of an SWD connector, it is connected to a circuit that allows me to use USB cable instead of an external ST-link device to upload code to it

Moderator edit: fixed bad link to video
 

ZCochran98

Joined Jul 24, 2018
87
First off, I see you joined today, so welcome to AAC!

Now, warning: long, semi-rambling response below. Preemptive tl;dr: even if you do USB programming, you'll still need an SWD programmer for at least one step of the project (the ST-LINK is inescapable, as far as I can tell).



I went through this same process recently myself (for NXP chips instead of STM), and this is what I found. Hopefully, it's accurate.

As @MrChips explained, it's effectively a separate, smaller microcontroller connected to the primary chip. However, you're not going to escape needing an SWD programmer or similar on-board, as that smaller microcontroller, which effectively converts USB to a protocol the primary processor can understand, needs to be programmed itself to be able to do that kind of conversion on the fly, so you'll need an SWD programmer to begin with anyway.

STM and NXP have different methods for this. NXP uses something called "openSDA," which converts USB to a combination of SPI and UART for the NXP chipset, while STM uses ST-LINK to convert to USB to their SWIM (single-wire interface module) protocol for their chips. Both use a secondary processor to do so, and as such require the SWD programmer to flash the chip used to do this conversion. ATMega is a little different, in that it trades the required SWD programmer for an AVR programmer (which uses SPI instead of JTAG/SWD, I believe). These are the chips used in Arduino boards, and typically have the required USB->RS-232 conversion programming preloaded.

Now, including such a schematic takes up a lot of board space, so if you're wanting to do an embedded system, be warned that a decent amount of PCB space will be required for the programmer, and would be better, overall, just to stick with the (extremely simple) SWD connector. If you're just wanting to learn about the STM32 family of chips, however, and want to make what amounts to your own Discovery board, then it is an interesting, to say the least, learning experience.

I have a schematic for the STM32F4 Discovery board attached (you can find their schematics on their website if you know where to look). The primary microcontroller is the STM32F407VGT6 processor, and the controller that converts USB to SWIM is done via the STM32F103C8T6 chip in the schematic (page 2), with the "single wire" connecting the two labelled "MCO" (thus "single-wire interface"). On the same page as the USB programmer bit you'll see a comment "Jumpers ON --> DISCOVERY Selected" and "Jumpers OFF --> ST-LINK Selected." If I'm not mistaken, this refers to which processor the SWD programmer is connected to: the main board or the ST-LINK chip (the one doing the USB conversion). How this connects to the main microcontroller is shown on page 3 of the schematic file.

Hopefully this helps either clear things up or give you ideas!
 

Attachments

Top