2025-07-17 11:08 AM - last edited on 2025-07-17 12:37 PM by mƎALLEm
I am using an STM32G0B0RET and trying to use USART2 w/ RS232 Flow Control (Both CTS and RTS) on pins PA0 - PA3. I am also trying to use pin PD5 as a standard GPIO_Output. PD5 has the additional functionality of being USART2_TX. However I am seeing weird behavior off of the PD5 pin as it never seems to pull the line over 0.01V. I have tried disabling flow control and moving the USART Init above the GPIO init in the main function.
My initial assumption was that because USART2 is active on the device, PD5 cannot be used as an output, however looking at the GPIO block diagram that doesn't seem like the expected behavior. This would lead me to believe that I can't use PD6 as its additional functionality is USART2_RX. But that means that pin isnt controlled by the microcontroller which means that potentially the data written to PD6 would appear as UART RX data internally to the device??? I am not sure what is wrong in this case. Any insight, suggestions, or tests would be greatly appreciated.
2025-07-17 11:42 AM
You should be able to use PDx for GPIO regardless of use of USART2 on PAx. Perhaps provide your code for GPIO init.
2025-07-17 1:16 PM
Tell us what you have in GPIOD->MODER, GPIOD->OTYPER and GPIOD->PUPDR at the point when the pin is misbehaving.
If you accidentally configured it as open-drain then it will never drive high, although it can pull high either through the built-in pull-up if enabled or external components.
How strongly do you know that there isn’t anything external to the stm32 that is keeping the pin low - either external components or a solder splash?
2025-07-17 1:46 PM
static void MX_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
/* USER CODE BEGIN MX_GPIO_Init_1 */
/* USER CODE END MX_GPIO_Init_1 */
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOF_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
__HAL_RCC_GPIOD_CLK_ENABLE();
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOB, CTRL1_Pin|CTRL2_Pin|CS4_Pin|CS3_Pin
|CS2_Pin, GPIO_PIN_RESET);
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOC, LED2_Pin|LED1_Pin|CS1_Pin, GPIO_PIN_RESET);
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOD, ALT_SPI_MOSI_Pin|ALT_SPI_MISO_Pin|ALT_SPI_SCK_Pin|EN4_Pin
|EN3_Pin|EN2_Pin|EN1_Pin, GPIO_PIN_RESET);
/*Configure GPIO pins : ID1_Pin ID2_Pin ID3_Pin GPIO_Daughter1_Pin
GPIO_Daughter2_Pin */
GPIO_InitStruct.Pin = ID1_Pin|ID2_Pin|ID3_Pin|GPIO_Daughter1_Pin
|GPIO_Daughter2_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
/*Configure GPIO pins : PC14 PC15 PC0 PC1
PC2 PC3 PC6 PC7 */
GPIO_InitStruct.Pin = GPIO_PIN_14|GPIO_PIN_15|GPIO_PIN_0|GPIO_PIN_1
|GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_6|GPIO_PIN_7;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
/*Configure GPIO pins : PA0 PA1 PA2 PA3
PA4 PA8 PA9 PA10
PA15 */
GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3
|GPIO_PIN_4|GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10
|GPIO_PIN_15;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/*Configure GPIO pins : GPIO_Daughter3_Pin GPIO_Daughter4_Pin CS_Daughter4_Pin CS_Daughter3_Pin
CS_Daughter2_Pin CS_Daughter1_Pin */
GPIO_InitStruct.Pin = GPIO_Daughter3_Pin|GPIO_Daughter4_Pin|CS_Daughter4_Pin|CS_Daughter3_Pin
|CS_Daughter2_Pin|CS_Daughter1_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
/*Configure GPIO pins : CTRL1_Pin CTRL2_Pin CS4_Pin CS3_Pin
CS2_Pin */
GPIO_InitStruct.Pin = CTRL1_Pin|CTRL2_Pin|CS4_Pin|CS3_Pin
|CS2_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
/*Configure GPIO pins : PB11 PB12 PB13 PB14
PB15 */
GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14
|GPIO_PIN_15;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
/*Configure GPIO pins : PD8 PD9 */
GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
/*Configure GPIO pins : LED2_Pin LED1_Pin CS1_Pin */
GPIO_InitStruct.Pin = LED2_Pin|LED1_Pin|CS1_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
/*Configure GPIO pin : ALT_SPI_MOSI_Pin */
GPIO_InitStruct.Pin = ALT_SPI_MOSI_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(ALT_SPI_MOSI_GPIO_Port, &GPIO_InitStruct);
/*Configure GPIO pins : ALT_SPI_MISO_Pin ALT_SPI_SCK_Pin EN4_Pin EN3_Pin
EN2_Pin EN1_Pin */
GPIO_InitStruct.Pin = ALT_SPI_MISO_Pin|ALT_SPI_SCK_Pin|EN4_Pin|EN3_Pin
|EN2_Pin|EN1_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
/* USER CODE BEGIN MX_GPIO_Init_2 */
/* USER CODE END MX_GPIO_Init_2 */
}
In addition to this. I tried making a new project through cubeMX and editing and building through a VSCode devcontainer. This time ONLY init'ing PD5. It worked!, Then I tried adding PD6 and removing PD5...it didn't... (Only PD5 or PD6 were ever initted at a time, never both)
This lead me to creating a new project in CubeIDE and doing the same test. PD5 was back to not working but PD6 was...could there be a bug in the code generation?
I will looking into drilling into the GPIOD fields tomorrow morning, thanks!