cancel
Showing results for 
Search instead for 
Did you mean: 

How to switch peripherals for the same pins in run-time (dynamically)?

ARaid.1
Associate III

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).

3 REPLIES 3

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.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

...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.

ARaid.1
Associate III

Okay, even if do not change at runtime, but just recompile and have each firmware version. And it's just not easy to do.