Mbed: Failed to extract configuration for custom board

I have created a custom embedded board, but when I try to build for mbed, platformio shows this error message:

CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/Clicker2_for_STM32.html
PLATFORM: ST STM32 8.0.0 > Clicker 2 for STM32
HARDWARE: STM32F407VGT6 168MHz, 128KB RAM, 1MB Flash
DEBUG: Current (stlink) External (blackmagic, jlink, stlink)
PACKAGES:

  • framework-mbed 6.60200.200722 (6.2.0)
  • toolchain-gccarmnoneeabi 1.90201.191206 (9.2.1)

Collecting mbed sources…
Detected custom target file
Failed to extract configuration for CLICKER2_FOR_STM32.
It might not be supported in the this Mbed release.
=========================================================================================================================================== [FAILED] Took 0.95 seconds ===========================================================================================================================================
The terminal process “C:\Users\chrigrat.platformio\penv\Scripts\platformio.exe ‘run’” terminated with exit code: 1.

platformio.ini:

[env:Clicker2_for_STM32]
platform = ststm32
board = Clicker2_for_STM32
framework = mbed
board_build.mbed.ldscript = $PROJECTSRC_DIR/TARGET_STM32F407xG/device/TOOLCHAIN_GCC_ARM/STM32F407XG.ld
build_flags = 
    -I$PROJECTSRC_DIR/TARGET_STM32F407xG
    -I$PROJECTSRC_DIR/TARGET_STM32F407xG/device
    -I$PROJECTSRC_DIR/TARGET_STM32F407xG/TARGET_CLICKER2_FOR_STM32

custom_targets.json:

{
    "Clicker2_for_STM32": {
      "inherits": [
          "MCU_STM32"
      ],
      "core": "Cortex-M4F",
      "extra_labels_add": [
          "STM32F4",
          "STM32F407xG"
      ],
      "macros_add": [
          "STM32F407xG"
      ],
      "config": {
          "clock_source": {
              "help": "Mask value : USE_PLL_HSE_EXTC (need HW patch) | USE_PLL_HSE_XTAL | USE_PLL_HSI",
              "value": "USE_PLL_HSE_XTAL|USE_PLL_HSI",
              "macro_name": "CLOCK_SOURCE"
          }
      },
      "detect_code": [
          "1234"
      ],
      "device_has_add": [
          "SERIAL_ASYNCH",
          "FLASH",
          "MPU"
      ],
      "device_name": "STM32F407VG"
    }
  }

board/Clicker2_for_STM32.json:

{
  "build": {
      "core": "stm32",
      "cpu": "cortex-m4",
      "extra_flags": "-DSTM32F4 -DSTM32F407xx -DSTM32F40_41xxx",
      "f_cpu": "168000000L",
      "mcu": "stm32f407vgt6",
      "variant": "CLICKER2_FOR_STM32",
      "product_line": "STM32F407xx",
      "zephyr": {
         "variant": "stm32f407"
      }
  },
  "debug": {
    "default_tools": [
      "stlink"
    ],
    "jlink_device": "STM32F407VG",
    "openocd_board": "stm32f407vg",
    "openocd_target": "stm32l4x",
    "svd_path": "STM32F40x.svd"
  },
  "frameworks": [
      "arduino",
      "mbed",
      "cmsis",
      "spl",
      "libopencm3",
      "stm32cube",
      "zephyr"
  ],
  "platforms": [
      "ststm32"
  ],
  "name": "Clicker 2 for STM32",
  "upload": {
      "maximum_ram_size": 131072,
      "maximum_size": 1048576,
      "protocol": "stlink",
      "protocols": [
        "jlink",
        "stlink",
        "blackmagic",
        "mbed"
      ]
  },
  "url": "https://www.mikroe.com/clicker-2-stm32f4",
  "vendor": "Mikroe"
}

Files in src/TARGET_STM32F407xG are copied from .platformio\packages\framework-mbed@6.51504.200716\targets\TARGET_STM\TARGET_STM32F4\TARGET_STM32F407xG (which uses the same uC) and edited to fit the new board.

the whole project can be checked out here: Bitbucket
How can this be fixed?

I updated the custom_targets.json file using the F4DISCOVERY board definition as a template:

{
    "Clicker2_for_STM32": {
        "inherits": ["FAMILY_STM32"],
        "core": "Cortex-M4F",
        "extra_labels_add": [
            "STM32F4",
            "STM32F407",
            "STM32F407xG",
            "STM32F407VG"
        ],
        "supported_toolchains": ["ARM", "uARM", "GCC_ARM", "IAR"],
        "config": {
            "clock_source": {
                "help": "Mask value : USE_PLL_HSE_EXTC (need HW patch) | USE_PLL_HSE_XTAL | USE_PLL_HSI",
                "value": "USE_PLL_HSE_XTAL|USE_PLL_HSI",
                "macro_name": "CLOCK_SOURCE"
            },
            "usb_speed": {
                "help": "USE_USB_OTG_FS or USE_USB_OTG_HS or USE_USB_HS_IN_FS",
                "value": "USE_USB_OTG_FS"
            }
        },
        "device_has_add": ["ANALOGOUT", "TRNG", "FLASH"],
        "release_versions": ["2", "5"],
        "device_name": "STM32F407VG"
    }
}

now mbed reports a different error:

CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/Clicker2_for_STM32.html
PLATFORM: ST STM32 8.0.0 > Clicker 2 for STM32
HARDWARE: STM32F407VGT6 168MHz, 128KB RAM, 1MB Flash
DEBUG: Current (stlink) External (blackmagic, jlink, stlink)
PACKAGES:
 - framework-mbed 6.60200.200722 (6.2.0)
 - toolchain-gccarmnoneeabi 1.90201.191206 (9.2.1)
Collecting mbed sources...
Detected custom target file
mbed build API internal error
target Clicker2_for_STM32 has an incomplete target definition
=========================================================================================================================================== [FAILED] Took 0.81 seconds ===========================================================================================================================================
The terminal process "C:\Users\chrigrat\.platformio\penv\Scripts\platformio.exe 'run'" terminated with exit code: 1.

I did some poking around inside the mbed framework and I think I have found where this problem comes from.
In .platformio\packages\framework-mbed\tools\targets\__init__.py, function def get_resolution_order(json_data, target_name, order, level=0), the key FAMILY_STM32 cannot be found in the collection of target descriptions. It seems as if the .platformio\packages\framework-mbed\targets\targets.json file is not considered when constructing the target object.

I created an issue for this: custom targets: target {} has an incomplete target definition · Issue #19 · platformio/builder-framework-mbed · GitHub

Hum, I remember I had problems as well for a custom board when switching to PIO MBED 6.
Tried to add this line just after core-M4F definition:
"default_toolchain": "GCC_ARM",

For the key world “FAMILY_STM32”, indeed it doesn’t work anymore for MBED6, you have to change it to “MCU_STM32”, a custom target example for PIO here.

For now I don’t even get to the point where the compiler starts working, but I’ll keep that in mind in case I have further issues.

this causes a different error message:

Failed to extract configuration for CLICKER2_FOR_STM32.
It might not be supported in the this Mbed release.

Ok, I get MBED working from your original bitbucket repository, I just had to edit custom_targets.json:

image

  • name of you target in capital letters
  • change inherit to MCU_STM32

But now there is compile issues with BUTTON1 definition, I don’t know if it is related ^^

You are building for mbedos 6.2.0 now where in the previous topic you were on the 5.X release right?

that was it! mbed does not report errors on the custom target any more.
I fixed the definition of BUTTON1 (and some other pin definitions, repo is updated). Compilation starts now, but compiling the files inside the TOOLCHAIN_* directories fails:

Compiling .pio\build\Clicker2_for_STM32\src\TARGET_STM32F407xG\device\TOOLCHAIN_GCC_ARM\startup_stm32f407xx.o
src\TARGET_STM32F407xG\device\TOOLCHAIN_ARM\startup_STM32F407xx.S: Assembler messages:
src\TARGET_STM32F407xG\device\TOOLCHAIN_ARM\startup_STM32F407xx.S:1: Error: junk at end of line, first unrecognized character is `*'
[...]
Compiling .pio\build\Clicker2_for_STM32\src\TARGET_STM32F407xG\device\TOOLCHAIN_IAR\startup_stm32f407xx.o
src\TARGET_STM32F407xG\device\TOOLCHAIN_ARM\startup_STM32F407xx.S:12: Error: junk at end of line, first unrecognized character is `*'
[...]
src\TARGET_STM32F407xG\device\TOOLCHAIN_ARM\startup_STM32F407xx.S:80: Error: bad instruction `dcd DMA1_Stream1_IRQHandler'

and many more lines like this. (I was following platform-ststm32/examples/mbed-rtos-custom-target at master · platformio/platform-ststm32 · GitHub setting up the project)

correct, I had an issue with pio update before but managed to solve it, and am now using mbed 6.2.0

1 Like

Delete the TOOLCHAIN_ARM folders or anything that is not TOOLCHAIN_GCC, otherwise it will attempt to assemble .S assembly files meant for the ARM assembler programm with the GCC assemler (as). Same goes for IAR and related.

almost there:

Generating LD script .pio\build\Clicker2_for_STM32\STM32F407XG.ld.link_script.ld
Linking .pio\build\Clicker2_for_STM32\firmware.elf
c:/users/gregor/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: .pio/build/Clicker2_for_STM32/src/TARGET_STM32F407xG/device/TOOLCHAIN_GCC_ARM/startup_stm32f407xx.o:(.isr_vector+0x0): multiple definition of `g_pfnVectors'; .pio/build/Clicker2_for_STM32/FrameworkMbed/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F407xG/TOOLCHAIN_GCC_ARM/startup_stm32f407xx.o:(.isr_vector+0x0): first defined here 
c:/users/gregor/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: .pio/build/Clicker2_for_STM32/src/TARGET_STM32F407xG/device/TOOLCHAIN_GCC_ARM/startup_stm32f407xx.o: in function `FPU_IRQHandler':
C:\Users\Gregor\Documents\PlatformIO\Projects\platformio-clicker2-for-stm32/src\TARGET_STM32F407xG\device\TOOLCHAIN_GCC_ARM/startup_stm32f407xx.S:132: multiple definition of `Default_Handler'; .pio/build/Clicker2_for_STM32/FrameworkMbed/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F407xG/TOOLCHAIN_GCC_ARM/startup_stm32f407xx.o:C:\Users\Gregor\.platformio\packages\framework-mbed\targets\TARGET_STM\TARGET_STM32F4\TARGET_STM32F407xG\TOOLCHAIN_GCC_ARM/startup_stm32f407xx.S:132: first defined here
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\Clicker2_for_STM32\firmware.elf] Error 1

is it possible to avoid having TOOLCHAIN_GCC_ARM etc in src\TARGET_STM32F407xG\device altogether and using the files from .platformio\packages\framework-mbed\targets\TARGET_STM\TARGET_STM32F4\TARGET_STM32F407xG instead? maybe via build_flags and board_build.mbed.ldscript parameters in platformio.ini?

board_build.mbed.ldscript = $PROJECTSRC_DIR/TARGET_STM32F407xG/device/TOOLCHAIN_GCC_ARM/STM32F407XG.ld
build_flags = 
    -I$PROJECTSRC_DIR/TARGET_STM32F407xG
    -I$PROJECTSRC_DIR/TARGET_STM32F407xG/device
    -I$PROJECTSRC_DIR/TARGET_STM32F407xG/TARGET_CLICKER2_FOR_STM32

Mhmm the startup source files are double;

Mbed-os already provides support for the general microcontroller line TARGET_STM32F407xG where the device folder and objects.h already exist, so you just need the TARGET_<board> folder. I think the reference project needs this because mbed-os doesn’t have support for the TARGET_STM32L452xE series itself and thus the extra folders and files are needed?

Anyways if I just remove the one startup .s file from the device folder I get

Generating LD script .pio\build\Clicker2_for_STM32\STM32F407XG.ld.link_script.ld
Linking .pio\build\Clicker2_for_STM32\firmware.elf
Checking size .pio\build\Clicker2_for_STM32\firmware.elf
Building .pio\build\Clicker2_for_STM32\firmware.bin
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=         ]   7.3% (used 9616 bytes from 131072 bytes)
Flash: [          ]   2.9% (used 30856 bytes from 1048576 bytes)
========================= [SUCCESS] Took 387.69 seconds =========================

that’s it! thank you! I removed the folder entirely and cleaned up platformio.ini. I also fixed the openocd configuration, now I can upload and debug as well.