STM32L052 generic board board not working?

I’ve read quite some topics and site about how to solve this, but I’m unable to find the right info. I’m trying to program a STM32L052R8T6 using STM32Duino via Platform.IO, but I’m unable to get it working. In Arduino, I’m able to use a generic STM32L0 series board with Generic L052R8Tx part number and compile a simple blink program and upload it with ST-link. I’m not sure how to do the same with Platform.IO.

I tried to use the following as a custom board definitions in a json file:

{
  "build": {
    "cpu": "cortex-m0plus",
    "extra_flags": "-DSTM32L0 -DSTM32L052xx",
    "f_cpu": "16000000L",
    "framework_extra_flags": {
      "arduino": "-D__CORTEX_SC=0"
    },
    "mcu": "stm32l052r8t6",
    "product_line": "STM32L052xx",
    "variant": "STM32L0xx/L052R(6-8)T_L053R(6-8)T_L063R8T"
  },
  "debug": {
    "default_tools": [
      "stlink"
    ],
    "jlink_device": "STM32L052R8",
    "onboard_tools": [
      "stlink"
    ],
    "openocd_target": "stm32l0",
    "svd_path": "STM32L052.svd"
  },
  "frameworks": [
    "arduino",
    "cmsis",
    "mbed",
    "stm32cube",
    "libopencm3",
    "zephyr"
  ],
  "name": "GDMS Main board",
  "platform": "ststm32",
  "upload": {
    "maximum_ram_size": 8192,
    "maximum_size": 65536,
    "protocol": "stlink",
    "protocols": [
      "jlink",
      "cmsis-dap",
      "stlink",
      "mbed"
    ]
  },
  "url": "https://developer.mbed.org/platforms/ST-Nucleo-L053R8/",
  "vendor": "ST"
}

My platformio.ini file looks like this:

[env:gdms-main]

platform = ststm32

board = gdms-main

framework = arduino

build_flags =

    -Os

    -D SERIAL_RX_BUFFER_SIZE=200        ;Increase USART RX buffer size

When trying to compile my files, I get the following error:

Building in release mode
Compiling .pio\build\gdms-main\FrameworkArduinoVariant\PeripheralPins.c.o
Compiling .pio\build\gdms-main\FrameworkArduinoVariant\generic_clock.c.o
Compiling .pio\build\gdms-main\FrameworkArduinoVariant\variant_NUCLEO_L053R8.cpp.o
Compiling .pio\build\gdms-main\FrameworkArduinoVariant\variant_generic.cpp.o
<command-line>: warning: ISO C99 requires whitespace after the macro name
Compiling .pio\build\gdms-main\SrcWrapper\src\HAL\stm32yyxx_hal.c.o
<command-line>: warning: ISO C99 requires whitespace after the macro name
<command-line>: warning: ISO C++11 requires whitespace after the macro name
Compiling .pio\build\gdms-main\SrcWrapper\src\HAL\stm32yyxx_hal_adc.c.o
<command-line>: fatal error: variant_GDMS-MAIN.h: No such file or directory

What do I need to do?

-Os is already the standard. Also I would avoid the ; at the end of the line. What does it do with just

build_flags = -DSERIAL_RX_BUFFER_SIZE=200

?

I should have removed that. It’s used for library not shown here. I now made a variant by copying the folder /variants/STM32L0xx/L052R(6-8)T_L053R(6-8)T_L063R8T to /variants/STM32L0xx/L052R6-GDMS and adjusted the json “variant” field to “STM32L0xx/L052R6-GDMS”. This compiles, although I still do get the “warning: ISO C99 requires whitespace after the macro name”. Next to that, it doesn’t link:

Linking .pio\build\gdms-main\firmware.elf
c:/users/ppott/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: .pio/build/gdms-main/SrcWrapper/src/stm32/hw_config.c.o: in function `hw_config_init':
hw_config.c:(.text.hw_config_init+0xe): undefined reference to `SystemClock_Config'
c:/users/ppott/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: .pio/build/gdms-main/SrcWrapper/src/stm32/uart.c.o: in function `uart_debug_init':
uart.c:(.text.uart_debug_init+0x50): undefined reference to `analogInputPin'
c:/users/ppott/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: uart.c:(.text.uart_debug_init+0x54): undefined reference to `digitalPin'
c:/users/ppott/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: .pio/build/gdms-main/SrcWrapper/src/stm32/uart.c.o: in function `uart_debug_write':
uart.c:(.text.uart_debug_write+0xe0): undefined reference to `analogInputPin'
c:/users/ppott/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: uart.c:(.text.uart_debug_write+0xe4): undefined reference to `digitalPin'
c:/users/ppott/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: .pio/build/gdms-main/lib3c7/libWire.a(Wire.cpp.o): in function `TwoWire::TwoWire()':
Wire.cpp:(.text._ZN7TwoWireC2Ev+0x20): undefined reference to `digitalPin'
c:/users/ppott/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: .pio/build/gdms-main/libFrameworkArduino.a(HardwareSerial.cpp.o): in function `HardwareSerial::HardwareSerial(unsigned long, unsigned long)':
HardwareSerial.cpp:(.text._ZN14HardwareSerialC2Emm+0x94): undefined reference to `digitalPin'
c:/users/ppott/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: HardwareSerial.cpp:(.text._ZN14HardwareSerialC2Emm+0x98): undefined reference to `analogInputPin'
c:/users/ppott/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: .pio/build/gdms-main/libFrameworkArduino.a(HardwareSerial.cpp.o): in function `HardwareSerial::setRx(unsigned long)':
HardwareSerial.cpp:(.text._ZN14HardwareSerial5setRxEm+0x48): undefined reference to `digitalPin'
c:/users/ppott/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: HardwareSerial.cpp:(.text._ZN14HardwareSerial5setRxEm+0x4c): undefined reference to `analogInputPin'
c:/users/ppott/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: .pio/build/gdms-main/libFrameworkArduino.a(HardwareSerial.cpp.o): in function `HardwareSerial::setTx(unsigned long)':
HardwareSerial.cpp:(.text._ZN14HardwareSerial5setTxEm+0x48): undefined reference to `digitalPin'
c:/users/ppott/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: HardwareSerial.cpp:(.text._ZN14HardwareSerial5setTxEm+0x4c): undefined reference to `analogInputPin'
c:/users/ppott/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: .pio/build/gdms-main/libFrameworkArduino.a(wiring_digital.c.o): in function `pinMode':
wiring_digital.c:(.text.pinMode+0xb8): undefined reference to `digitalPin'
c:/users/ppott/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: wiring_digital.c:(.text.pinMode+0xc4): undefined reference 
to `analogInputPin'
c:/users/ppott/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: .pio/build/gdms-main/libFrameworkArduino.a(wiring_digital.c.o): in function `digitalWrite':
wiring_digital.c:(.text.digitalWrite+0x68): undefined reference to `digitalPin'
c:/users/ppott/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: wiring_digital.c:(.text.digitalWrite+0x74): undefined reference to `analogInputPin'
c:/users/ppott/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: .pio/build/gdms-main/libFrameworkArduino.a(pins_arduino.c.o): in function `analogInputToPinName':
pins_arduino.c:(.text.analogInputToPinName+0x130): undefined reference to `analogInputPin'
c:/users/ppott/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: pins_arduino.c:(.text.analogInputToPinName+0x13c): undefined reference to `digitalPin'
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\gdms-main\firmware.elf] Error 1

The variant.cpp might have some #ifdef which are not adapted and yet the these definitions may be blacked out. Can you upload your whole current project + custom variant folder?

You can download it here:

Just to be clear: first I tried to use the board “nucleo-L053R8” in platformio.ini and added board_build.mcu=stm32l052r8t6. This compiles and I can even flash it, but it wouldn’t boot. Figured out that was caused due to wrong clock settings. I now basically copied those board files and adjusted it to the STM32L052R8T6, redefined the clock settings in STM32CubeMX and copy / paste these values into generic_clock.c

Well one thing I can definitely tell you is that PlatformIO auto-generates the macro name -DARDUINO_GDMS-MAIN because you called the board definition file gdms-main.json (uppercode conversion + -DARDUINO_ prefix). Also as I’ve pointed out above the #ifdefs in the variant code didn’t look right.

Further, there is no need to have separate board and variant folders, you can put the boards folder directly into the project and also the variants folder since the board_build.variants_dir option exists.

Please check out the cleaned-up project GitHub - maxgerhardt/pio-custom-l052. It’s completely standalone, you only need to open the project and hit build.

(EDIT: Just update the code and platformio.ini regarding the serial speed and printing so that it may actually be visible.)

Thank you SO much! This did the trick! That was not easy to find!