10000 stm32/i2cslave: Add support for H7 MCUs. · rlucia/micropython@2c3fa4a · GitHub
[go: up one dir, main page]

Skip to content

Commit 2c3fa4a

Browse files
committed
stm32/i2cslave: Add support for H7 MCUs.
1 parent 643d2a0 commit 2c3fa4a

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

ports/stm32/i2cslave.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ void i2c_slave_ev_irq_handler(i2c_slave_t *i2c) {
6060
}
6161
}
6262

63-
#elif defined(STM32F7)
63+
#elif defined(STM32F7) || defined(STM32H7)
6464

6565
void i2c_slave_init_helper(i2c_slave_t *i2c, int addr) {
6666
i2c->CR1 = I2C_CR1_STOPIE | I2C_CR1_ADDRIE | I2C_CR1_RXIE | I2C_CR1_TXIE;

ports/stm32/i2cslave.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,16 @@ typedef I2C_TypeDef i2c_slave_t;
3333
void i2c_slave_init_helper(i2c_slave_t *i2c, int addr);
3434

3535
static inline void i2c_slave_init(i2c_slave_t *i2c, int irqn, int irq_pri, int addr) {
36-
int en_bit = RCC_APB1ENR_I2C1EN_Pos + ((uintptr_t)i2c - I2C1_BASE) / (I2C2_BASE - I2C1_BASE);
37-
RCC->APB1ENR |= 1 << en_bit;
36+
int i2c_idx = ((uintptr_t)i2c - I2C1_BASE) / (I2C2_BASE - I2C1_BASE);
37+
#if defined(STM32F4) || defined(STM32F7)
38+
RCC->APB1ENR |= 1 << (RCC_APB1ENR_I2C1EN_Pos + i2c_idx);
3839
volatile uint32_t tmp = RCC->APB1ENR; // Delay after enabling clock
3940
(void)tmp;
41+
#elif defined(STM32H7)
42+
RCC->APB1LENR |= 1 << (RCC_APB1LENR_I2C1EN_Pos + i2c_idx);
43+
volatile uint32_t tmp = RCC->APB1LENR; // Delay after enabling clock
44+
(void)tmp;
45+
#endif
4046

4147
i2c_slave_init_helper(i2c, addr);
4248

0 commit comments

Comments
 (0)
0