Skip to content

Commit b5f864d

Browse files
Updated HAL_I1C_ErrorCallback funtion to store information about error reason in obj_s->event. This will help user or application to check the reason for the error caused. This address the issue reported in the below link: #14059
Summary of changes: Impact of changes Migration actions required Pull request type [x] Patch update (Bug fix / Target update / Docs update / Test update / Refactor) [] Feature update (New feature / Functionality change / New API) [] Major update (Breaking change E.g. Return code change / API behaviour change) Test results [] No Tests required for this change (E.g docs only update) [x] Covered by existing mbed-os tests (Greentea or Unittest) [] Tests / results supplied as part of this PR Signed-off-by: Affrin Pinhero <[email protected]>
1 parent a3be10c commit b5f864d

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

targets/TARGET_STM/i2c_api.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1067,6 +1067,8 @@ void HAL_I2C_ErrorCallback(I2C_HandleTypeDef *hi2c)
10671067
/* Get object ptr based on handler ptr */
10681068
i2c_t *obj = get_i2c_obj(hi2c);
10691069
struct i2c_s *obj_s = I2C_S(obj);
1070+
uint32_t event_code = 0;
1071+
10701072
#if DEVICE_I2CSLAVE
10711073
I2C_HandleTypeDef *handle = &(obj_s->handle);
10721074
uint32_t address = 0;
@@ -1076,6 +1078,11 @@ void HAL_I2C_ErrorCallback(I2C_HandleTypeDef *hi2c)
10761078
}
10771079
#endif
10781080

1081+
1082+
if ((handle->ErrorCode & HAL_I2C_ERROR_AF) == HAL_I2C_ERROR_AF) {
1083+
/* Keep Set event flag */
1084+
event_code = (I2C_EVENT_TRANSFER_EARLY_NACK) | (I2C_EVENT_ERROR_NO_SLAVE);
1085+
}
10791086
DEBUG_PRINTF("HAL_I2C_ErrorCallback:%d, index=%d\r\n", (int) hi2c->ErrorCode, obj_s->index);
10801087

10811088
/* re-init IP to try and get back in a working state */
@@ -1090,7 +1097,7 @@ void HAL_I2C_ErrorCallback(I2C_HandleTypeDef *hi2c)
10901097
#endif
10911098

10921099
/* Keep Set event flag */
1093-
obj_s->event = I2C_EVENT_ERROR;
1100+
obj_s->event = event_code | I2C_EVENT_ERROR;
10941101
}
10951102

10961103
const PinMap *i2c_master_sda_pinmap()

0 commit comments

Comments
 (0)