Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix repeated start for transactional I2C API on STM32 devices with I2C v2 #15394

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions targets/TARGET_STM/i2c_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -931,21 +931,17 @@ static void prep_for_restart_if_needed(struct i2c_s *obj_s) {
* STOP at the end of the current transaction.
*/
static uint32_t get_hal_xfer_options(struct i2c_s *obj_s, bool stop) {
if (obj_s->state == STM_I2C_SB_READ_IN_PROGRESS || obj_s->state == STM_I2C_SB_WRITE_IN_PROGRESS) {
if(stop) {
// Generate restart condition and stop at end
return I2C_OTHER_AND_LAST_FRAME;
} else {
// Generate restart condition but don't send STOP
return I2C_OTHER_FRAME;
}
(void)obj_s;

// Note: The naming used by STM32 HAL is quite counterintuitive. "OTHER_FRAME" means "always send a
// start/restart condition at the start of the frame". In contrast, "FIRST_FRAME" means "don't send
// a start/restart if the previous transfer was going the same direction".
if(stop) {
// Generate start condition and stop at end
return I2C_OTHER_AND_LAST_FRAME;
} else {
if(stop) {
// Generate start condition and stop at end
return I2C_FIRST_AND_LAST_FRAME;
} else {
return I2C_LAST_FRAME;
}
// Generate only the start condition
return I2C_OTHER_FRAME;
}
}

Expand Down