Skip to content

Commit 02c5e08

Browse files
authored
Merge pull request #12350 from maciejbocianski/fix_fpga_i2c_test
implements i2c_free for STM
2 parents 236c336 + 0b634e5 commit 02c5e08

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F411xE/TARGET_NUCLEO_F411RE/PeripheralPinMaps.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ MSTD_CONSTEXPR_OBJ_11 const PinMap PinMap_I2C_SDA[] = {
9494
};
9595

9696
MSTD_CONSTEXPR_OBJ_11 const PinMap PinMap_I2C_SCL[] = {
97-
{PA_8, I2C_3, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C3)},
97+
//{PA_8, I2C_3, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C3)}, // Connected to MCO
9898
{PB_6, I2C_1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C1)},
9999
{PB_8, I2C_1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C1)},
100100
{PB_10, I2C_2, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C2)},

targets/TARGET_STM/i2c_api.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,48 @@ void i2c_init_internal(i2c_t *obj, const i2c_pinmap_t *pinmap)
369369
#endif
370370
}
371371

372+
void i2c_deinit_internal(i2c_t *obj)
373+
{
374+
struct i2c_s *obj_s = I2C_S(obj);
375+
376+
i2c_hw_reset(obj);
377+
378+
HAL_I2C_DeInit(&(obj_s->handle));
379+
380+
#if defined I2C1_BASE
381+
if (obj_s->i2c == I2C_1) {
382+
__HAL_RCC_I2C1_CLK_DISABLE();
383+
}
384+
#endif
385+
#if defined I2C2_BASE
386+
if (obj_s->i2c == I2C_2) {
387+
__HAL_RCC_I2C2_CLK_DISABLE();
388+
}
389+
#endif
390+
#if defined I2C3_BASE
391+
if (obj_s->i2c == I2C_3) {
392+
__HAL_RCC_I2C3_CLK_DISABLE();
393+
}
394+
#endif
395+
#if defined I2C4_BASE
396+
if (obj_s->i2c == I2C_4) {
397+
__HAL_RCC_I2C4_CLK_DISABLE();
398+
}
399+
#endif
400+
#if defined FMPI2C1_BASE
401+
if (obj_s->i2c == FMPI2C_1) {
402+
__HAL_RCC_FMPI2C1_CLK_DISABLE();
403+
}
404+
#endif
405+
406+
pin_mode(obj_s->sda, PullNone);
407+
pin_mode(obj_s->scl, PullNone);
408+
409+
obj_s->sda = NC;
410+
obj_s->scl = NC;
411+
obj_s->i2c = (I2CName)NC;
412+
}
413+
372414
#if STATIC_PINMAP_READY
373415
#define I2C_INIT_DIRECT i2c_init_direct
374416
void i2c_init_direct(i2c_t *obj, const i2c_pinmap_t *pinmap)
@@ -396,6 +438,11 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl)
396438
I2C_INIT_DIRECT(obj, &explicit_i2c_pinmap);
397439
}
398440

441+
void i2c_free(i2c_t *obj)
442+
{
443+
i2c_deinit_internal(obj);
444+
}
445+
399446

400447
void i2c_frequency(i2c_t *obj, int hz)
401448
{

0 commit comments

Comments
 (0)