Skip to content

Commit bc1c0ce

Browse files
committed
mbed: add stm32 i2c patch
1 parent 5568969 commit bc1c0ce

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
From e7fb3b80769ec498d1dcaa9421caaa19ed7975ca Mon Sep 17 00:00:00 2001
2+
From: Jamie Smith <[email protected]>
3+
Date: Mon, 20 Mar 2023 21:05:20 -0700
4+
Subject: [PATCH] Fix repeated start for transactional I2C API on STM32 devices
5+
with I2C v2
6+
7+
---
8+
targets/TARGET_STM/i2c_api.c | 24 ++++++++++--------------
9+
1 file changed, 10 insertions(+), 14 deletions(-)
10+
11+
diff --git a/targets/TARGET_STM/i2c_api.c b/targets/TARGET_STM/i2c_api.c
12+
index 6ba7fcc6496..266eeaa5772 100644
13+
--- a/targets/TARGET_STM/i2c_api.c
14+
+++ b/targets/TARGET_STM/i2c_api.c
15+
@@ -931,21 +931,17 @@ static void prep_for_restart_if_needed(struct i2c_s *obj_s) {
16+
* STOP at the end of the current transaction.
17+
*/
18+
static uint32_t get_hal_xfer_options(struct i2c_s *obj_s, bool stop) {
19+
- if (obj_s->state == STM_I2C_SB_READ_IN_PROGRESS || obj_s->state == STM_I2C_SB_WRITE_IN_PROGRESS) {
20+
- if(stop) {
21+
- // Generate restart condition and stop at end
22+
- return I2C_OTHER_AND_LAST_FRAME;
23+
- } else {
24+
- // Generate restart condition but don't send STOP
25+
- return I2C_OTHER_FRAME;
26+
- }
27+
+ (void)obj_s;
28+
+
29+
+ // Note: The naming used by STM32 HAL is quite counterintuitive. "OTHER_FRAME" means "always send a
30+
+ // start/restart condition at the start of the frame". In contrast, "FIRST_FRAME" means "don't send
31+
+ // a start/restart if the previous transfer was going the same direction".
32+
+ if(stop) {
33+
+ // Generate start condition and stop at end
34+
+ return I2C_OTHER_AND_LAST_FRAME;
35+
} else {
36+
- if(stop) {
37+
- // Generate start condition and stop at end
38+
- return I2C_FIRST_AND_LAST_FRAME;
39+
- } else {
40+
- return I2C_LAST_FRAME;
41+
- }
42+
+ // Generate only the start condition
43+
+ return I2C_OTHER_FRAME;
44+
}
45+
}
46+

0 commit comments

Comments
 (0)