-
Notifications
You must be signed in to change notification settings - Fork 2k
Porting Guide
This page will give you an overview on how to proceed if you want port RIOT to a new platform. You will get an overview on the controller and board specific interfaces that need to be implemented and also some of the common pitfalls and misconceptions will be pointed out.
This guide assumes that the port is done in a 'gcc' environment making use of the 'newlib'. In case some other (or none at all) C standard library is used, the part describing the system calls is to be adapted accordingly.
Things to do first:
- know the name of your board and CPU (e.g. arduino-due/sam3x8e or msba2/lpc2387)
- know your silicon (get all documentation available)
- check you have the right toolchain
- get header files for CPU register definitions (you don't want to define them by hand)
- get the memory mapping, start addresses and sizes of flash and RAM memory
- how to get your binary on the device
- how to interact with the device (which
/dev/tty*
port) - test steps above by building - flashing - running - interacting with an example known to work
- RIOT/core
- RIOT/sys
- RIOT/drivers
- RIOT/cpu
Containing controller specific code - RIOT/boards
Containing board specific code, as pin definitions etc
The interfaces that have to be implemented in the CPU specific code are defined
in RIOT/core/include/arch/
. These cover functions that are essential for
the kernel to work like interrupt handling and thread management but also provides
interfaces for timers and a generic IO function and power mode management.
List of files:
atomic_arch.h
hwtimer_arch.h
io_arch.h
irq_arch.h
lpm_arch.h
reboot_arch.h
thread_arch.h
Implementing these interfaces is mandatory but not limited to these.
Documentation can be found here
Board specific implementations and definition should lie in its own directory
in RIOT/boards/$BOARDNAME
. These should cover e.g. GPIO definitions, UART
configurations and configurations providing CPU frequency and timer resolutions
needed.
Mandatory however are:
- Definitions of macros to control LEDs on the board:
#define LED_GREEN_ON ....
#define LED_GREEN_OFF ....
#define LED_GREEN_TOGGLE ....
#define LED_RED_ON ....
#define LED_RED_OFF ....
#define LED_RED_TOGGLE ....
- Definition of the CPU frequency:
#define F_CPU (24000000UL)
- Implementation of
board_init
function which gets call immediately after startup code and before kernel initialization.
void board_init(void)
{
....
}
Also, for each board there has to be a Makefile.include
providing information
on the development environment. This covers the toolchain and its flags, the tool
used to flash the binary and defines the CPU used for this board. Examples can
be found in RIOT/boards/
Recommended file structure:
BOARDNAME CPUNAME
| |
+->include +->include
| | | |
| +---->board.h | +---->cpu.h
| +---->periph_conf.h | +---->cpu-conf.h
+->board.c | +---->hwtimer_cpu.h
+->Makefile | +---->[cpu-specific-headers]
+->Makefile.include +->cpu.c
+->atomic_arch.c
+->hwtimer_arch.c
+->io_arch.c
+->irq_arch.c
+->lpm_arch.c
+->reboot_arch.c
+->thread_arch.c
+->[syscalls.c]
+->[startup.c|S]
+->[linkerscript.ld]
+->Makefile
+->Makefile.include
+->periph
|
+-->gpio.c
+-->timer.c
+-->uart.c
+-->...
Work is in progress to unify interfaces for drivers of peripheral hardware
modules. This will increase portability and provides consistent usage of drivers.
To follow the progress watch RIOT/drivers/include/periph/
- Create file and folder structure [TODO: prepare template to copy]
- write/find
linkerscript.ld
for your CPU - write/find startup code for your CPU (
startup.c
) - implement
LED_*
macros inboard.h
- implement UART driver
- implement timer driver and map to hwtimer
- implement stack setup and context switching in
thread_arch.c
- implement remaining CPU/core interfaces
- Congratulations, you have got a basic port