33Getting started on the STM8 CPU the easy way by using an Arduino-like
44programming API.
55
6- This project makes the most important features of the Arduino API available
7- for the STM8S. It is based on free tools that are available for Linux,
8- MacOS, and Windows: SDCC, make, and stm8flash .
6+ This project is based on free tools that are available for Linux, MacOS, and
7+ Windows: SDCC, make, and stm8flash. Since it's based on the SDCC Small
8+ Devices compiler, I called it "Small Devices -uino" or "Small-duino" .
99
10- Since it's based on the SDCC Small Devices compiler, I called it "Small
11- Devices -uino" or "Small-duino".
10+ It fully integrates with the Arduino IDE or can be used
11+ independently (GUI-less) with very easy Makefiles based on the amazing
12+ [ Arduino.mk makefile] ( https://github.com/sudar/Arduino-Makefile ) by
13+ [ Sudar] ( http://sudarmuthu.com> ) .
1214
1315This project is not supposed to be “better than Arduino”. It’s purpose
1416is to give you a head start into a different CPU architecture if you happen
@@ -29,147 +31,85 @@ forum. It will help to catch my attention to prefix your topic with
2931"[ sduino] ".
3032
3133
32- ## Table of Contents
33-
34- * [ Project Website] ( https://tenbaht.github.io/sduino/ )
35- * [ Usage example] ( #usage )
36- * [ Supported hardware] ( #supported-hardware )
37- * [ Why use a STM8 instead of an ATmega?] ( #why-use-a-stm8-instead-of-an-atmega )
38- * [ Library support] ( #library-support )
39- * [ Compatibility with the Arduino world] ( #compatibility-with-the-arduino-world )
40-
41-
42-
43-
44- ## Usage example
45-
46- * Preview: IDE integration is on the way now! It already works for Linux (and
47- probably MacOS), Windows is to follow soon*
48-
49- If you have ever used the Arduino environment before you will feel at home
50- right away, despite this project beeing based on a makefile rather than the
51- full Arduino IDE. But don't be afraid, it is based on the amazing
52- [ Arduino.mk makefile] ( https://github.com/sudar/Arduino-Makefile ) by
53- [ Sudar] ( http://sudarmuthu.com> ) to control the build process, that makes
54- everything very easy.
55-
56- First, let's make an LED blink using the Blink example from Arduino:
57-
58- ``` c
59- /*
60- Blink
61- Turns on an LED on for one second, then off for one second, repeatedly.
34+ ## Installation
6235
63- This example code is in the public domain.
64- */
36+ Starting with version 0.3.0 automatic IDE integration is supported via the
37+ Arduino Boards Manager. This is the recommanded way of installation now. For
38+ a manual non-IDE installation please check the full [ installation
39+ instructions] ( https://tenbaht.github.io/sduino/install/ ) .
6540
66- #include < Arduino.h>
41+ Arduino IDE versions 1.8.5 and 1.6.13 are tested, but any version >=1.6.6
42+ should work.
6743
68- // Pin 13 has an LED connected on most Arduino boards.
69- // Pin 3 for the STM8S103 break out board
70- // give it a name:
71- int led = LED_BUILTIN;
44+ Supported Systems:
45+ * Linux 64 bit: Tested on Ubuntu 16.04
46+ * Linux 32 bit: Tested on Ubuntu 16.04
47+ * Windows: Tested on Windows 7. Sduino might work on XP (not tested), but
48+ the ST-Link/V2 driver is not available anymore for XP.
49+ * MacOS: Not tested, but should be very close to working. Will need a manual
50+ install, but IDE integration should be easy now. Any volunteers?
7251
73- // the setup routine runs once when you press reset:
74- void setup () {
75- // initialize the digital pin as an output.
76- pinMode (led, OUTPUT);
77- }
52+ Start the Arduino-IDE. In File->Preferences, Settings tab, enter
53+ https://github.com/tenbaht/sduino/raw/master/package_sduino_stm8_index.json
54+ as an Additional Boards Manager URL.
7855
79- // the loop routine runs over and over again forever:
80- void loop () {
81- digitalWrite (led, HIGH); // turn the LED on (HIGH is the voltage level)
82- delay (1000); // wait for a second
83- digitalWrite (led, LOW); // turn the LED off by making the voltage LOW
84- delay (1000); // wait for a second
85- }
86- ```
56+ Open Tools->Board:...->Boards Manager. Find Sduino by typing 'sd' into
57+ the search line. Click on the list entry, Click on Install.
8758
88- All we need for a full build is this very basic ` Makefile ` :
59+ Now you should find a new entry "STM8S Boards" in the list at
60+ Tools->Board:... Choose * STM8S103F3 Breakout Board* from the list, open the
61+ standard Blink example from File->Examples->01. Basics->Blink and compile it
62+ by hitting 'Verify'.
8963
90- ``` make
91- BOARD_TAG = stm8sblue
9264
93- include ../../sduino/sduino.mk
94- ```
9565
96- Compile and upload it :
66+ ### Uploading to the board
9767
98- make upload
68+ To upload the compiled sketch to the hardware you need an ST-Link/V2
69+ compatible flash programmer. They are very cheap, starting at $2.50 on
70+ Aliexpress or eBay.
9971
100- Done! Your first STM8 based project is up and running!
72+ #### ST-Link/V2 for Linux
10173
74+ Required lines in /etc/udev/rules.d/99-stlink.rules:
10275
103- # # Supported hardware
76+ # ST-Link/V2 programming adapter
10477
105- Anything with an STM8S103 or STM8S003 should work. For example, the
106- 70-cent-[STM8S103 breakout boards](https ://tenbaht.github.io/sduino/hardware/stm8blue),
107- [ESP14 Wifi boards](https ://tenbaht.github.io/sduino/hardware/esp14),
108- or even the [W1209 thermostat boards](https ://www.aliexpress.com/wholesale?SearchText=w1209)
109- that are abundant on aliexpress and Amazon. All you need to get started is a
110- simple ST-Link/V2 compatible flash programmer, available for less then $3
111- from China.
78+ # ST-Link V1, ST-Discovery boards
79+ ATTR{idVendor}=="0483", ATTR{idProduct}=="3744", MODE="0666", GROUP="pl
11280
113- The STM8 series by ST might be the cheapest CPUs on the market while still
114- being as powerful as the ATmega series. That makes them every Chinese
115- engineer's darling and chances are pretty good that you will find an '003 if
116- you crack open any cheap appliance like an irrigation, temperature, or
117- charging controller.
81+ # ST-Link/V2, the china adapter with the green plastic housing
82+ ATTR{idVendor}=="0483", ATTR{idProduct}=="3748", MODE="0666", GROUP="pl
11883
119- The '003 or '103 CPUs feature a 16MHz internal oscillator, 8kB flash, 1kB
120- RAM and 128 or 640 byte EEPROM. They both include a UART, SPI, I2C, PWM,
121- five 10 bit ADC inputs, 3 timers, and up to 14 I/O pins - quite similar to
122- an Atmel ATmega8 as it was used on the first Arduino boards.
12384
124- Support for the more powerful
125- [STM8S105 Discovery board](https ://tenbaht.github.io/sduino/hardware/stm8sdiscovery)
126- is very fresh, but should work now. At least Blink.c works already. These
127- amazing $9 boards offer even more resources, come with a build-in flash
128- programmer and are very similar to an Arduino Uno with an ATmega328 CPU.
12985
130- Find more information here : [Supported Boards](https://tenbaht.github.io/sduino/hardware)
86+ #### ST-Link/V2 for Windows
13187
88+ Download and install the ST-Link/v2 driver ** before you plug in the flash
89+ tool** : [ STSW-LINK009 driver download]
90+ (http://www.st.com/en/development-tools/stsw-link009.html ) (Registration
91+ required, but very easy)
13292
13393
134- # # Why use a STM8 instead of an ATmega?
94+ #### Serial upload
13595
136- The fairly new ESP-14 module includes a STM8S003F3P6. Wifi and a
137- programmable I/O-CPU for just over two dollars - that might be the most
138- compelling reason to get started on the STM8S series. Apart from pure
139- curiosity and eagerness to learn something new, of course.
96+ Most larger STM8 CPUs (unfortunately not the popular STM8S103) even come
97+ with a builtin bootloader. Support for programming via a simple serial
98+ adapter for these devices is planned, but not implemented yet.
14099
141- The simple STM8S103F breakout boards are powerful and dirt cheap. They cost
142- well under one dollar. You can get three boards and one flash programmer
143- together for well under five dollars on http ://www.aliexpress.com/ ,
144- including shipping from China.
145100
146- The major downside is the lack of information and community support for the
147- STM8. The community support and the sheer number of existing libraries for
148- all kinds of sensors and hardware is outstanding in the Arduino world. If
149- you just want to get something done, go for an Arduino board. Nothing will
150- give you faster and easier results.
151101
152- For commercial use the STM8S offers some interesting advantages :
153-
154- **Motor control** : The STM8 has a strong focus on motor and position control
155- systems. Things you need to handle yourself on an ATmega are implemented in
156- hardware and work independently of the state of the software. There is even
157- hardware support for quadrature encoders as used in position sensors and
158- rotary encoders.
159-
160- **Low power modes** : The numbers in the datasheets don't look that different,
161- but in real life the STM8 can be powered two or three times longer using the
162- same battery capacity due to the finer control on the power modes (very,
163- very careful programming required).
102+ ## Compatibility with the Arduino world
164103
165- **Value for the money** : 40 to 60 cents for a STM8 with 14 I/O pins compared to
166- $1.60-$3.00 for an ATmega8.
104+ Unfortunatly there is no free C++ compiler for the STM8. This makes it
105+ impossible to do a full 1:1 port of the whole enviroment as is has been done
106+ for the STM32 and the ESP8266.
167107
168- **Upgrade path** : The peripheral units of the STM8 are identical or at least
169- very, very similar to the ones used with the STM32 family of 32 bit
170- ARM-Cortex CPUs. This makes it is relatively easy to migrate existing
171- software between the 8- and the 32-bit world. This is quite unique among the
172- other CPUs .
108+ This is not a drop-in replacement for an AVR, but thanks to some C
109+ preprocessor magic the programming API is still very, very similar and it is
110+ often enough to just move over the opening bracket of the class
111+ instanciation statement and to replace the dot in a method call for an
112+ underscore .
173113
174114
175115
@@ -185,24 +125,3 @@ HD44780 controller.
185125
186126For more sophisticated output there are libraries for Nokia-5110-type
187127graphical LCDs and SSD1306-based graphical OLED displays.
188-
189-
190-
191- # # Compatibility with the Arduino world
192-
193- I adopted the Arduino core functionality for the STM8S to set up a simple
194- programming environment. But unfortunatly there is no free C++ compiler
195- for these CPUs. This makes it impossible to do a full port of the whole
196- enviroment and integrate it with the Arduino IDE and build system as it
197- has been done for the STM32 and the ESP8266.
198-
199- This is not a drop-in replacement for an AVR, but the programming API is
200- still very, very similar. Thanks to some C preprocessor magic it is often
201- enough to just move over the opening bracket of the class instanciation
202- statement and to replace the dot in a method call for an underscore.
203-
204- The whole Arduino build system is deeply based on the assumption of
205- processing C++ source files. I am not sure if it would be even possible to
206- configure a build process based only on C files without modifing the IDE
207- sources. This makes a full IDE integration very unlikely.
208-
0 commit comments