Skip to content

Commit 7f68465

Browse files
authored
Merge pull request #14631 from affrinpinhero-2356/feature_i2c_CB_error
driver/I2C: STm32: Updated HAL_I2C_ErrorCallback function to store information about error reason in obj_s->event
2 parents 26c6b75 + b5f864d commit 7f68465

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)