Skip to content

Commit 9ece911

Browse files
committed
update stm8flash and stm8gal for Linux
1 parent 66e6565 commit 9ece911

6 files changed

Lines changed: 238 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
99
- using stm8gal to upload using the builtin bootloader of larger STM8 devices
1010
- Support for Sduino-UNO board
1111

12+
### Changed
13+
- updated stm8flash to support more STM8 devices (and espstlink for Linux
14+
and OSX)
15+
- updated SDCC to version 3.8.0
16+
17+
### Fixed
18+
- Serial_serial_print_sn()
19+
1220

1321

1422
## [0.3.3 - 2017-11-14]
Lines changed: 230 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,230 @@
1+
# Compiling the tools
2+
3+
## stm8gal
4+
5+
Project page: https://github.com/gicking/stm8gal
6+
7+
git clone [email protected]:gicking/stm8gal.git
8+
9+
10+
11+
12+
### For Linux
13+
14+
cd stm8gal
15+
make
16+
cp -av stm8gal /usr/local/bin
17+
18+
### For Linux 32 bit on a 64 bit Linux system
19+
20+
Required packages:
21+
22+
apt install gcc-multilib libusb-1.0-0-dev:i386
23+
24+
Compiling stm8gal requires a small modification in the Makefile. For CFLAGS
25+
and LDFLAGS change the `=` operator to `+=` to allow for additional
26+
parameters on the command line:
27+
28+
29+
cd stm8gal
30+
sed -i '/FLAGS/ s/ = / += /' Makefile
31+
32+
Now start the compiler:
33+
34+
CFLAGS=-m32 LDFLAGS=-m32 make
35+
36+
37+
38+
### For Windows
39+
40+
Windows does not support an SPI device. Apply this patch to disable
41+
compilation of spi_spidev_comm.c for Windows:
42+
43+
```diff
44+
diff --git a/Makefile b/Makefile
45+
index 24b0057..053d17b 100644
46+
--- a/Makefile
47+
+++ b/Makefile
48+
@@ -4,7 +4,7 @@ CC = gcc
49+
CFLAGS = -c -Wall -I./STM8_Routines
50+
#CFLAGS += -DDEBUG
51+
LDFLAGS = -g3 -lm
52+
-SOURCES = bootloader.c hexfile.c main.c misc.c serial_comm.c spi_spidev_comm.c spi_Arduino_comm.c
53+
+SOURCES = bootloader.c hexfile.c main.c misc.c serial_comm.c spi_Arduino_comm.c
54+
INCLUDES = globals.h misc.h bootloader.h hexfile.h serial_comm.h spi_spidev_comm.h spi_Arduino_comm.h main.h
55+
STM8FLASH = STM8_Routines/E_W_ROUTINEs_128K_ver_2.1.s19 STM8_Routines/E_W_ROUTINEs_128K_ver_2.0.s19 STM8_Routines/E_W_ROUTINEs_256K_ver_1.0.s19 STM8_Routines/E_W_ROUTINEs_32K_ver_1.3.s19 STM8_Routines/E_W_ROUTINEs_32K_ver_1.4.s19 STM8_Routines/E_W_ROUTINEs_128K_ver_2.2.s19 STM8_Routines/E_W_ROUTINEs_32K_ver_1.0.s19 STM8_Routines/E_W_ROUTINEs_128K_ver_2.4.s19 STM8_Routines/E_W_ROUTINEs_32K_ver_1.2.s19 STM8_Routines/E_W_ROUTINEs_32K_verL_1.0.s19 STM8_Routines/E_W_ROUTINEs_8K_verL_1.0.s19
56+
STM8INCLUDES = $(STM8FLASH:.s19=.h)
57+
@@ -16,6 +16,7 @@ RM = rm -fr
58+
# add optional SPI support via spidev library (Windows not yet supported)
59+
ifeq (,$(findstring Win,$(OS)))
60+
CFLAGS += -DUSE_SPIDEV
61+
+ SOURCES += spi_spidev_comm.c
62+
endif
63+
64+
# add optional GPIO reset via wiringPi library (Raspberry only)
65+
diff --git a/misc.c b/misc.c
66+
index 9fe02a0..67b5c0d 100644
67+
--- a/misc.c
68+
+++ b/misc.c
69+
@@ -22,7 +22,7 @@
70+
// WIN32 specific
71+
#if defined(WIN32)
72+
73+
- #include "Windows.h"
74+
+ #include "windows.h"
75+
76+
// forground colours
77+
#define FG_BLACK 0
78+
```
79+
80+
Now compile:
81+
82+
- on a Windows system: `make`
83+
- using mingw on Linux: `make CC=i686-w64-mingw32-gcc OS=Win`
84+
85+
86+
87+
88+
## stm8flash
89+
90+
Project page: https://github.com/vdudouyt/stm8flash
91+
92+
Compiling for Linux and OSX is straight forward, Windows is more
93+
complicated. Current versions of stm8flash support the espstlink programmer.
94+
The programmer is conneced via USB and a virtual serial port, not over Wifi
95+
and for serial access the termios library is used. Being a POSIX function,
96+
this is not supported by mingw, only by cygwin. As a workaround I use this
97+
patch to disable the espstlink functionality on Windows systems:
98+
99+
```diff
100+
diff --git a/Makefile b/Makefile
101+
index 7ed48d1..e76a69f 100644
102+
--- a/Makefile
103+
+++ b/Makefile
104+
@@ -39,6 +39,7 @@ else
105+
LIBS = -lusb-1.0
106+
LIBUSB_CFLAGS =
107+
CC ?= GCC
108+
+ SKIP_ESP = yes
109+
BIN_SUFFIX =.exe
110+
endif
111+
112+
@@ -47,8 +48,12 @@ override CFLAGS := $(BASE_CFLAGS) $(LIBUSB_CFLAGS) $(CFLAGS)
113+
114+
115+
BIN =stm8flash
116+
-OBJECTS =stlink.o stlinkv2.o espstlink.o main.o byte_utils.o ihex.o srec.o stm8.o libespstlink.o
117+
-
118+
+OBJECTS =stlink.o stlinkv2.o main.o byte_utils.o ihex.o srec.o stm8.o
119+
+ifeq ($(SKIP_ESP),yes)
120+
+ override CFLAGS += -DNO_ESP
121+
+else
122+
+ OBJECTS +=espstlink.o libespstlink.o
123+
+endif
124+
125+
.PHONY: all clean install
126+
127+
diff --git a/main.c b/main.c
128+
index ce19e47..29a25d2 100644
129+
--- a/main.c
130+
+++ b/main.c
131+
@@ -54,6 +54,7 @@ programmer_t pgms[] = {
132+
stlink2_swim_read_range,
133+
stlink2_swim_write_range,
134+
},
135+
+#ifndef NO_ESP
136+
{
137+
"espstlink",
138+
0,
139+
@@ -64,6 +65,7 @@ programmer_t pgms[] = {
140+
espstlink_swim_read_range,
141+
espstlink_swim_write_range,
142+
},
143+
+#endif
144+
{ NULL },
145+
};
146+
147+
@@ -72,9 +74,15 @@ void print_help_and_exit(const char *name, bool err) {
148+
fprintf(stream, "Usage: %s [-c programmer] [-S serialno] [-p partno] [-s memtype] [-b bytes] [-r|-w|-v] <filename>\n", name);
149+
fprintf(stream, "Options:\n");
150+
fprintf(stream, "\t-? Display this help\n");
151+
- fprintf(stream, "\t-c programmer Specify programmer used (stlink, stlinkv2 or espstlink)\n");
152+
+ fprintf(stream, "\t-c programmer Specify programmer used (stlink, stlinkv2"
153+
+#ifndef NO_ESP
154+
+ " or espstlink"
155+
+#endif
156+
+ ")\n");
157+
fprintf(stream, "\t-S serialno Specify programmer's serial number. If not given and more than one programmer is available, they'll be listed.\n");
158+
+#ifndef NO_ESP
159+
fprintf(stream, "\t-d port Specify the serial device for espstlink (default: /dev/ttyUSB0)\n");
160+
+#endif
161+
fprintf(stream, "\t-p partno Specify STM8 device\n");
162+
fprintf(stream, "\t-l List supported STM8 devices\n");
163+
fprintf(stream, "\t-s memtype Specify memory type (flash, eeprom, ram, opt or explicit address)\n");
164+
```
165+
166+
Obviously, a better approach would be the use of a simple intermediate
167+
cross-platform layer like
168+
[libserialport](https://sigrok.org/wiki/Libserialport).
169+
170+
171+
172+
173+
### For Linux
174+
175+
Required packages:
176+
177+
- for 64 bit systems: `apt install libusb-1.0-0-dev`
178+
- for 32 bit systems: `apt install libusb-1.0-0-dev:i386`
179+
180+
git clone [email protected]:vdudouyt/stm8flash.git
181+
cd stm8flash
182+
make
183+
cp -av stm8flash /usr/local/bin
184+
185+
186+
187+
### For Linux 32 bit on a 64 bit Linux system
188+
189+
Required packages:
190+
191+
apt install gcc-multilib libusb-1.0-0-dev:i386
192+
193+
Compiling stm8flash:
194+
195+
cd stm8flash
196+
CFLAGS=-m32 make
197+
198+
199+
200+
201+
202+
### Cross-Compiling for windows on a Linux system
203+
204+
apt install mingw-w64 mingw-w64-tools
205+
206+
cd stm8flash
207+
make CC=i686-w64-mingw32-gcc PLATFORM=w7
208+
209+
210+
211+
### For Windows on a Windows system
212+
213+
214+
https://github.com/orlp/dev-on-windows/wiki/Installing-GCC--&-MSYS2
215+
216+
- Open msys window, execute `pacman -Syuu`, close window.
217+
- repeat the before step until no more updates are found.
218+
- do eigther the full install (700MB):
219+
pacman -S --needed base-devel mingw-w64-i686-toolchain
220+
- or the reduced install (350MB):
221+
pacman -S --needed mingw-w64-i686-toolchain make grep sed pkg-config
222+
- minimum install (150MB):
223+
pacman -S --needed mingw-w64-i686-binutils mingw-w64-i686-crt-git
224+
mingw-w64-i686-gcc mingw-w64-i686-gcc-libs mingw-w64-i686-headers-git
225+
mingw-w64-i686-libmangle-git mingw-w64-i686-libwinpthread-git
226+
mingw-w64-i686-make mingw-w64-i686-pkg-config mingw-w64-i686-tools-git
227+
mingw-w64-i686-winpthreads-git mingw-w64-i686-winstorecompat-git
228+
229+
- copy `libusb-1.0/libusb.h` and `libusb.dll` into current directory
230+
- `make CFLAGS="-I. -L."`
26.3 KB
Binary file not shown.
16.2 KB
Binary file not shown.
23.2 KB
Binary file not shown.
15.8 KB
Binary file not shown.

0 commit comments

Comments
 (0)