AnsweredAssumed Answered

STM32F401 - HAL_UART_Receive() - Buggy?

Question asked by MWP on Jan 16, 2017
Latest reply on Jan 16, 2017 by Clive One

Hi all,

 

I believe HAL_UART_Receive() is buggy.

 

Test case:

uint8_t data[2] = {0xAA, 0xBB};

HAL_UART_Receive(&huart1, &data[0], 1, 100);

 

You would expect data[0] to be the data received from the USART, and data[1] to be left alone as 1 is the specified size in bytes.

This is not the case. HAL_UART_Receive() whacks data[1] as well (sets it to a value of 0).

 

Its quite clear why this happens looking at the source for HAL_UART_Receive()...

HAL_StatusTypeDef HAL_UART_Receive(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout)
{
uint16_t* tmp;
......
tmp = (uint16_t*) pData;

......

*tmp = (uint16_t)(huart->Instance->DR & (uint16_t)0x00FFU);

......

}

 

Seems to be a pretty basic mistake?

Outcomes