Project organisation in CubeIDE - how to go about libraries
Background: most of our development so far has been with AVR and cmd line based, using make files for testing. We only ever used IDE's for compiling for target and uploading: Arduino IDE for prototyping with bootloader and MpLab without bootloader for production hardware. We are now transitioning some hardware to STM32 and plan to do any new developments on that platform.
The issue we are running into is that the integration of all hardware initialisation in the main.c file is different from the existing code: libraries with hardware interaction have all platform-specific code in separate c/h files.
For example, a module that uses EE may have a writeEE and readEE function that are defined in 2 separate c files, e.g. atTiny402EE.c and atMegaEE.c. On an STM32 without internal EE, we will use external EE, so we will need functions that are in must cases only wrappers around HAL_I2C_Mem_Read(), etc.
My question is: where should this live?
- inside the main.c file? : I prefer not, because that will become way to big, although initialisation(MX_I2C1_Init) is placed there automatically by the device config tool
- in a separate source file inside the project folder (where)? : I prefer not, because the exact same file will probably be needed in other projects - as the HAL function is identical for multiple STM32's (is it?). If this is the way to do it, in which folder should it live?
- in a separate project? if so, if I start a new "C Project" and select "static library", I am asked to select the toolchain and end up in the device configuration tool: which is exactly what I am trying to avoid - this should be generic (because it should only be compiled when compiled/linked by the include in the abovementioned main.c)
- as a separate source outside any projects in some custom folder in the workspace? in this case, what headers do I need to include for this to compile?
Or some other way? I probably completely mis the point of the organisation of the STM project / main.c file, but I am used to working with small files with narrow scope and I try to avoid duplicating code between projects at all cost...
Is there some documentation about project organisation / STM32Cube philosophy that I have missed?


