From 1e7dcc22a613e113469784f45e388a7f2701937e Mon Sep 17 00:00:00 2001 From: Ali Hozhabri Date: Fri, 7 Nov 2025 20:47:20 +0100 Subject: [PATCH 1/2] drivers: entropy: Fix non-stop RNG ISR firing for STM32WB09 Fix the TRNG driver issue regarding non-stop ISR firing for STM32WB09 by clearing RNG_IRQ_SR_ERROR_IRQ flag. Signed-off-by: Ali Hozhabri --- drivers/entropy/entropy_stm32.h | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/entropy/entropy_stm32.h b/drivers/entropy/entropy_stm32.h index 2ddc6fbac1c61..9405d55485c6e 100644 --- a/drivers/entropy/entropy_stm32.h +++ b/drivers/entropy/entropy_stm32.h @@ -56,6 +56,7 @@ static inline void ll_rng_clear_seis(RNG_TypeDef *RNGx) #if defined(CONFIG_SOC_SERIES_STM32WB0X) # if defined(CONFIG_SOC_STM32WB09XX) LL_RNG_SetResetHealthErrorFlags(RNGx, 1); + WRITE_REG(RNGx->IRQ_SR, RNG_IRQ_SR_ERROR_IRQ); # else LL_RNG_ClearFlag_FAULT(RNGx); # endif From 041af345fc28bce605a43baa344ce083a4e3b9fa Mon Sep 17 00:00:00 2001 From: Ali Hozhabri Date: Fri, 7 Nov 2025 20:53:09 +0100 Subject: [PATCH 2/2] drivers: entropy: Modify the recover_seed_error function for WB0x Exclude the WB0x series from discarding data 12 times from the RNG data register. Add a comment to the recover_seed_error function explaining the reason for reading and discarding data from the RNG data register 12 times. Signed-off-by: Ali Hozhabri --- drivers/entropy/entropy_stm32.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/entropy/entropy_stm32.c b/drivers/entropy/entropy_stm32.c index 602daf19277fa..5b7b444b57ccd 100644 --- a/drivers/entropy/entropy_stm32.c +++ b/drivers/entropy/entropy_stm32.c @@ -301,9 +301,14 @@ static int recover_seed_error(RNG_TypeDef *rng) { ll_rng_clear_seis(rng); +#if !defined(CONFIG_SOC_SERIES_STM32WB0X) + /* After a noise source error is detected, 12 words must be read from the RNG_DR register + * and discarded to restart the entropy generation. + */ for (int i = 0; i < 12; ++i) { (void)ll_rng_read_rand_data(rng); } +#endif /* !CONFIG_SOC_SERIES_STM32WB0X */ if (ll_rng_is_active_seis(rng) != 0) { return -EIO; @@ -419,7 +424,7 @@ static uint16_t generate_from_isr(uint8_t *buf, uint16_t len) byte = random_byte_get(); #if !IRQLESS_TRNG NVIC_ClearPendingIRQ(IRQN); -#endif /* IRQLESS_TRNG */ +#endif /* !IRQLESS_TRNG */ if (byte < 0) { continue;