diff --git a/drivers/i2c/i2c_ll_stm32.c b/drivers/i2c/i2c_ll_stm32.c index f834aa658f78..29f5a5ae08fe 100644 --- a/drivers/i2c/i2c_ll_stm32.c +++ b/drivers/i2c/i2c_ll_stm32.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -173,10 +174,11 @@ static int i2c_stm32_transfer(const struct device *dev, struct i2c_msg *msg, /* Prevent driver from being suspended by PM until I2C transaction is complete */ #ifdef CONFIG_PM_DEVICE_RUNTIME (void)pm_device_runtime_get(dev); -#else - pm_device_busy_set(dev); #endif + /* Prevent the clocks to be stopped during the i2c transaction */ + pm_policy_state_lock_get(PM_STATE_SUSPEND_TO_IDLE, PM_ALL_SUBSTATES); + current = msg; while (num_msgs > 0) { @@ -194,10 +196,10 @@ static int i2c_stm32_transfer(const struct device *dev, struct i2c_msg *msg, num_msgs--; } + pm_policy_state_lock_put(PM_STATE_SUSPEND_TO_IDLE, PM_ALL_SUBSTATES); + #ifdef CONFIG_PM_DEVICE_RUNTIME (void)pm_device_runtime_put(dev); -#else - pm_device_busy_clear(dev); #endif k_sem_give(&data->bus_mutex);