2023-05-23 12:19 PM
I have a board that has a connector. Another board is mounted on top of it. This additional board may require either GPIO, or UART, or SPI on the same signals. But I need to change peripherals and work with pins without recompiling the code, without changing the firmware. It is required to do this at run-time (dynamically). The question is how to achieve this using STM32CubeMX and HAL/LL code? Are there any AppNotes? (I can achieve this by programming registers, no problem, I'm interested in how this is done within the framework of the CubeMx / HAL / LL paradigm).
2023-05-23 12:36 PM
Bit niche so likely something you'll have to think through end-to-end rather than dropping out of the code generator.
Without recompiling, you can partition your initialization code to separate the possible use cases, then selectively initialize sub-components based on options or flags. Perhaps modify behaviour of callbacks or other functions based on the configuration settings.
Literally on-the-fly, you'd need to remap pins via the AFR[x] mux settings. And other MODER settings if the nature of the pin driver needs to change, etc.
2023-05-23 01:29 PM
...you can partition your initialization code to separate the possible use cases, then selectively initialize sub-components based on options or flags...
I suppose that I will have to make several sub-projects with configured peripherals and borrow the generated code from them.
Is there a similarity of conditional compilation in CubeMX?
Problem with code re-generation. After all, this will have to interfere with the generated Cube / HAL / LL code, but it is constantly overwritten.
2023-05-23 01:32 PM
Okay, even if do not change at runtime, but just recompile and have each firmware version. And it's just not easy to do.