Problem flashing TSDZ2 on linux SWIM error 0x05

Joakim

1 W
Joined
May 27, 2023
Messages
50
Location
Östersund
I bought a ready cable from eco cycles (st-link + connector to speed sensor)

I'm on linux. I can make a backup of existing firmware just fine, but when trying to clear eeprom or flash I only get
SWIM error 0x04
SWIM error 0x05

I have tried the remove protection step, and converting to binary format. According to this wiki: Flash the firmware on TSDZ2

Any ideas?

Example command output:

Code:
stm8flash -c stlinkv2 -p "stm8s105?6" -w src/controller/data_empty.ihx  255 ✘
Determine FLASH area
STLink: v2, JTAG: v29, SWIM: v7, VID: 8304, PID: 4837
Due to its file extension (or lack thereof), "src/controller/data_empty.ihx" is considered as INTEL HEX format!
Address 4000 is out of range at line 1

Code:
stm8flash -c stlinkv2 -p "stm8s105?6" -w releases/TSDZ2-20.1C.2-2-initialflash.hex
Determine FLASH area
STLink: v2, JTAG: v29, SWIM: v7, VID: 8304, PID: 4837
Due to its file extension (or lack thereof), "releases/TSDZ2-20.1C.2-2-initialflash.hex" is considered as INTEL HEX format!
30310 bytes at 0x8000... SWIM error 0x05

Code:
stm8flash -c stlinkv2 -p "stm8s105?6" -w releases/TSDZ2-20.1C.2-2-initialflash.hex.bin
Determine FLASH area
STLink: v2, JTAG: v29, SWIM: v7, VID: 8304, PID: 4837
Due to its file extension (or lack thereof), "releases/TSDZ2-20.1C.2-2-initialflash.hex.bin" is considered as RAW BINARY format!
30310 bytes at 0x8000... SWIM error 0x04

Code:
echo "00 00 ff 20 df 00 ff 00 ff 00 ff 00 ff 00 ff" | xxd -r -p > option_bytes_pwm_n_channels_enabled.bin
stm8flash -c stlinkv2 -p "stm8s105?6" -s opt -w option_bytes_pwm_n_channels_enabled.bin
Determine OPT area
STLink: v2, JTAG: v29, SWIM: v7, VID: 8304, PID: 4837
Due to its file extension (or lack thereof), "option_bytes_pwm_n_channels_enabled.bin" is considered as RAW BINARY format!
15 bytes at 0x4800... SWIM error 0x05

If I click compile & flash in java configurator it saves the config.h but nothing else seems to happen
 
Last edited:
From the wiki:
If flashing does not work, try turning on the display.
I am doing this with the battery turned off / disconnected. Trying to turn on the display does nothing. Am I missing something here?
 
I noticed I suddenly got the SWIM error while backing up firmware as well. Disconnecting/connecting usb got that working again.

Then I did the same with setting the option bytes, which suddenly went through as well. But no luck doing the actual flash, still SWIMx04/05.

This seems frighteningly random!
 
Maybe try turning on debugging before running make on stm8flash? Looks like line 10 in the makefile does it:
No idea what's causing your problem but talking to microcontrollers can be hit-and-miss in my experience. I've had lots of issues related to PC voltages and sensitivity over the years, shouldn't be an issue over USB but keeping all cable lengths as short as possible would be step one imo. I'd consider adding additional earths too but that can sometimes be counter-productive, for example the Votol Canbus interface seems to get upset with more than just the canlow and canhigh connections.
 
I guess eco cycles must have sold a bunch of these cables and flashed a good amount of tsdz2s so I find it strange if they would create a cable that is too long 🤔 I dont understand this stuff about voltages and ground in regards to flashing stm8

I do understand software though and I’m not sure how a debug build of stm8flash would help, will it produce additional output?

The cable is a closed system, how would I add earths or adjust voltage on this?
 
I managed to get it to work by applying this patch to stm8flash: Fix flashing controllers with no NRST pin by not-fl3 · Pull Request #157 · vdudouyt/stm8flash
That was a long shot, but pretty much the only thing I could find with "0x05"

I first applied the option bytes then just did a regular flash with a binary file

Code:
echo "00 00 ff 20 df 00 ff 00 ff 00 ff 00 ff 00 ff" | xxd -r -p > option_bytes_pwm_n_channels_enabled.bin
stm8flash -c stlinkv2 -p "stm8s105?6" -s opt -w option_bytes_pwm_n_channels_enabled.bin
Code:
stm8flash -c stlinkv2 -p "stm8s105?6" -w releases/TSDZ2-20.1C.2-2-initialflash.hex.bin

Didnt do the clean_eeprom step, hope I get no side effects. Everything seems to work, but I have no speed sensor and could only ride for 20 seconds at a time, until I fix that :)
 
Back
Top