Skip to content

Commit

Permalink
Merge pull request #15394 from mbed-ce/upstreamed/stm32-i2c-repeated-…
Browse files Browse the repository at this point in the history
…start-fix

Fix repeated start for transactional I2C API on STM32 devices with I2C v2
  • Loading branch information
0xc0170 authored Apr 11, 2023
2 parents 3aab43f + e7fb3b8 commit 65f45cd
Showing 1 changed file with 10 additions and 14 deletions.
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

0 comments on commit 65f45cd

Please sign in to comment.