cancel
Showing results for 
Search instead for 
Did you mean: 

USART4 Tx idle stays low STM32G070

PSicl.2
Associate II

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:

  • UART init
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();
  }
}
  • Clock and GPIO init
    __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);
  •  USART4 CR1 register

CR1 = 0x0d = 1101

UE = 1, UESM = 0, RE = 1, TE = 1

  • USART4 ISR register

ISR = 0x6200e2

Framing error = 1, TEACK = 1, REACK = 1

  • FW version 1.6.2

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();
    }
  •  Hardware connection

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

11 REPLIES 11

> 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

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:

  • Disable TAMPER
  • Move TAMPER from IN2 to IN1 on PC13

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.