cancel
Showing results for 
Search instead for 
Did you mean: 

Hi, can someone suggest me how to configure GPIO ports of stm32f407 MUC as bidirectional IO

Cpatt.1
Associate II
 
3 REPLIES 3
KnarfB
Principal III

At register level, there is an IDR (input data register) and ODR (output data register). They both work independently, i.e. you can read back the IO value with IDR while in output "mode".

This works with HAL as well:

So you might setup a GPIO pin as open-drain output with a pull-up in the chip configuration or code:

  /*Configure GPIO pin : PA0 */
  GPIO_InitStruct.Pin = GPIO_PIN_0;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;
  GPIO_InitStruct.Pull = GPIO_PULLUP;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

and read back the current pin level using

GPIO_PinState val = HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_0);

and change the output level using

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0, val );

as you like.

hth

KnarfB

If Open Drain is not an option because of its inherent limitations, you can of course change the "direction" of given pin simply by changing its respective GPIO_MODER field.

I don't think this is something easily clickable in CubeMX, though.

JW

Piranha
Chief II

AN4899 nicely explains GPIO in details.