"Src\main.h:4:10: fatal error: stm32f4xx_hal.h: No such file or directory" error with STM L432KC on STM32Cube Framework

…So you’re building for board = nucleo_l432kc. That means you must include stm32l4xx_hal.h, not stm32f4xx_hal.h. It’s pointless to try and include the F4 HAL for a L4 chip.

If you want the project to work in both cases, you can do

#if defined(STM32F4xx) || defined(STM32F4)
#include "stm32f4xx_hal.h"
#elif defined(STM32L432xx)
#include "stm32l4xx_hal.h"
#else
#error "Unknown chip"
#endif

You can look at the available macros in the board definitions, e.g.,

or add your own ones in the platformio.ini for each environment using build_flags.

1 Like