Skip to content

Commit 0bee690

Browse files
committed
STM32: I2C: Don't use global init variables
No need to store the init status of each IP. Init can be called again in case we try to recover.
1 parent 2b53dfc commit 0bee690

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

targets/TARGET_STM/TARGET_STM32F4/i2c_api.c

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,6 @@
4242
#define FLAG_TIMEOUT ((int)0x1000)
4343
#define LONG_TIMEOUT ((int)0x8000)
4444

45-
int i2c1_inited = 0;
46-
int i2c2_inited = 0;
47-
int i2c3_inited = 0;
48-
int fmpi2c1_inited = 0;
49-
5045
#if DEVICE_I2C_ASYNCH
5146
#define I2C_S(obj) (struct i2c_s *) (&((obj)->i2c))
5247
#else
@@ -66,8 +61,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
6661
MBED_ASSERT(obj_s->i2c != (I2CName)NC);
6762

6863
// Enable I2C1 clock and pinout if not done
69-
if ((obj_s->i2c == I2C_1) && !i2c1_inited) {
70-
i2c1_inited = 1;
64+
if (obj_s->i2c == I2C_1) {
7165
// Configure I2C pins
7266
pinmap_pinout(sda, PinMap_I2C_SDA);
7367
pinmap_pinout(scl, PinMap_I2C_SCL);
@@ -80,8 +74,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
8074
__I2C1_CLK_ENABLE();
8175
}
8276
// Enable I2C2 clock and pinout if not done
83-
if ((obj_s->i2c == I2C_2) && !i2c2_inited) {
84-
i2c2_inited = 1;
77+
if (obj_s->i2c == I2C_2) {
8578
// Configure I2C pins
8679
pinmap_pinout(sda, PinMap_I2C_SDA);
8780
pinmap_pinout(scl, PinMap_I2C_SCL);
@@ -95,8 +88,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
9588
}
9689
#if defined I2C3_BASE
9790
// Enable I2C3 clock and pinout if not done
98-
if ((obj_s->i2c == I2C_3) && !i2c3_inited) {
99-
i2c3_inited = 1;
91+
if (obj_s->i2c == I2C_3) {
10092
// Configure I2C pins
10193
pinmap_pinout(sda, PinMap_I2C_SDA);
10294
pinmap_pinout(scl, PinMap_I2C_SCL);
@@ -112,8 +104,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
112104

113105
#if defined FMPI2C1_BASE
114106
// Enable I2C3 clock and pinout if not done
115-
if ((obj_s->i2c == FMPI2C_1) && !fmpi2c1_inited) {
116-
fmpi2c1_inited = 1;
107+
if (obj_s->i2c == FMPI2C_1) {
117108
// Configure I2C pins
118109
pinmap_pinout(sda, PinMap_I2C_SDA);
119110
pinmap_pinout(scl, PinMap_I2C_SCL);

0 commit comments

Comments
 (0)