STM32 in-circuit SWD programming protocol - Page 1
Forum section: electronics / general

author: Karel
author_rank: Super Contributor
timestamp: October 09, 2018, 09:13:38 am
content: I'm not able to find the STM32 in-circuit SWD programming protocol (using NRST, SWCLK and SWDIO) documentation on the STM website.Could somebody be so kind kind to point me to it?Thanks

author: andersm
author_rank: Super Contributor
timestamp: October 09, 2018, 09:22:19 am
content: There's no programming protocol as such. You either write to the flash controller registers directly, or you upload a programming stub into RAM. You might want to check out the source codes of OpenOCD, or the Black Magic probe.

author: Karel
author_rank: Super Contributor
timestamp: October 09, 2018, 09:30:32 am
content: Thanks.Actually, I only want to know if some kind of "programming voltage" higher than normal Vdd is used during in-circuit programming (like with PIC32).I want to connect a reset generator chip to the NRST pin of an STM32 and I don't want to get it destroyed by using in-circuit programming.

author: dgtl
author_rank: Regular Contributor
timestamp: October 09, 2018, 10:08:51 am
content: The SWD is designed by ARM and used on most of the Cortex-M microcontrollers. Find its documentation at ARM web site.The RST is not part of SWD interface itself, although it is in the same connector. (SWDIO, SWCLK are required, SWO is optional for tracing); you can debug without reset connected, but then you have to reset via other uc-specific means (or jump back to reset vector, that leaves peripherals not reset). There is no "programming voltage" on reset pin. It is just the reset; used to reset the uc once new code has been uploaded.

author: SiliconWizard
author_rank: Super Contributor
timestamp: October 09, 2018, 03:29:39 pm
content: Quote from: dgtl on October 09, 2018, 10:08:51 amYep. Just keep in mind that in some cases you won't be able to connect to the MCU via SWD without actually resetting it. For instance if the MCU is in sleep mode. Never been able to connect to a sleeping STM32 MCU. I guess it's all dependent on the clock. A non-running clock will prevent you from connecting AFAIK. Some low-power modes shut the clock down - in this case, you have to reset it or otherwise wake the MCU. People who use low-power modes will get bitten at least once by this.

author: ataradov
author_rank: Super Contributor
timestamp: October 09, 2018, 04:23:27 pm
content: Thankfully we are past days of high voltages for programming. It would probably be safe to assume that all devices designed in the last decade don't have this nasty stuff.

author: ehughes
author_rank: Frequent Contributor
timestamp: October 09, 2018, 04:24:19 pm
content: http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0314h/Chdhfbhc.htmlYou wont need extra programming voltage. Flash programming requires some intelligence. In almost all cases, the host downloads a small program into the target MCU to do the flash programming using RAM as a mailbox to sent commands.SWD is actually a pretty good way for 2 CPUs to communicate. It is "built in" and allows a host to get access to the bus of the target device.

author: SiliconWizard
author_rank: Super Contributor
timestamp: October 09, 2018, 04:34:59 pm
content: Quote from: ehughes on October 09, 2018, 04:24:19 pmThat's interesting. Would you have any source code showing how to implement an SWD "master" on an ARM CPU?

author: ataradov
author_rank: Super Contributor
timestamp: October 09, 2018, 04:36:57 pm
content: Quote from: SiliconWizard on October 09, 2018, 04:34:59 pmHere you go -https://github.com/ataradov/embedded-swd

author: JPortici
author_rank: Super Contributor
timestamp: October 09, 2018, 06:27:01 pm
content: Quote from: Karel on October 09, 2018, 09:30:32 amwhich isn't required, otherwise the PIC32 couldn't perform self-programming

author: SiliconWizard
author_rank: Super Contributor
timestamp: October 09, 2018, 06:52:55 pm
content: High voltages were once required for embedded EEPROM/Flash programming. Most modern MCUs now embed internal charge pumps so that no external high voltage is required.As for PIC32s, beside the ICD port, they can be debugged and programmed via a standard JTAG. Never tried that but I've seen it supported by OpenOCD for instance.

author: Karel
author_rank: Super Contributor
timestamp: October 09, 2018, 06:58:49 pm
content: Quote from: JPortici on October 09, 2018, 06:27:01 pmOfcourse you are right. Probably it was with the (older) 8-bit pic's that they required a higher voltage on the MCLR pin for programming.

author: ehughes
author_rank: Frequent Contributor
timestamp: October 09, 2018, 07:45:52 pm
content: QuoteNothing that is open source. ataradov's link is a good start.

author: JPortici
author_rank: Super Contributor
timestamp: October 09, 2018, 08:08:33 pm
content: Quote from: Karel on October 09, 2018, 06:58:49 pmvery oldin fact, the earliest PIC with LVP i have here was released 13 years ago.

author: technix
author_rank: Super Contributor
timestamp: October 11, 2018, 12:04:45 pm
content: Quote from: ehughes on October 09, 2018, 07:45:52 pmThe ARM CMSIS-DAP is also open source, and also look into OpenOCD source code for more details.

author: josip
author_rank: Regular Contributor
timestamp: October 11, 2018, 01:53:37 pm
content: There is also open source example from silabs:Application Note 62 Programming Internal Flash Over the Serial Wire Debug Interfacehttps://www.silabs.com/documents/public/application-notes/an0062.pdf

author: technix
author_rank: Super Contributor
timestamp: October 11, 2018, 02:27:48 pm
content: If you went down the route of using SWD memory access as a way of inter-processor communication, make sure you have a good understanding on synchronization primitives and their implementation so you don’t accidentally mess up anything.

author: none
author_rank: Contributor
timestamp: December 03, 2018, 10:23:29 am
content: https://static.docs.arm.com/ihi0031/d/debug_interface_v5_2_architecture_specification_IHI0031D.pdfhttps://www.arm.com/files/pdf/Serial_Wire_Debug.pdfActually, start with the Reference Manual, section "Debug Support".