stm32/i2cslave: Add support for H7 MCUs.

This commit is contained in:
Damien George 2019-04-08 14:28:45 +10:00
parent 643d2a0e86
commit 2c3fa4ad82
2 changed files with 9 additions and 3 deletions

View File

@ -60,7 +60,7 @@ void i2c_slave_ev_irq_handler(i2c_slave_t *i2c) {
}
}
#elif defined(STM32F7)
#elif defined(STM32F7) || defined(STM32H7)
void i2c_slave_init_helper(i2c_slave_t *i2c, int addr) {
i2c->CR1 = I2C_CR1_STOPIE | I2C_CR1_ADDRIE | I2C_CR1_RXIE | I2C_CR1_TXIE;

View File

@ -33,10 +33,16 @@ typedef I2C_TypeDef i2c_slave_t;
void i2c_slave_init_helper(i2c_slave_t *i2c, int addr);
static inline void i2c_slave_init(i2c_slave_t *i2c, int irqn, int irq_pri, int addr) {
int en_bit = RCC_APB1ENR_I2C1EN_Pos + ((uintptr_t)i2c - I2C1_BASE) / (I2C2_BASE - I2C1_BASE);
RCC->APB1ENR |= 1 << en_bit;
int i2c_idx = ((uintptr_t)i2c - I2C1_BASE) / (I2C2_BASE - I2C1_BASE);
#if defined(STM32F4) || defined(STM32F7)
RCC->APB1ENR |= 1 << (RCC_APB1ENR_I2C1EN_Pos + i2c_idx);
volatile uint32_t tmp = RCC->APB1ENR; // Delay after enabling clock
(void)tmp;
#elif defined(STM32H7)
RCC->APB1LENR |= 1 << (RCC_APB1LENR_I2C1EN_Pos + i2c_idx);
volatile uint32_t tmp = RCC->APB1LENR; // Delay after enabling clock
(void)tmp;
#endif
i2c_slave_init_helper(i2c, addr);