STM32cube default hal files as library

Hi, I hope someone can help me. I have a stm32 project where I have different hardware configurations but similar software components. My idea was to create a PlatformIO lib with the base functionality that every project can use. This works with the general code, but when I move the stm32g4xx_it.c and stm32g4xx_it.h for example to the lib folder. The linker does not find them any more (or this is what I think happens).

My project structure is as follows:

├───boards
│   └───stm32g474ret6.json
├───include
│   ├───stm32g4xx_hal_conf.h
│   └───main.h
├───lib
│   └───BaseLib
│       ├───include
│             └───stm32g4xx_it.h
│       └───src
│             └───stm32g4xx_it.c
├───src
│   └───main.c
└───test
[env]
monitor_speed = 115200

[env:STM32]
platform = ststm32
board = stm32g474ret6
framework = stm32cube
debug_tool = stlink
upload_protocol = stlink
board_build.stm32cube.custom_config_header = yes
build_flags = 
    -Ilib/BaseLib

When I copy the lib files to the src and include folder, everything works as intended.

Does anyone know if this setup is possible?

It looks like a wrong structure to me. See the readme inside the lib folder:

lib/README:

This directory is intended for project specific (private) libraries.
PlatformIO will compile them to static libraries and link into the executable file.

The source code of each library should be placed in a separate directory
(“lib/your_library_name/[Code]”).

For example, see the structure of the following example libraries Foo and Bar:

.
├── lib
│   ├── Bar
│   │   ├── doc
│   │   ├── examples
│   │   ├── src
│   │   │   ├── Bar.cpp
│   │   │   └── Bar.h
│   │   └── library.json (optional. for custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
│   ├── Foo
│   │   ├── Foo.c
│   │   └── Foo.h
│   └── README --> THIS FILE
├── platformio.ini
├── src
│   └── main.c

Use lib_archive = no to fix linking.

Duplicate of

1 Like

Was due to bad text formatting, corrected.

1 Like