diff --git a/drivers/bluetooth/hci/hci_stm32wb0.c b/drivers/bluetooth/hci/hci_stm32wb0.c index 7bc0f1080bf8b..66cae4b8964ca 100644 --- a/drivers/bluetooth/hci/hci_stm32wb0.c +++ b/drivers/bluetooth/hci/hci_stm32wb0.c @@ -343,7 +343,7 @@ static int ble_pm_action(const struct device *dev, static void rng_get_random(void *num, size_t size) { - const struct device *dev = DEVICE_DT_GET(DT_DRV_INST(0)); + const struct device *dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_entropy)); int res; /* try to allocate from pool */ diff --git a/drivers/entropy/entropy_stm32.c b/drivers/entropy/entropy_stm32.c index ac2062f5a4b63..33b4a8651894d 100644 --- a/drivers/entropy/entropy_stm32.c +++ b/drivers/entropy/entropy_stm32.c @@ -36,6 +36,12 @@ #define STM32_CONDRST_SUPPORT #endif +#if IRQLESS_TRNG +#define MAX_AVAIL_RND_NUM 1 +#else +#define MAX_AVAIL_RND_NUM 4 /* Internal four-word FIFO */ +#endif /* IRQLESS_TRNG */ + /* * This driver need to take into account all STM32 family: * - simple rng without hardware fifo and no DMA. @@ -327,10 +333,16 @@ static int recover_seed_error(RNG_TypeDef *rng) { ll_rng_clear_seis(rng); - for (int i = 0; i < 12; ++i) { + for (int i = 0; i < MAX_AVAIL_RND_NUM; ++i) { (void)ll_rng_read_rand_data(rng); } +#if defined(CONFIG_SOC_STM32WB09XX) + if (LL_RNG_GetErrorIrq(rng)) { + SET_BIT(rng->IRQ_SR, RNG_IRQ_SR_ERROR_IRQ); + } +#endif /* CONFIG_SOC_STM32WB09XX */ + if (ll_rng_is_active_seis(rng) != 0) { return -EIO; } @@ -445,7 +457,7 @@ static uint16_t generate_from_isr(uint8_t *buf, uint16_t len) ret = random_sample_get(&rnd_sample); #if !IRQLESS_TRNG NVIC_ClearPendingIRQ(IRQN); -#endif /* IRQLESS_TRNG */ +#endif /* !IRQLESS_TRNG */ if (ret < 0) { continue; diff --git a/drivers/entropy/entropy_stm32.h b/drivers/entropy/entropy_stm32.h index 420841c20203c..0fe446afa120d 100644 --- a/drivers/entropy/entropy_stm32.h +++ b/drivers/entropy/entropy_stm32.h @@ -109,7 +109,9 @@ static inline rng_sample_t ll_rng_read_rand_data(RNG_TypeDef *RNGx) * 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); + if (LL_RNG_GetFfFullIrq(RNGx)) { + SET_BIT(RNGx->IRQ_SR, RNG_IRQ_SR_FF_FULL_IRQ); + } return rnd; #elif defined(CONFIG_SOC_SERIES_STM32WB0X) diff --git a/soc/st/stm32/stm32wb0x/Kconfig.defconfig b/soc/st/stm32/stm32wb0x/Kconfig.defconfig index 3206f4b877b8f..9de986ed923dc 100644 --- a/soc/st/stm32/stm32wb0x/Kconfig.defconfig +++ b/soc/st/stm32/stm32wb0x/Kconfig.defconfig @@ -20,6 +20,9 @@ endif # STM32WB0_RADIO_TIMER if BT +config SYSTEM_WORKQUEUE_STACK_SIZE + default 1152 + config BT_AUTO_PHY_UPDATE default n