Hello,
We are looking at using the Nordic Semi nRF5340 part. We are currently running on the nRF52840 part. Is there a porting guide available and/or, does anyone have experience porting to the M33 core ?
Thx,
Aidan
Hello,
We are looking at using the Nordic Semi nRF5340 part. We are currently running on the nRF52840 part. Is there a porting guide available and/or, does anyone have experience porting to the M33 core ?
Thx,
Aidan
Hi Aiden,
(FYI not an ARM guy, just a fellow engineer I havenât ported nRF parts specifically, but I have ported other parts. When the vendor has an SDK for the part youâre interested in, the port is pretty easy, but you just have to understand the mbed internals and how the exporter and compiler picks the right files for the right target.
I wrote this guide for my company as a supplement to this doc from mbed: https://os.mbed.com/docs/mbed-os/v6.2/porting/porting-custom-boards.html
Now, they talk about some custom_boards.json file, and Iâve never gotten that to work. I just modify mbedâs targets.json directly to add my target.
My guide speaks to porting a Kinetis part, but the idea is similar. Since thereâre already nordic parts in mbed, itâs very easy to add a folder with any extra code you need for the nRF5340 (or the code might already be in there and you just have to get the right macros picked out!) Hereâs the guide:
ââ"
So, starting with adding a new part to the targets.json file⊠(If you donât know what that means,read the porting guideâ) The thing they donât mention is that âextra_labelsâ are parsed top to bottom, and it looks recursively. So if you look at, for instance,
MCU_K22F512, then you can traverse the directory structure under âtargetsâ in mbed-os ( the TARGET_ part is left out of the json keys ) as follows:
âFreescaleâ, â adds just the mbed_rtx.h header, note all the other folders under TARGET_Freescale arenât added ( yet ) b/c those folders start with TARGET_.
âMCUXpresso_MCUSâ, â this folder is NOW available for adding b/c the previous line added a folder that contains it. If you were to swap the two entries above, it would not work.The TARGET_MCUXpresso_MCUS folder adds a top layer of âgenericâ code that all the folders below will share. api folder has the mapping from mbed HAL to Kinetis SDK HAL for most drivers. Some other drivers are done farther down the hierarchy. Meaning each folder below will have to have its own copy of any file missing at this level. Example: serial.c"
KSDK2_MCUS", â I think this is legacy, ignore
âMCU_K22Fâ, â Next level. Here you see serial, spi, us_tickerâŠand these drivers are SPECIFIC to K22F. Also, you see a folder called drivers. Here is the meat of the driver layer. Theyâve basically copied the Kinetis SDK folder called âdriversâ into here. They all start with âfsl_â The mbed HAL files ( ex serial.c ) simply provide glue logic into the Kinetis HAL drivers. You can download this âdriversâ folder from NXP ( alongside some other folders you wonât need )
âMCU_K22F512â, < even more specific. The main thing you find here is âfsl_device_registers.hâ and some other h files that define the processor specific register map, defining symbols that the Kinetis SDK understands
âFRDMâ, < now weâve gone beyond processor specific to actual BOARD specific. Hence, all you see here is a pin map ( stuff like SD_SPI_OUT, etc ), and some clock management ( b/c each board clock file has to be tweaked based on what kind of crystal is on the board to provide a time base )
And thatâs itâŠyou start with generic files, and any c files they can get away with writing once for ALL processors. Then it gets more specificâŠwhat can they write that will work for all K22âs. Finally, you get to the specific flavor of K22, and you end up with a dumping ground for pretty much the entire Kinetis SDK, as generated BY NXP FOR that SPECIFIC processor. Finally, folders are added to support a specific board
Roughly, the layers are like so, but just remember, THE directories DONâT exactly match this hierarchyâŠbut the c files that are ultimately included DO:
mbed-hal
Kinetis SDK
Processor specific register map files
Board specific pin maps and clock stuff
So then, how to port? RoughlyâŠ
Add to the targets.json file. Donât forget to choose the correct macros for the FSL ( see a âcousinâ chip for an example )
Go to NXP and download the Kinetis SDK for your specific processor. Keep the folder handy, but out of the mbed tree for now. Youâll want to copy things in piecemeal.
Find out the âleast common denominatorâ between your proc and an mbed supported one. For my case, I added code starting at the TARGET_MCU_K22F level, so I was able to not have to write any new mbed_hal stuffâŠthe existing HAL code works because the Kinetis SDK has the same function names across processorsâŠjust different guts based on the specific part you picked when you downloaded the Kinetis SDK from NXP
Files of note: cmsis_nvic and cmsis arenât from the Kinetis SDK. You can copy them from another TARGET, but you MUST change the number of interrupt vectors to the correct one based on your proc
TOOLCHAIN: You can start with files provided via the Kinetis SDK. Pick the right toolchain when you download, and youâll get what you need. Now, mbed adds some special sauce to these files ( I think to support their bootloader? )âŠso youâll want to look at a similar file from another TARGET already in mbed, and kind of merge what you get from Kinetis SDK with what mbed. The design pattern was fairly obvious, theyâre just adding an extra section to the linker file
.s file stays more or less the same
.icf file needs the extra bootloader? related section
âAdditional IAR steps: Add correct key value pair to iar_definitions.âjson
Add your own Pinmap, clock files, etc, by copying from another TARGET and using it as a template. Youâll be changing those files to match your specific board.
âThe kinetis clock config tool ( MCUXpresso Config Tools ) is very useful. It will generate clock_config .h/.c for you based on your board and desired clock rates. Rename those files to fsl_clock_config.h ( b/c the rest of the API is going to be looking to include âfsl_clock_config.hâ ) These files will live at your âboardâ level TARGET_ folder ( the bottom most folder in the hierarchy )
Also to note about that toolâŠthe âautoâ divider calculation didnât really work for me. Kept yelling about conflicting constraints. I ended up just manually calculating all the dividers and suchâŠbut the GUI, rules checking, and code gen is still definitely worth it
Hello Alex,
Thanks for taking the time to reply and the detailed answer. I will dig into the detail you provided and take a look at the NXP m33 SDK.
Aidan
Hi Aidan,
Did you manage to get the nRF5340 up and running with Mbed OS? We are also looking into doing the porting now.
Thanks a lot in advance.
Kind regards,
Jeppe