Close

Use the Force (on stlinkv2's)

andrew-clappAndrew Clapp wrote 08/27/2020 at 22:08 • 2 min read • Like

The cheap stlinkv2 usb dongles can be feisty.  Yeah, you can pick them up for $3 with free shipping from faraway if you are willing to wait for them to show up.  And that can really have some appeal to the underfunded programmer.

After finishing the first minimum viable product version of the software for a neat embedded device, the programming apparatus immediately decided to take a long-lunch.  The stlinkv2's in it stopped playing nice.  I started by updating the firmware to the latest from ST, which did not work.  Fortunately, it did not entirely brick the programmers.  After flashing many versions of the official firmware from ST, I have found that the one mentioned here still works with stm8flash for the most part.  It's older, but that's what works for now.

https://www.carminenoviello.com/2016/02/26/restore-st-link-interface-bad-update-2-26-15-firmware/

This software that ST provides is a java app that other folks have written at-length about.  There seems to be a different zip file version of it for every version of the stlinkv2 firmware.  Is that really the easiest way to do it?

The next problem was that it worked, repeatedly flashing onto the same device, but when I plugged in a new device to program, the usb programmers stopped responding.  I suspect because the firmware is so old.

Workaround.  After trying a bunch of different ways to reset the usb device for each programmer before trying to use stm8flash, I found that this one worked pretty consistently.  The usbreset.c code compiled readily on both my main linux box and on the raspberry pi in my flashing apparatus.

https://askubuntu.com/questions/645/how-do-you-reset-a-usb-device-from-the-command-line/290519#290519

resetting stlink devices
Resetting USB device /dev/bus/usb/001/005
Reset successful
Resetting USB device /dev/bus/usb/001/006
Reset successful

It's not ideal, but it works.  Flashing devices resumes normally after the reset.

Like

Discussions

Andrew Clapp wrote 08/28/2020 at 14:45 point

Along these lines, option #3 presented itself as the DIY way.  This one uses a blue pill STM32 and programs it as an stlinkv2.  I find this very appealing.

http://slemi.info/2018/08/14/making-your-own-st-link-v2/

  Are you sure? yes | no

Thomas wrote 08/28/2020 at 11:53 point

Out of pure curiosity I ordered one of those pod-like STLINK-V2 clones that might be closer to the "real thing" - why curious? I have never managed to program an STM8L101F3P6 or an STM8L001J3M3 under Linux! Long story short: it didn't work even after upgrading the firmware.

Using ST's STLINK update tool on the one cheap dongle that I use most, however, worked. I guess that I was just lucky.

Maybe, just maybe, the pod like variant is a bit more likely to be compatible with STLINK-V2, which might be interesting for use cases like yours.

  Are you sure? yes | no

Travis Bemann wrote 08/28/2020 at 16:48 point

There is also a stlink package on most Linux distros and on FreeBSD. Warning though - it is highly commended that you pull the git repository for this, switch to the devel branch, and build that, due to issues with the stock 1.6 release of stlink

  Are you sure? yes | no