stm8flash icon indicating copy to clipboard operation
stm8flash copied to clipboard

Cannot read STM8 flash using SWIM with stlinkv2 clones

Open abliss opened this issue 6 months ago • 6 comments

I am trying to read the flash of an stm8s105k6 using an stlinkv2 clone. I have had no success so far. After enabling debug output, I get this:

sudo ./stm8flash -p stm8s105k6 -c stlinkv2 -s flash -r fw00.bin
Determine FLASH area
     GET_VERSION
STLink: v2, JTAG: v37, SWIM: v7, VID: 8304, PID: 4837
     GET_CURRENT_MODE
        -> 03 00
     SWIM READBUFSIZE
        -> 0x1800
     SWIM READ_CAP 01
        -> 00 01 02 07 00 00 00 00
     SWIM ASSERT_RESET
     SWIM READSTATUS
        status 00 00 00 00
     SWIM ENTER_SEQ
     SWIM READSTATUS
        status 01 00 00 00
     SWIM READSTATUS
        status 01 00 00 00
     SWIM READSTATUS
        status 04 00 00 00
     SWIM READSTATUS
        status 04 00 00 00
     SWIM READSTATUS
        status 04 00 00 00
     SWIM READSTATUS
        status 04 00 00 00
     SWIM READSTATUS
        status 04 00 00 00
SWIM error 0x04

I have tried two seemingly-different clones at several different firmwares, and always the same result. I attached an oscilloscope to the SWIM line, and I always see a waveform like this:

Image

the SWIM line starts high, then goes low for 20ms, then goes back high, and that's it. I was expecting to see the SWIM initialization sequence as described in the STMicro manual:

Image

When I plug the stlinkv2 into a windows machine and run stlink's Visual Programmer, I do indeed see a waveform that looks like the SWIM initialization sequence:

Image

Any idea what I'm doing wrong?

abliss avatar Jul 16 '25 18:07 abliss

I am seeing the same issue using a clone stm8linkv2 running on MacOSX.

tdfocus-png avatar Sep 30 '25 12:09 tdfocus-png

I got more info but I am not really convinced there is much stm8flash can do to make this easier.

I was able to get stm8flash to access my devboard if I first accessed it via STVP (in my case in a virtualbox Windows VM) and then disconnecting the power to my devboard and then reconnecting power. Then I go to stm8flash and issue the -u and things work.

Now I've tried to do this power on/off trick just using stm8flash and it didn't seem to work for me. So I am not sure if there is some state STVP sets the STLINK in that allows stm8flash to get the status ok from ENTER_SEQ.

tdfocus-png avatar Oct 02 '25 12:10 tdfocus-png

A correction to my last comment. It ends up that if I power off my dev board I have to go through the dance with svtp before stm8flash can recognize my dev board through stlinkv2 and get past the 0x4 readstatus. It seem like SVTP is doing something with the stlinkv2 that get stlinkv2 and my dev board able to talk to each other.

tdfocus-png avatar Oct 03 '25 12:10 tdfocus-png

I think there are some differences in hardward/firmware. I encountered a similar issue on a Mac.

A 2016 metal case one works perfectly well (STLink: v2, JTAG: v46, SWIM: v7, VID: 8304, PID: 4837) The ST-Link Utility shows V2.J46.S7

A recent purchase on Amazon does not work on Mac with SWIM error 0x04 (STLink: v2, JTAG: v37, SWIM: v7, VID: 8304, PID: 4837) The ST-Link Utility shows V2.J37.S7

Image

Image

I tried to use ST-Link Utility in Windows to flash them both to J37. The metal one still works, while the plastic one still does not. The waveform is the same as you get.

Their main chip is different and layout is different. But the SWIM part seems the same.

Image

Probably the chip makes a difference.

DeqingSun avatar Oct 15 '25 16:10 DeqingSun

I have the Amazon blue one too, so you probably are right that something has changed.

tdfocus-png avatar Oct 22 '25 12:10 tdfocus-png

Just got a metal case one from Taobao. The main chip has no mark but the SWIM does work with stm8flash. I believe some manufacturers did cost down design with a plastic case, and some changes in circuit.

Image

DeqingSun avatar Oct 29 '25 12:10 DeqingSun