PlatformIO Community

Custom Target for Mbed / Atmelsam

I’m trying to build for Mbed framework using a custom target. The instructions are clear and the sample project works fine for me.

However, when I add my desired target to custom_targets.json, the build tool claims “Cannot find the configuration file for your board!”. How can I correct that?

It seems like the Atmelsam build script isn’t looking in the project directory for custom_targets.json in the same way that the build script for NXP LPC1768 does.

Also, why does the working build choose “framework-mbed 5.51304.190826 (5.13.4)” and the non-working board build choose “framework-mbed 4.151.0 (1.51)”?

To reproduce:

  1. Download
  2. pio run

(PlatformIO, version 4.0.3)

Processing working_board (platform: nxplpc; framework: mbed; board: working_board)
Verbose mode can be enabled via `-v, --verbose` option
PLATFORM: NXP LPC 4.4.0 > Custom board based on NXP LPC1768
HARDWARE: LPC1768 96MHz, 64KB RAM, 512KB Flash
DEBUG: Current (cmsis-dap) On-board (cmsis-dap) External (blackmagic, jlink)
PACKAGES: toolchain-gccarmnoneeabi 1.70201.0 (7.2.1), framework-mbed 5.51304.190826 (5.13.4)
Collecting mbed sources...
Detected custom target file
LDF: Library Dependency Finder ->
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 4 compatible libraries
Scanning dependencies...
No dependencies
Compiling .pio/build/working_board/src/main.o
Linking .pio/build/working_board/firmware.elf
Building .pio/build/working_board/firmware.bin
Checking size .pio/build/working_board/firmware.elf
Memory Usage ->
DATA:    [=         ]   5.3% (used 3441 bytes from 65536 bytes)
PROGRAM: [=         ]   6.3% (used 33236 bytes from 524288 bytes)
==================================================================== [SUCCESS] Took 4.88 seconds ====================================================================

Processing adafruit_feather_m0_mbed (platform: atmelsam; framework: mbed; board: adafruit_feather_m0_mbed)
Verbose mode can be enabled via `-v, --verbose` option
PLATFORM: Atmel SAM 3.8.0 > Adafruit Feather M0 Mbed
HARDWARE: SAMD21G18A 48MHz, 32KB RAM, 256KB Flash
DEBUG: Current (atmel-ice) External (atmel-ice, blackmagic, jlink)
PACKAGES: toolchain-gccarmnoneeabi 1.70201.0 (7.2.1), framework-mbed 4.151.0 (1.51)
Cannot find the configuration file for your board! Please read instructions here /Users/frank/.platformio/packages/framework-mbed@4.151.0/platformio/README.txt
===================================================================== [FAILED] Took 0.46 seconds =====================================================================

Environment               Status    Duration
------------------------  --------  ------------
working_board             SUCCESS   00:00:04.877
adafruit_feather_m0_mbed  FAILED    00:00:00.465
=============================================================== 1 failed, 1 succeeded in 00:00:05.342 ===============================================================

Answer to one of the questions above: PLATFORMIO/platforms/atmelsam/platform.json contains dependency specifications that dictate what version of Mbed to use.

The problem is in atmelsam/builder/frameworks/mbed/, where PIO looks up the Mbed config of a board/variant. By adding a single line in the following section I was able to specify the variant in my adafruit_feather_m0_mbed.json custom board file.

variants_remap = util.load_json(
    join(FRAMEWORK_DIR, "platformio", "variants_remap.json"))
board_type = env.subst("$BOARD")
variant = variants_remap[
    board_type] if board_type in variants_remap else board_type.upper()

# Added the following line to override variant with property from board.json file:
variant = env.BoardConfig().get("build.variant", variant) 

mbed_config = get_mbed_config(variant)

It’s not full custom variant support, but at least with this change I can define a new board based on an existing variant and get it to build cleanly.

1 Like