2024-10-23 01:06 AM - edited 2024-10-23 01:06 AM
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?
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?
Solved! Go to Solution.
2024-10-23 01:33 AM - edited 2024-10-23 01:35 AM
Note that there is an Arduino core for STM32:
@EvO wrote: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
You can configure CubeMX to generate separate .c/.h files:
If you're familiar with the Arduino setup() and loop() structure for your user code, that can easily be achieved in the Cube-generated structure as:
That way, you can leave all the generated code alone - much as you never see Arduino's main() - and just work in your own files with your setup() and loop() functions ...
#ArduinoSetupLoop
2024-10-23 01:33 AM - edited 2024-10-23 01:35 AM
Note that there is an Arduino core for STM32:
@EvO wrote: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
You can configure CubeMX to generate separate .c/.h files:
If you're familiar with the Arduino setup() and loop() structure for your user code, that can easily be achieved in the Cube-generated structure as:
That way, you can leave all the generated code alone - much as you never see Arduino's main() - and just work in your own files with your setup() and loop() functions ...
#ArduinoSetupLoop
2024-10-23 01:45 AM - edited 2024-11-06 01:20 AM
The standard project structure that CubeIDE generates is:
I would create a separate folder for my user code - at the same level as Core.
But you can structure your projects entirely as you wish.
CubeIDE documentation:
https://www.st.com/en/development-tools/stm32cubeide.html#documentation
Wiki:
https://wiki.st.com/stm32mcu/wiki/STM32CubeIDE:Introduction_to_STM32CubeIDE
Training videos:
#CubeIDEProjectStructure #FolderStructure
2024-10-23 01:53 AM
@Andrew Neil wrote:I would create a separate folder for my user code - at the same level as Core.
For example:
In this case, my user code is in the 'common' folder
(I called it "common" because it is common to several projects: details here, if you're interested)
2024-10-23 02:02 AM
Thank you Andrew, that really helps. Especially the Code Generator bit. I will still have to duplicate some boiler plate code between projects, but at least there will be specific places where to put the wrappers. This should be the default IMHO.
I wasn't after replicating anything arduino-like and the setup / while(1) structure is already in the STM main.c, so that was good enough for me, as those are are only calling a single function each in my case. Also I wasn't after using ArduinoIDE to manage the STM projects (and miss out on debugging).
Your 2nd msg about the project structure was also very useful, I did not come across any of that in the documentation.
2024-10-23 02:06 AM
@EvO wrote:I wasn't after using ArduinoIDE to manage the STM projects (and miss out on debugging).
Current Arduino IDE supports debugging - doesn't it?
2024-10-23 02:14 AM
There is an icon, but it is greyed out and when I hover over it, it sais "Debugging is not supported by 'Arduino Mega or Mega 2560'. Same for a few other chips, so I have never used it. MPLab does support some debugging which has come in helpful before.
Generally I don't need much debugging on target HW because everything is under TDD, except for hardware-specific stuff. I hope using the HAL libs will do the rest :)