STM8 RTOS for IAR Embedded Workbench

This week Atomthreads became the first RTOS to support Embedded Workbench (EWSTM8), the STM8 compiler launched by IAR last month. EWSTM8 provides a full professional-grade development and debug environment with support for hardware debuggers including the low cost STM8S Discovery platform. IAR offer a 30-day evaluation of the full version, as well as a time-unlimited 8KB “Kickstart” edition (with a few non-core features disabled).

As I described in the announcement for the Cosmic/STM8 port, the STM8 architecture contains only a very limited number of CPU registers, and IAR have worked around this by augmenting the CPU register set with 16 “virtual” registers (?b0 to ?b15) implemented in byte-addressable SRAM on the STM8, making up a total of 16 bytes. This was an interesting port from an RTOS development point of view, because the contents of these virtual registers must be maintained between threads in the same way that CPU registers are. In other words you must treat these locations in memory just as you would treat a CPU register from a context-switch point of view.

In the case of Atomthreads only the ?b8 to ?b15 virtual registers actually need to be saved and restored in the context-switch assembler routine. ?b0 to ?b7 are compiler scratch registers, and hence would always have been saved by the compiler (if necessary) before entry to the context-switch routine. The same can be said of the CPU registers which are also scratch registers that do not need to be preserved by a called function. However ?b8 to ?b15 are expected by the compiler to be preserved across function calls, and hence these 8 bytes needs to be saved and restored in the context-switch assembler.

The Cosmic STM8 compiler also uses a virtual register scheme, with three named locations (c_x, c_y and c_lreg) making up a total of 10 bytes. These must also be maintained separately between thread contexts, but because Cosmic treats all of the virtual registers as scratch registers, the Atomthreads context-switch assembler routine for Cosmic does not need to save and restore their contents. They are saved anyway by the C compiler when calling the context switch routine, and only if necessary, when making cooperative thread switches (where a thread schedules itself out), and are always saved by interrupt handlers when a preemptive thread switch occurs (where a thread has been interrupted and is being scheduled out).

Support for both of these STM8 compilers is now available in the Atomthreads development repository, available from atomthreads.com or direct from Github.

Bookmark and Share This Article
[del.icio.us] [Digg] [Google] [Reddit] [Slashdot] [StumbleUpon] [Technorati] [Twitter] [Yahoo!] [Email]
This entry was posted in Projects and tagged , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>