33Getting started on the STM8 CPU the easy way by using an Arduino-like
44programming API.
55
6- The SPL (standard peripheral library) [ offered by
7- ST] ( http://www.st.com/en/embedded-software/stsw-stm8069.html ) is very
8- powerful and very similar to the one used for the STM32 CPU series offering
9- a relatively easy upgrade path in case a project outgrows the capabilities
10- of the 8-bit STM8 series. But using that library is not very intuitive and
11- still requires a fairly detailed knowledge of the CPU internals.
12-
13- The Arduino project was very successful in offering a simplified API hiding
14- most of the complexity of embedded system programming while still allowing
15- for advanced programming technics.
16-
176This project makes the most important features of the Arduino API available
18- for the STM8S. I needed to port an existing project from an ATmega to a
19- better suited (read: cheaper) platform. As the project is based on some
20- Arduino libraries porting parts of the Arduino environment was the logical
21- first step. After doing that porting the firmware was finished in a
22- couple of days.
23-
24- Find more in detail information about the supported boards, needed tools and
25- the library APIs on the
7+ for the STM8S. It is based on free tools that are available for Linux, MacOS, and
8+ Windows.
9+
10+ Please find more detailed information about the supported boards, the needed tools
11+ and the library APIs on the
2612[ project documentation files] ( https://github.com/tenbaht/sduino/blob/master/docs/index.md ) .
2713
28- All you need to get stated is a simple STM8S103F breakout board and a
29- ST-Link V2 compatible flash programmer. Three boards and one flash
30- programmer together are available for well under five dollars on
31- http://www.aliexpress.com/ .
3214
33- * Amazing!*
15+
16+
17+ ## Table of Contents
18+
19+ * [ Project Website] ( blob/master/docs/index.md )
20+ * [ Usage example] ( #usage )
21+ * [ Installation] ( #installation )
22+ * [ Supported hardware] ( #supported-hardware )
23+ * [ Why use a STM8 instead of an ATmega?] ( #why-use-a-stm8-instead-of-an-atmega )
24+ * [ Compatibility with the Arduino world] ( #compatibility-with-the-arduino-world )
25+ * [ Current status and to-do list] ( #current-status-and-to-do-list )
26+ * [ Further reading and application notes] ( #further-reading-and-application-notes )
3427
3528
3629
3730## Usage
3831
3932If you have ever used the Arduino environment before you will feel at home
40- right away. The compilation is controlled by a makefile based on the amazing
33+ right away, despite this project beeing based on a makefile rather than the
34+ full Arduino IDE. But don't be afraid, it is based on the amazing
4135[ Arduino.mk makefile] ( https://github.com/sudar/Arduino-Makefile ) by
42- [ Sudar] ( http://sudarmuthu.com> ) .
36+ [ Sudar] ( http://sudarmuthu.com> ) to control the build process, that makes
37+ everything very easy.
4338
4439Let's blink an LED using the Blink example from Arduino:
4540
46- ```
41+ ``` c
4742/*
4843 Blink
4944 Turns on an LED on for one second, then off for one second, repeatedly.
@@ -89,37 +84,101 @@ Done! Your first STM8 based project is up and running!
8984
9085
9186
92- # # Tools used
9387
94- This project is based on free tools that are available for Linux, MacOS, and
95- Windows. It uses the small devices C compiler (SDCC) for compiling,
88+ # # Installation
89+
90+ This project uses the small devices C compiler (SDCC) for compiling,
9691[stm8flash](https ://github.com/vdudouyt/stm8flash) for uploading the binary
97- to the CPU, and simple Makefiles for the build process.
92+ to the CPU, and simple Makefiles for the build process. Support for the
93+ Cosmic compiler under Windows and integration into the ST visual developer
94+ IDE might be possible, but is not done (yet?).
95+
96+ This is a quick overview for the installation on a Linux system. Check the
97+ [installation instructions](https ://github.com/tenbaht/sduino/blob/master/docs/install.md)
98+ for other systems.
99+
100+
101+ Download and extract the
102+ [lastest snapshot build for SDCC](http ://sdcc.sourceforge.net/snap.php) to
103+ `/opt` :
104+
105+ sudo mkdir /opt
106+ sudo tar xvjf ~/Downloads/sdcc-snapshot* -C /opt
107+
108+ Make sure make is available :
109+
110+ sudo apt-get install make
111+
112+ Download/clone this repository somewhere convinient (but separate from your
113+ existing Arduino files, at least for now) :
114+
115+ git clone
[email protected] :tenbaht/sduino.git
116+
117+ compile an example sketch :
98118
99- SDCC support for the STM8 is still quite fresh and not very mature. It
100- improves significantly from version to version. Be sure to use
101- [the latest snapshot build](http ://sdcc.sourceforge.net/snap.php) from the
102- [project site on sourceforge](http ://sdcc.sourceforge.net/), not the older
103- version that might be included in your distribution. Version 3.5.0 as
104- included with ubuntu 16.04 is definitly too old and compilation will fail
105- due to some compiler errors.
106- [More information on installing SDCC](blob/master/docs/sdcc.md)
119+ cd sduino/sduino/examples/01.Basics/Blink
120+ make
121+
122+
123+ More details and instructions for MacOS and Windows in the
124+ [installation instructions](https ://github.com/tenbaht/sduino/blob/master/docs/install.md).
107125
108- Support for the Cosmic compiler under Windows and integration into the ST
109- visual developer IDE might be possible, but is not done (yet?).
110126
111127
112128
113129# # Supported hardware
114130
115131[STM8S103 breakout board](blob/master/docs/hardware/stm8blue.md) :
116- works
132+ works.
133+ [ESP14 Wifi board](blob/master/docs/hardware/esp14.md) : works.
134+ [STM8S105 Discovery board](blob/master/docs/hardware/stm8disco.md) :
135+ not supported yet, but work in progress.
117136
118- [ESP14 Wifi board](blob/master/docs/hardware/esp14.md) :
119- untested, but expected to work.
137+ Find more information here : [Supported Boards](blob/master/docs/hardware.md)
120138
121- [STM8S105 Discovery board](blob/master/docs/hardware/stm8disco.md) :
122- not supported yet, but work in progress.
139+
140+
141+ # # Why use a STM8 instead of an ATmega?
142+
143+ The fairly new ESP-14 module includes a STM8S003F3P6. Wifi and a
144+ programmable I/O-CPU for just over two dollars - that might be the most
145+ compelling reason to get started on the STM8S series. Apart from pure
146+ curiosity and eagerness to learn something new, of course.
147+
148+ The simple STM8S103F breakout boards are powerful and dirt cheap. They cost
149+ well under one dollar. You can get three boards and one flash programmer
150+ together for well under five dollars on http ://www.aliexpress.com/ ,
151+ including shipping from China.
152+
153+ *Amazing!*
154+
155+ The major downside is the lack of information and community support for the
156+ STM8. The community support and the sheer number of existing libraries for
157+ all kinds of sensors and hardware is outstanding in the Arduino world. If
158+ you just want to get something done, go for an Arduino board. Nothing will
159+ give you faster and easier results.
160+
161+ For commercial use the STM8S offers some interesting advantages :
162+
163+ **Motor control** : The STM8 has a strong focus on motor and position control
164+ systems. Things you need to handle yourself on an ATmega are implemented in
165+ hardware and work independently of the state of the software. There is even
166+ hardware support for quadrature encoders as used in position sensors and
167+ rotary encoders.
168+
169+ **Low power modes** : The numbers in the datasheets don't look that different,
170+ but in real life the STM8 can be powered two or three times longer using the
171+ same battery capacity due to the finer control on the power modes (very,
172+ very careful programming required).
173+
174+ **Value for the money** : 40 to 60 cents for a STM8 with 14 I/O pins compared to
175+ $1.60-$3.00 for an ATmega8.
176+
177+ **Upgrade path** : The peripheral units of the STM8 are identical or at least
178+ very, very similar to the ones used with the STM32 family of 32 bit
179+ ARM-Cortex CPUs. This makes it is relatively easy to migrate existing
180+ software between the 8- and the 32-bit world. This is quite unique among the
181+ other CPUs.
123182
124183
125184
@@ -132,22 +191,20 @@ enviroment and integrate it with the Arduino IDE and build system as is
132191has been done for the STM32 and the ESP8266.
133192
134193This is not a drop-in replacement for an AVR, but the programming API is
135- still very, very similar. Adopting existing libraries from C++ to C for
136- use with the simplified C API is often easy and can be done in a matter of
137- minutes, depending on the degree of dependency on specific hardware
138- features.
139-
140- The whole Arduino build system is deeply based on the assumption of C++
141- source files. I am not sure if it would be even possible to configure a
142- build process based only on C files. This makes a full IDE integration
143- very unlikely.
194+ still very, very similar. Adopting existing libraries from C++ to C for use
195+ with the simplified C API is often easy and can be done quite fast,
196+ depending on the degree of dependency on specific hardware features.
144197
145- Using a converter/compiler like `cfront` to translate from C++ to C might be
146- an option.
198+ The whole Arduino build system is deeply based on the assumption of
199+ processing C++ source files. I am not sure if it would be even possible to
200+ configure a build process based only on C files without modifing the IDE
201+ sources. This makes a full IDE integration very unlikely.
147202
203+ Using a converter/compiler like
204+ [cfront](https ://en.wikipedia.org/wiki/Cfront) to translate from C++ to C
205+ might be an option.
148206
149207
150- # # Current status and to-do list
151208
152209# # Current status and to-do list
153210
@@ -195,6 +252,7 @@ module WCharacter
195252module WString
196253
197254
255+ # ### Unresolved problems
198256
199257The compile environment needs to detect which interrupts are actively used
200258and link only the needed ones into the binary. See test/digitalWrite :
@@ -204,33 +262,14 @@ routines are pulled into the binary by the interrupt table in main.c.
204262
205263
206264
207- # # Why use a STM8 instead of an ATmega?
208-
209- The fairly new ESP-14 module includes a STM8S003F3P6. Wifi and a
210- programmable I/O-CPU for just over two dollars - that might be the most
211- compelling reason to get started on the STM8S series. Apart from pure
212- curiosity and eagerness to learn something new, of course.
265+ # # Alternative solutions
213266
214- The community support and the sheer number of existing libraries for all kinds
215- of sensors and hardware is outstanding in the Arduino world. If you just
216- want to get something done, go for an Arduino board. Nothing will give you
217- faster and easier results.
218-
219- For commercial use the STM8S offers some interesting advantages :
220-
221- **Motor control** : The STM8 has a strong focus on motor and position control
222- systems. Things you need to handle yourself on an ATmega are implemented in
223- hardware and work independently of the state of the software. There is even
224- hardware support for quadrature encoders as used in position sensors and
225- rotary encoders.
226-
227- **Low power modes** : The numbers in the datasheets don't look that different,
228- but in real life the STM8 can be powered two or three times longer using the
229- same battery capacity due to the finer control on the power modes (very,
230- very careful programming required).
231-
232- **Value for the money** : 40 to 60 cents for a STM8 with 14 I/O pins compared to
233- $1.60-$3.00 for an ATmega8.
267+ The SPL (standard peripheral library) [offered by
268+ ST](http ://www.st.com/en/embedded-software/stsw-stm8069.html) is very
269+ powerful and very similar to the one used for the STM32 CPU series offering
270+ a relatively easy upgrade path in case a project outgrows the capabilities
271+ of the 8-bit STM8 series. But using that library is not very intuitive and
272+ still requires a fairly detailed knowledge of the CPU internals.
234273
235274
236275
@@ -249,6 +288,7 @@ Using the analog-to-digital converter of the STM8S microcontroller
249288
250289Many examples and presentations about the STM8S :
251290https ://github.com/VincentYChen/STM8teach
291+ It contains the SPL examples from ST, the most useful resource on the STM8 :
252292https ://github.com/VincentYChen/STM8teach/tree/master/code/Project/STM8S_StdPeriph_Examples
253293
254294Using the ADC :
@@ -259,20 +299,3 @@ https://sourceforge.net/p/oggstreamer/oggs-stm8-firmware-001/ci/master/tree/rx_r
259299
260300[AN3139](http ://www.st.com/resource/en/application_note/cd00262293.pdf):
261301Migration guideline within the STM8L familiy
262-
263-
264-
265-
266- # # Pin number mappings
267-
268- The Arduino environment uses its own pin numbering scheme independent from
269- the physical CPU pin numbers. Many Arduino sketches and libraries contain
270- hard-coded assumptions about the number of pins with special functions.
271- Ideally, all these numbers would be the same and all programs could be
272- compiled without changes.
273-
274- [Here](blob/master/docs/pin_mapping.md)
275- I discuss some possible pin mapping strategies and check how close we could
276- get the the ideal mapping. Unfortunatly, it turns out that a perfect mapping
277- is not possible.
278-
0 commit comments