Skip to content

Commit 6cdac88

Browse files
committed
SMT32 I2C: initialize clock before configuring PINs
This is needed especially for F1 family but can apply to all.
1 parent ee9c8ac commit 6cdac88

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
@@ -203,70 +203,70 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
203203
// Enable I2C1 clock and pinout if not done
204204
if (obj_s->i2c == I2C_1) {
205205
obj_s->index = 0;
206+
__HAL_RCC_I2C1_CLK_ENABLE();
206207
// Configure I2C pins
207208
pinmap_pinout(sda, PinMap_I2C_SDA);
208209
pinmap_pinout(scl, PinMap_I2C_SCL);
209210
pin_mode(sda, PullUp);
210211
pin_mode(scl, PullUp);
211212
obj_s->event_i2cIRQ = I2C1_EV_IRQn;
212213
obj_s->error_i2cIRQ = I2C1_ER_IRQn;
213-
__HAL_RCC_I2C1_CLK_ENABLE();
214214
}
215215
#endif
216216
#if defined I2C2_BASE
217217
// Enable I2C2 clock and pinout if not done
218218
if (obj_s->i2c == I2C_2) {
219219
obj_s->index = 1;
220+
__HAL_RCC_I2C2_CLK_ENABLE();
220221
// Configure I2C pins
221222
pinmap_pinout(sda, PinMap_I2C_SDA);
222223
pinmap_pinout(scl, PinMap_I2C_SCL);
223224
pin_mode(sda, PullUp);
224225
pin_mode(scl, PullUp);
225226
obj_s->event_i2cIRQ = I2C2_EV_IRQn;
226227
obj_s->error_i2cIRQ = I2C2_ER_IRQn;
227-
__HAL_RCC_I2C2_CLK_ENABLE();
228228
}
229229
#endif
230230
#if defined I2C3_BASE
231231
// Enable I2C3 clock and pinout if not done
232232
if (obj_s->i2c == I2C_3) {
233233
obj_s->index = 2;
234+
__HAL_RCC_I2C3_CLK_ENABLE();
234235
// Configure I2C pins
235236
pinmap_pinout(sda, PinMap_I2C_SDA);
236237
pinmap_pinout(scl, PinMap_I2C_SCL);
237238
pin_mode(sda, PullUp);
238239
pin_mode(scl, PullUp);
239240
obj_s->event_i2cIRQ = I2C3_EV_IRQn;
240241
obj_s->error_i2cIRQ = I2C3_ER_IRQn;
241-
__HAL_RCC_I2C3_CLK_ENABLE();
242242
}
243243
#endif
244244
#if defined I2C4_BASE
245245
// Enable I2C3 clock and pinout if not done
246246
if (obj_s->i2c == I2C_4) {
247247
obj_s->index = 3;
248+
__HAL_RCC_I2C4_CLK_ENABLE();
248249
// Configure I2C pins
249250
pinmap_pinout(sda, PinMap_I2C_SDA);
250251
pinmap_pinout(scl, PinMap_I2C_SCL);
251252
pin_mode(sda, PullUp);
252253
pin_mode(scl, PullUp);
253254
obj_s->event_i2cIRQ = I2C4_EV_IRQn;
254255
obj_s->error_i2cIRQ = I2C4_ER_IRQn;
255-
__HAL_RCC_I2C4_CLK_ENABLE();
256256
}
257257
#endif
258258
#if defined FMPI2C1_BASE
259259
// Enable I2C3 clock and pinout if not done
260260
if (obj_s->i2c == FMPI2C_1) {
261261
obj_s->index = 4;
262+
__HAL_RCC_FMPI2C1_CLK_ENABLE();
262263
// Configure I2C pins
263264
pinmap_pinout(sda, PinMap_I2C_SDA);
264265
pinmap_pinout(scl, PinMap_I2C_SCL);
265266
pin_mode(sda, PullUp);
266267
pin_mode(scl, PullUp);
267268
obj_s->event_i2cIRQ = FMPI2C1_EV_IRQn;
268269
obj_s->error_i2cIRQ = FMPI2C1_ER_IRQn;
269-
__HAL_RCC_FMPI2C1_CLK_ENABLE();
270270
}
271271
#endif
272272

0 commit comments

Comments
 (0)