8
\$\begingroup\$

I am using interrupt based UART IO (no DMA).

HAL_UART_Transmit_IT function sets EIE bit in CR3 register. According to STM32F407 datasheet (and real behaviour), this generates interrupt only in multi buffer mode (when DMAR bit is set). EIE enables interrupt generation for frame error (FE), overrun error (ORE), noise error (NE). This error, as I understand, only for receiving.

Part of HAL_UART_IRQHandler function:

tmp1 = __HAL_UART_GET_FLAG(huart, UART_FLAG_ORE);
tmp2 = __HAL_UART_GET_IT_SOURCE(huart, UART_IT_ERR);
/* UART Over-Run interrupt occurred ----------------------------------------*/
if((tmp1 != RESET) && (tmp2 != RESET))
{ 
  __HAL_UART_CLEAR_OREFLAG(huart);

  huart->ErrorCode |= HAL_UART_ERROR_ORE;
}

if(huart->ErrorCode != HAL_UART_ERROR_NONE)
{
  /* Set the UART state ready to be able to start again the process */
  huart->State = HAL_UART_STATE_READY;

  HAL_UART_ErrorCallback(huart);
}  

HAL_UART_IRQHandler checks for each error. If error occurred and EIE bit is set, it resets UART state, but doesn't reset interrupt enabling bits, so TXE interrupt will be always generated, but UART_Transmit_IT function treats state HAL_UART_STATE_READY as invalid and doesn't do anything. Infinite loop.

Part of UART_Transmit_IT function:

static HAL_StatusTypeDef UART_Transmit_IT(UART_HandleTypeDef *huart)
  {
  uint16_t* tmp;
  uint32_t tmp1 = 0;

  tmp1 = huart->State;
  if((tmp1 == HAL_UART_STATE_BUSY_TX) || (tmp1 == HAL_UART_STATE_BUSY_TX_RX))
  {
  }
  else
  {
    return HAL_BUSY;
  }
}

Is it a bug in Cube HAL?

\$\endgroup\$
3
\$\begingroup\$

It is a bug.

I asked same question on the ST forum: https://my.st.com/d5c15f59

They confirmed it.

\$\endgroup\$
  • \$\begingroup\$ The "my.st.com" link requires a login. I found this thread on the ST forum, which I think is the reporting of this problem, and is accessible without a login, so readers may find that useful. \$\endgroup\$ – SamGibson Oct 17 '16 at 17:58
0
\$\begingroup\$

Did you try to download the lastest version of Cube HAL for your MCU?

My HAL_UART_Transmit_IT() function seems very different than yours. Maybe you have an older version with bugs.

Try access st.com and search for the lastest version of Cube HAL. Inside the archive you'll find some example with USART.

\$\endgroup\$
  • \$\begingroup\$ HAL_UART_Transmit_IT and UART_Transmit_IT are different functions. First only sets up interrupts, while second actually transmits data \$\endgroup\$ – rublag Nov 6 '15 at 3:42
  • \$\begingroup\$ Yes, but you know that second function can only be call by other HAL function not direct by user? And i just open my HAL source files and find UART_Transmit_IT and its different than the part you paste above. Other option if you still think there is a bug is to write the same question on st forum. \$\endgroup\$ – Gabriel Rezende Germanovix Nov 6 '15 at 4:03

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.