Skip to main content
Ofer
Associate III
October 18, 2021
Question

Programming secondary chip using SWD interface

Hi

I have a chip in main board that can be programmed using SWD interface.

  1. Can I use the SWD of the STM32F407 to program another chip (and not just for programming and debugging the STM32) ?
  2. If so - Are there any HAL functions ?

Thanks

This topic has been closed for replies.

15 replies

S.Ma
Principal
October 18, 2021

Embedding debug probe function is far from simple. Typically bootoader enables reflashing through uart, i2c, spi. Application code on target for in application programming is another way. HAL doesn't provide SWD serial function.

Ofer
OferAuthor
Associate III
October 18, 2021

Hi

I'm sure it is not a simple task, but I might be doing it if it technically possible.

I see in the reference manual: https://www.st.com/resource/en/reference_manual/dm00031020-stm32f405-415-stm32f407-417-stm32f427-437-and-stm32f429-439-advanced-arm-based-32-bit-mcus-stmicroelectronics.pdf

page 1695 a list of registers that may help me doing this task.

Is someone ever did it ?

Tesla DeLorean
Guru
October 18, 2021

The SWD protocol on the MCU side is implemented in hardware. It's not designed to host other devices, and is not inherently a software/firmware based method. ie combinational/synchronous logic clocking into the 10's of MHz

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Peter BENSCH
ST Technical Moderator
October 18, 2021

That would be a kind of daisy chain, but no, unfortunately this is not possible with SWD and there are no functions for it.

Regards

/Peter

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
Ofer
OferAuthor
Associate III
October 18, 2021

Hi Peter, I'm not sure you understood me correctly.

I'm not trying to program from PC to the STM32 and from then to the other chip.

I'm trying to control the STM32 to program the other chip directly with no other host.

Thanks

TDK
October 18, 2021

Daisy chain or not, it's not supported. The SWD pins are only for programming that device.

You can certainly emulate the SWD protocol using other pins (or even the SWD pins), but that's not a realistic solution and certainly isn't supported in HAL.

"If you feel a post has answered your question, please click ""Accept as Solution""."
Andrew Neil
Super User
October 18, 2021

"Can I use the SWD of the STM32F407 to program another chip"

No. The SWD in the microcontroller is a "slave" - it can't be a "master" to another microcontroller.

Have you looked at CMSIS DAP ?

https://os.mbed.com/handbook/CMSIS-DAP

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Ofer
OferAuthor
Associate III
October 19, 2021

Thanks to all of you for your answers.

It is not urgent task, but I have to select the pinout to the board.

I will try both options (using the SWD of the STM + using simple GPIOs for bit-banging)

TDK
October 19, 2021
Consider programming the other chip with the bootloader and controlling it with GPIOs connected to the BOOT0 pin, the NRST pin, and the relevant bootloader communication method such as UART. This will be much easier than using SWD.
"If you feel a post has answered your question, please click ""Accept as Solution""."