Skip to content

Commit

Permalink
cpu/stm32_common: disable i2c in release
Browse files Browse the repository at this point in the history
the hardware peripheral should be disabled before stopping the
peripheral clock.
  • Loading branch information
Toon Stegen committed Jun 8, 2020
1 parent e32c772 commit ac9afbe
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions cpu/stm32/periph/i2c_1.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,21 @@ int i2c_acquire(i2c_t dev)

periph_clk_en(i2c_config[dev].bus, i2c_config[dev].rcc_mask);

/* enable device */
i2c_config[dev].dev->CR1 |= I2C_CR1_PE;

return 0;
}

void i2c_release(i2c_t dev)
{
assert(dev < I2C_NUMOF);

/* disable device */
i2c_config[dev].dev->CR1 &= ~(I2C_CR1_PE);

_wait_for_bus(i2c_config[dev].dev);

periph_clk_dis(i2c_config[dev].bus, i2c_config[dev].rcc_mask);

mutex_unlock(&locks[dev]);
Expand Down
8 changes: 8 additions & 0 deletions cpu/stm32/periph/i2c_2.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,21 @@ int i2c_acquire(i2c_t dev)

periph_clk_en(i2c_config[dev].bus, i2c_config[dev].rcc_mask);

/* enable device */
i2c_config[dev].dev->CR1 |= I2C_CR1_PE;

return 0;
}

void i2c_release(i2c_t dev)
{
assert(dev < I2C_NUMOF);

/* disable device */
i2c_config[dev].dev->CR1 &= ~(I2C_CR1_PE);

_wait_for_bus(i2c_config[dev].dev);

periph_clk_dis(i2c_config[dev].bus, i2c_config[dev].rcc_mask);

#ifdef STM32_PM_STOP
Expand Down

0 comments on commit ac9afbe

Please sign in to comment.