Skip to content

implements i2c_free for STM #12350

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ MSTD_CONSTEXPR_OBJ_11 const PinMap PinMap_I2C_SDA[] = {
};

MSTD_CONSTEXPR_OBJ_11 const PinMap PinMap_I2C_SCL[] = {
{PA_8, I2C_3, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C3)},
//{PA_8, I2C_3, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C3)}, // Connected to MCO
{PB_6, I2C_1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C1)},
{PB_8, I2C_1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C1)},
{PB_10, I2C_2, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C2)},
Expand Down
47 changes: 47 additions & 0 deletions targets/TARGET_STM/i2c_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,48 @@ void i2c_init_internal(i2c_t *obj, const i2c_pinmap_t *pinmap)
#endif
}

void i2c_deinit_internal(i2c_t *obj)
{
struct i2c_s *obj_s = I2C_S(obj);

i2c_hw_reset(obj);

HAL_I2C_DeInit(&(obj_s->handle));

#if defined I2C1_BASE
if (obj_s->i2c == I2C_1) {
__HAL_RCC_I2C1_CLK_DISABLE();
}
#endif
#if defined I2C2_BASE
if (obj_s->i2c == I2C_2) {
__HAL_RCC_I2C2_CLK_DISABLE();
}
#endif
#if defined I2C3_BASE
if (obj_s->i2c == I2C_3) {
__HAL_RCC_I2C3_CLK_DISABLE();
}
#endif
#if defined I2C4_BASE
if (obj_s->i2c == I2C_4) {
__HAL_RCC_I2C4_CLK_DISABLE();
}
#endif
#if defined FMPI2C1_BASE
if (obj_s->i2c == FMPI2C_1) {
__HAL_RCC_FMPI2C1_CLK_DISABLE();
}
#endif

pin_mode(obj_s->sda, PullNone);
pin_mode(obj_s->scl, PullNone);

obj_s->sda = NC;
obj_s->scl = NC;
obj_s->i2c = (I2CName)NC;
}

#if STATIC_PINMAP_READY
#define I2C_INIT_DIRECT i2c_init_direct
void i2c_init_direct(i2c_t *obj, const i2c_pinmap_t *pinmap)
Expand Down Expand Up @@ -396,6 +438,11 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl)
I2C_INIT_DIRECT(obj, &explicit_i2c_pinmap);
}

void i2c_free(i2c_t *obj)
{
i2c_deinit_internal(obj);
}


void i2c_frequency(i2c_t *obj, int hz)
{
Expand Down