SMT32 I2C: initialize clock before configuring PINs

This is needed especially for F1 family but can apply to all.
pull/3429/head
Laurent MEUNIER 2016-12-08 09:51:35 +01:00
parent ee9c8acbe4
commit 6cdac88a1c
1 changed files with 5 additions and 5 deletions

View File

@ -203,6 +203,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
// Enable I2C1 clock and pinout if not done
if (obj_s->i2c == I2C_1) {
obj_s->index = 0;
__HAL_RCC_I2C1_CLK_ENABLE();
// Configure I2C pins
pinmap_pinout(sda, PinMap_I2C_SDA);
pinmap_pinout(scl, PinMap_I2C_SCL);
@ -210,13 +211,13 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
pin_mode(scl, PullUp);
obj_s->event_i2cIRQ = I2C1_EV_IRQn;
obj_s->error_i2cIRQ = I2C1_ER_IRQn;
__HAL_RCC_I2C1_CLK_ENABLE();
}
#endif
#if defined I2C2_BASE
// Enable I2C2 clock and pinout if not done
if (obj_s->i2c == I2C_2) {
obj_s->index = 1;
__HAL_RCC_I2C2_CLK_ENABLE();
// Configure I2C pins
pinmap_pinout(sda, PinMap_I2C_SDA);
pinmap_pinout(scl, PinMap_I2C_SCL);
@ -224,13 +225,13 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
pin_mode(scl, PullUp);
obj_s->event_i2cIRQ = I2C2_EV_IRQn;
obj_s->error_i2cIRQ = I2C2_ER_IRQn;
__HAL_RCC_I2C2_CLK_ENABLE();
}
#endif
#if defined I2C3_BASE
// Enable I2C3 clock and pinout if not done
if (obj_s->i2c == I2C_3) {
obj_s->index = 2;
__HAL_RCC_I2C3_CLK_ENABLE();
// Configure I2C pins
pinmap_pinout(sda, PinMap_I2C_SDA);
pinmap_pinout(scl, PinMap_I2C_SCL);
@ -238,13 +239,13 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
pin_mode(scl, PullUp);
obj_s->event_i2cIRQ = I2C3_EV_IRQn;
obj_s->error_i2cIRQ = I2C3_ER_IRQn;
__HAL_RCC_I2C3_CLK_ENABLE();
}
#endif
#if defined I2C4_BASE
// Enable I2C3 clock and pinout if not done
if (obj_s->i2c == I2C_4) {
obj_s->index = 3;
__HAL_RCC_I2C4_CLK_ENABLE();
// Configure I2C pins
pinmap_pinout(sda, PinMap_I2C_SDA);
pinmap_pinout(scl, PinMap_I2C_SCL);
@ -252,13 +253,13 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
pin_mode(scl, PullUp);
obj_s->event_i2cIRQ = I2C4_EV_IRQn;
obj_s->error_i2cIRQ = I2C4_ER_IRQn;
__HAL_RCC_I2C4_CLK_ENABLE();
}
#endif
#if defined FMPI2C1_BASE
// Enable I2C3 clock and pinout if not done
if (obj_s->i2c == FMPI2C_1) {
obj_s->index = 4;
__HAL_RCC_FMPI2C1_CLK_ENABLE();
// Configure I2C pins
pinmap_pinout(sda, PinMap_I2C_SDA);
pinmap_pinout(scl, PinMap_I2C_SCL);
@ -266,7 +267,6 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
pin_mode(scl, PullUp);
obj_s->event_i2cIRQ = FMPI2C1_EV_IRQn;
obj_s->error_i2cIRQ = FMPI2C1_ER_IRQn;
__HAL_RCC_FMPI2C1_CLK_ENABLE();
}
#endif