Skip to content

Commit a521df2

Browse files
committed
stm32/i2c: Fix clock enable for I2C4 on STM32F7 MCUs.
This was broken by 5aec051 when adding support for I2C4 on H7 MCUs. Signed-off-by: Damien George <[email protected]>
1 parent a7d34b6 commit a521df2

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

ports/stm32/i2c.c

+9-13
Original file line numberDiff line numberDiff line change
@@ -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
312312
// Enable I2C peripheral clock
313313
volatile uint32_t tmp;
314314
(void)tmp;
315-
switch (i2c_id) {
316-
case 0:
317-
case 1:
318-
case 2:
319-
RCC->APB1ENR |= RCC_APB1ENR_I2C1EN << i2c_id;
320-
tmp = RCC->APB1ENR; // delay after RCC clock enable
321-
break;
322-
#if defined(STM32H7)
323-
case 3:
324-
RCC->APB4ENR |= RCC_APB4ENR_I2C4EN;
325-
tmp = RCC->APB4ENR; // delay after RCC clock enable
326-
break;
327-
#endif
315+
#if defined(STM32H7)
316+
if (i2c_id == 3) {
317+
RCC->APB4ENR |= RCC_APB4ENR_I2C4EN;
318+
tmp = RCC->APB4ENR; // delay after RCC clock enable
319+
} else
320+
#endif
321+
{
322+
RCC->APB1ENR |= RCC_APB1ENR_I2C1EN << i2c_id;
323+
tmp = RCC->APB1ENR; // delay after RCC clock enable
328324
}
329325

330326
// Initialise I2C peripheral

0 commit comments

Comments
 (0)