SGKlee
SGKlee

Reputation: 82

Timeout in UART communication (STM's HAL_UART_Transmit(...))

I am using the STM32Cube_FW_G0_V1.5.0 firmware. And I observed that I allways get a timeout in the function HAL_WaitOnFlagUntilTimeout (the function is added below).

Does someone has suggestion what can go wrong and how to fix it concretely?

partial main.c code:

  /* USER CODE BEGIN PV */
  uint8_t txdata[30] = "Hallo Peter \n\r";
  /* USER CODE END PV */

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* Configure the system clock */
  SystemClock_Config();

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_DMA_Init();
  MX_I2C1_Init();
  MX_RTC_Init();
  MX_SPI1_Init();
  MX_USART1_UART_Init();
  MX_USART2_UART_Init();
  MX_DAC1_Init();
  /* USER CODE BEGIN 2 */

  HAL_UART_Transmit(&huart1, txdata, sizeof(txdata), 100);

HAL function code of timeout which is called in the transmit function:

HAL_StatusTypeDef UART_WaitOnFlagUntilTimeout(UART_HandleTypeDef *huart, uint32_t Flag, FlagStatus Status,
                                              uint32_t Tickstart, uint32_t Timeout)
{
  /* Wait until flag is set */
  while ((__HAL_UART_GET_FLAG(huart, Flag) ? SET : RESET) == Status)
  {
    /* Check for the Timeout */
    if (Timeout != HAL_MAX_DELAY)
    {
      if (((HAL_GetTick() - Tickstart) > Timeout) || (Timeout == 0U))
      {
        /* Disable TXE, RXNE, PE and ERR (Frame error, noise error, overrun error)
           interrupts for the interrupt process */
        ATOMIC_CLEAR_BIT(huart->Instance->CR1, (USART_CR1_RXNEIE_RXFNEIE | USART_CR1_PEIE |
                                                USART_CR1_TXEIE_TXFNFIE));
        ATOMIC_CLEAR_BIT(huart->Instance->CR3, USART_CR3_EIE);

        huart->gState = HAL_UART_STATE_READY;
        huart->RxState = HAL_UART_STATE_READY;

        __HAL_UNLOCK(huart);

        return HAL_TIMEOUT;
      }

And this is the UART configuration (of Acconeer's datasheet): enter image description here

Upvotes: 0

Views: 4785

Answers (1)

pmacfarlane
pmacfarlane

Reputation: 4297

Most likely the other side is not configured for hardware flow control, so the STM32 never sees the clear-to-send signal being set.

You could disable hardware flow-control on the STM32 UART, or configure the other side to use hardware flow-control. (And ensure all the RTS/CTS signals are connected.)

Upvotes: 1

Related Questions