From 9ec647ffc36c05d96269624ee330698533eb07ab Mon Sep 17 00:00:00 2001 From: Yannis Damigos Date: Wed, 11 Dec 2019 21:59:46 +0200 Subject: [PATCH 1/4] i2c_ll_stm32: Add timeout to I2C read/write functions Add timeout to I2C read/write functions in interrupt mode. Fixes #21293 Signed-off-by: Yannis Damigos --- drivers/i2c/i2c_ll_stm32.h | 2 ++ drivers/i2c/i2c_ll_stm32_v1.c | 3 --- drivers/i2c/i2c_ll_stm32_v2.c | 27 ++++++++++++++++++++++++--- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/drivers/i2c/i2c_ll_stm32.h b/drivers/i2c/i2c_ll_stm32.h index a0e770580838..8bac06983650 100644 --- a/drivers/i2c/i2c_ll_stm32.h +++ b/drivers/i2c/i2c_ll_stm32.h @@ -9,6 +9,8 @@ #ifndef ZEPHYR_DRIVERS_I2C_I2C_LL_STM32_H_ #define ZEPHYR_DRIVERS_I2C_I2C_LL_STM32_H_ +#define STM32_I2C_TIMEOUT_USEC 1000 + typedef void (*irq_config_func_t)(struct device *port); struct i2c_stm32_config { diff --git a/drivers/i2c/i2c_ll_stm32_v1.c b/drivers/i2c/i2c_ll_stm32_v1.c index 0b4fc5dc8184..ece9c4824d9a 100644 --- a/drivers/i2c/i2c_ll_stm32_v1.c +++ b/drivers/i2c/i2c_ll_stm32_v1.c @@ -23,9 +23,6 @@ LOG_MODULE_REGISTER(i2c_ll_stm32_v1); #include "i2c-priv.h" -#define STM32_I2C_TRANSFER_TIMEOUT_MSEC 500 - -#define STM32_I2C_TIMEOUT_USEC 1000 #define I2C_REQUEST_WRITE 0x00 #define I2C_REQUEST_READ 0x01 #define HEADER 0xF0 diff --git a/drivers/i2c/i2c_ll_stm32_v2.c b/drivers/i2c/i2c_ll_stm32_v2.c index 1b3ee69f9453..611f2838d190 100644 --- a/drivers/i2c/i2c_ll_stm32_v2.c +++ b/drivers/i2c/i2c_ll_stm32_v2.c @@ -92,7 +92,9 @@ static void stm32_i2c_enable_transfer_interrupts(struct device *dev) static void stm32_i2c_master_mode_end(struct device *dev) { const struct i2c_stm32_config *cfg = DEV_CFG(dev); +#if defined(CONFIG_I2C_SLAVE) struct i2c_stm32_data *data = DEV_DATA(dev); +#endif I2C_TypeDef *i2c = cfg->i2c; stm32_i2c_disable_transfer_interrupts(dev); @@ -105,7 +107,6 @@ static void stm32_i2c_master_mode_end(struct device *dev) #else LL_I2C_Disable(i2c); #endif - k_sem_give(&data->device_sync_sem); } #if defined(CONFIG_I2C_SLAVE) @@ -316,6 +317,7 @@ static void stm32_i2c_event(struct device *dev) return; end: stm32_i2c_master_mode_end(dev); + k_sem_give(&data->device_sync_sem); } static int stm32_i2c_error(struct device *dev) @@ -346,6 +348,7 @@ static int stm32_i2c_error(struct device *dev) return 0; end: stm32_i2c_master_mode_end(dev); + k_sem_give(&data->device_sync_sem); return -EIO; } @@ -382,6 +385,7 @@ int stm32_i2c_msg_write(struct device *dev, struct i2c_msg *msg, const struct i2c_stm32_config *cfg = DEV_CFG(dev); struct i2c_stm32_data *data = DEV_DATA(dev); I2C_TypeDef *i2c = cfg->i2c; + int32_t err = 0; data->current.len = msg->len; data->current.buf = msg->buf; @@ -395,7 +399,15 @@ int stm32_i2c_msg_write(struct device *dev, struct i2c_msg *msg, stm32_i2c_enable_transfer_interrupts(dev); LL_I2C_EnableIT_TX(i2c); - k_sem_take(&data->device_sync_sem, K_FOREVER); + err = k_sem_take(&data->device_sync_sem, + K_MSEC(STM32_I2C_TIMEOUT_USEC / 1000)); + if (err < 0) { + if (LL_I2C_IsEnabledReloadMode(i2c)) { + LL_I2C_DisableReloadMode(i2c); + } + stm32_i2c_master_mode_end(dev); + data->current.is_err = err; + } if (data->current.is_nack || data->current.is_err || data->current.is_arlo) { @@ -430,6 +442,7 @@ int stm32_i2c_msg_read(struct device *dev, struct i2c_msg *msg, const struct i2c_stm32_config *cfg = DEV_CFG(dev); struct i2c_stm32_data *data = DEV_DATA(dev); I2C_TypeDef *i2c = cfg->i2c; + int32_t err = 0; data->current.len = msg->len; data->current.buf = msg->buf; @@ -444,7 +457,15 @@ int stm32_i2c_msg_read(struct device *dev, struct i2c_msg *msg, stm32_i2c_enable_transfer_interrupts(dev); LL_I2C_EnableIT_RX(i2c); - k_sem_take(&data->device_sync_sem, K_FOREVER); + err = k_sem_take(&data->device_sync_sem, + K_MSEC(STM32_I2C_TIMEOUT_USEC / 1000)); + if (err < 0) { + if (LL_I2C_IsEnabledReloadMode(i2c)) { + LL_I2C_DisableReloadMode(i2c); + } + stm32_i2c_master_mode_end(dev); + data->current.is_err = err; + } if (data->current.is_nack || data->current.is_err || data->current.is_arlo) { From fd9e7eb37897c41304c2c8714e09941c844645b9 Mon Sep 17 00:00:00 2001 From: Yannis Damigos Date: Sat, 14 Dec 2019 18:51:29 +0200 Subject: [PATCH 2/4] dts/st,stm32-i2c*: Add timeout-us property in yaml Add timeout-us property in yaml Signed-off-by: Yannis Damigos --- dts/bindings/i2c/st,stm32-i2c-v1.yaml | 5 +++++ dts/bindings/i2c/st,stm32-i2c-v2.yaml | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/dts/bindings/i2c/st,stm32-i2c-v1.yaml b/dts/bindings/i2c/st,stm32-i2c-v1.yaml index 51fb56f1fa2b..76fbc5b1ac69 100644 --- a/dts/bindings/i2c/st,stm32-i2c-v1.yaml +++ b/dts/bindings/i2c/st,stm32-i2c-v1.yaml @@ -13,3 +13,8 @@ properties: interrupts: required: true + + timeout-us: + type: int + required: false + description: Transaction timeout in microseconds diff --git a/dts/bindings/i2c/st,stm32-i2c-v2.yaml b/dts/bindings/i2c/st,stm32-i2c-v2.yaml index 5dcf30b39342..ecb8526bb8c6 100644 --- a/dts/bindings/i2c/st,stm32-i2c-v2.yaml +++ b/dts/bindings/i2c/st,stm32-i2c-v2.yaml @@ -13,3 +13,8 @@ properties: interrupts: required: true + + timeout-us: + type: int + required: false + description: Transaction timeout in microseconds From e61e0268350810a6b6ed13be4dcb3e81cb7731ae Mon Sep 17 00:00:00 2001 From: Yannis Damigos Date: Sat, 14 Dec 2019 18:56:34 +0200 Subject: [PATCH 3/4] i2c_ll_stm32: Get timeout value from DT Get timeout value from DT Signed-off-by: Yannis Damigos --- drivers/i2c/i2c_ll_stm32.c | 43 ++++++++++++++++++----------------- drivers/i2c/i2c_ll_stm32.h | 3 +-- drivers/i2c/i2c_ll_stm32_v1.c | 38 +++++++++++++++---------------- drivers/i2c/i2c_ll_stm32_v2.c | 6 ++--- 4 files changed, 44 insertions(+), 46 deletions(-) diff --git a/drivers/i2c/i2c_ll_stm32.c b/drivers/i2c/i2c_ll_stm32.c index 68500afb6513..af4b9cf031b4 100644 --- a/drivers/i2c/i2c_ll_stm32.c +++ b/drivers/i2c/i2c_ll_stm32.c @@ -289,27 +289,28 @@ static void i2c_stm32_irq_config_func_##name(struct device *dev) \ #endif /* CONFIG_I2C_STM32_INTERRUPT */ -#define STM32_I2C_INIT(name) \ -STM32_I2C_IRQ_HANDLER_DECL(name); \ - \ -static const struct i2c_stm32_config i2c_stm32_cfg_##name = { \ - .i2c = (I2C_TypeDef *)DT_REG_ADDR(DT_NODELABEL(name)), \ - .pclken = { \ - .enr = DT_CLOCKS_CELL(DT_NODELABEL(name), bits), \ - .bus = DT_CLOCKS_CELL(DT_NODELABEL(name), bus), \ - }, \ - STM32_I2C_IRQ_HANDLER_FUNCTION(name) \ - .bitrate = DT_PROP(DT_NODELABEL(name), clock_frequency), \ -}; \ - \ -static struct i2c_stm32_data i2c_stm32_dev_data_##name; \ - \ -DEVICE_AND_API_INIT(i2c_stm32_##name, DT_LABEL(DT_NODELABEL(name)), \ - &i2c_stm32_init, &i2c_stm32_dev_data_##name, \ - &i2c_stm32_cfg_##name, \ - POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE, \ - &api_funcs); \ - \ +#define STM32_I2C_INIT(name) \ +STM32_I2C_IRQ_HANDLER_DECL(name); \ + \ +static const struct i2c_stm32_config i2c_stm32_cfg_##name = { \ + .i2c = (I2C_TypeDef *)DT_REG_ADDR(DT_NODELABEL(name)), \ + .pclken = { \ + .enr = DT_CLOCKS_CELL(DT_NODELABEL(name), bits), \ + .bus = DT_CLOCKS_CELL(DT_NODELABEL(name), bus), \ + }, \ + STM32_I2C_IRQ_HANDLER_FUNCTION(name) \ + .bitrate = DT_PROP(DT_NODELABEL(name), clock_frequency), \ + .timeout = DT_PROP_OR(DT_NODELABEL(name), timeout_ms, UINT32_MAX) \ + }; \ + \ +static struct i2c_stm32_data i2c_stm32_dev_data_##name; \ + \ +DEVICE_AND_API_INIT(i2c_stm32_##name, DT_LABEL(DT_NODELABEL(name)), \ + &i2c_stm32_init, &i2c_stm32_dev_data_##name, \ + &i2c_stm32_cfg_##name, \ + POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE, \ + &api_funcs); \ + \ STM32_I2C_IRQ_HANDLER(name) /* I2C instances declaration */ diff --git a/drivers/i2c/i2c_ll_stm32.h b/drivers/i2c/i2c_ll_stm32.h index 8bac06983650..76bfdcc008b6 100644 --- a/drivers/i2c/i2c_ll_stm32.h +++ b/drivers/i2c/i2c_ll_stm32.h @@ -9,8 +9,6 @@ #ifndef ZEPHYR_DRIVERS_I2C_I2C_LL_STM32_H_ #define ZEPHYR_DRIVERS_I2C_I2C_LL_STM32_H_ -#define STM32_I2C_TIMEOUT_USEC 1000 - typedef void (*irq_config_func_t)(struct device *port); struct i2c_stm32_config { @@ -20,6 +18,7 @@ struct i2c_stm32_config { struct stm32_pclken pclken; I2C_TypeDef *i2c; uint32_t bitrate; + uint32_t timeout; }; struct i2c_stm32_data { diff --git a/drivers/i2c/i2c_ll_stm32_v1.c b/drivers/i2c/i2c_ll_stm32_v1.c index ece9c4824d9a..cf5adddb4b5f 100644 --- a/drivers/i2c/i2c_ll_stm32_v1.c +++ b/drivers/i2c/i2c_ll_stm32_v1.c @@ -617,8 +617,7 @@ int32_t stm32_i2c_msg_write(struct device *dev, struct i2c_msg *msg, stm32_i2c_enable_transfer_interrupts(dev); LL_I2C_EnableIT_TX(i2c); - if (k_sem_take(&data->device_sync_sem, - K_MSEC(STM32_I2C_TRANSFER_TIMEOUT_MSEC)) != 0) { + if (k_sem_take(&data->device_sync_sem, K_USEC(cfg->timeout)) != 0) { LOG_DBG("%s: WRITE timeout", __func__); stm32_i2c_reset(dev); return -EIO; @@ -639,8 +638,7 @@ int32_t stm32_i2c_msg_read(struct device *dev, struct i2c_msg *msg, stm32_i2c_enable_transfer_interrupts(dev); LL_I2C_EnableIT_RX(i2c); - if (k_sem_take(&data->device_sync_sem, - K_MSEC(STM32_I2C_TRANSFER_TIMEOUT_MSEC)) != 0) { + if (k_sem_take(&data->device_sync_sem, K_USEC(cfg->timeout)) != 0) { LOG_DBG("%s: READ timeout", __func__); stm32_i2c_reset(dev); return -EIO; @@ -690,7 +688,7 @@ static inline int check_errors(struct device *dev, const char *funcname) return -EIO; } -static int stm32_i2c_wait_timeout(uint16_t *timeout) +static int stm32_i2c_wait_timeout(uint32_t *timeout) { if (*timeout == 0) { return 1; @@ -708,13 +706,14 @@ int32_t stm32_i2c_msg_write(struct device *dev, struct i2c_msg *msg, struct i2c_stm32_data *data = DEV_DATA(dev); I2C_TypeDef *i2c = cfg->i2c; uint32_t len = msg->len; - uint16_t timeout; + const uint32_t timeout_us = cfg->timeout; + uint32_t timeout; uint8_t *buf = msg->buf; msg_init(dev, msg, next_msg_flags, saddr, I2C_REQUEST_WRITE); if (msg->flags & I2C_MSG_RESTART) { - timeout = STM32_I2C_TIMEOUT_USEC; + timeout = timeout_us; while (!LL_I2C_IsActiveFlag_SB(i2c)) { if (stm32_i2c_wait_timeout(&timeout)) { LL_I2C_GenerateStopCondition(i2c); @@ -728,7 +727,7 @@ int32_t stm32_i2c_msg_write(struct device *dev, struct i2c_msg *msg, uint8_t header = slave | HEADER; LL_I2C_TransmitData8(i2c, header); - timeout = STM32_I2C_TIMEOUT_USEC; + timeout = timeout_us; while (!LL_I2C_IsActiveFlag_ADD10(i2c)) { if (stm32_i2c_wait_timeout(&timeout)) { LL_I2C_GenerateStopCondition(i2c); @@ -745,7 +744,7 @@ int32_t stm32_i2c_msg_write(struct device *dev, struct i2c_msg *msg, LL_I2C_TransmitData8(i2c, slave | I2C_REQUEST_WRITE); } - timeout = STM32_I2C_TIMEOUT_USEC; + timeout = timeout_us; while (!LL_I2C_IsActiveFlag_ADDR(i2c)) { if (LL_I2C_IsActiveFlag_AF(i2c) || stm32_i2c_wait_timeout(&timeout)) { LL_I2C_ClearFlag_AF(i2c); @@ -758,7 +757,7 @@ int32_t stm32_i2c_msg_write(struct device *dev, struct i2c_msg *msg, } while (len) { - timeout = STM32_I2C_TIMEOUT_USEC; + timeout = timeout_us; while (1) { if (LL_I2C_IsActiveFlag_TXE(i2c)) { break; @@ -775,7 +774,7 @@ int32_t stm32_i2c_msg_write(struct device *dev, struct i2c_msg *msg, len--; } - timeout = STM32_I2C_TIMEOUT_USEC; + timeout = timeout_us; while (!LL_I2C_IsActiveFlag_BTF(i2c)) { if (stm32_i2c_wait_timeout(&timeout)) { LL_I2C_GenerateStopCondition(i2c); @@ -800,13 +799,14 @@ int32_t stm32_i2c_msg_read(struct device *dev, struct i2c_msg *msg, struct i2c_stm32_data *data = DEV_DATA(dev); I2C_TypeDef *i2c = cfg->i2c; uint32_t len = msg->len; - uint16_t timeout; + const uint32_t timeout_us = cfg->timeout; + uint32_t timeout; uint8_t *buf = msg->buf; msg_init(dev, msg, next_msg_flags, saddr, I2C_REQUEST_READ); if (msg->flags & I2C_MSG_RESTART) { - timeout = STM32_I2C_TIMEOUT_USEC; + timeout = timeout_us; while (!LL_I2C_IsActiveFlag_SB(i2c)) { if (stm32_i2c_wait_timeout(&timeout)) { LL_I2C_GenerateStopCondition(i2c); @@ -820,7 +820,7 @@ int32_t stm32_i2c_msg_read(struct device *dev, struct i2c_msg *msg, uint8_t header = slave | HEADER; LL_I2C_TransmitData8(i2c, header); - timeout = STM32_I2C_TIMEOUT_USEC; + timeout = timeout_us; while (!LL_I2C_IsActiveFlag_ADD10(i2c)) { if (stm32_i2c_wait_timeout(&timeout)) { LL_I2C_GenerateStopCondition(i2c); @@ -831,7 +831,7 @@ int32_t stm32_i2c_msg_read(struct device *dev, struct i2c_msg *msg, slave = saddr & 0xFF; LL_I2C_TransmitData8(i2c, slave); - timeout = STM32_I2C_TIMEOUT_USEC; + timeout = timeout_us; while (!LL_I2C_IsActiveFlag_ADDR(i2c)) { if (stm32_i2c_wait_timeout(&timeout)) { LL_I2C_GenerateStopCondition(i2c); @@ -842,7 +842,7 @@ int32_t stm32_i2c_msg_read(struct device *dev, struct i2c_msg *msg, LL_I2C_ClearFlag_ADDR(i2c); stm32_i2c_generate_start_condition(i2c); - timeout = STM32_I2C_TIMEOUT_USEC; + timeout = timeout_us; while (!LL_I2C_IsActiveFlag_SB(i2c)) { if (stm32_i2c_wait_timeout(&timeout)) { LL_I2C_GenerateStopCondition(i2c); @@ -859,7 +859,7 @@ int32_t stm32_i2c_msg_read(struct device *dev, struct i2c_msg *msg, LL_I2C_TransmitData8(i2c, slave | I2C_REQUEST_READ); } - timeout = STM32_I2C_TIMEOUT_USEC; + timeout = timeout_us; while (!LL_I2C_IsActiveFlag_ADDR(i2c)) { if (LL_I2C_IsActiveFlag_AF(i2c) || stm32_i2c_wait_timeout(&timeout)) { LL_I2C_ClearFlag_AF(i2c); @@ -883,7 +883,7 @@ int32_t stm32_i2c_msg_read(struct device *dev, struct i2c_msg *msg, } while (len) { - timeout = STM32_I2C_TIMEOUT_USEC; + timeout = timeout_us; while (!LL_I2C_IsActiveFlag_RXNE(i2c)) { if (stm32_i2c_wait_timeout(&timeout)) { LL_I2C_GenerateStopCondition(i2c); @@ -892,7 +892,7 @@ int32_t stm32_i2c_msg_read(struct device *dev, struct i2c_msg *msg, } } - timeout = STM32_I2C_TIMEOUT_USEC; + timeout = timeout_us; switch (len) { case 1: if (msg->flags & I2C_MSG_STOP) { diff --git a/drivers/i2c/i2c_ll_stm32_v2.c b/drivers/i2c/i2c_ll_stm32_v2.c index 611f2838d190..95b7d895f183 100644 --- a/drivers/i2c/i2c_ll_stm32_v2.c +++ b/drivers/i2c/i2c_ll_stm32_v2.c @@ -399,8 +399,7 @@ int stm32_i2c_msg_write(struct device *dev, struct i2c_msg *msg, stm32_i2c_enable_transfer_interrupts(dev); LL_I2C_EnableIT_TX(i2c); - err = k_sem_take(&data->device_sync_sem, - K_MSEC(STM32_I2C_TIMEOUT_USEC / 1000)); + err = k_sem_take(&data->device_sync_sem, K_USEC(cfg->timeout)); if (err < 0) { if (LL_I2C_IsEnabledReloadMode(i2c)) { LL_I2C_DisableReloadMode(i2c); @@ -457,8 +456,7 @@ int stm32_i2c_msg_read(struct device *dev, struct i2c_msg *msg, stm32_i2c_enable_transfer_interrupts(dev); LL_I2C_EnableIT_RX(i2c); - err = k_sem_take(&data->device_sync_sem, - K_MSEC(STM32_I2C_TIMEOUT_USEC / 1000)); + err = k_sem_take(&data->device_sync_sem, K_USEC(cfg->timeout)); if (err < 0) { if (LL_I2C_IsEnabledReloadMode(i2c)) { LL_I2C_DisableReloadMode(i2c); From 59e3a4178524e17e03cef8755ce9a0cf8f95fec4 Mon Sep 17 00:00:00 2001 From: Yannis Damigos Date: Sun, 15 Dec 2019 14:24:36 +0200 Subject: [PATCH 4/4] i2c_ll_stm32_v2: Add transaction timeout to polling mode Add transaction timeout to polling mode Signed-off-by: Yannis Damigos --- drivers/i2c/i2c_ll_stm32_v2.c | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/drivers/i2c/i2c_ll_stm32_v2.c b/drivers/i2c/i2c_ll_stm32_v2.c index 95b7d895f183..e3af254172f1 100644 --- a/drivers/i2c/i2c_ll_stm32_v2.c +++ b/drivers/i2c/i2c_ll_stm32_v2.c @@ -493,11 +493,29 @@ int stm32_i2c_msg_read(struct device *dev, struct i2c_msg *msg, } #else /* !CONFIG_I2C_STM32_INTERRUPT */ -static inline int check_errors(struct device *dev, const char *funcname) +static int stm32_i2c_wait_timeout(uint32_t *timeout) +{ + if (*timeout == 0) { + return 1; + } else { + k_busy_wait(1); + (*timeout)--; + return 0; + } +} + +static inline int check_errors(struct device *dev, uint32_t *timeout, + const char *funcname) { const struct i2c_stm32_config *cfg = DEV_CFG(dev); I2C_TypeDef *i2c = cfg->i2c; + if (stm32_i2c_wait_timeout(timeout)) { + LL_I2C_GenerateStopCondition(i2c); + LOG_DBG("%s: Timeout", funcname); + goto error; + } + if (LL_I2C_IsActiveFlag_NACK(i2c)) { LL_I2C_ClearFlag_NACK(i2c); LOG_DBG("%s: NACK", funcname); @@ -530,14 +548,15 @@ static inline int check_errors(struct device *dev, const char *funcname) return -EIO; } -static inline int msg_done(struct device *dev, unsigned int current_msg_flags) +static inline int msg_done(struct device *dev, uint32_t *timeout, + unsigned int current_msg_flags) { const struct i2c_stm32_config *cfg = DEV_CFG(dev); I2C_TypeDef *i2c = cfg->i2c; /* Wait for transfer to complete */ while (!LL_I2C_IsActiveFlag_TC(i2c) && !LL_I2C_IsActiveFlag_TCR(i2c)) { - if (check_errors(dev, __func__)) { + if (check_errors(dev, timeout, __func__)) { return -EIO; } } @@ -561,6 +580,7 @@ int stm32_i2c_msg_write(struct device *dev, struct i2c_msg *msg, I2C_TypeDef *i2c = cfg->i2c; unsigned int len = 0U; uint8_t *buf = msg->buf; + uint32_t timeout = cfg->timeout; msg_init(dev, msg, next_msg_flags, slave, LL_I2C_REQUEST_WRITE); @@ -571,7 +591,7 @@ int stm32_i2c_msg_write(struct device *dev, struct i2c_msg *msg, break; } - if (check_errors(dev, __func__)) { + if (check_errors(dev, &timeout, __func__)) { return -EIO; } } @@ -581,7 +601,7 @@ int stm32_i2c_msg_write(struct device *dev, struct i2c_msg *msg, len--; } - return msg_done(dev, msg->flags); + return msg_done(dev, &timeout, msg->flags); } int stm32_i2c_msg_read(struct device *dev, struct i2c_msg *msg, @@ -591,13 +611,14 @@ int stm32_i2c_msg_read(struct device *dev, struct i2c_msg *msg, I2C_TypeDef *i2c = cfg->i2c; unsigned int len = 0U; uint8_t *buf = msg->buf; + uint32_t timeout = cfg->timeout; msg_init(dev, msg, next_msg_flags, slave, LL_I2C_REQUEST_READ); len = msg->len; while (len) { while (!LL_I2C_IsActiveFlag_RXNE(i2c)) { - if (check_errors(dev, __func__)) { + if (check_errors(dev, &timeout, __func__)) { return -EIO; } } @@ -607,7 +628,7 @@ int stm32_i2c_msg_read(struct device *dev, struct i2c_msg *msg, len--; } - return msg_done(dev, msg->flags); + return msg_done(dev, &timeout, msg->flags); } #endif