2025-09-16 5:40 AM
Hi,
I discovered today with some of my students this potential bug in the stm32g431xx.h file:
#define RNG_CR_CED_Pos (5U)
#define RNG_CR_CED_Msk (0x1UL << RNG_CR_IE_Pos) /*!< 0x00000020 */
#define RNG_CR_CED RNG_CR_IE_Msk
As RNG_CR_IE_Pos is equal to 3... This mask is not correct.
It is quite strange: the comment is true... according to the Reference manuel 0440.
I suggest this correction:
#define RNG_CR_CED_Pos (5U)
#define RNG_CR_CED_Msk (0x1UL << RNG_CR_CED_Pos) /*!< 0x00000020 */
#define RNG_CR_CED RNG_CR_CED_Msk
(I checked the last version of this file using this official github : https://github.com/STMicroelectronics/cmsis-device-g4/blob/7c39c32593b03764aaa57531588b8bf7cdd443a5/Include/stm32g431xx.h )
In the HAL, the assert can't detect the fail... "checking itself" :
assert_param(IS_RNG_CED(hrng->Init.ClockErrorDetection));
And this line used this CED... faking:
MODIFY_REG(hrng->Instance->CR, RNG_CR_CED, hrng->Init.ClockErrorDetection);
've fun...
Thx,
Samuel.