From 7288223a28c7a24fae8112824cdeee4cd71ea017 Mon Sep 17 00:00:00 2001 From: Mathieu Choplain Date: Wed, 19 Mar 2025 15:32:16 +0100 Subject: [PATCH] drivers: entropy: stm32: clear data available IRQ flag on WB09 The STM32WB09 TRNG does not clear FIFO_FULL IRQ flag in hardware once the FIFO is no longer full, a behavior which differs from all other series. This results in spurious IRQs, as the TRNG IRQ line effectively remains high forever once a single interrupt has been generated. Clear the flag in software after reading from the FIFO on STM32WB09 SoC. N.B.: the error IRQ flag is already handled properly, as this flag must also be cleared by software on other series. Signed-off-by: Mathieu Choplain --- drivers/entropy/entropy_stm32.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/drivers/entropy/entropy_stm32.h b/drivers/entropy/entropy_stm32.h index 530af9c89ac..533cc031493 100644 --- a/drivers/entropy/entropy_stm32.h +++ b/drivers/entropy/entropy_stm32.h @@ -91,7 +91,19 @@ static inline uint32_t ll_rng_is_active_drdy(RNG_TypeDef *RNGx) static inline uint16_t ll_rng_read_rand_data(RNG_TypeDef *RNGx) { #if defined(CONFIG_SOC_STM32WB09XX) - return (uint16_t)LL_RNG_GetRndVal(RNGx); + uint16_t rnd = (uint16_t)LL_RNG_GetRndVal(RNGx); + + /** + * STM32WB09 TRNG does not clear IRQ flags in hardware. + * We must clear the "FIFO full" flag now that we consumed data + * from it to ensure the TRNG's IRQ line goes back to low state. + * + * Raw register access is performed because STM32CubeWB0 v1.0.0 + * package is lacking the LL function to clear IRQ flags. + */ + WRITE_REG(RNG->IRQ_SR, RNG_IRQ_SR_FF_FULL_IRQ); + + return rnd; #elif defined(CONFIG_SOC_SERIES_STM32WB0X) /* STM32WB05 / STM32WB06 / STM32WB07 */ return LL_RNG_ReadRandData16(RNGx);