2017-11-26 07:27 AM
I am working with the UART_Hyperterminal_IT example in STM32Cube_FW_F2_V1.7.0. My micro is STM32F217.
My calls to HAL_UART_Receive_IT() are blocking. That is probably the expected behavior, but I would prefer to:
1. have the call return immediately with some bad status if no data is available
or
2. use some other call that checks data available in the UART before I call Read.
Is that possible?
2017-11-26 11:58 AM
Not supposed to block,
You can read the USART->SR to check for RXNE, might actually be a macro for that, __HAL_USART_GET_FLAG() ?
2017-11-26 01:47 PM
Thanks, Clive, that did it!
HAL_UART_Receive_IT() does seem to block. Here is my main loop:
int loopCount = 0;
GlFeigInit(&UartHandle);
while (1)
{
loopCount += 1;
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_1, (loopCount & 0x0001) ?
GPIO_PIN_SET : GPIO_PIN_RESET);
GlFeigTick(&UartHandle);
}
and here is the top of GlFeigTick():
void GlFeigTick(UART_HandleTypeDef * pUartHandle_p)
{
uint8_t ch;
if (HAL_UART_GetState(pUartHandle_p) == HAL_UART_STATE_READY)
{
HAL_StatusTypeDef rc = HAL_TIMEOUT;
rc = HAL_UART_Receive_IT(pUartHandle_p, &ch, 1); //BLOCKS!!!!!
if (rc == HAL_OK)
{
If I comment out the call to HAL_UART_Receive_IT, B1 toggles at about 1 MHz. If I uncomment that call, B1 changes state when I send a byte to USART2. Checking RXNE in the UART before trying to read was the fix:
void GlFeigTick(UART_HandleTypeDef * pUartHandle_p)
{
uint8_t ch;
if (HAL_UART_GetState(pUartHandle_p) == HAL_UART_STATE_READY)
{
HAL_StatusTypeDef rc = HAL_TIMEOUT;
int notEmpty = __HAL_USART_GET_FLAG(pUartHandle_p, USART_FLAG_RXNE);
if (notEmpty)
{
rc = HAL_UART_Receive_IT(pUartHandle_p, &ch, 1); //BLOCKS!!!!!
}
if (rc == HAL_OK)
{
This code toggles B1, i.e. it does not block, but when I send a byte it gets processed under HAL_OK.
Best Regards,
Larry