2024-06-14 08:05 AM
Hello everyone,
I successfully used USART1 and USART3 in my application. However, when trying to use USART4, Rx is working but not Tx. The idle signal stays at 0V all the time.
Here is what I already check:
static void MX_USART4_UART_Init(void)
{
huart4.Instance = USART4;
huart4.Init.BaudRate = 115200;
huart4.Init.WordLength = UART_WORDLENGTH_8B;
huart4.Init.StopBits = UART_STOPBITS_1;
huart4.Init.Parity = UART_PARITY_NONE;
huart4.Init.Mode = UART_MODE_TX_RX;
huart4.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart4.Init.OverSampling = UART_OVERSAMPLING_16;
huart4.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
huart4.Init.ClockPrescaler = UART_PRESCALER_DIV1;
huart4.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
if (HAL_UART_Init(&huart4) != HAL_OK)
{
Error_Handler();
}
}
__HAL_RCC_USART4_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
/**USART4 GPIO Configuration
PA0 ------> USART4_TX
PA1 ------> USART4_RX
*/
GPIO_InitStruct.Pin = TX4_Aux_Pin|RX4_Aux_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Alternate = GPIO_AF4_USART4;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/* USER CODE BEGIN USART4_MspInit 1 */
/* USART3 interrupt Init */
HAL_NVIC_SetPriority(USART3_4_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(USART3_4_IRQn);
CR1 = 0x0d = 1101
UE = 1, UESM = 0, RE = 1, TE = 1
ISR = 0x6200e2
Framing error = 1, TEACK = 1, REACK = 1
I updated the firmware version but with no result. I noticed the addition of HAL_RCCEx_PeriphCLKConfig in hal_msp.c driver but it can't be applied to USART4.
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART1;
PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK1;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
{
Error_Handler();
}
No short-circuit on Rx or Tx. I am measuring signal at MCU output and there is nothing after.
I tested everything I could think of. You will maybe have other ideas. Tell me if you need more details (registers values, function output, signal measurement). Thank you in advance.
MCU : STM32G070CBT6
Clock source : internal clock
Driver : HAL
Solved! Go to Solution.
2024-06-18 07:11 AM
> Do you think it could be the answer ?
Yes; if you set PA0 to TAMPER it overrides the GPIO settings.
I don't know how do you set TAMPER to use PC13; I don't use TAMPER and I don't use Cube.
JW
2024-06-18 07:16 AM
Thank you so much waclawek.jan for helping me.
So to recap, PA0 was not usable because TAMP_IN2 was enable and was overriding GPIO settings.
The solution is either:
In addition, to disable TAMPER on IN2 (PA0), you can use HAL_RTCEx_DeactivateTamper function. Or if you don't use HAL, you can change TAMP->CR1 register.