Skip to content

Commit aec4f2d

Browse files
LMESTMadbridge
authored andcommitted
SMT32 I2C: initialize clock before configuring PINs
This is needed especially for F1 family but can apply to all.
1 parent 6906fbb commit aec4f2d

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

targets/TARGET_STM/i2c_api.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,70 +215,70 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
215215
// Enable I2C1 clock and pinout if not done
216216
if (obj_s->i2c == I2C_1) {
217217
obj_s->index = 0;
218+
__HAL_RCC_I2C1_CLK_ENABLE();
218219
// Configure I2C pins
219220
pinmap_pinout(sda, PinMap_I2C_SDA);
220221
pinmap_pinout(scl, PinMap_I2C_SCL);
221222
pin_mode(sda, PullUp);
222223
pin_mode(scl, PullUp);
223224
obj_s->event_i2cIRQ = I2C1_EV_IRQn;
224225
obj_s->error_i2cIRQ = I2C1_ER_IRQn;
225-
__HAL_RCC_I2C1_CLK_ENABLE();
226226
}
227227
#endif
228228
#if defined I2C2_BASE
229229
// Enable I2C2 clock and pinout if not done
230230
if (obj_s->i2c == I2C_2) {
231231
obj_s->index = 1;
232+
__HAL_RCC_I2C2_CLK_ENABLE();
232233
// Configure I2C pins
233234
pinmap_pinout(sda, PinMap_I2C_SDA);
234235
pinmap_pinout(scl, PinMap_I2C_SCL);
235236
pin_mode(sda, PullUp);
236237
pin_mode(scl, PullUp);
237238
obj_s->event_i2cIRQ = I2C2_EV_IRQn;
238239
obj_s->error_i2cIRQ = I2C2_ER_IRQn;
239-
__HAL_RCC_I2C2_CLK_ENABLE();
240240
}
241241
#endif
242242
#if defined I2C3_BASE
243243
// Enable I2C3 clock and pinout if not done
244244
if (obj_s->i2c == I2C_3) {
245245
obj_s->index = 2;
246+
__HAL_RCC_I2C3_CLK_ENABLE();
246247
// Configure I2C pins
247248
pinmap_pinout(sda, PinMap_I2C_SDA);
248249
pinmap_pinout(scl, PinMap_I2C_SCL);
249250
pin_mode(sda, PullUp);
250251
pin_mode(scl, PullUp);
251252
obj_s->event_i2cIRQ = I2C3_EV_IRQn;
252253
obj_s->error_i2cIRQ = I2C3_ER_IRQn;
253-
__HAL_RCC_I2C3_CLK_ENABLE();
254254
}
255255
#endif
256256
#if defined I2C4_BASE
257257
// Enable I2C3 clock and pinout if not done
258258
if (obj_s->i2c == I2C_4) {
259259
obj_s->index = 3;
260+
__HAL_RCC_I2C4_CLK_ENABLE();
260261
// Configure I2C pins
261262
pinmap_pinout(sda, PinMap_I2C_SDA);
262263
pinmap_pinout(scl, PinMap_I2C_SCL);
263264
pin_mode(sda, PullUp);
264265
pin_mode(scl, PullUp);
265266
obj_s->event_i2cIRQ = I2C4_EV_IRQn;
266267
obj_s->error_i2cIRQ = I2C4_ER_IRQn;
267-
__HAL_RCC_I2C4_CLK_ENABLE();
268268
}
269269
#endif
270270
#if defined FMPI2C1_BASE
271271
// Enable I2C3 clock and pinout if not done
272272
if (obj_s->i2c == FMPI2C_1) {
273273
obj_s->index = 4;
274+
__HAL_RCC_FMPI2C1_CLK_ENABLE();
274275
// Configure I2C pins
275276
pinmap_pinout(sda, PinMap_I2C_SDA);
276277
pinmap_pinout(scl, PinMap_I2C_SCL);
277278
pin_mode(sda, PullUp);
278279
pin_mode(scl, PullUp);
279280
obj_s->event_i2cIRQ = FMPI2C1_EV_IRQn;
280281
obj_s->error_i2cIRQ = FMPI2C1_ER_IRQn;
281-
__HAL_RCC_FMPI2C1_CLK_ENABLE();
282282
}
283283
#endif
284284

0 commit comments

Comments
 (0)