From 8f2c45c5af40301a00cbd4166379e96e033b3eca Mon Sep 17 00:00:00 2001 From: Krishna Mohan Dani Date: Wed, 12 May 2021 00:16:22 +0530 Subject: [PATCH] Driver: I2C: STM32F4: Fix for every alternate i2c read failure in F2, F4 & L1 families. This commit fixes the i2c driver issue reported in the below link: https://github.com/ARMmbed/mbed-os/issues/13967 on STM32F4xx platform. The data type of XferOperation has been changed from uint8_t to uint32_t so that it can hold a 32bit value (for example: I2C_OTHER_FRAME or I2C_OTHER_AND_LAST_FRAME). Signed-off-by: Krishna Mohan Dani --- targets/TARGET_STM/TARGET_STM32F2/objects.h | 2 +- targets/TARGET_STM/TARGET_STM32F4/objects.h | 2 +- targets/TARGET_STM/i2c_api.c | 8 +++++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/targets/TARGET_STM/TARGET_STM32F2/objects.h b/targets/TARGET_STM/TARGET_STM32F2/objects.h index 98eb64d2be..65d4484c83 100644 --- a/targets/TARGET_STM/TARGET_STM32F2/objects.h +++ b/targets/TARGET_STM/TARGET_STM32F2/objects.h @@ -122,7 +122,7 @@ struct i2c_s { PinName scl; IRQn_Type event_i2cIRQ; IRQn_Type error_i2cIRQ; - uint8_t XferOperation; + uint32_t XferOperation; volatile uint8_t event; #if DEVICE_I2CSLAVE uint8_t slave; diff --git a/targets/TARGET_STM/TARGET_STM32F4/objects.h b/targets/TARGET_STM/TARGET_STM32F4/objects.h index 6042c824b6..8c42e83c0c 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/objects.h +++ b/targets/TARGET_STM/TARGET_STM32F4/objects.h @@ -106,7 +106,7 @@ struct i2c_s { int scl_func; IRQn_Type event_i2cIRQ; IRQn_Type error_i2cIRQ; - uint8_t XferOperation; + uint32_t XferOperation; volatile uint8_t event; #if DEVICE_I2CSLAVE uint8_t slave; diff --git a/targets/TARGET_STM/i2c_api.c b/targets/TARGET_STM/i2c_api.c index 257a345aad..69dcf6e067 100644 --- a/targets/TARGET_STM/i2c_api.c +++ b/targets/TARGET_STM/i2c_api.c @@ -86,6 +86,10 @@ static I2C_HandleTypeDef *i2c_handles[I2C_NUM]; #define FLAG_TIMEOUT ((int)0x1000) #endif +#ifdef I2C_IP_VERSION_V1 +#define I2C_STATE_NONE ((uint32_t)(HAL_I2C_MODE_NONE)) +#endif + /* Declare i2c_init_internal to be used in this file */ void i2c_init_internal(i2c_t *obj, const i2c_pinmap_t *pinmap); @@ -1057,7 +1061,9 @@ void HAL_I2C_MasterRxCpltCallback(I2C_HandleTypeDef *hi2c) /* Get object ptr based on handler ptr */ i2c_t *obj = get_i2c_obj(hi2c); struct i2c_s *obj_s = I2C_S(obj); - +#ifdef I2C_IP_VERSION_V1 + hi2c->PreviousState = I2C_STATE_NONE; +#endif /* Set event flag */ obj_s->event = I2C_EVENT_TRANSFER_COMPLETE; }