diff --git a/drivers/entropy/entropy_stm32.c b/drivers/entropy/entropy_stm32.c index 70c594e287f..2f7c724ad41 100644 --- a/drivers/entropy/entropy_stm32.c +++ b/drivers/entropy/entropy_stm32.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -243,7 +244,9 @@ static uint16_t rng_pool_get(struct rng_pool *rngp, uint8_t *buf, uint16_t len) len = dst - buf; available = available - len; - if (available <= rngp->threshold) { + if ((available <= rngp->threshold) + && !LL_RNG_IsEnabledIT(entropy_stm32_rng_data.rng)) { + pm_constraint_set(PM_STATE_SUSPEND_TO_IDLE); LL_RNG_EnableIT(entropy_stm32_rng_data.rng); } @@ -297,6 +300,7 @@ static void stm32_rng_isr(const void *arg) byte); if (ret < 0) { LL_RNG_DisableIT(entropy_stm32_rng_data.rng); + pm_constraint_release(PM_STATE_SUSPEND_TO_IDLE); } k_sem_give(&entropy_stm32_rng_data.sem_sync); @@ -492,6 +496,12 @@ static int entropy_stm32_rng_init(const struct device *dev) LL_RNG_SetHealthConfig(dev_data->rng, DT_INST_PROP(0, health_test_config)); #endif + /* Prevent the clocks to be stopped during the duration the + * rng pool is being populated. The ISR will release the constraint again + * when the rng pool is filled. + */ + pm_constraint_set(PM_STATE_SUSPEND_TO_IDLE); + LL_RNG_EnableIT(dev_data->rng); LL_RNG_Enable(dev_data->rng);