cancel
Showing results for 
Search instead for 
Did you mean: 

How to conditionally select between pin configurations at compile time?

SHugh.2
Associate III

We have a project where, due to various issues found during development, I've modified the PCB layout and changed a few pin allocations.

Is there any way to include multiple configurations from CubeMX and select between these at compile time?

This would allow us to gradually transition from the old hardware to the new rather than having to upgrade all units to the new PCB before we can release any software updates.

It's something I've done many times in the past on the PIC where I/O was configured in the code, but as it's all handled within Cube for the STM32 it isn't as obvious how to achieve it.

10 REPLIES 10
Pavel A.
Evangelist III

You can define one or more C symbols to distinguish hardware variants right in the Cube project(s).

In the generated code these definitions will go to main.h; any code that includes the main.h will see them.