AnsweredAssumed Answered

STM32CubeF4 __HAL_UART_CLEAR_FLAG macro is incorrect

Question asked by Dan K. on May 30, 2014
Latest reply on May 30, 2014 by Montassar BEN ROMDHANE
The STM32CubeF4 __HAL_UART_CLEAR_FLAG( ) macro is incorrect because it does a read-modify-write. If a status bit becomes set in the USART_SR register by the hardware between the read and the write, that change will be lost because the read-modify-write ANDing process will clear any bits that were cleared when the read occurred, clearing any newly set bits as well.

Likewise a similar problem exists with the __HAL_ADC_CLEAR_FLAG( ), __HAL_I2C_CLEAR_FLAG( ), __HAL_SPI_CLEAR_CRCERRFLAG( ), and __HAL_WWDG_CLEAR_FLAG( ).

In the case of the __HAL_SPI_CLEAR_CRCERRFLAG( ) macro, it has a hidden side effect of always clearing the FRE bit during the read step in the read-modify-write process.

These problems were uncovered when investigating a similar problem with the TIMx interrupts.
See: [DEAD LINK /public/STe2ecommunities/mcu/Lists/STM32Java/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/STM32Java/STM32F4xx%20HAL_TIM_IRQHandler%20misses%20interrupts%20on%20nearly%20overlapping%20TIM%20interrupts&FolderCTID=0x01200200770978C69A1141439FE559EB459D758000F9A0E3A95BA69146A17C2E80209ADC21]STM32F4xx HAL_TIM_IRQHandler misses interrupts on nearly overlapping TIM interrupts