Alternate path to Src folder

The topic is old, but I didn’t even think that this could cause a problem. As you can see, I have the src and the Inc folder are in the Core folder, I do not want to copy the contents of the folders since the project is under development and there is an option that I will change the configuration in CubeMX. It would seem that there is no problem to do everything according to the documentation
https://docs.platformio.org/en/latest/projectconf/section_platformio.html#include-dir

but it didn’t work.
[env:demo_f030f4]
platforms = stm32
board = demo_f030f4
framework = stm32cube
upload_protocol = stlink
lib_archive = no
;include_dir = Core/Inc
src_dir = Core/Src
build_flags =
-I Core/Inc
, i.e. if the Inc and Src folder are copied to the root of the project, then the project is compiled, but not in the current form.
I would appreciate your help!

These have to be in the [platformio] section, not in the [env:...] section…

2 Likes

As usual, my carelessness let me down. Thanks!

It did not seem like a difficult task, but for the second hour I can not understand why I am getting an error. It’s not hard for me to copy all the header and C files into their respective project folders, but I don’t think this is the right solution. Please help me.
Doesn’t work in either the first or the second option
1.
[env:genericSTM32G030F6_stm32cube]
platform = ststm32
board = generic STM32G030F6
framework=stm32cube
upload_protocol = stlink
lib_archive=no

build_flags =
-ggdb
-I Core/VL53L0

[env]
build_flags =
-I Core/VL53L0
Снимок экрана 2022-04-14 в 13.38.17

After some experiments and restarting the IDE, the underline disappeared and when I click on the file name, I go where I need to, but something does not work correctly. when compiling, errors appear related to the unavailability of the functions contained in the included file.

[env:genericSTM32G030F6_stm32cube]
platform = ststm32
board = genericSTM32G030F6
framework = stm32cube
upload_protocol = stlink
lib_archive = no

build_type = debug
build_flags = 
      -ggdb
      -I Core/VL53L0
      -I Core/VL53L0/core/inc
      -I Core/VL53L0/platform/inc
...
Compiling .pio/build/genericSTM32G030F6_stm32cube/FrameworkCMSISDevice/gcc/startup_stm32g030xx.o
Compiling .pio/build/genericSTM32G030F6_stm32cube/FrameworkCMSISDevice/system_stm32g0xx.o
Archiving .pio/build/genericSTM32G030F6_stm32cube/libFrameworkCMSISDevice.a
Indexing .pio/build/genericSTM32G030F6_stm32cube/libFrameworkCMSISDevice.a
Linking .pio/build/genericSTM32G030F6_stm32cube/firmware.elf
.pio/build/genericSTM32G030F6_stm32cube/src/main.o: In function `main':
/Users/pavluchenko/Documents/STM.3/STM32G030/Core/Src/main.c:4248: undefined reference to `IR_Init'
collect2: error: ld returned 1 exit status
*** [.pio/build/genericSTM32G030F6_stm32cube/firmware.elf] Error 1

But if you do that with

Then Core/VL53L0 is not compiled? What about src_dir = Core

I will try to describe everything in order. This project was created in STM32CubeMx, the project structure is saved, i.e.

Core/Srs 
Core/Inc

In this case, for normal compilation, it is enough

[platformio]
include_dir = Core/Inc

And everything works great.
That was your tip, thanks!
But now I need to add API files which has its own structure.

API_Folder /Folder1/Src
API_Folder /Folder1/Inc
API_Folder /Folder2/Src
API_Folder /Folder2/Inc
API_Folder /file.h
API_Folder/file.c

I place the API folder in the Core folder

Core/Srs
Core/Inc
Core/API

and I specify it in the ini file according to the documentation

[env:genericSTM32G030F6_stm32cube]
platform = ststm32
board = generic STM32G030F6
framework=stm32cube
upload_protocol = stlink
lib_archive=no
build_type = debug
build_flags =
      -ggdb
      -I Core/VL53L0
      -I Core/VL53L0/core/inc
      -I Core/VL53L0/platform/inc

In main.c file

#include "ranging_vl53l0x.h"

When I click on the file name ranging_vl53l0x.h the file opens, but when I compile I get an error

pio run -t clean
pio run
...
Linking .pio/build/genericSTM32G030F6_stm32cube/firmware.elf
.pio/build/genericSTM32G030F6_stm32cube/src/main.o: In function `main':
/Users/pavluchenko/Documents/STM.3/LampSTM32G030/Core/Src/main.c:4252: undefined reference to `InitONE'
/Users/pavluchenko/Documents/STM.3/LampSTM32G030/Core/Src/main.c:4331: undefined reference to `ProcessONE'
/Users/pavluchenko/Documents/STM.3/LampSTM32G030/Core/Src/main.c:4332: undefined reference to `GetRangeONE'

These functions are contained in ranging_vl53l0x.c

I think it’s related to the linker, but I don’t understand how to tell him the location of files and folders in the project.

These commands add the files to the include path but not necessary to the sources to be compiled. Try moving the VL53L0 folder to lib/ and change the -I files accordingly.

2 Likes

It worked!
I sincerely thank you for your daily help to the members of the community. I think it is difficult to overestimate your contribution to the development of the product, because without quality help the product will not become good and affordable for many people. :handshake:

1 Like

Unfortunately, what is happening is beyond my understanding.

  1. Files in the API folder - compilation successfully
  2. Files in Core/Src and Core/Inc folders - compilation successful
    But in the second case, I get the correct data from the sensor, in the first I don’t. In this case, the code does not change, only the folders and -I in ini change, i.e. i just transfer files and comment/uncomment three lines
    ; -i library/VL53L0
    ; -I lib/VL53L0/kernel/incl.
    ; -I lib/VL53L0/platform/inc
    After each compilation pio run -t clean i.e. there is no problem in this.

That is… weird. You already have lib_archive=no so there should be no problems with a library file trying to install /override _WEAK functions for say the HAL SPI, I2C or whatever driver.

Since you already have upload_protocol = stlink which infers debug_tool = stlink, debugging should work. Can you see at which point it breaks in the execution flow or what is different between the two variants?