From 940e483cb3ee2f1878dbcc6dc25c077d0c990b43 Mon Sep 17 00:00:00 2001 From: Hermann Kraus Date: Sun, 14 Oct 2018 00:06:10 +0200 Subject: [PATCH] Add unlock function and documentation for STM8S005. --- Makefile | 20 ++++++++++++++++---- README.md | 34 +++++++++++++++++++++++++--------- 2 files changed, 41 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index bd90d92..1676558 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,7 @@ +CONTROLLER=stm8s105k6 +SDCC=sdcc +STM8FLASH=stm8flash + MAIN=main.c SRC=system.c systemtimer.c strings.c flash.c uart.c displays.c button.c encoder.c encoderbutton.c beep.c fan.c load.c adc.c ringbuffer.c RELS=$(SRC:.c=.rel) @@ -6,17 +10,25 @@ all: bin bin: $(MAIN) $(RELS) @mkdir -p bin - /home/dev/local/sdcc-3.6.0/bin/sdcc --std-c11 --opt-code-size -mstm8 -lstm8 $(MAIN) $(wildcard bin/*.rel) -o bin/ + $(SDCC) --std-c11 --opt-code-size -mstm8 -lstm8 $(MAIN) $(wildcard bin/*.rel) -o bin/ .c.rel: @mkdir -p bin - /home/dev/local/sdcc-3.6.0/bin/sdcc -c --std-c11 --opt-code-size -mstm8 -lstm8 $< -o bin/ + $(SDCC) -c --std-c11 --opt-code-size -mstm8 -lstm8 $< -o bin/ clean: @rm -rf bin -flash: bin - /home/dev/local/stm8flash/stm8flash -c stlinkv2 -p stm8s105k4 -w bin/main.ihx +#echo "0000ff00ff00ff00ff00ff00ff00ff" | xxd -r -p > misc/default_opt.bin +unlock: + $(STM8FLASH) -c stlinkv2 -p $(CONTROLLER) -s opt -w misc/default_opt.bin + #$(STM8FLASH) -c stlinkv2 -p $(CONTROLLER) -u # Works only in stm8flash versions after git commit f3f547b4 + +flash: + $(STM8FLASH) -c stlinkv2 -p $(CONTROLLER) -w bin/main.ihx + +eeprom: + $(STM8FLASH) -c stlinkv2 -p $(CONTROLLER) -s eeprom -w misc/eeprom.bin .SUFFIXES: .c .rel diff --git a/README.md b/README.md index 7c964c3..506dd0a 100644 --- a/README.md +++ b/README.md @@ -7,24 +7,40 @@ The load can be ordered from China (AliExpress, eBay etc), something like this o ![The electronic load](docs/1.jpg) -Added features: -* full control via UART +## Added features +* full control via UART (connected to pins T and R) * calibration (via direct EEPROM programming) * parameters (e.g. minimal current) are changable * bootloader can be enabled -I would recommend to not program the chip in the device, because: -* then you cannot return to original firmware if you don't like this one -* it's STM8S**0**05K6T6C, that means you can one program it about 100 times -* you cannot user a simple USB-UART adapter to program it first time +## Programming +Programming the chip in the device has some drawbacks: +* you cannot return to original firmware if you don't like this one +* you cannot use a simple USB-UART adapter to program it first time -Take rather a new (empty) STM8S**1**05K4T6C or STM8S**1**05K6T6C and solder it. +Also the datasheet claims a write endurance of only 100 flash cycles but this is probably only for marketing purposes as it [contains the same die](https://hackaday.io/project/16097-eforth-for-cheap-stm8s-gadgets/log/76731-stm8l001j3-a-new-sop8-chip-and-the-limits-of-stm8flash) as the STM8S105 which is rated for 10000 cycles. -Programmer connection: +### Programmer connection +Connect an STLink V2 to the pins at the bottom of the board: ![Programmer connection](docs/2.jpg) -[Analog part schematic](http://www.voltlog.com/pub/dummy-load-sch.pdf) (one correction: PB3 is connected to +12V via 20k). +### Flashing +If you are using the chip which is already on the board you first have to unlock it via + + make unlock + +Then you write the new firmware with + + make flash + +and if you are flashing for the first time you also have to program the EEPROM: + + make eeprom + + +[Analog part schematic](http://www.voltlog.com/pub/dummy-load-sch.pdf) (corrections: PB3 is connected to +12V via 20k, R27 is 510 Ohm). +[Full schematic](https://github.com/ArduinoHannover/ZPB30A1_Firmware/raw/master/hardware/schematic.pdf) (one correction: polarity of D6 is reversed). Calibration values in the code are for my instance, may be you have to adjust them for your one.