stm32/i2cslave: Add support for WB MCUs.

Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Damien George 2020-06-18 13:40:30 +10:00
parent afd47d58ac
commit 4c8a68df6f
2 changed files with 10 additions and 1 deletions

View File

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

View File

@ -28,6 +28,11 @@
#include STM32_HAL_H #include STM32_HAL_H
#if !defined(I2C2_BASE)
// This MCU doesn't have I2C2_BASE, define it so that the i2c_idx calculation works.
#define I2C2_BASE (I2C1_BASE + ((I2C3_BASE - I2C1_BASE) / 2))
#endif
typedef I2C_TypeDef i2c_slave_t; typedef I2C_TypeDef i2c_slave_t;
void i2c_slave_init_helper(i2c_slave_t *i2c, int addr); void i2c_slave_init_helper(i2c_slave_t *i2c, int addr);
@ -42,6 +47,10 @@ static inline void i2c_slave_init(i2c_slave_t *i2c, int irqn, int irq_pri, int a
RCC->APB1LENR |= 1 << (RCC_APB1LENR_I2C1EN_Pos + i2c_idx); RCC->APB1LENR |= 1 << (RCC_APB1LENR_I2C1EN_Pos + i2c_idx);
volatile uint32_t tmp = RCC->APB1LENR; // Delay after enabling clock volatile uint32_t tmp = RCC->APB1LENR; // Delay after enabling clock
(void)tmp; (void)tmp;
#elif defined(STM32WB)
RCC->APB1ENR1 |= 1 << (RCC_APB1ENR1_I2C1EN_Pos + i2c_idx);
volatile uint32_t tmp = RCC->APB1ENR1; // Delay after enabling clock
(void)tmp;
#endif #endif
i2c_slave_init_helper(i2c, addr); i2c_slave_init_helper(i2c, addr);