Create a custom board using a board listed as not compatible with Mbed 6 (but was good for Mbed 2)

I have a rather old FRDM-K20D50M dev board, which I was hoping to reuse with Mbed-Studio (this board was once ok with MbedOS 2).

So when I plug it in via the OpenSDA connection, Mbed Studio still recognises the DAPlink connection. Happy days.

However, when I seek the build target it has the FRDM-K20D50M listed, but it is flagged as not compatible.

This is worse actually than not having it listed at all, because when I create a custom_targets.json and use the name FRDM-K20D50M, it still won’t accept.

So (first question) how do I delete that name from the unwanted list to allow me to create my custom target.

Personally, I cannot see why this board would be incompatible as it has same memory as an FRDM-KL25Z board (128 KB flash / 16 KB SRAM) and runs a wee bit faster, clocking at 50MHz rather than 48MHz for KL25Z.

All I have to do is change processor from M0 to, M4 for this board and then fiddle with macros.

So (2nd question) what are the steps after creating the custom_target file. What macro’s do I need to define. Then what about linking etc. to get it to flash onto the device.

Just to note that the documentation page does not look complete… it just stops at defining a custom_target. There has to be more.

Anyhow, this seems to me to be a good board to use to get my feet wet creating a custom target so any tips/advice will be gladly appreciated.



In my experience, there’re basically two steps to creating a custom target. The first is to create custom_targets.json in your project root folder, and add your target to it. We can look at the old target definition of your board from Mbed 5.15 to get a pretty good idea of what needs to go in there. I think it would be something like:

  "CustomK20D50M": {
        "inherits": ["Target"],
        "core": "Cortex-M4",
        "extra_labels": ["Freescale", "K20XX"],
        "is_disk_virtual": true,
        "supported_toolchains": ["GCC_ARM", "ARM"],
        "detect_code": ["0230"],
        "device_has": [
        "release_versions": ["5"],
        "device_name": "MK20DX128xxx5"

The next thing you need to do is create a directory called TARGET_CustomK20D50M in the root directory of your project and put the porting files needed for your custom target in there. It looks like, in Mbed 6, they completely removed the TARGET_K20XX folder from the sources. So you’ll probably need to add both the files from this folder and its K20D50M subfolder to the custom target directory.
Note that these target files are now several years old, so I have no idea if they will work with Mbed 6 out of the box or not. If you do get them working, though, you might want to post them as a custom target so anyone can use the K20D50M!

1 Like

Thanks! This is really helpful. I’ll let you know if I succeed. I have been experimenting, which is never a good idea. Hopefully I haven’t bricked the board… at the mo’ I’m getting the “mbed has crashed” blinking pattern. No doubt, I’ll find out soon enough with this new guidance.

You would be better off using Mbed2 online for the K20D50.
Since OS5 even with bare metal smaller targets suffer with too much flash and ram resources being used just to flash an LED.
Mbed Studio online should be okay too but haven’t tried it yet on the smaller devices.

I got it to compile after a few tweaks. There was a missing console_tx and console_rx for usb serial and a few missing lines of code but all resolvable.

However, I’m not sure if it’s my board (as in I damaged it in a previous hack attempt) or I’m still missing something as getting a fatal error after mbed studio uploads the binary.

++ MbedOS Error Info ++
Error Status: 0x80FF0144 Code: 324 Module: 255
Error Message: Assertion failed: !are_interrupts_enabled()
Location: 0x173F
File: ./mbed-os/hal/source/mbed_critical_section_api.c+54
Error Value: 0x0
For more info, visit:
-- MbedOS Error Info --

UPDATE: I just unplugged the device and uploaded the code from Mbed Studio again and it works! Happy days.

Seems ok with building bare metal or standard blinky. This is the result from blinky compile:

Elf2Bin: mbed-os-example-blinky
| Module               |     .text |   .data |     .bss |
| [lib]/c_w.l          |  4518(+0) |  16(+0) |  348(+0) |
| [lib]/libcppabi_w.l  |    44(+0) |   0(+0) |    0(+0) |
| anon$$obj.o          |    32(+0) |   0(+0) | 1024(+0) |
| main.o               |   308(+0) |   0(+0) |    0(+0) |
| mbed-os/cmsis        |  9634(+0) | 168(+0) | 6610(+0) |
| mbed-os/connectivity |   224(+0) |   0(+0) |    0(+0) |
| mbed-os/drivers      |    92(+0) |   0(+0) |    0(+0) |
| mbed-os/hal          |   708(+0) |   0(+0) |    2(+0) |
| mbed-os/platform     |  7275(+0) |  64(+0) |  341(+0) |
| mbed-os/rtos         |   430(+0) |   0(+0) |    0(+0) |
| mbed-os/targets      |  2195(+0) |   4(+0) |   12(+0) |
| Subtotals            | 25460(+0) | 252(+0) | 8337(+0) |
Total Static RAM memory (data + bss): 8589(+0) bytes
Total Flash memory (text + data): 25712(+0) bytes
Image: BUILD/K20D50M/ARMC6/mbed-os-example-blinky.bin

I am rather curious to learn why the K20D50 “device_has” does not include “USTICKER” in the targets json file.
If I do not include it then the compiler complains as functions like us_ticker_irq_handler are undefined.
If I do include USTICKER it compiles but then functions like timer and ticker do not work as crashes the MCU.
Also wait_us does not appear to work either.