2020-03-18 03:49 AM
When we use UART as DATA 8bits with parity, STM32F4xx_HAL_driver for UART accesses one byte beyond the specified buffer. Could you please confirm attached patch?
In stm32f4xx_hal_uart.c , there are other similar problems.
Solved! Go to Solution.
2020-05-05 05:36 AM
This issue will be fixed in the coming release of Cube firmware package for all impacted series.
2020-03-18 04:15 PM
I'm not seeing where this accesses any more than exactly one byte in the given scenario. Perhaps explain more why you think what you do.
2020-03-18 04:58 PM
The driver accesses buffer as uint16_t, if the setting is data 8bits with
parity. So, when we use for example HAL_UART_receive(), the driver write “0x00�?
to the next last byte. “0x00�? is derived bit mask “0x00ff�?.
2020-03-18 05:14 PM
pRxBuffPtr is of type uint8_t *. So the statement *huart->pRxBuffPtr = (uint8_t) tmp only accesses a single byte.
It only accesses it as a uint16_t if parity is none and wordlength is 9 bits.
Edit: I see now you're referring to the before-diff statements and not the after-diff statements. I agree with your assessment.
2020-03-18 05:28 PM
2984 /**
2985 * @brief Receives an amount of data in non blocking mode
2986 * @param huart Pointer to a UART_HandleTypeDef structure that contains
2987 * the configuration information for the specified UART module.
2988 * @retval HAL status
2989 */
2990 static HAL_StatusTypeDef UART_Receive_IT(UART_HandleTypeDef *huart)
2991 {
2992 uint16_t *tmp;
2993
2994 /* Check that a Rx process is ongoing */
2995 if (huart->RxState == HAL_UART_STATE_BUSY_RX)
2996 {
2997 if (huart->Init.WordLength == UART_WORDLENGTH_9B)
2998 {
2999 tmp = (uint16_t *) huart->pRxBuffPtr;
3000 if (huart->Init.Parity == UART_PARITY_NONE)
3001 {
3002 *tmp = (uint16_t)(huart->Instance->DR & (uint16_t)0x01FF);
3003 huart->pRxBuffPtr += 2U;
3004 }
3005 else
3006 {
3007 *tmp = (uint16_t)(huart->Instance->DR & (uint16_t)0x00FF);
3008 huart->pRxBuffPtr += 1U;
3009 }
3010 }
3011 else
3012 {
3013 if (huart->Init.Parity == UART_PARITY_NONE)
3014 {
3015 *huart->pRxBuffPtr++ = (uint8_t)(huart->Instance->DR & (uint8_t)0x00FF);
3016 }
3017 else
3018 {
3019 *huart->pRxBuffPtr++ = (uint8_t)(huart->Instance->DR & (uint8_t)0x007F);
3020 }
3021 }
3022
Please refer to the avobe.
This code is stm32f4xx_hal_uart.c in version 1.25.0.
When we use DATA 8bits with parity, Init.WordLength is UART_WORDLENGTH_9B.
2020-03-18 05:36 PM
At line 3007, the driver accesses as 16bit.
2020-03-18 05:55 PM
The same code exists in STM32F1xx, STM32F2xx and STM32L1xx
But, other MCU series have other UART hard logic, so the same codes don't exist.
2020-03-18 05:57 PM
My attached file is partial solution for this issue. Other accesses exist in this driver.
2020-03-18 06:01 PM
This bug has been present since at least v1.21.0, which is the oldest firmware I have on my computer.
2020-04-08 08:59 AM
Hello,
I will review this issue and come back to you with update.
Thank your for your contribution and the issue reporting.
Best Regards,
Imen