mirror of
https://github.com/kelvinlawson/atomthreads.git
synced 2026-03-02 02:23:15 +01:00
272 lines
11 KiB
Plaintext
272 lines
11 KiB
Plaintext
---------------------------------------------------------------------------
|
|
|
|
Library: Atomthreads
|
|
Author: Kelvin Lawson <info@atomthreads.com>
|
|
Website: http://atomthreads.com
|
|
License: BSD Revised
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
STM8 PORT - IAR COMPILER
|
|
|
|
This folder contains a port of the Atomthreads real time kernel for the
|
|
STM8 processor architecture. These instructions cover usage of Atomthreads
|
|
with the IAR Embedded Workbench compiler (EWSTM8).
|
|
|
|
Compiler-agnostic aspects of the usage of Atomthreads can be found in README.
|
|
|
|
Instructions for users of the other compilers are available in README-SDCC,
|
|
README-COSMIC and README-RAISONANCE.
|
|
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
PREREQUISITES
|
|
|
|
The port works out-of-the-box with the IAR compiler tools for building.
|
|
Applications are generated in ELF format and can be programmed and debugged
|
|
using the IAR Embedded Workbench GUI or the free STVP (visual programmer
|
|
tool). At this time there does not appear to be a command-line programmer
|
|
application suitable for use with STM8.
|
|
|
|
IAR Embedded Workbench for STM8 is a Windows-only application. For
|
|
users of other operating systems the IAR tools may work in environments
|
|
like Wine, but the USB programming tools are less likely to be supported.
|
|
Embedded Workbench for STM8 can, however, be run successfully within a VM
|
|
such as VirtualBox, including USB download and debug.
|
|
|
|
The core software prerequisites are therefore:
|
|
* IAR Embedded Workbench STM8
|
|
|
|
Use with alternative compiler tools may require some modification, but you
|
|
can easily replace the EWSTM8 IDE by your own favourite programmer if
|
|
required (e.g. STVP).
|
|
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
BUILDING THE SOURCE
|
|
|
|
You may build Atomthreads using whichever build environment you desire. For
|
|
your convenience we provide both a ready-rolled Makefile-based build system
|
|
and an Embedded Workbench (EWSTM8) project. The EWSTM8 project permits easy
|
|
building, programming and debugging, but does not easily support building
|
|
a wide range of application builds within the same project, which is
|
|
useful for building the numerous automated tests. For the automated tests
|
|
you may find it easier to use the Makefile which automatically builds all
|
|
automated tests.
|
|
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
BUILD VIA EWSTM8 PROJECT
|
|
|
|
For building applications using the EWSTM8 IDE you can use the sample
|
|
project file atomthreads-sample-iar.ewp. This builds a sample full
|
|
application which runs the "sem1" automated test. Applications can be
|
|
downloaded directly to the target hardware (e.g. STM8S-Discovery) and run
|
|
via the integrated debugger. You can start the application running, and
|
|
confirm that the LED flashes once per second (if running on an
|
|
STM8S-Discovery) to ensure that the test has passed.
|
|
|
|
This is also a good starting point for building your own applications:
|
|
simply modify the file tests-main.c which starts the test application.
|
|
You can run any of the other automated tests by replacing the file sem1.c
|
|
within the project by another of the tests within the atomthreads tests
|
|
folder. This is rather painful using a GUI interface due to the large
|
|
number of test files, and you may prefer to use the Makefile-based system
|
|
instead which builds all automated tests in one command.
|
|
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
BUILD VIA MAKEFILE
|
|
|
|
A Makefile is also provided for building the kernel, port and automated
|
|
tests. This is particularly useful for building the automated tests
|
|
because many different independent applications need to be built which is
|
|
not easily achieved within the EWSTM8 environment.
|
|
|
|
For a Windows system you can obtain a Make application suitable for use
|
|
with the IAR compiler from:
|
|
|
|
* http://www.cosmic-software.com/comp_utils/GNU_Make.zip
|
|
|
|
Assuming you install the above into C:\Program Files\GNU_MAKE, you
|
|
should set up your environment variables as follows:
|
|
|
|
* set PATH=%PATH%;C:\Program Files\GNU_MAKE;C:\Program Files\IAR Systems\Embedded Workbench 6.0\stm8\bin
|
|
* set MAKE_MODE=DOS
|
|
|
|
|
|
The full build is carried out using simply:
|
|
|
|
* make -f iar.mak
|
|
|
|
All objects are built into the 'build-iar' folder under ports/stm8. The
|
|
build process builds separate target applications for each automated test,
|
|
and appropriate .elf or .s19 files can be found in the build folder ready
|
|
for downloading to and running on the target. Because of the limited
|
|
resources on the STM8, and the large amount of automated tests, each test
|
|
is built and run as a separate application.
|
|
|
|
|
|
All built objects etc can be cleaned using:
|
|
|
|
* make -f iar.mak clean
|
|
|
|
|
|
The Atomthreads sources are documented using Doxygen markup. You can build
|
|
both the kernel and STM8 port documentation from this folder using:
|
|
|
|
* make -f iar.mak doxygen
|
|
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
PROGRAMMING MAKEFILE-BUILT APPLICATIONS TO THE TARGET DEVICE
|
|
|
|
When developing within EWSTM8, programs can be downloaded directly to the
|
|
target. If, however, you are building applications separately using a
|
|
Makefile or similar, then you are not able to program the application
|
|
using EWSTM8. None of the tools delivered by ST appear to be designed to
|
|
cater for those who build applications externally, but it is possible using
|
|
STVP.
|
|
|
|
The following development workflow can be used (note that these settings
|
|
apply to the STM8S-Discovery):
|
|
|
|
* Build app using Makefile.
|
|
* Open STVP and configure to use Swim ST-Link for CPU STM8105C6.
|
|
* Open application .s19 file and program using "Program All Tabs".
|
|
|
|
Unfortunately STVP does not have a command to reset and start the CPU
|
|
running, but it can be forced into doing so by reconfiguring the
|
|
programmer:
|
|
|
|
* Select "Configure ST Visual Programmer" from the Configure menu.
|
|
|
|
Your application should now be programmed and running.
|
|
|
|
If you wish to program and run another application then you can open and
|
|
program it in STVP, then use the Configure menu again to reset the
|
|
device and start it running.
|
|
|
|
Other programming tools may exist but are not apparent in the toolset
|
|
delivered for use the STM8S Discovery platform.
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
RUNNING THE AUTOMATED TESTS
|
|
|
|
Atomthreads contains a set of generic kernel tests which can be run on any
|
|
port to prove that all core functionality is working on your target.
|
|
|
|
The full set of tests can be found in the top-level 'tests' folder. The
|
|
Makefile builds each of these tests as independent applications in the
|
|
'build' folder. Run them individually using the STVP process described
|
|
above. For example to run the 'kern1.c' test use STVP to program and run
|
|
it.
|
|
|
|
You may also build the tests using the EWSTM8 project, but to run each
|
|
different test you must manually remove the previous test module (e.g.
|
|
kern1.c) and replace it with one of other tests, which can be quite time
|
|
consuming compared to building all tests in one command via the Makefile.
|
|
|
|
To view the test results, watch the LED on the STM8S-Discovery. This will
|
|
flash once per second if the test passed, and once every 1/8 second if the
|
|
test failed.
|
|
|
|
If you wish to use the UART, connect a serial debug cable to your target
|
|
platform (defaults to 9600bps 8N1). On starting, the test applications
|
|
print out "Go" on the UART. Once the test is complete they will print
|
|
out "Pass" or "Fail", along with other information if the test failed.
|
|
|
|
Most of the tests complete within a few seconds, but some (particularly
|
|
the stress tests) can take several seconds, so be patient.
|
|
|
|
The full suite of tests endeavours to exercise as much of the kernel code
|
|
as possible, and can be used for quick confirmation of core OS
|
|
functionality if you ever need to make a change to the kernel or port.
|
|
|
|
The test application main() is contained in tests-main.c. This initialises
|
|
the OS, creates a main thread, and calls out to the test modules. It also
|
|
initialises the UART driver for use by stdout.
|
|
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
WRITING APPLICATIONS
|
|
|
|
The easiest way to start a new application which utilises the Atomthreads
|
|
scheduler is to base your main application startup on tests-main.c. This
|
|
initialises the OS, sets up a UART and calls out to the test module entry
|
|
functions. You can generally simply replace the call to the test modules by
|
|
a call to your own application startup code.
|
|
|
|
Projects developed within EWSTM8 can be started using the sample project
|
|
atomthreads-sample-iar.ewp. If you wish to create your own EWSTM8 project
|
|
from scratch, then you should ensure you change the project settings for
|
|
both Debug and Release builds as follows:
|
|
|
|
* General Options -> Target -> Device: CPU part (e.g. "STM8S105C6")
|
|
* C/C++ Compiler -> Diagnostics: Suppress "Pa050"
|
|
* C/C++ Compiler -> Preprocessor -> Defined Symbols:
|
|
CPU part (e.g. "STM8S105")
|
|
Thread stack-checking if required ("ATOM_STACK_CHECKING")
|
|
For example "STM8S105, ATOM_STACK_CHECKING"
|
|
* Assembler -> Diagnostics: Suppress "Pa050"
|
|
* Repeat above for Debug and Release projects (you may want to
|
|
disable ATOM_STACK_CHECKING for Release builds).
|
|
|
|
Other options you may wish to change:
|
|
|
|
* Tools -> Options -> Editor -> EOL Characters: "Preserve". This preserves
|
|
the line endings, bearing in mind that the Atomthreads kernels works
|
|
with many host operating system toolchains.
|
|
* Options -> Debugger -> "ST Link" (e.g. for STM8S Discovery)
|
|
|
|
Add the .C and .S modules from the following folders:
|
|
* kernel
|
|
* ports/stm8
|
|
* ports/stm8s-periphs
|
|
|
|
Set include paths as appropriate.
|
|
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
IAR COMPILER VIRTUAL REGISTERS
|
|
|
|
The STM8 has only very few CPU registers, so the IAR compiler augments
|
|
them with sixteen "virtual" registers, which are simply locations in fast
|
|
memory. These registers are called ?b0 to ?b15.
|
|
|
|
The Atomthreads context switch for IAR/STM8 takes advantage of the fact
|
|
that all CPU and most virtual registers are automatically saved on the
|
|
stack by the compiler when calling out to C functions (and even then only
|
|
if necessary). Only the virtual registers ?b8 to ?b15 are expected to be
|
|
preserved by called functions, so these are the only registers that
|
|
callers to the context switch routine will not automatically save if
|
|
necessary.
|
|
|
|
For cooperative context switches (where a thread calls an OS kernel
|
|
function to schedule itself out), most registers will therefore already
|
|
be saved on a thread's stack if necessary. Only ?b8 to ?b15 actually have
|
|
to be saved in the context switch routine, making cooperative switches
|
|
potentially very cheap if few registers must be preserved.
|
|
|
|
For preemptive switches (where an ISR has interrupted a thread and wishes
|
|
to switch to a new thread), the interrupt handler prologue automatically
|
|
saves all CPU registers (actually done automatically by the CPU) and the
|
|
virtual registers ?b0 to ?b7. Still only the registers ?b8 to ?b15 have to
|
|
be saved by the context-switch routine, but in this case ?b0 to ?b7 and the
|
|
CPU registers are always saved on the thread's stack by the ISR prologue.
|
|
This is because the ISR has no knowledge of what registers the interrupted
|
|
thread was using, so we cannot take advantage of the potential for saving
|
|
fewer than the full set of registers that we achieve with cooperative
|
|
switches.
|
|
|
|
|
|
---------------------------------------------------------------------------
|