Skip to content

Commit 05c5fdf

Browse files
committed
add installation instructions for Windows
1 parent efbba34 commit 05c5fdf

7 files changed

Lines changed: 236 additions & 61 deletions

File tree

docs/hardware/esp14.png

-13 Bytes
Loading

docs/hardware/esp14.svg

Lines changed: 4 additions & 4 deletions
Loading

docs/index.md

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ http://www.aliexpress.com/ .
3636
with github pages and the preinstalled jekyll-themes?)
3737

3838
1. [Introduction and Overview](index.md)
39-
2. [API descriptions and migration guidelines](api.md)
39+
2. [Installing the needed tools](install.md)
40+
3. [API descriptions and migration guidelines](api.md)
4041
* [Standard Arduino functions]()
4142
* [HardwareSerial]()
4243
* [SPI]()
@@ -46,14 +47,14 @@ with github pages and the preinstalled jekyll-themes?)
4647
* [Mini_SSD1306 library for monochrome OLED-displays](api/Mini_SSD1306.md)
4748
* [Stepper library](api/Stepper.md)
4849
* [Servo library](api/Servo.md)
49-
3. [Supported Boards](hardware.md)
50+
4. [Supported Boards](hardware.md)
5051
* [stm8blue: simple breakout board, STM8S103](hardware/stm8blue.md)
5152
* [ESP14: Wifi board, STM8S003](hardware/esp14.md)
5253
* [STM8S105Discovery: Evaluation board made my ST](hardware/stm8disco.md)
53-
4. [Ways to define a pin mapping](pin_mapping.md)
54-
5. [Installing and using the SDCC compiler](sdcc.md)
55-
6. [Using the SPL with SDCC and sduino](spl.md)
56-
7. [C preprocessor macro magic](macro.md)
54+
5. [Ways to define a pin mapping](pin_mapping.md)
55+
6. [Using the SDCC compiler](sdcc.md)
56+
7. [Using the SPL with SDCC and sduino](spl.md)
57+
8. [C preprocessor macro magic](macro.md)
5758

5859

5960

@@ -117,18 +118,13 @@ Done! Your first STM8 based project is up and running!
117118
## Tools used
118119

119120
This project is based on free tools that are available for Linux, MacOS, and
120-
Windows. It uses the small devices C compiler (SDCC) for compiling,
121+
Windows. [Installation instructions](install.htmk)
122+
123+
It uses the small devices C compiler (SDCC) for compiling,
121124
[stm8flash](https://github.com/vdudouyt/stm8flash) for uploading the binary
122125
to the CPU, and simple Makefiles for the build process.
123126

124-
SDCC support for the STM8 is still quite fresh and not very mature. It
125-
improves significantly from version to version. Be sure to use
126-
[the latest snapshot build](http://sdcc.sourceforge.net/snap.php) from the
127-
[project site on sourceforge](http://sdcc.sourceforge.net/), not the older
128-
version that might be included in your distribution. Version 3.5.0 as
129-
included with ubuntu 16.04 is definitly too old and compilation will fail
130-
due to some compiler errors.
131-
[More information on installing and using SDCC](sdcc.md)
127+
[More information on using SDCC](sdcc.md)
132128

133129
Support for the Cosmic compiler under Windows and integration into the ST
134130
visual developer IDE might be possible, but is not done (yet?).
@@ -263,7 +259,7 @@ still very close to the C++ version and porting an existing application is
263259
not hard. Check out the [API migration guidelines](api.md) for details.
264260

265261

266-
### General communication
262+
### Libraries for general communication
267263

268264
#### SPI
269265
Real hardware-SPI up to 10MHz.
@@ -289,7 +285,7 @@ The standard serial interface.
289285

290286

291287

292-
### Display
288+
### Libraries for displays
293289

294290
#### LiquidCrystal
295291
Supports text LCD based on the HD44780 and compatibles, that includes almost
@@ -310,13 +306,11 @@ pixels. I2C support only. Based on the Adafruit-libray Adafruit_SSD1306.
310306
[API description](api/Mini_SSD.md)
311307

312308

313-
### Motor
309+
### Libraries for motor control
314310

315311
#### Stepper
316-
For stepper motors with 2, 4 or 5 phases. This library has a slightly
317-
diffent user interface than the usual singleton libraries. This allow it to
318-
handle more than one stepper per Sketch.
319-
[API description](api/Stepper.md)
312+
For stepper motors with 2, 4 or 5 phases. This library can handle multiple
313+
steppers per Sketch. [API description](api/Stepper.md)
320314

321315

322316
#### Servo
@@ -330,7 +324,7 @@ of timers: the library can control 12 servos using only 1 timer.
330324

331325
Floating point arithmetics is supported by the SDCC standard library, but it
332326
comes at a pretty high cost in terms of code space and CPU load. This is how
333-
much the generated code grows by add one single float operation instead of
327+
much the generated code grows by using a single float operation compared to
334328
using a long int:
335329

336330
Floating point operation |approx. code size
@@ -345,7 +339,7 @@ log10f() | 3437 Bytes
345339
The Arduino standard example '01. Basics/ReadAnalogVoltage' is a very simple
346340
simple program with only very little floating point arithmetics. But it
347341
already uses 7336 bytes of flash. A similar sketch using integer arithmetics
348-
result in much shorter code of only 3791 bytes.
342+
results in much more compact code occuping only 3791 bytes.
349343

350344
Float does work, but is better to be avoided and replaced by fixed point
351345
arithmetics whenever possible.
@@ -435,6 +429,9 @@ $1.60-$3.00 for an ATmega8.
435429
[sduino project website](https://tenbaht.github.io/sduino/):
436430
More in detail information about supported boards, tools and the API.
437431

432+
[Quick introduction to the Arduino.mk makefile]
433+
(http://hackaday.com/2015/10/01/arduino-development-theres-a-makefile-for-that/)
434+
438435
[PM0051](http://www.st.com/resource/en/programming_manual/cd00191343.pdf):
439436
STM8AF Flash programming manual
440437
[UM0470](http://www.st.com/resource/en/user_manual/cd00173911.pdf):

docs/install.md

Lines changed: 144 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,104 @@
11
# Installing the needed tools
22

3-
All tools are available for Linux, Windows and MacOS, most of them even for
3+
All tools are available for Linux, MacOS and Windows, most of them even for
44
Raspbian on a RaspberryPi.
55

6-
D
6+
SDCC support for the STM8 is still quite fresh and not very mature. It
7+
improves significantly from version to version. Be sure to use
8+
[the latest snapshot build](http://sdcc.sourceforge.net/snap.php) from the
9+
[project site on sourceforge](http://sdcc.sourceforge.net/), not the older
10+
version that might be included in your distribution.
11+
12+
713

814
## Linux
915

16+
Download the lastest snapshot build for SDCC from
17+
http://sdcc.sourceforge.net/snap.php and extract it under `/opt`.
18+
19+
mkdir /opt
20+
tar xvjf ~/Downloads/sdcc-snapshot* -C /opt
21+
22+
`make` is part of the standard repository for any Linux distribution.
23+
Example for Debian-type systems (like Ubuntu, Mint, Elementary etc.):
24+
25+
apt-get install make
26+
27+
`stm8flash` is included in the tools directory of this repository. Copy it
28+
to a convient place in your path, e.g. `/usr/local/bin`. To use it you might
29+
need to add a udev rule in order to access the USB port. Save this as root
30+
in in `/etc/udev/rules.d/99-stlink.rules`:
31+
32+
# ST-Link/V2 programming adapter
33+
34+
# ST-Link V1, if using a STM8S discovery board
35+
# important: It needs a special entry in /etc/modprob/blacklist
36+
ATTR{idVendor}=="0483", ATTR{idProduct}=="3744", MODE="0666", GROUP="plugdev"
37+
38+
# ST-Link/V2, the china adapter with the green plastic housing
39+
ATTR{idVendor}=="0483", ATTR{idProduct}=="3748", MODE="0666", GROUP="plugdev"
40+
1041

11-
easy.
1242

13-
apt-get install build-essentials
43+
## MacOS
44+
45+
Quite similar. [Install Homebrew](https://brew.sh/) if you haven't done it
46+
yet, than:
47+
48+
brew make
1449
mkdir /opt
1550
tar xvjf sdcc-snapshot* -C /opt
1651

17-
done.
52+
Not sure about stm8flash, I didn't try it. Have a look at the
53+
[stm8flash repository](https://github.com/vdudouyt/stm8flash).
54+
1855

1956

2057

2158
## Windows
2259

23-
Harder, as we need to install some package management first.
60+
Harder, but still possible. It is lacking all the tools, a package system to
61+
install them and even a file system concept where to store them. For
62+
convinience, I collected the bare minimum of needed tools in a
63+
[separate repository](https://github.com/tenbaht/sduino-windowstools).
64+
Download it and copy the directory tree into the sduino
65+
directory. Add the sduino/tools/bin directory to your path or move the files
66+
in there to a directory that is already in your path.
67+
68+
You are not bound to `stm8flash`, you can use the regular flash tool by ST
69+
as well.
70+
71+
72+
73+
### The individual pieces
74+
75+
All the tools in the convinience package are 32 bit. If you need the 64 bit
76+
versions you might have to collect them yourself.
77+
78+
You need SDCC, `make` with some basic tools and maybe `stm8flash`. Get SDCC
79+
from the project website. `make` is a standard tool included in either
80+
MinGW/Msys or cygwin. Both are fine, MinGW/Msys is smaller. `stm8flash` from
81+
the [stm8flash repository](https://github.com/vdudouyt/stm8flash).
82+
2483

25-
You need SDCC,
26-
make and git. SDCC from the project website, make and git are standard tools
27-
included in either MinGW or cygwin. Both are fine, MinGW is smaller.
2884

29-
SDCC:
85+
#### SDCC
3086

31-
1. Download the lastes snapshot build from http://sdcc.sourceforge.net/snap.php
32-
2. unzip into c:\\sduino
87+
1. Download the lastest snapshot build from http://sdcc.sourceforge.net/snap.php
88+
2. unzip into c:\sdcc (use a path name without whitespace)
3389

34-
[MinGW](http://www.mingw.org/wiki/MSYS)
90+
You only need support for the stm8. You can safely delete all the files
91+
related to the pic1x CPUs (that safes more than 90% of the used disk space
92+
and leaves only 20MB out of 240MB)
93+
94+
95+
#### MinGW
96+
97+
[MinGW/MSys](http://www.mingw.org/wiki/MSYS) and
98+
[cygwin](https://www.cygwin.com/) are both fine. cygwin aims to be an almost
99+
complete POSIX environment (which is nice, but we don't need it here). MinGW
100+
wants to be more compact and works with the native Windows API. That is good
101+
enough for this purpose.
35102

36103
1. Check the
37104
[MinGW Installation Notes](http://www.mingw.org/wiki/Getting_Started)
@@ -46,8 +113,70 @@ SDCC:
46113
command: `mingw-get install msys-base`
47114
6. Now `ls` or `make` should work.
48115

116+
For efficiency, the Makefile is configured to use dash instead of bash as a
117+
shell. `egrep` is replaced by `grep -E`. The bare minimum of tools you will
118+
need to run the Arduino.mk makefile:
119+
120+
dash make
121+
awk cat cut expr grep head ls mkdir sed tr uname which
122+
123+
124+
125+
126+
#### stm8flash
127+
128+
A precompiled windows binary was in the stm8flash repository for a while but
129+
got removed at one point. I used an
130+
[old version](https://github.com/vdudouyt/stm8flash/raw/39b1a9ec1dd26030065c3e476fc3b7b89626e21d/stm8flash.exe)
131+
of the file. You might prefer to compile your own version from the
132+
[stm8flash repository](https://github.com/vdudouyt/stm8flash) using either
133+
MinGW or cygwin. For compiling, you will need the libusb windows binary:
134+
http://libusb.info/ (I used the MinGW32 dll)
135+
136+
137+
138+
139+
### General problems using Windows
140+
141+
It works, but using the Arduino.mk makefile with Windows is slow. **Very**
142+
slow. Painfully slow. Compiling-the-Blink-example-takes-about-40-seconds
143+
kind of slow. Yes, seriously. No kidding. 40 seconds. Measured on a 3GHz
144+
machine with 4GB RAM.
145+
146+
There is no easy fix, the underlying problem is a fundamental one. It is not
147+
about the compilation itself, it is the way Makefiles are written and
148+
executed. The whole concept relies on forking subprocesses for all the shell
149+
calls. Unfortunately, there is nothing like a fork in Windows and to work
150+
around that is painfully slow.
151+
152+
It would be great if somebody could manage to modify the original Arduino
153+
build system to support non-C++-builds. Or to integrate it somehow into the
154+
STVD IDE. Or replace the painfully slow parameter checking part of the
155+
makefile (that causes the majority of forking) by a single shell script that
156+
gets called by the makefile and delivers the results in no time. Or use
157+
[cmake](www.cmake.org). Or whatever.
158+
159+
Until than the least annoying way out might be using a virtual machine
160+
running a simple Linux system. Ubuntu Mate or a basic Debian install for
161+
example. Virtual Box is great for this purpose and freely available.
162+
163+
164+
165+
## Possible improvements
166+
167+
### All-inclusive packages
49168

50-
git:
51-
https://git-for-windows.github.io/
169+
One of the big convinience points of the Arduino project are the
170+
easy-to-install all-inclusive packages without any external dependencies.
171+
They don't require any prior knowledge to set up a full cross-compiler tool
172+
chain.
52173

174+
Something like that would be very nice for the STM8 as well, but I didn't go
175+
that far. You still have to do some work yourself. You definitly need the
176+
compiler SDCC. `stm8flash` is a simple tool to transfer the compiled program
177+
to the CPU, but any other flash tool supporting the SWIM protocol will do.
178+
The build process is controlled by `make`. It is a standard tool with any
179+
UNIX system but available for windows as well.
53180

181+
Alternative ways of controlling the build process exist, but then you are
182+
on your own to set it up.

sduino/Arduino.mk

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,11 @@ else
317317
ifeq ($(ARCHITECTURE),sam)
318318
ARDUINO_ARCH_FLAG = -DARDUINO_ARCH_SAM
319319
else
320-
ARDUINO_ARCH_FLAG = -DARDUINO_ARCH_$(shell echo $(ARCHITECTURE) | tr '[:lower:]' '[:upper:]')
320+
ifeq ($(ARCHITECTURE),stm8)
321+
ARDUINO_ARCH_FLAG = -DARDUINO_ARCH_STM8
322+
else
323+
ARDUINO_ARCH_FLAG = -DARDUINO_ARCH_$(shell echo $(ARCHITECTURE) | tr '[:lower:]' '[:upper:]')
324+
endif
321325
endif
322326
endif
323327
endif
@@ -867,7 +871,7 @@ endif
867871
ifeq ($(strip $(NO_CORE)),)
868872
ifndef MONITOR_BAUDRATE
869873
ifeq ($(words $(LOCAL_PDE_SRCS) $(LOCAL_INO_SRCS)), 1)
870-
SPEED = $(shell egrep -h 'Serial[._]begin *\([0-9]+\)' $(LOCAL_PDE_SRCS) $(LOCAL_INO_SRCS) | sed -e 's/[^0-9]//g'| head -n1)
874+
SPEED = $(shell grep -E -h 'Serial[._]begin *\([0-9]+\)' $(LOCAL_PDE_SRCS) $(LOCAL_INO_SRCS) | sed -e 's/[^0-9]//g'| head -n1)
871875
MONITOR_BAUDRATE = $(findstring $(SPEED),300 1200 2400 4800 9600 14400 19200 28800 38400 57600 115200)
872876
endif
873877

sduino/Common.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ else
8181
endif
8282

8383
ifeq ($(CURRENT_OS),WINDOWS)
84-
ifneq ($(shell echo $(ARDUINO_DIR) | egrep '^(/|[a-zA-Z]:\\)'),)
84+
ifneq ($(shell echo $(ARDUINO_DIR) | grep -E '^(/|[a-zA-Z]:\\)'),)
8585
echo $(error On Windows, ARDUINO_DIR must be a relative path)
8686
endif
8787
endif

0 commit comments

Comments
 (0)