# When trying to flash new data, I am getting an error that I can't write to addresses below 0x4000 on ST8M105x6. How to fix this?

For context, I am not very well versed into MCUs and the STM8 chip. I have an ebike with a TSDZ2 motor, and I am trying to flash a new firmware on it to support my higher capacity battery. The chip inside is an ST8S105x6

The files I am trying to flash (52v{data,program}memory.s19) are here: https://drive.google.com/drive/folders/1eGcBtTj8GrGQ4tDJAECr6ejMrpW2ZqvH

This is the guide I was following: https://www.eco-ebike.com/blogs/eco-cycles-instructionals/tsdz2-motor-firmware-programming

I connected only three wires: GND, +5V, and SWIM (there is not enough space to physically connect the RST wire in the mounted connector as I don't own a spare proprietary connector to this system.)

When I try to flash with the stm8 utility on Linux (the ST Programmer software for Windows refuses to start the flashing process, maybe it's because I'm using an STLinkV2 knock off USB dongle from eBay?), this is the error I am getting:

\$ sudo ./stm8flash -c stlinkv2 -p stm8s105?6 -w ~/Downloads/52vdatamemory.s19
Determine FLASH area
Due to its file extension (or lack thereof), "/home/user/Downloads/52vdatamemory.s19" is considered as MOTOROLA S-RECORD format!
Address 00004000 is out of range at line 1


The connection is good, because I can read and dump the current firmware with the same setup.

I have updated the STLink dongle to the latest version firmware using the ST supplied updater (on Windows.)

So why can't I write to this address, and how could I fix it? Should I just delete anything below 0x4000 in my .s19 file? On the screenshots from the guide above, it looks like the ST software starts at 0x4000... But then is the data below 0x4000 relevant at all? If not, why include it in the .s19 file?

• Check the memory-map given in the STM8S105 documentation, memory regions 0x0 - 0x4000 are ROM/RAM/Reserved. You should not attempt to write to this region. Application firmware code should be placed at 0x8000 - 0x10000. – markus-nm Jan 31 at 11:56