Building Core-Agnostic Library with stm32h755xx.h in Dual-Core STM32H755 Project
Description:
I am developing a library for an STM32H755-based project, where the library is responsible for controlling LEDs via `HAL_GPIO_WritePin()`. The library needs to be core-agnostic and should work when linked into both the CM4 and CM7 projects. However, I’m encountering an issue with the inclusion of the `stm32h755xx.h` header file. stm32h755xx.h is included by stm32h7xx.h when STM32H755xx is defined in stm32h7xx.h which is a requirement.
The `stm32h755xx.h` file requires either the `CORE_CM4` or `CORE_CM7` preprocessor directive to be defined, as it contains core-specific definitions and includes (`core_cm4.h` or `core_cm7.h`). Since the library is being built independently, it does not know ahead of time whether it will be used in the CM4 or CM7 project. The core definition (`CORE_CM4` or `CORE_CM7`) is specified in the main project but is not known during the library build.
My goal is to have a single library build that can be linked into both the CM4 and CM7 projects without needing to compile separate versions for each core. Is there a recommended way to structure the build so that the library can remain core-agnostic while satisfying the requirement of `stm32h755xx.h`? Any suggestions on how to resolve this issue would be appreciated.
Key Points:
- The library will be linked into both CM4 and CM7 projects.
- The library itself is core-agnostic, with no specific core-dependent code.
- stm32h755xx.h requires either CORE_CM4 or CORE_CM7 to be defined.
- The library build process doesn’t know in advance which core it will be linked to.
- I intend to use this approach with other core-agnostic libraries, for example, a servo library that will be writing to PWM pins.
How can I structure my library or build process to resolve this core-specific dependency while maintaining a single core-agnostic library?


