Author Topic: STM32 in-circuit SWD programming protocol  (Read 12174 times)

0 Members and 1 Guest are viewing this topic.

Offline KarelTopic starter

  • Super Contributor
  • ***
  • Posts: 2219
  • Country: 00
STM32 in-circuit SWD programming protocol
« on: October 09, 2018, 09:13:38 am »
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  :)
 

Offline andersm

  • Super Contributor
  • ***
  • Posts: 1198
  • Country: fi
Re: STM32 in-circuit SWD programming protocol
« Reply #1 on: October 09, 2018, 09:22:19 am »
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.

Offline KarelTopic starter

  • Super Contributor
  • ***
  • Posts: 2219
  • Country: 00
Re: STM32 in-circuit SWD programming protocol
« Reply #2 on: October 09, 2018, 09:30:32 am »
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.
 

Offline dgtl

  • Regular Contributor
  • *
  • Posts: 183
  • Country: ee
Re: STM32 in-circuit SWD programming protocol
« Reply #3 on: October 09, 2018, 10:08:51 am »
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.
 
The following users thanked this post: Karel

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14488
  • Country: fr
Re: STM32 in-circuit SWD programming protocol
« Reply #4 on: October 09, 2018, 03:29:39 pm »
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).

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

 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11269
  • Country: us
    • Personal site
Re: STM32 in-circuit SWD programming protocol
« Reply #5 on: October 09, 2018, 04:23:27 pm »
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.
Alex
 

Offline ehughes

  • Frequent Contributor
  • **
  • Posts: 409
  • Country: us
Re: STM32 in-circuit SWD programming protocol
« Reply #6 on: October 09, 2018, 04:24:19 pm »
http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0314h/Chdhfbhc.html


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

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14488
  • Country: fr
Re: STM32 in-circuit SWD programming protocol
« Reply #7 on: October 09, 2018, 04:34:59 pm »
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.

That's interesting. Would you have any source code showing how to implement an SWD "master" on an ARM CPU?
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11269
  • Country: us
    • Personal site
Re: STM32 in-circuit SWD programming protocol
« Reply #8 on: October 09, 2018, 04:36:57 pm »
That's interesting. Would you have any source code showing how to implement an SWD "master" on an ARM CPU?

Here you go - https://github.com/ataradov/embedded-swd
Alex
 
The following users thanked this post: ogden, SiliconWizard, trevmar

Offline JPortici

  • Super Contributor
  • ***
  • Posts: 3461
  • Country: it
Re: STM32 in-circuit SWD programming protocol
« Reply #9 on: October 09, 2018, 06:27:01 pm »
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).

which isn't required, otherwise the PIC32 couldn't perform self-programming
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14488
  • Country: fr
Re: STM32 in-circuit SWD programming protocol
« Reply #10 on: October 09, 2018, 06:52:55 pm »
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.
 

Offline KarelTopic starter

  • Super Contributor
  • ***
  • Posts: 2219
  • Country: 00
Re: STM32 in-circuit SWD programming protocol
« Reply #11 on: October 09, 2018, 06:58:49 pm »
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).

which isn't required, otherwise the PIC32 couldn't perform self-programming

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

Offline ehughes

  • Frequent Contributor
  • **
  • Posts: 409
  • Country: us
Re: STM32 in-circuit SWD programming protocol
« Reply #12 on: October 09, 2018, 07:45:52 pm »
Quote
That's interesting. Would you have any source code showing how to implement an SWD "master" on an ARM CPU?


Nothing that is open source.  ataradov's link is a good start. 
 

Offline JPortici

  • Super Contributor
  • ***
  • Posts: 3461
  • Country: it
Re: STM32 in-circuit SWD programming protocol
« Reply #13 on: October 09, 2018, 08:08:33 pm »
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).

which isn't required, otherwise the PIC32 couldn't perform self-programming

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


very old :) in fact, the earliest PIC with LVP i have here was released 13 years ago.
 

Offline technix

  • Super Contributor
  • ***
  • Posts: 3507
  • Country: cn
  • From Shanghai With Love
    • My Untitled Blog
Re: STM32 in-circuit SWD programming protocol
« Reply #14 on: October 11, 2018, 12:04:45 pm »
Quote
That's interesting. Would you have any source code showing how to implement an SWD "master" on an ARM CPU?


Nothing that is open source.  ataradov's link is a good start.
The ARM CMSIS-DAP is also open source, and also look into OpenOCD source code for more details.
 

Offline josip

  • Regular Contributor
  • *
  • Posts: 152
  • Country: hr
Re: STM32 in-circuit SWD programming protocol
« Reply #15 on: October 11, 2018, 01:53:37 pm »
There is also open source example from silabs:
Application Note 62 Programming Internal Flash Over the Serial Wire Debug Interface

https://www.silabs.com/documents/public/application-notes/an0062.pdf
 

Offline technix

  • Super Contributor
  • ***
  • Posts: 3507
  • Country: cn
  • From Shanghai With Love
    • My Untitled Blog
Re: STM32 in-circuit SWD programming protocol
« Reply #16 on: October 11, 2018, 02:27:48 pm »
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.
 

Offline none

  • Contributor
  • Posts: 32
  • Country: 00
« Last Edit: December 03, 2018, 12:27:02 pm by none »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf