-
Notifications
You must be signed in to change notification settings - Fork 178
Add content from PR #619 #625
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
1393960
ab77cde
7a0bf17
862668c
2576b1a
b9ef3f2
dbee003
24dfa01
8b562e6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,46 @@ | ||
<h2 id="target-port">Targets</h2> | ||
<h2 id="target-port">Porting targets</h2> | ||
|
||
Adding a new microcontroller to Arm Mbed OS 5 depends on CMSIS-CORE and CMSIS-Pack. Please make sure that the microcontroller already has these available. | ||
This document discusses requirements for porting Mbed OS to a derivative target of any one of the Mbed Enabled™ targets. To port the MCU to Mbed OS as well, along with a custom board based on the MCU, please follow our [more detailed porting guide](docs/development/reference/porting-targets.html). | ||
|
||
#### Adding a new microcontroller and board | ||
Adding a new microcontroller to Arm® Mbed OS 5 depends on CMSIS-CORE and CMSIS-Pack. The microcontroller must have these available. | ||
|
||
First fork the `mbed-os` repository on GitHub into your own user account. We will use the placeholder `USERNAME` to refer to your username in the following documentation, `MCU_NAME` to refer to the new microcontroller you are adding and `BOARD_NAME` to refer to the new board you are adding. Import an Mbed OS example, and add your fork of `mbed-os` using: | ||
[Mbed Cloud Client](https://cloud.mbed.com/docs/current) provides reference implementation for three Mbed Enabled targets: the K64F, NUCLEO_F429ZI and the UBLOX_EVK_ODIN_W2. You do not need to port Mbed OS or the Cloud Client if you are using one of these three boards. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not related to porting for Mbed OS (it's mbed cloud client only) and should be moved elsewhere. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @theotherjimmy :This is coming from the Cloud Client porting. There will be a section in the Cloud docs as well that points to this porting guide (correct?? @jen3andruska ). This is intended for folks who plan to (ultimately) port Cloud Client, but need Mbed OS running on their custom platform in the first place. Once they have Mbed OS running on their custom platform, users will link back to Cloud docs for the "rest" of the MCC porting (@AnotherButler : can you link to the MCC porting doc from here that @jen3andruska is working on?). This doc creates a bridge between Cloud porting and OS porting - which are both required for a custom platform. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ashok-rao I dont' think that it's worded well if that's the case. I also think that linking from the mbed-os docs to the cloud docs implies that to get mbed-os support you also need cloud support. I think it has much more potential to do harm in this way than it has the potential to do good by helping those porting cloud. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have to agree with @theotherjimmy. I'm not sure why we need to mention the fact that MCC implements porting for k64f or other platforms here. This is a document about porting Mbed-OS and I don't think we need to mention MCC ports available for Mbed-OS, it actually confuses me to read that in introduction. What I would suggest is create a section named "Related Links or Other reference" and may be we can capture things like "Also look into... MCC ports, HAL porting guides". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we mentioning MCC here, we are talking about porting the OS, after the OS is ported we can start porting the MCC. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @bulislaw : That's the ultimate goal. In order to reach the top floor (Pelion Cloud Client), we need to clear the ground floor (OS port running successfully on whatever board the customer has) .. and no probs if they use K64 / F429 / ODIN as these are already working in the examples.. however, the problem comes when they use an F429 MCU on a custom PCB (not NUCLEO) or a K64 (not FRDM) or ODIN (not EVK / MTB..) .. this guide should help them get Mbed OS running on those custom boards 1st. Then, they can move to PCC.. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not happy with the current wording which is confusing; as said above this page is about porting the OS. |
||
|
||
### Summary of steps | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we have one clear section per step? |
||
|
||
1. Add your target to `targets.json`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That assumes cloud porting, not the system. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't a new target needs to be added here anyways for building from CLI ? |
||
1. Identify your target’s features. | ||
1. Identify any existing parent targets. | ||
1. Identify macros required for your target's compilation. | ||
1. Identify supported compilers and the Mbed OS release version. | ||
1. Add the target entry in `targets.json`. | ||
1. Verify that you can now pass your target to `mbed compile`. | ||
1. Add your target port. | ||
1. Create the directory structure. | ||
1. Add an entry for the target in `mbed_rtx.h`. | ||
1. Add startup code, CMSIS headers, NVIC headers and **all** relevant drivers from the CMSIS specifications. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think a bold "all" here does anyone any good. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree with @theotherjimmy |
||
1. Implement APIs, HAL, the system clock configuration and any other additional clocks. | ||
1. Add toolchain-specific linker descriptions. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be good to mention the HAL tests we have under mbed-os\TESTS\mbed_hal which can be used to verify HAL porting. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup, a link would be valuable too |
||
1. Add peripherals and pin names for the target. | ||
1. Compile with CLI on a supported compiler. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CLI -> Mbed CLI |
||
|
||
### Target properties | ||
|
||
You can identify our sample target by the following: | ||
|
||
- Target build name `MY_BOARD_1`. | ||
- Vendor `MY_VENDOR`, device family `MY_FAMILY` and the device on the board `MY_DEVICE`. | ||
- A Cortex-M4F based core. | ||
- Porting for Mbed OS v5.x, which requires support for Arm Compiler 5, GCC Arm Embedded and IAR EWARM. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is changing, as we are adding ARMv8M platforms which only need to support ARMC6 for now. So, depending on Core Archicture we may support all of these compilers or ARMC6 only if its ARMv8M based core. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree. Let's add a line here for v8 only requirements. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is that requirement in the right place? Not sure whether you're documenting terminology or requirements |
||
- A serial (UART) interface connected to the CMSIS-DAP implementation. | ||
- Requirement that the macro `CPU_DEVICE_1` compiles the vendor-provided HAL for the device mounted on the board. | ||
- Requirement that the macro `FAMILY_MY_FAMILY` compiles the vendor-provided HAL for the family of the device. | ||
|
||
All of these requirements directly map to relevant tags in the `targets.json` entry for our target. This is shown in the following step. | ||
|
||
### Adding a new microcontroller and board | ||
|
||
First fork the `mbed-os` repository. This example uses the placeholder `USERNAME` to refer to your username in the following documentation, `MCU_NAME` to refer to the new microcontroller you are adding and `BOARD_NAME` to refer to the new board you are adding. Import an Mbed OS example, and add your fork of `mbed-os` using: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "your username" -> "your github username" Without that we could be refering to os.mbed.com or something else. |
||
|
||
``` | ||
mbed import mbed-os-example-blinky | ||
|
@@ -17,7 +53,7 @@ git branch my-new-target -u USERNAME | |
cd .. | ||
``` | ||
|
||
#### Target description | ||
### Target description | ||
|
||
Add the target description to `mbed-os\targets\targets.json` using keys that the [Adding and configuring targets section](/docs/development/tools/adding-and-configuring-targets.html) describes. We recommend that you run the [targets lint script](/docs/development/tools/adding-and-configuring-targets.html#style-guide) on your target hierarchy before submitting your pull request: | ||
|
||
|
@@ -34,9 +70,173 @@ Add the target description to `mbed-os\targets\targets.json` using keys that the | |
} | ||
``` | ||
|
||
#### HAL porting | ||
### Directory structure | ||
|
||
The target’s directory structure has the following hierarchy: | ||
|
||
- The top level lists the manufacturer. This is the same for all targets that a vendor supports. | ||
- The device family. This is specific to a family. | ||
- A specific device in the family. This only applies to the single device. | ||
- The specific board that uses the MCU in the previous level. You can use this for pin maps. | ||
|
||
``` | ||
/mbed-os/targets/TARGET_<Manf>/TARGET_<Device_Family>/TARGET_<specific_MCU>/TARGET_<specific_board>/ | ||
``` | ||
|
||
This sample implementation uses: | ||
|
||
``` | ||
/mbed-os/targets/TARGET_MY_VENDOR/TARGET_MY_FAMILY/TARGET_MY_DEVICE_1/TARGET_MY_BOARD_1/ | ||
``` | ||
|
||
### Entry in `mbed_rtx.h` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That looks good but shouldn't it go in |
||
|
||
The `mbed_rtx` header file defines the core requirements for the RTOS, such as clock frequency, initial stack pointer, stack size, task counts and other macros. This sample target has the following specifications: | ||
|
||
``` | ||
|
||
#elif defined(TARGET_MyTarget123) | ||
|
||
#ifndef INITIAL_SP | ||
#define INITIAL_SP (0x20030000UL) | ||
#endif | ||
|
||
#if defined(__CC_ARM) || defined(__GNUC__) | ||
#define ISR_STACK_SIZE (0x1000) | ||
#endif | ||
|
||
#ifndef OS_TASKCNT | ||
#define OS_TASKCNT 14 | ||
#endif | ||
#ifndef OS_MAINSTKSIZE | ||
#define OS_MAINSTKSIZE 256 | ||
#endif | ||
#ifndef OS_CLOCK | ||
#define OS_CLOCK 120000000 | ||
#endif | ||
``` | ||
|
||
Please refer to your chosen MCU's reference manual for these values. | ||
|
||
### Startup and HAL | ||
|
||
Ensure that the drivers are present at the correct level in the directory structure: | ||
|
||
1. Add startup code and CMSIS specific headers. You may obtain the startup code and other CMSIS specific headers from the device manufacturer or the CMSIS packs from KEIL®. | ||
1. Add peripherals to the `device_has_add` key in `targets.json` and include all relevant drivers for all these peripherals. | ||
1. Implement Mbed OS HAL APIs for all hardware peripherals mentioned in `device_has`. | ||
1. Ensure that `Objects.h` declares peripherals and is available in the `/api` directory. | ||
|
||
### Linker files | ||
|
||
Each supported toolchain listed in your new target's `supported_toolchains` configuration needs a linker file. Each compiler supports a different style of linker files with a different extension: | ||
|
||
- Add a scatter file, with the extension `.sct`, for Arm Compiler 5. | ||
- Add a linker script, with the extension `.ld`, for GCC Arm Embedded. | ||
- Add an IAR Linker file, with the extension `.icf`, for IAR EWARM. | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @AnotherButler : Can you please add: "You will also need to add the startup codes (*.s) in the respective directories as well for ARMCC, GCC and IAR." There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ashok-rao There is no reason that startup code has to be assembly, and that startup code cannot be shared between compilers. Assembly must have a capitol |
||
### Pin names | ||
|
||
Add peripheral names and pin names, following standard naming conventions for common peripherals. Define these pins in the `PinNames.h` header file at the board level. Please refer to the [sample directory structure](sample-directory-structure) for the directory structure. | ||
|
||
Define a default for each peripheral. Define the DAPLink serial pins as `STDIO_UART_RX` and `STDIO_UART_TX`. For example: | ||
|
||
```C | ||
#ifndef MBED_PINNAMES_H | ||
#define MBED_PINNAMES_H | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
typedef enum { | ||
PA_0 = 0x00, | ||
PA_1 = 0x01, | ||
PA_1 = 0x01, | ||
<snip> | ||
|
||
// Generic signals namings | ||
LED1 = PB_2, | ||
LED2 = PB_10, | ||
LED_RED = LED1, | ||
LED_BLUE = LED2, | ||
USER_BUTTON = PC_13, | ||
|
||
// Standardized button names | ||
BUTTON1 = USER_BUTTON, | ||
|
||
SERIAL_TX = PA_8, | ||
SERIAL_RX = PA_12, | ||
|
||
I2C_SCL = PA_17, | ||
I2C_SDA = PA_18, | ||
|
||
SPI_MOSI = PA_4, | ||
SPI_MISO = PA_7, | ||
SPI_SCK = PA_6, | ||
SPI_CS = PA_16, | ||
|
||
//DAPLink | ||
STDIO_UART_RX = SERIAL_RX | ||
STDIO_UART_TX = SERIAL_TX | ||
USBRX = STDIO_UART_RX, | ||
USBTX = STDIO_UART_TX, | ||
SWDIO = PA_26, | ||
SWCLK = PA_25, | ||
NTRST = PA_13, | ||
} PinName; | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif | ||
``` | ||
|
||
### Compiling with a supported compiler | ||
|
||
You can verify that the new board port compiles by using an [example application](/docs/development/tutorials/mbed-os-quick-start.html), and checking out the branch containing your port in the `mbed-os` subdirectory. | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @AnotherButler : Can you please add: "With the Mbed CLI, the command to use in the example's root directory is: mbed compile -t -m <YOUR_NEW_TARGET's_NAME> -c . And if you face any build errors at this point, please add any missing headers, add/remove peripherals as required, ensure the linker scripts & startup code are in place. For simplicity, you can start with only the serial peripheral and add other peripherals once the Mbed OS port builds successfully." There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @AnotherButler, @ashok-rao Don't add the |
||
### Sample directory structure | ||
|
||
Below is an example of all of the files that you would add for a target from vendor `MY_VENDOR`, with an MCU `MY_DEVICE_1`, from device family `MY_FAMILY_1`, mounted on the board `MY_BOARD_1` and supporting the `SERIAL` device: | ||
|
||
``` | ||
mbed-os | ||
└── targets | ||
└── TARGET_MY_VENDOR | ||
├── TARGET_MY_FAMILY | ||
│ ├── TARGET_MY_DEVICE_1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like this tree, I was explaining the structure this week to at least 2 issues regarding not having Can we use |
||
│ │ ├── TARGET_MY_BOARD_1 | ||
│ │ │ ├── PeripheralNames.h | ||
│ │ │ ├── PeripheralPins.c | ||
│ │ │ ├── PeripheralPins.h | ||
│ │ │ ├── clock_config.c | ||
│ │ │ ├── clock_config.h | ||
│ │ │ └── device.h | ||
│ │ ├── TOOLCHAIN_ARM | ||
│ │ │ ├── device.sct | ||
│ │ │ └── startup.S | ||
│ │ ├── TOOLCHAIN_GCC | ||
│ │ │ ├── device.ld | ||
│ │ │ └── startup.S | ||
│ │ ├── TOOLCHAIN_IAR | ||
│ │ │ ├── device.icf | ||
│ │ │ └── startup.S | ||
│ │ ├── clock.c | ||
│ │ ├── clock.h | ||
│ │ ├── uart.c | ||
│ │ ├── uart.h | ||
│ │ └── us_ticker.c | ||
│ └── api | ||
│ ├── Objects.h | ||
│ └── PortNames.h | ||
└── mbed_rtx.h | ||
``` | ||
|
||
### HAL porting | ||
|
||
There are many more APIs to implement. You enable the following APIs by adding a `device_has` attribute to the MCU_NAME target definition in `targets.json` and providing an implementation of the API declared in the API header. | ||
There are many more APIs to implement. You enable the following APIs by adding a `device_has` attribute to the `MCU_NAME` target definition in `targets.json`, and providing an implementation of the API declared in the API header. | ||
|
||
device_has | API header | ||
-----------------|------------------ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be useful to create a link for each of the below header files to actual files in mbed-os repo. Not a big deal, but would be convenient. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could at least make them a link to their respective porting pages. |
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That doesn't make any sense. This document is about porting the MCU... We are trying to merge two pages talking about slightly different thing. Oh and the
docs/development/reference/porting-targets.html
doesn't exists as far as i can tell.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the confusing part is "To port the MCU to Mbed OS as well, along with a custom board based on the MCU, please follow our more detailed porting guide. " ...
@AnotherButler : Would it be clear if we just mention "To port an MCU itself (rather than a derived target of the MCU), please refer to the detailed porting guide here" ?
Maybe we also need to mention clearly somewhere, what "porting an MCU" vs "porting a derived target" means as well.. before the start of this document.
@theotherjimmy .. thoughts??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where's the "more detailed porting guide"? Also, this page should address porting any new boards/MCU - not just a derivative.