Failed to integrate custom stm32 board with zephyr

Hello everyone,

I try to implement the ST nucleo f303k8 board for the zephyr framework. I started with the official zephyr repository. I successfully implemented the board, the soc and the dts for the f303x8 series. I was able to build the board with the hello world example using the CLI tool west and the zephyr sdk. Now I would like to integrate the new board to the awesome vscode extension PlatformIO. I used the nice guide to add the custom board to PlatformIO.

First issue I had to solve was to add the new mcu in the “framework-zephyr/soc/arm/st_stm32/stm32f3/Kconfig.soc” file with:

config SOC_STM32F303X8
	bool "STM32F303X8"

I tried to put the modified Kconfig.soc with the new soc into the zephyr project folder but that would not solve the issue. How can I solve that so I don’t have to modify the original framework file?

After temporary fixing the first issue I get some cmake errors I am not able to solve.

 Executing task in folder zephyr_test: platformio run <

Processing nucleo_f303k8 (platform: ststm32; board: nucleo_f303k8; framework: zephyr)
Verbose mode can be enabled via `-v, --verbose` option
PLATFORM: ST STM32 (8.1.0) > ST Nucleo F303K8
HARDWARE: STM32F303K8 72MHz, 40KB RAM, 64KB Flash
DEBUG: Current (jlink) External (jlink, stlink)
 - framework-zephyr 2.20300.200823 (2.3.0) 
 - framework-zephyr-canopennode 0.0.0-alpha+sha.5c6b0566d5 
 - framework-zephyr-civetweb 0.0.0-alpha+sha.99129c5efc 
 - framework-zephyr-cmsis 0.0.0-alpha+sha.542b2296e6 
 - framework-zephyr-fatfs 0.0.0-alpha+sha.9ee6b9b951 
 - framework-zephyr-hal-st 0.0.0-alpha+sha.5b3ec3e182 
 - framework-zephyr-hal-stm32 0.0.0-alpha+sha.d1bc80d021 
 - framework-zephyr-libmetal 0.0.0-alpha+sha.3c3c9ec83b 
 - framework-zephyr-littlefs 0.0.0-alpha+sha.0aefdda69d 
 - framework-zephyr-loramac-node 0.0.0-alpha+sha.29e516ec58 
 - framework-zephyr-lvgl 0.0.0-alpha+sha.74fc2e753a 
 - framework-zephyr-mbedtls 0.0.0-alpha+sha.4bf099f125 
 - framework-zephyr-mcuboot 0.0.0-alpha+sha.e88113bbeb 
 - framework-zephyr-mcumgr 0.0.0-alpha+sha.5885efb7ca 
 - framework-zephyr-mipi-sys-t 0.0.0-alpha+sha.957d46bc3c 
 - framework-zephyr-open-amp 0.0.0-alpha+sha.724f7e2a45 
 - framework-zephyr-openthread 0.0.0-alpha+sha.a83d18cf18 
 - framework-zephyr-segger 0.0.0-alpha+sha.6fcf61606d 
 - framework-zephyr-tinycbor 0.0.0-alpha+sha.40daca97b4 
 - framework-zephyr-tinycrypt 0.0.0-alpha+sha.3e9a49d267 
 - framework-zephyr-trusted-firmware-m 0.0.0-alpha+sha.7de2daa196 
 - tool-cmake 3.16.4 
 - tool-dtc 1.4.7 
 - tool-gperf 3.0.4 
 - tool-ninja 1.7.1 
 - toolchain-gccarmnoneeabi 1.80201.181220 (8.2.1)
Reading CMake configuration...
-- Application: /home/sebastian/Programnieren/embedded/zephyr_test/zephyr
-- Zephyr version: 2.3.0 (/home/sebastian/.platformio/packages/framework-zephyr)
-- Found Python3: /home/sebastian/.platformio/penv/bin/python3.6 (found suitable exact version "3.6.9") found components: Interpreter 
-- Board: nucleo_f303k8
-- Found dtc: /home/sebastian/.platformio/packages/tool-dtc/dtc (found suitable version "1.4.7", minimum required is "1.4.6")
-- Found toolchain: gnuarmemb (/home/sebastian/.platformio/packages/toolchain-gccarmnoneeabi)
-- Found BOARD.dts: /home/sebastian/Programnieren/embedded/zephyr_test/zephyr/boards/arm/nucleo_f303k8/nucleo_f303k8.dts
-- Generated zephyr.dts: /home/sebastian/Programnieren/embedded/zephyr_test/.pio/build/nucleo_f303k8/zephyr/zephyr.dts
-- Generated devicetree_unfixed.h: /home/sebastian/Programnieren/embedded/zephyr_test/.pio/build/nucleo_f303k8/zephyr/include/generated/devicetree_unfixed.h
Parsing /home/sebastian/.platformio/packages/framework-zephyr/Kconfig
Loaded configuration '/home/sebastian/Programnieren/embedded/zephyr_test/zephyr/boards/arm/nucleo_f303k8/nucleo_f303k8_defconfig'
Configuration saved to '/home/sebastian/Programnieren/embedded/zephyr_test/.pio/build/nucleo_f303k8/zephyr/.config'
Kconfig header saved to '/home/sebastian/Programnieren/embedded/zephyr_test/.pio/build/nucleo_f303k8/zephyr/include/generated/autoconf.h'
-- The C compiler identification is GNU 8.2.1
-- The CXX compiler identification is GNU 8.2.1
-- The ASM compiler identification is GNU
-- Found assembler: /home/sebastian/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc
-- Cache files will be written to: /home/sebastian/.cache/zephyr
-- Configuring incomplete, errors occurred!
See also "/home/sebastian/Programnieren/embedded/zephyr_test/.pio/build/nucleo_f303k8/CMakeFiles/CMakeOutput.log".
See also "/home/sebastian/Programnieren/embedded/zephyr_test/.pio/build/nucleo_f303k8/CMakeFiles/CMakeError.log".

Python path: /home/sebastian/.platformio/penv/bin/python3.6
CMake Error at /home/sebastian/.platformio/packages/framework-zephyr-hal-stm32/stm32cube/CMakeLists.txt:11 (string):
  string no output variable specified

CMake Error at /home/sebastian/.platformio/packages/framework-zephyr-hal-stm32/stm32cube/CMakeLists.txt:12 (string):
  string sub-command REPLACE requires at least four arguments.

======================================================== [FAILED] Took 2.98 seconds ========================================================
The terminal process "platformio 'run'" terminated with exit code: 1.

Terminal will be reused by tasks, press any key to close it.

I looked at the “/home/sebastian/.platformio/packages/framework-zephyr-hal-stm32/stm32cube/CMakeLists.txt” file and there is some logic to decide which mcu driver the compiler should use.
I guess that in some point cmake misses to pass the mcu type or it is missing at all.
What I don’t understand is why the config is building with the zephyr SDK and the tool west but not with PlatformIO.

I put the whole project with the CMakeOutput.txt and the CMakeError.txt into my dropbox so you can test if you can reproduce this error.

My system specs are:
Linux Mint 19.2
vscode version 1.51.0
PlatformIO version 2.2.0

Thanks in advance for the help and the awesome PlatformIO extension.

I managed to solve the Issue myself.
As it turns out the soc and the dts folder in my Project had no effect to the building of the Project.
I put the modified soc and dts files directly to the .platformio folder and it worked.
However I would like to have the modified files only in the project so I can share the whole project with the board more easily.
As the guid suggest I have to add set (BOARD_ROOT "${CMAKE_CURRENT_SOURCE_DIR}") to the CMackeList.txt of the project. But this sets the environmental variable for the boars to the project folder. When I try to do this with set (SOC_ROOT "${CMAKE_CURRENT_SOURCE_DIR}") I would need the whole soc folder from zephyr to have all references for the soc.
What I want is this. So that the cmake sees the soc folder in my project as an additional source folder and not as the only one to use. How I would need to modify the CMakeList.txt to achieve this goal?

Hey mate, I’m trying to integrate custom board that uses STM32F103RET6 into Zephyr, flashed using STLINK. May I know what’s your progress on this?

I haven’t try WEST yet, and a simple blinky example with PlatformIO + Zephyr compiles fine but isn’t working.