2025-06-20 1:36 AM
Hello everyone,
Does anyone have experience with changing the function of a pin in program?(Not CubeMX tool)
I'm currently using the STM32H5 MCU to develop a motor drive inverter.
For rotor angle feedback, we’re considering two options: Encoder (ABZ) and Hall sensors.
As shown below, when configuring TIM2 in Encoder + Index mode, it occupies PA0, PA1, and PA4. However, if TIM2 is configured in Input Capture mode (for Hall sensors), it uses PA0, PA1, and PA2 instead.
We want to let the user select the desired feedback method (either Hall or Encoder), and then have the firmware initialize the corresponding pin configuration at runtime.
So, my question is: how should I config the CubeMX configuration from the beginning, and how can I implement the function initialization in code to change different function?
Has anyone had experience with this type of setup?"