Custom board compile error variant_MYBOARD.h does not exist

Hi,

I have developed a custom PCB with the STM32F042G6U6 microcontroller. Since there is no other board with this chip available, i need to make my own board definition. I followed the steps as described here, but upon compilation I get the error: fatal error: variant_MYBOARD.h: No such file or directory

To create the myboard.json file I copied the contents of the nucleo_f042k6.json board and changed the relevant fields. myboard.json is as follows:

{
  "build": {
    "cpu": "cortex-m0",
    "extra_flags": "-DSTM32F0 -DSTM32F042x6",
    "f_cpu": "48000000L",
    "mcu": "stm32f042g6u6",
    "product_line": "STM32F042x6",
    "variant": "STM32F0xx/F042G(4-6)U"
  },
  "connectivity": [
    "can"
  ],
  "debug": {
    "default_tools": [
      "jlink"
    ],
    "jlink_device": "STM32F042G6",
    "onboard_tools": [
      "jlink"
    ],
    "openocd_board": "st_nucleo_f0",
    "openocd_target": "stm32f0x",
    "svd_path": "STM32F042x.svd"
  },
  "frameworks": [
    "arduino",
    "cmsis",
    "stm32cube",
    "libopencm3"
  ],
  "name": "My Board",
  "upload": {
    "maximum_ram_size": 6144,
    "maximum_size": 32768,
    "protocol": "jlink",
    "protocols": [
      "jlink",
      "cmsis-dap",
      "stlink",
      "blackmagic",
      "mbed"
    ]
  },
  "url": "https://developer.mbed.org/platforms/ST-Nucleo-F042K6/",
  "vendor": "ST"
}

What is happening and how to resolve this?

Br,
Jan

The STM32Duino builder script tries to automatically infer the name of the to-be-used variant header from the name of the board definition file or the used MCU.

This scheme seems to fail for your board. In that case, you manually put the to-be-used header in the board definition.

Here’s also an example that contains a custom board definition along with a custom variant folder:

https://github.com/nikorainto/radiolib-lorawan-example

Oh. Actually, I would suggest not to create a custom variant (variant_XXX.h/.cpp) unless you really have a need for strong custom modifications. You can use the existing STM32F0xx/F042G(4-6)U/variant_generic.h and .cpp file already without creating your own variant, only a board definition.

{
  "build": {
    "arduino": {
      "variant_h": "variant_generic.h"
    },
    "cpu": "cortex-m0",
    "extra_flags": "-DSTM32F0 -DSTM32F042x6 -DARDUINO_GENERIC_F042G6UX",
    "f_cpu": "48000000L",
    "mcu": "stm32f042g6u6",
    "product_line": "STM32F042x6",
    "variant": "STM32F0xx/F042G(4-6)U"
  },
  "connectivity": [
    "can"
  ],
  "debug": {
    "default_tools": [
      "jlink"
    ],
    "jlink_device": "STM32F042G6",
    "onboard_tools": [
      "jlink"
    ],
    "openocd_board": "st_nucleo_f0",
    "openocd_target": "stm32f0x",
    "svd_path": "STM32F042x.svd"
  },
  "frameworks": [
    "arduino",
    "cmsis",
    "stm32cube",
    "libopencm3"
  ],
  "name": "My Board",
  "upload": {
    "maximum_ram_size": 6144,
    "maximum_size": 32768,
    "protocol": "jlink",
    "protocols": [
      "jlink",
      "cmsis-dap",
      "stlink",
      "blackmagic",
      "mbed"
    ]
  },
  "url": "https://developer.mbed.org/platforms/ST-Nucleo-F042K6/",
  "vendor": "ST"
}

File names etc. with respect to https://github.com/stm32duino/Arduino_Core_STM32/blob/main/variants/STM32F0xx/F042G(4-6)U.

If the generic clocking code is insufficient for your board (it does HSI48, no PLL), then you can place a

extern "C" void SystemClock_Config(void) {
  /* your custom init */
}

in your firmware code to overwrite the function. In anycase though, the internal clock should always work.

1 Like