How to exclude framework .c files?

Hi, I am working with the stm32cube framework. It includes all peripheral library files. Sometimes there are compile errors in library files I don’t need in the project. How can I exclude the unnecessary files from compilation?

Sometimes? You compile the same code multiple times and it only errors out sometimes?

Continuing the discussion from How to exclude framework .c files?:

Fortunately no… :slight_smile:
I mean, it happens sometimes in new projects. For example
.platformio\packages\framework-stm32cubef1\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_iwdg.c:124:83: error: ‘LSI_STARTUP_TIME’ undeclared (first use in this function); did you mean ‘LSE_STARTUP_TIMEOUT’?

I don’t even use the watchdog. My quick and dirty workaround is manually inserting the definition to the lib file:
#define LSI_STARTUP_TIME 85U /*!< LSI Maximum startup time in us */

But why it occoured in this project, and not in many others?

collecting the required library files to the project itself could be good solution too, instead of using the library in the framework. The CubeMx makes the selection for the project, unfortunately I don’t know an easy way to convert the format it provides for PIO.

Can you show a minimal project that reproduces this error?

Sure, thank you for help. It’s an irda receiver for micro car racing timer.
https://drive.google.com/file/d/1tT0dad6wqUEL1jJs2rFMxfAZVucySZ1b/view?usp=sharing

But this isn’t a PlatformIO project with a platformio.ini. I meant a PlatformIO project that throws that

error.

Sorry, I sent a wrong file.
https://drive.google.com/file/d/1iZitmGypF3cFGDdASiqCrLeGcKyWlJq2/view?usp=sharing

Have you looked at Build Middlewares?

In your include/ folder you have stm32f1xx.h, stm32f103xb.h and stm32f1xx_hal_conf.h which don’t belong in the project because they are already provided by PlatformIO’s version of the STM32HAL framework files. So the STM32HAL source files are reading these headers files which are likely meant for a different STM32HAL version, and mixing versions is not good. I suggest you simply delete them from the project.

The stm32f1xx_hal_conf.h file is project specific, for example it enables uart’s by uncommenting lines:
/*#define HAL_DAC_MODULE_ENABLED /
#define HAL_DMA_MODULE_ENABLED
/
#define HAL_ETH_MODULE_ENABLED /
/
#define HAL_FLASH_MODULE_ENABLED /
#define HAL_GPIO_MODULE_ENABLED
/
#define HAL_I2C_MODULE_ENABLED */
Simply deleting it is not viable.

So it seems, that using the CubeMX generated file require the same HAL version in CubeMX and PIO - not sure how to do that.

Another possibility is not using the PIO framework, just the CubeMX library files. I tried, but got many errors, not easy.

It is, because the linker will throw out unused functions at the end anyways and PlatformIO’s default file enables all modules. But, you can also keep this file, just use per docs (STM32Cube — PlatformIO latest documentation)

board_build.stm32cube.custom_config_header = yes

At first I didn’t included the stm32f1xx_hal_conf.h, but the irda (uart1) not worked. That’s why I included it.

The file C:\Users\<user>\.platformio\packages\framework-stm32cubef1\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_conf.h definitely has

#define HAL_IRDA_MODULE_ENABLED

but if it didn’t work, feel free to use your own config header.

I did some more tests. In the test I used the framework, and added only the CubeMx generated main.c and main.h.
This way the irda port is not working. Debugging it shows, that the reason is the improper RCC settings. The uart init function is called, does it’s job, but it can’t write the registers of the uart because the clock of the peripheral is missing.

Then there may be a bug in the STM32Cube files PlatformIO is using.

When you setup the project to be bare-metal from the PlatformIO perspective (no framework = stm32cube) and you add the STM32HAL files that CubeMX autogenerates you into the project, then the project works fully?

It works in Keil and CubeIde, as CubeMX generates the project. Not ready yet, but the ports are working.
I tried to collect the files for PIO, but got many error messages, and gave up. Maybe I have to be more persistent next time.

But this is the base project you want to import into PlatformIO right?

That was my first unfinished effort to import it to PIO.
Here is the Keil version:
https://drive.google.com/file/d/1p2Uk4xdIMxSLw-hwQdBLQyIEVh_ULKL8/view?usp=sharing
Thank you for the help.

Do you have an export for STM32IDE targeting GCC? PlatformIO uses GCC here, the Keil version doesn’t include the startup files and linker scripts for GCC.

Its the CubeIde version: https://drive.google.com/file/d/1TvhoA3MaWyU5fMlssj95ekp4h7EasuxA/view?usp=sharing