diff options
| author | Damien George <damien@micropython.org> | 2024-03-28 13:53:24 +1100 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2024-05-03 17:22:22 +1000 |
| commit | a521df27dc483c5376ef7e348aa9fbbd0c4e67a9 (patch) | |
| tree | a7b1b32d0c488239f41091d30890b00cb70589a1 | |
| parent | a7d34b6f7c48cd5920ae52b2e6fb35cc196a606b (diff) | |
stm32/i2c: Fix clock enable for I2C4 on STM32F7 MCUs.
This was broken by 5aec051f9f0e1be9750ca4f08478275f298087a3 when adding
support for I2C4 on H7 MCUs.
Signed-off-by: Damien George <damien@micropython.org>
| -rw-r--r-- | ports/stm32/i2c.c | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/ports/stm32/i2c.c b/ports/stm32/i2c.c index 9d128acc3..a1fde7e6b 100644 --- a/ports/stm32/i2c.c +++ b/ports/stm32/i2c.c @@ -312,19 +312,15 @@ int i2c_init(i2c_t *i2c, mp_hal_pin_obj_t scl, mp_hal_pin_obj_t sda, uint32_t fr // Enable I2C peripheral clock volatile uint32_t tmp; (void)tmp; - switch (i2c_id) { - case 0: - case 1: - case 2: - RCC->APB1ENR |= RCC_APB1ENR_I2C1EN << i2c_id; - tmp = RCC->APB1ENR; // delay after RCC clock enable - break; - #if defined(STM32H7) - case 3: - RCC->APB4ENR |= RCC_APB4ENR_I2C4EN; - tmp = RCC->APB4ENR; // delay after RCC clock enable - break; - #endif + #if defined(STM32H7) + if (i2c_id == 3) { + RCC->APB4ENR |= RCC_APB4ENR_I2C4EN; + tmp = RCC->APB4ENR; // delay after RCC clock enable + } else + #endif + { + RCC->APB1ENR |= RCC_APB1ENR_I2C1EN << i2c_id; + tmp = RCC->APB1ENR; // delay after RCC clock enable } // Initialise I2C peripheral |
