Custom board : undefined references error during build

I’m encountering a build error while compiling a project with a custom similar to Rumba32 board using the STM32 platform and the ARM GCC toolchain in PlatformIO. The build fails with multiple “undefined reference” errors related to PinMap_TIM, SystemClock_Config, digitalPin, and others.

Here are the warnings and the error :

c:/users/cedella/.platformio/packages/toolchain-gccarmnoneeabi@1.90201.191206/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: .pio/build/rumba_custom/SrcWrapper/src/stm32/analog.cpp.o: in function `pwm_stop':
analog.cpp:(.text.pwm_stop+0x58): undefined reference to `PinMap_TIM'
c:/users/cedella/.platformio/packages/toolchain-gccarmnoneeabi@1.90201.191206/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: .pio/build/rumba_custom/SrcWrapper/src/stm32/hw_config.c.o: in function `hw_config_init':
hw_config.c:(.text.hw_config_init+0x12): undefined reference to `SystemClock_Config'
c:/users/cedella/.platformio/packages/toolchain-gccarmnoneeabi@1.90201.191206/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: .pio/build/rumba_custom/libFrameworkArduino.a(usbd_if.c.o): in function `USBD_SystemClockConfigFromResume':
usbd_if.c:(.text.USBD_SystemClockConfigFromResume+0xa): undefined reference to `SystemClock_Config'
c:/users/cedella/.platformio/packages/toolchain-gccarmnoneeabi@1.90201.191206/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: .pio/build/rumba_custom/libFrameworkArduino.a(wiring_digital.c.o): in function `pinMode':
wiring_digital.c:(.text.pinMode+0xb4): undefined reference to `digitalPin'
c:/users/cedella/.platformio/packages/toolchain-gccarmnoneeabi@1.90201.191206/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: wiring_digital.c:(.text.pinMode+0xbc): undefined reference to `PinMap_TIM'
c:/users/cedella/.platformio/packages/toolchain-gccarmnoneeabi@1.90201.191206/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: wiring_digital.c:(.text.pinMode+0xc0): undefined reference to `analogInputPin'
c:/users/cedella/.platformio/packages/toolchain-gccarmnoneeabi@1.90201.191206/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: .pio/build/rumba_custom/libFrameworkArduino.a(wiring_digital.c.o): in function `digitalWrite':
wiring_digital.c:(.text.digitalWrite+0x64): undefined reference to `digitalPin'
c:/users/cedella/.platformio/packages/toolchain-gccarmnoneeabi@1.90201.191206/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: wiring_digital.c:(.text.digitalWrite+0x70): undefined reference to `analogInputPin'
c:/users/cedella/.platformio/packages/toolchain-gccarmnoneeabi@1.90201.191206/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: .pio/build/rumba_custom/libFrameworkArduino.a(wiring_digital.c.o): in function `digitalRead':
wiring_digital.c:(.text.digitalRead+0x64): undefined reference to `digitalPin'
c:/users/cedella/.platformio/packages/toolchain-gccarmnoneeabi@1.90201.191206/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: wiring_digital.c:(.text.digitalRead+0x70): undefined reference to `analogInputPin'
c:/users/cedella/.platformio/packages/toolchain-gccarmnoneeabi@1.90201.191206/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: .pio/build/rumba_custom/libFrameworkArduino.a(usbd_conf.c.o): in function `HAL_PCD_MspInit':
usbd_conf.c:(.text.HAL_PCD_MspInit+0x118): undefined reference to `PinMap_USB_OTG_FS'
c:/users/cedella/.platformio/packages/toolchain-gccarmnoneeabi@1.90201.191206/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: usbd_conf.c:(.text.HAL_PCD_MspInit+0x128): undefined reference to `PinMap_USB_OTG_HS'
c:/users/cedella/.platformio/packages/toolchain-gccarmnoneeabi@1.90201.191206/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: .pio/build/rumba_custom/libFrameworkArduino.a(HardwareSerial.cpp.o): in function `HardwareSerial::setRx(unsigned long)':
HardwareSerial.cpp:(.text._ZN14HardwareSerial5setRxEm+0x40): undefined reference to `digitalPin'
c:/users/cedella/.platformio/packages/toolchain-gccarmnoneeabi@1.90201.191206/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: HardwareSerial.cpp:(.text._ZN14HardwareSerial5setRxEm+0x44): undefined reference to `analogInputPin'
c:/users/cedella/.platformio/packages/toolchain-gccarmnoneeabi@1.90201.191206/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: .pio/build/rumba_custom/libFrameworkArduino.a(HardwareSerial.cpp.o): in function `HardwareSerial::setTx(unsigned long)':
HardwareSerial.cpp:(.text._ZN14HardwareSerial5setTxEm+0x40): undefined reference to `digitalPin'
c:/users/cedella/.platformio/packages/toolchain-gccarmnoneeabi@1.90201.191206/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: HardwareSerial.cpp:(.text._ZN14HardwareSerial5setTxEm+0x44): undefined reference to `analogInputPin'
c:/users/cedella/.platformio/packages/toolchain-gccarmnoneeabi@1.90201.191206/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: .pio/build/rumba_custom/libFrameworkArduino.a(HardwareSerial.cpp.o): in function `HardwareSerial::HardwareSerial(void*, HalfDuplexMode_t)':
HardwareSerial.cpp:(.text._ZN14HardwareSerialC2EPv16HalfDuplexMode_t+0x6c): undefined reference to `PinMap_UART_RX'
c:/users/cedella/.platformio/packages/toolchain-gccarmnoneeabi@1.90201.191206/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: HardwareSerial.cpp:(.text._ZN14HardwareSerialC2EPv16HalfDuplexMode_t+0x70): undefined reference to `PinMap_UART_TX'
c:/users/cedella/.platformio/packages/toolchain-gccarmnoneeabi@1.90201.191206/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: .pio/build/rumba_custom/libf64/libSPI.a(SPI.cpp.o): in function `SPIClass::SPIClass()':
SPI.cpp:(.text._ZN8SPIClassC2Ev+0x54): undefined reference to `analogInputPin'
c:/users/cedella/.platformio/packages/toolchain-gccarmnoneeabi@1.90201.191206/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: SPI.cpp:(.text._ZN8SPIClassC2Ev+0x58): undefined reference to `digitalPin'
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\rumba_custom\firmware.elf] Error 1

It seems like the linker is unable to find references for several STM32-related functions and variables. I’m using a custom board configuration for the Rumba, and it seems like some essential STM32 HAL functions (like SystemClock_Config) and pin mapping references (PinMap_TIM, digitalPin, etc.) are missing or not properly linked.

What I did to configure my custom board:

  1. I created a folder called “boards” in the root of my project, containing the JSON file for the custom board named rumba_custom.json.
{
  "build": {
    "cpu": "cortex-m4",
    "extra_flags": "-DSTM32F446xx",
    "f_cpu": "180000000L",
    "framework_extra_flags": {
      "arduino": "-DCUSTOM_PERIPHERAL_PINS"
    },
    "mcu": "stm32f446ret6",
    "product_line": "STM32F446xx",
    "variant": "STM_CUSTOM"
  },
  "connectivity": [
    "can"
  ],
  "debug": {
    "jlink_device": "STM32F446RE",
    "openocd_target": "stm32f4x",
    "svd_path": "STM32F446x.svd"
  },
  "frameworks": [
    "arduino",
    "cmsis",
    "stm32cube",
    "libopencm3"
  ],
  "name": "3D Printer control board",
  "upload": {
    "maximum_ram_size": 131072,
    "maximum_size": 524288,
    "protocol": "stlink",
    "protocols": [
      "jlink",
      "cmsis-dap",
      "stlink",
      "blackmagic",
      "serial"
    ]
  },
  "url": "https://github.com/Aus3D/RUMBA32",
  "vendor": "RUMBA"
}
  1. I created a folder called “variants” in the same location, with another folder inside it named “STM_CUSTOM”. In this folder, I placed the variant files as well as the PeripheralPins files.
  2. I modified the platformio.ini file as follows:
[env:rumba_custom]
platform = ststm32@15.4.1
framework = arduino
extends = env:FYSETC_S6
board = rumba_custom

board_build.ldscript = my_linkerscript.ld


board_build.offset = 0x8000
board_upload.offset_address = 0x08008000


upload_protocol = dfu
monitor_speed = 115200

lib_deps = 
	https://github.com/RudolphRiedel/FT800-FT813/archive/refs/heads/5.x.zip
build_flags = 
	-D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC
	-D USBCON
	-D EVE_RiTFT50
	-D EVE_CS=PC6
    -D EVE_PDN=PC7
	-I variants/STM_CUSTOM
	-D ARDUINO_RUMBA32
monitor_dtr = 1

Has anyone encountered a similar issue or know how to resolve these undefined reference errors?

Thank you!

you miss here, variant links to existed board as base for your custom. Then h files is used from variant, dont require your folder variant…

If the STM_CUSTOM folder is just chilling in the root of your PlatformIO project, then it won’t be found.

Checkout the custom variant folder structure and needed platformio.ini commands in

or