Stm32f1xx_hal_conf.h ignored...or is it something else?

Hello there!

I am trying to build some code for stm32 using stm32cube framework and VS code. Although expirienced .NET developer, I have very limited knowledge of C/C++. I have managed to use several libraries but just this one is creating a problem for me. This is what I have in platform.ini:

[env:genericSTM32F103RB]
platform = ststm32
board = genericSTM32F103RB
framework = stm32cube
lib_ldf_mode = deep+
build_flags =
-D __FREERTOS
-D USE_HAL_DRIVER

And this is what’s creating problem (this is just relevant portion):

|-- [include]
| |-- stm32f1xx_hal_conf.h
|-- [lib]
| |-- [WDTM]
| | |-- wdt_stm32f1.c
|-- [src]
| |-- main.c

wdt_stm32f1.c includes stm32f1xx_hal.h
stm32f1xx_hal.h includes stm32f1xx_hal_conf.h (which I assume will be picked up from my include folder)
stm32f1xx_hal_conf.h defines HAL_IWDG_MODULE_ENABLED which means stm32f1xx_hal_iwdg.h will be included
stm32f1xx_hal_iwdg.c has this function HAL_IWDG_Start which is defined within #ifdef HAL_IWDG_MODULE_ENABLED. HAL_IWDG_Start is called from wdt_stm32f1.c but during build I get error “undefined reference to HAL_IWDG_Start”. It’s like stm32f1xx_hal_conf.h from my include folder that defines HAL_IWDG_MODULE_ENABLED is ignored.

No matter what I do I just can’t get this to work. I have exhausted all the options (considering my limited knowledge) and have nothing left to try. If anyone could point me to right direction I would appreciate very much!

Thank you!

PlatformIO first compiles the libraries (the files in the lib directory in your case) and then the project itself (files in src and include). When compiling the libraries, it will NOT include any files from the project. However, it will include library files when compiling the project itself.

In mathematical terms: The dependencies are assumed to form a directed graph with the project as the root.

Now stm32cube has some rather unfortunate dependencies and a confusing file organization. To resolve it, it usually works to move header files with shared configuration information (like stm32f1xx_hal_conf.h) to a new directory lib/common, i.e. a directory called common within the lib folder.

If it doesn’t help, I also recommend to search for stm32cube in this forum. You aren’t the first person to be challenged by stm32cube quirks.

Moving config file to lib/common didn’t help. Error is the same. But thank you for your suggestion anyway. Your insight helped me with some other shared configuration files. Since they weren’t included when I had them in include folder I copied them in folder where library code is. Moving all those files to lib/common is a nicer option.

I’ll try to search more for the solution. If any other idea crosses your mind that I could try, please let me know.

I am not sure if this is going to help anyone ever…but the problem was that library that I was using was built against older version of HAL driver. HAL_IWDG_Start has been removed and now it is enough to call HAL_IWDG_Init. Now it’s all working. Thank you manuelbl for taking time to look into this.