6 years, 6 months ago.

Custom Targets

Hi,

I'm trying to add custom targets to my mbed program. I followed the documentation on this page: https://docs.mbed.com/docs/mbed-os-handbook/en/latest/advanced/mbed_targets/

I added a "custom_targets.json" file to the root of my mbed project and defined the custom targets I needed. I then tried to statically compile the mbed-os library by calling:

mbed compile -t GCC_ARM -m CUSTOM_MCU library source=mbed-os build=./BUILD

I get an error saying that my CUSTOM_MCU is not a supported target... even though it's in my custom_targets.json file.

How does one add custom targets?

Additionally, if I have a program that must support various targets and features can I name a directory in my program TARGET_CUSTOM_MCU and it will only be built if the build target is CUSTOM_MCU? Similarly, can I preface other directories with FEATURE_CUSTOM to only build when the build target has the CUSTOM feature?

The documentation on the Testing page (https://docs.mbed.com/docs/mbed-os-handbook/en/latest/advanced/testing/#building-process) hints that this functionality exists:

"Test discovery also obeys the same rules that are used when building your project. This means that tests that are placed under a directory with a prefix such as TARGET_, TOOLCHAIN_ or FEATURE_ will only be discovered, built and run if your current configuration matches this prefix."

It seems that for 5.9.2 you can and should put the custom_targets.json file in the root directory of the project just as stated on the documentation page..

posted by Tomasz CEDRO 09 Jul 2018

1 Answer

6 years, 6 months ago.

So I've just tested this against Mbed OS 5.6 and creating a custom target through custom_targets.json works fine for me. I've put the file in the root of my project. Are you on an older version of Mbed OS?

Regarding FEATURE, yes this is included based on the name on file system and the list of features the board supports. You can set this either through the target configuration or by setting target.features_add in mbed_app.json.

Regarding TARGET... I think this is based on the extra_labels configuration.

Accepted Answer

I just synced my mbed-os fork with the official github so I'm up to date... I fixed the issue by moving the custom_targets.json file to the root directory of my mbed-os folder...

My project is structured like:

Project Directory
|
- custom_targets.json <------ BAD!!!
- mbed-os
--- custom_targets.json <----- MOVE HERE!!!
- mbed-dsp
- other libs
- families
--- device_1
--- device_2

For future reference to anyone who stumbles on this question:

mbed CLI will take into consideration your build configuration (targets, features, etc) when discovering files to build. For example, you can make reusable APIs for sensors/features and then have a HAL/device-specific driver by putting that code in TARGET_KL26 or whatever platform you're using.

This works with features as well ie: any code in a FEATURE_CUSTOM folder will only be built if the build target has the "custom" feature. There is one caveat - mbed CLI only allows a certain keywords to be in the features list. You can add your own by looking at init.py in mbed-os/tools/config/

I added a custom_config.py script in that directory and just appended my custom features list to the allowed_features global in init.py and then mbed CLI won't complain about your custom feature attributes.

posted by George Beckstein 06 Oct 2017