STM32 CubeMX with PlatformIO

Hope any one have some idea what is going on. or how to fix this.
I found some similar posts but not this solution

I made a real simple workspace with 2 lines of code.
blink a led.

now the problem.
CubeMX
put the source folder in Core\Src
de incude folder is in Core\Inc

if i copy the \core\src\ and \core\inc\ folder
in just the root project folder \Src\

this is my platformIO ini.

[platformio]
default_envs = disco_f051r8

[env:disco_f051r8]
platform = ststm32
board = disco_f051r8
framework = stm32cube
board_build.mcu = stm32f051r8t6
upload_protocol = stlink
build_flags =
-I./Core/Inc
-I./Core/Src

board_build.f_cpu = 48000000L

also i changed the c_cpp_properties.json.
so added the paths
Core\Src
Core\Inc

it builds and every thing works.

i get the following error.

Found 18 compatible libraries
Scanning dependencies…
No dependencies
Building in release mode
Linking .pio\build\disco_f051r8\firmware.elf
.pio\build\disco_f051r8\libFrameworkCMSISDevice.a(startup_stm32f051x8.o): In function LoopFillZerobss': (.text.Reset_Handler+0x32): undefined reference to main’
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\disco_f051r8\firmware.elf] Error 1

Doing a -I flag just means “add to include header serach path”, it will not build any source files inside those folders.

Nope. That one is autogenerated from the platformio.ini options, you should never modify that, because changes will be reset. You need to get the platformio.ini right, then a correct c_cpp_properties.json will follow naturally.

Cna you show a screenshot of your current project?

Hi Mr Gerhardt,

i checked this project.

the strange thing is if i move the src and inc folder from Core directory.
one step higher, like root of the project and there move the inc and src.

every things builds debugs etc etc.

Also if i change platformio.ini

with the -I parameter.

my main.c get red.
and in the main.c the main.h gets red.

image

so i am not sure what the -I parameter does for the path but i gets broken.

This makes no sense. Source files are supposed to be in src/. (Unless you do a hack with the src_dir setting). Please restructure your project to conform to the folder structure that PlatformIO expects: Source files that you want to build are to be placed in src/.

Hi Max,

one problem was the project was in the STM32 folder. of cubeMX.

i now moved the project to the PlatformIO project ( default ) folder.

all paths where wrong in JSON launch and the c_cpp_properties file.

PlatformIO is realy not happy if the project folder is some where else.

also i have to check the ini setting for
include_dir
build_flags

after moving the project and adding ( include_dir )

it builds a little further,
and now get this error

*** [.pio\build\disco_f051r8\firmware.elf] Implicit dependency C:\Users\jdv1\.platformio\platforms\ststm32\builder\include_dir' not found, needed by target .pio\build\disco_f051r8\firmware.elf’.

What is the project folder structure and platformio.ini now, in full?

Hi Max,

i fiddle a little with the ini settings.

and i see changes in the c_cpp_properties.

after changing the include_dir

i see platformIO always wants a projec,root,dir \src
and an \include

my project structure is how the CubeSTM32 makes it.
project folder and then.
Core\Src
Core\Inc

it there a parameter to do that ?

{
“configurations”: [
{
“name”: “PlatformIO”,
“includePath”: [
“c:/Users/jdv1/Documents/PlatformIO/Projects/proj3_EWARM/src”,
“c:/Users/jdv1/Documents/PlatformIO/Projects/proj3_EWARM/include”,

to show it better i can add some ASCI art.

├── Core
│ ├── Src
│ │ └── main.c
│ └── Inc
│ └── main.h

could this be the right magic word to use a different source dir ?

PLATFORMIO_SRC_DIR

I moved the Core\Inc and the Core\Src folders.
to the root of the project

and it builds every thing works.

so no my question how can change the Src folder and Inc folder,
to a different path. ? or is it by design Include and Src ?

See

Similiar

https://docs.platformio.org/en/latest/projectconf/sections/platformio/options/directory/include_dir.html