cancel
Showing results for 
Search instead for 
Did you mean: 

CubeMX MX_GPIO_Init() Set GPIO output level at runtime before initialization

Jens_
Associate II

Hello,

I want to know if there is a way to set the GPIO output level for an output at runtime before it will be initialized by the CubeMX generated MX_GPIO_Init() function?

In other words: The MX_GPIO_Init() function writes the in CubeMX configured value to a GPIO output before intializing it:

/*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(***_GPIO_Port, ***_Pin, GPIO_PIN_SET);

Can I somehow get CubeMX to insert a variable name/value instead of the define 'GPIO_PIN_SET' which would allow me to change the value before calling the MX_GPIO_Init() function?

My intention is to decide at runtime if this pin should be initialized to high or low. I could copy&paste the generated MX_GPIO_Init() and adapt it to my needs, but then I am not in sync with the CubeMX project anymore. Also changing the pin value after the initialization is not an option for me because I don't want a wrong value at the pin.

Thanks,

Jens

Edit: Tried to clarify the 'runtime' aspect of the question.

2 REPLIES 2
Foued_KH
ST Employee

Hello @Jens_​ ,

Open STM32CubeMX, Configure and select I / O :

0693W00000bh7BQQAY.png 

(1).GPIO output level (pin initial level setting)

  • The High output is initialized to a High level
  • The Low output is initialized to a Low level

(2) . GPIO mode (GPIO output mode)

  • Output Push pull output has strong high and low levels, which can supply power to IO equipment
  • The Output Open Drain output mode is strong low level. Only low level can supply power to IO equipment, but high level can only be output as a signal

(3) . GPIO pull up / pull down

  • No pull up and no pull down
  • Pull up internal pull-up resistance
  • Pull down internal resistance

(4) . maximum output speed (pin speed setting)

  • Low low speed
  • Medium medium speed
  • High speed
  • Very High

(5) . user label

  • Set the name of the pin

Hope I helped you!

Foued

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Jens_
Associate II

Hello Foued,

this looks like the normal workflow with a constant definition. This does not work for me.

I want to decide at runtime before initialization if the pin shall be high or low.

Best Regards,

Jens