21
\$\begingroup\$

Can I program all kinds of SWD-programmable chips (ARM-MCUs) with ST-Link?

\$\endgroup\$
5
  • \$\begingroup\$ "The ST-LINK/V2 is an in-circuit debugger and programmer for the STM8 and STM32 microcontroller families." I don't think you can immediately, but it should be achievable in theory. Someone managed to connect it to a LPC MCU here : lpcware.com/content/forum/… \$\endgroup\$
    – Fluffy
    Commented Aug 4, 2016 at 14:42
  • 2
    \$\begingroup\$ Perhaps in some cases if you use something like openocd rather than the ST software. If you run into difficulty there are open source CMSIS-DAP implementations you could flash onto it, which are more universal by placing the host software in finer control of the details. \$\endgroup\$ Commented Aug 4, 2016 at 14:46
  • \$\begingroup\$ This isn't what you asked, but there are also debuggers that cover multiple targets such as the PE micro debuggers. \$\endgroup\$
    – user57037
    Commented Aug 5, 2016 at 6:06
  • 3
    \$\begingroup\$ I use ST link to program lpc1549, it works. \$\endgroup\$
    – Farrukh
    Commented Jul 20, 2017 at 7:25
  • \$\begingroup\$ yes the st-link can be used on various cortex-m based chips from other brands. \$\endgroup\$
    – old_timer
    Commented May 28, 2020 at 20:48

5 Answers 5

9
\$\begingroup\$

You could also flash the st-link and convert it to a Black Magic Probe. The same image will also convert a Blue Pill into a BMP.

I've done both. The Blue Pill has the advantage that the usb-rs232 bridge the BMP exports is easily available.

The BMP supports a range of chips to include but not limited to:
ST Microelectronics STM32F0, STM32F1, STM32F3, STM32F2, STM32F4, STM32F7, STM32L0, STM32L1, STM32L4
Atmel SAM3N, SAM3X, SAM3S, SAM3U, SAM4S, SAM4L, SAM D20, D21
Nordic nRF51, nRF52 (These are why I use the BMP)

The BMP is open source, can be used for commercial programming and the hardware can be cheap(The "real" BMP costs around $60, a blue pill 5 pack from amazon was less than $20 shipped).

\$\endgroup\$
7
\$\begingroup\$

To add to the existing answer; some chips are known not to work properly with ST-LINK and OpenOCD.

In particular, if your target is from the Atmel SAMD21 family of MCUs, you are likely to run into weird issues, where the processor is detected, but any attempts to erase flash sectors fail with an error.

The reason is rather involved, to quote:

AFAIK the problem is in half word (16-bit) write to NVMCTRL->CTRLA register. STLink does not implement half word memory access and OpenOCD emulates is as two byte operations. Unfortunately CTRLA register comprises from key and command an have to be written atomically. If STLink writes two bytes, NVM controller sets PROGE bit in STATUS: "An invalid command and/or a bad keyword was/were written in the NVM Command register"

The workaround involves recompiling OpenOCD with code patches. Not fun.

However, if you don't mind flashing your ST-Link (through another ST-Link), you can convert it to a CMSIS-DAP adapter, which works just fine with the SAMD and should also work with STM32 and other Cortex-M chips.

\$\endgroup\$
1
\$\begingroup\$

Yes I believe this is possible, although I haven't tried it. You would likely be in breach of the ST Licence agreement, if you tried programming devices other than those from ST

As an example Segger (One of the market leaders in debuggers and programmers) supports converting your ST-Link to J-link (essentially overwriting the ST-Link chip with the Segger code). This is also reversible, so if you want to restore your ST-link device back to its original form you can.

There are several version of ST-Link, however. Take a look at the following links which provide further info and a guide on how to do this.

https://www.segger.com/jlink-st-link.html
https://www.segger.com/jlink-ob.html

\$\endgroup\$
2
  • 1
    \$\begingroup\$ I have been using the stlink header on nucleo and discovery boards on most of the the major cortex-m brands...and the ones I couldnt get it to work on were issues getting openocd configured not the stlink. \$\endgroup\$
    – old_timer
    Commented Jul 14, 2017 at 12:44
  • 1
    \$\begingroup\$ Flashing an ST-Link to a J-Link will only work(and be legal) on either a Nucleo or Discovery board and only for use with the targeted MCU. Read the Seggar license terms, they are quite restrictive. As far as I know, the Seggar flasher will not even work on a stand alone ST-Link. \$\endgroup\$
    – GB - AE7OO
    Commented Mar 17, 2019 at 13:40
1
\$\begingroup\$

Yes, its possible. i am using stlink v2 (original, as well as Chinese usb stick type clones) with Coocox IDE. Coocox has also standalone programmer app - CoFlash, Which could be used to program a lot of chips. I have experience with only two series: LPC176x and LPC175x, over SWD interface. And i haven't any issues with those chips. I also haven't made any specific changes or updates for the programmers (except that original st link required the high voltage level at TVCC (PIN1), otherwise, it didnt allow to program chip, so i connected directly pin 19 (3.3vcc) to pin 1 on stlink v2).

\$\endgroup\$
0
\$\begingroup\$

An STLink V2/V2.1 or V3 with recent firmware can also be used with the PC-Hosted Blackmagic pc-stlinkv2 platform. Compile with "make PROBE_HOST=pc-stlinkv2", start the debug server with "blackmagic_stlinkv2" and connect to :2000 in gdb or directly load binaries with "blackmagic_stlinkv2 ". This works with all targets that BMP knows. However V3 activly denies working on non-ST targets, while V2 does not care.

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.