STMicroelectronics / stm32h7xx_hal_driver

Provides the STM32Cube MCU Component "hal_driver" of the STM32H7 series.
BSD 3-Clause "New" or "Revised" License
97 stars 41 forks source link

HAL_UART_RegisterRxEventCallback fails if there is a transmit ongoing #29

Closed dergentk closed 8 months ago

dergentk commented 2 years ago

Description It is impossible to set an RxEventCallback (with HAL_UART_RegisterRxEventCallback) if a transmit is active on the port.

How To Reproduce start a UART transmit with HAL_UART_Transmit_IT. then immediately thereafter call HAL_UART_RegisterRxEventCallback. That call will fail.

Analysis This is caused by the fact that HAL_UART_RegisterRxEventCallback checks the value of the gState field instead of the RxState like all other receive releated functions do. I don't see a reason for this difference. As far is I can tell the RxEventCallback is unrelated to transmit so checking gState appears to be a mistake.

My Solution Changing gState in HAL_UART_RegisterRxEventCallback and HAL_UART_UnregisterRxEventCallback to RxState makes the problem go away, as expected. And it did not cause unwanted side effects in my testing.

ASELSTM commented 1 year ago

ST Internal Reference: 158193

ASELSTM commented 1 year ago

Hi @dergentk,

First excuse this late answer. Indeed, you are right, the check should be done on RxState and not on gState. This will be fixed and integrated in a future release. Thank you for reporting this and thank you fir your contribution.

With regards,

TOUNSTM commented 8 months ago

Fixed in https://github.com/STMicroelectronics/stm32h7xx_hal_driver/commit/a52bb3a5155f180d94d22ba7ebf26e9de2456b61