|
1 | | -# Porting guide: adding target support to mbed OS 5 |
2 | | - |
3 | | -There are two typical ways to add target support to mbed OS: Either you'll be adding a [completely new microcontroller](#adding-a-new-microcontroller) and board, or you'll be adding a new board that contains an [already-supported microcontroller](#adding-a-new-board-or-module). |
4 | | - |
5 | | -There is a dependency on CMSIS-CORE and CMSIS-Packs, so make sure the microcontroller already has these available. |
6 | | - |
7 | | -## Adding a new microcontroller |
8 | | - |
9 | | -Add the empty target implementation reference to the working directory using: |
10 | | - |
11 | | -``` |
12 | | -mbed add mbed-os-example-new-target |
13 | | -cd mbed-os-example-new-target\mbed-os |
14 | | -git checkout master |
15 | | -git pull |
16 | | -git checkout -b my-new-target |
17 | | -git remote set-url origin https://github.com/USERNAME/mbed-os |
18 | | -cd .. |
19 | | -``` |
20 | | - |
21 | | -### Target description |
22 | | - |
23 | | -Add the target description to ```mbed-os\targets\targets.json``` |
24 | | - |
25 | | -``` json |
26 | | -"MCU_NAME": { |
27 | | - "inherits": ["Target"], |
28 | | - "core": "Cortex-M3", |
29 | | - "supported_toolchains": ["ARM", "GCC_ARM", "IAR"], |
30 | | - "extra_labels": ["VENDOR", "MCU_FAMILY", "MCU_NAME"], |
31 | | - "macros": [], |
32 | | - "device_has": ["SERIAL", "STDIO_MESSAGES"] |
33 | | -}, |
34 | | -"BOARD_NAME": { |
35 | | - "inherits": ["MCU_NAME"] |
36 | | -} |
37 | | -``` |
38 | | - |
39 | | -### Bootstrap code |
40 | | - |
41 | | -There are a number of files needed before a first successful compile. CMSIS-CORE files are needed for start-up and peripheral memory addresses as well as the linker scripts for ARM, IAR and GCC toolchains. These files are usually in the ```mbed-os\targets\TARGET_VENDOR\TARGET_MCU_FAMILY\TARGET_MCUNAME\device``` directory. |
42 | | - |
43 | | -If the microcontroller has a SYS_TICK the RTOS will configure this, so only a few macros are needed in ```mbed-os\targets\TARGET_VENDOR\mbed-rtx.h```. |
44 | | - |
45 | | -Some extensions to CMSIS-CORE are also required for dynamic vector relocation. ```mbed-os\targets\TARGET_VENDOR\TARGET_MCUNAME\cmsis.h``` is the entry point to the target for mbed OS software. This will include the vector relocation additions and device-specific headers that include CMSIS-CORE. A relocation routine is needed in ```mbed-os\targets\TARGET_VENDOR\TARGET_MCUNAME\cmsis_nvic.c and .h``` |
46 | | - |
47 | | -Now verify your target is identified by using ```mbed compile -m MCU_NAME -t <toolchain>```. This should compile. |
48 | | - |
49 | | -The next step is to enable the test harness dependencies. To run the test suite there is a minimum requirement of GPIO, microsecond ticker and serial implementation, all explained below. |
50 | | - |
51 | | -### GPIO |
52 | | - |
53 | | -The ```gpio_s``` is for referencing memory-mapped GPIO registers and passing related pin information or other IO operation data that the HAL needs. These structures are defined in ```objects.h```. The required implementation definition is in ```mbed-os\hal\gpio_api.h```. |
54 | | - |
55 | | -### SERIAL |
56 | | - |
57 | | -The ```serial_s``` is for referencing memory-mapped Serial registers and passing related pin and peripheral operation information data that the HAL needs. These structures are defined in ```objects.h```. The required implementation definition is in ```mbed-os\hal\serial_api.h```. |
58 | | - |
59 | | -### US TICKER |
60 | | - |
61 | | -The microsecond ticker is a system resource that is used for many API and other timing utilities. It needs a one microsecond resolution and should be implemented using a free-running hardware counter or timer with match register. |
62 | | -The required implementation definition is in ```mbed-os\hal\us_ticker_api.h```. |
63 | | - |
64 | | -At this point, we should be able to compile a handful of tests: |
65 | | - |
66 | | -``mbed test -m BOARD_NAME --compile -t <toolchain>`` |
67 | | - |
68 | | -To execute the tests you'll need to already support [mbed-ls](https://github.com/armmbed/mbed-ls). |
69 | | - |
70 | | -### All the others |
71 | | - |
72 | | -At this point, the HAL structure should be familiar as a programming model. There are many more APIs to implement, which are enabled by adding a ```device_has``` attribute to the MCU_NAME and then providing the implementation. |
73 | | - |
74 | | -## Adding a new board or module |
75 | | - |
76 | | -Coming soon. |
| 1 | +!{https://raw.githubusercontent.com/sg-/porting-guide/master/porting-quick.md} |
0 commit comments