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:
- Add the new target to the build system
- Add a CMSIS module for the given target
- 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"]
CMSIS Module¶
Each target has its standalone CMSIS directory under its vendor directory, for example:
- libraries/mbed/vendor/Freescale/cmsis/KL25Z
- libraries/mbed/vendor/NXP/cmsis/LPC2368
- libraries/mbed/vendor/NXP/cmsis/LPC1768
- libraries/mbed/vendor/NXP/cmsis/LPC11U24
- libraries/mbed/vendor/NXP/cmsis/LPC812
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 proper 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:
- libraries/mbed/vendor/Freescale/capi/KL25Z
- libraries/mbed/vendor/NXP/capi/LPC2368
- libraries/mbed/vendor/NXP/capi/LPC1768
- libraries/mbed/vendor/NXP/capi/LPC11U24
- libraries/mbed/vendor/NXP/capi/LPC812
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:
- GPIO API
- us ticker API:
void us_ticker_init(void);
uint32_t us_ticker_read(void)
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: