You are viewing an older revision! See the latest version

mbed SDK porting

The porting of the mbed SDK to a new target is divided in three steps:

  1. Add the new target to the build system
  2. Add a CMSIS module for the given target
  3. Implement the mbed library drivers for the given target

The source code of the mbed SDK (tools + libraries) is available in this repository: https://github.com/mbedmicro/mbed

Before starting the mbed SDK porting, you might want to familiarize with the mbed library internals first.

Build System

Adding a new target to the build system is as easy as adding a new Target class to this python module: workspace_tools/targets.py

For example, this is the Target class for the LPC1768:

class LPC1768(Target):
    def __init__(self):
        Target.__init__(self)
        
        self.core = "Cortex-M3"
        self.vendor = "nxp"
        
        self.supported_toolchains = ["ARM", "GCC_ARM", "GCC_CS", "GCC_CR", "IAR"]

An instance of this new Target class has to be added to the TARGETS list:

TARGETS = [
    LPC2368(),
    LPC1768(),
    LPC11U24(),
    KL25Z()
]

When scanning for source code to be compiled, directories named like one of the TARGETS are considered "target specific" and get included only if they match with the desired microcontroller target name.

CMSIS Module

Each target has its standalone CMSIS directory under its vendor directory, for example:

The content of the CMSIS folder for a given target is usually provided by the CMSIS-CORE distributed by the silicon vendor itself.

The addition/modification that should be provided by the mbed SDK are:

  • Add a startup file and linker script for the specific target and toolchain, properly configuring the memory model.
  • Implement the cmsis_nvic API for dynamically setting the vector table.

mbed Library Drivers

Currently, all the target dependent code, implementing the mbed library drivers API, is divided in "vendors" directories, for example:

The reason behind this choice is that, very often, a silicon vendor is reusing the same digital IP for implementing the peripherals of its SoC, therefore its drivers usually share large part of the code.

Each target does have a standalone directory containing the headers defining many of its specific features, for example:

Probably the most important file, at the beginning of a port to a new target, is device.h.

device.h contains all the defines that enable/disable the inclusion of a certain set of peripherals in the mbed library.

When you start a port for a new target, setting all these defines to 0 will quickly allow you to compile the whole mbed library and start running tests.

Currently, the bare minimum you should implement to start running the first tests is:

Having this initial block in place will allow you to run simple programs like the mbed hello world:

#include "mbed.h"

DigitalOut myled(LED1);

int main() {
    while(1) {
        myled = 1;
        wait(0.2);
        myled = 0;
        wait(0.2);
    }
}

This is the full list of the mbed drivers API that could be potentially implemented for a target:


All wikipages