2021-01-29 08:56 PM
2021-01-30 02:48 AM
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
2021-01-30 04:14 AM
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
2021-01-30 04:33 AM
AN4899 nicely explains GPIO in details.