Skip to content
Andrey edited this page Nov 1, 2019 · 2 revisions

What is the point?

When you have the W1209 board in your hands and realize that this is almost what you need. But to make it really useful it would be better to change its functionality a little bit according to your needs. For example, you need to set delay for the relay action in seconds or even hours instead of minutes. And at this point you are facing the fact that to have this little change you have to rewrite whole functionality from the scratch. Would you do it? I suppose not.

The primary target of this project is to provide a starting point for anyone who would like to create his own project.

How to build and upload?

I believe, there is not a single way to compile C-source into binary image and upload it into STM8 micro-controller. But due to the fact that Ubuntu Linux is the only OS on my workstation, tools that are compatible with Linux have been selected. So at this moment I can only describe the build environment I've started with.

Tools being used

mandatory:

  • Source control - Git is a free and open source distributed version control system.

  • Build control - GNU Make is a tool which controls the generation of executables and other non-source files of a program.

  • C Compiler - SDCC Small Device C Compiler

  • SWIM upload - stm8flash is a free and opensource tool that's able to communicate through the SWIM interface of ST-LINKs under Linux.

optional:

And of course this software is free of charge. So do not forget to at least mentally say thanks to all peoples who support these projects. Personally, I take my hat off with gratitude to those who have spent their time and efforts developing such useful and free software.

Build procedure

incomplete paragraph

~/src$ git clone https://github.com/mister-grumbler/w1209-firmware

~/src$ cd w1209-firmware

~/src/w1209-firmware$ make

The image file thermostat.ihx will be located within ./Build sub-folder.

Upload procedure

It depends on the equipment you have. In my case it is a cheap ST-Link V2 clone which I have bought on Aliexpress market. This USB stick is so spread that you may find a lot of info about it. ST-Link V2 interface connected to W1209 board

The software tool which is being used for uploading is stm8flash. Well, yes, you have to build this tool from the source files.

Make sure you have installed all necessary tools like pkg-config, make, ... beforehand.

~/src$ git clone https://github.com/vdudouyt/stm8flash.git

~/src$ cd stm8flash

~/src/stm8flash$ make

The following command is not mandatory. You may put the compiled binary into your local ~/bin and then run it directly or update PATH environment variable.

~/src/stm8flash$ sudo make install

The command to upload a firmware image file is:

w1209-firmware$ stm8flash -c stlinkv2 -p stm8s003?3 -w <path to image file>

Should it be mentioned that in this case you will lose the original firmware? And it is well known that there is no way to make a backup copy. So you were warned.

When you'll try to upload your firmware file at first time, you have to got a error. This is because the flash-memory is locked on factory, more likely, to save intellectual property and prohibit grabbing of original firmware. You can find several different tips on how to unlock this flash memory on the Internet. I found helpful the following one (and this results in erasing all the contents of the flash memory):

~/src/stm8flash$ echo "00 00 ff 00 ff 00 ff 00 ff 00 ff" | xxd -r -p > ./reset_flash.bin

~/src/stm8flash$ stm8flash -c stlinkv2 -p stm8s103f3 -s opt -w ./reset_flash.bin