Skip to content

Commit fc2a851

Browse files
chrismas9dpgeorge
authored andcommitted
stm32: Enable I2CTarget for STM32L4.
STM32L4 uses the same I2C controller as STM32WB. Change `defined(STM32WB)` to `defined(STM32L4) || defined(STM32WB) ` in relevant files. Also remove the dummy definition of I2C2_BASE for STM32L432xx. It's now provided by the dummy definition in `i2cslave.h`. Signed-off-by: Chris Mason <[email protected]> Signed-off-by: Damien George <[email protected]>
1 parent 4db2cf0 commit fc2a851

File tree

4 files changed

+4
-8
lines changed

4 files changed

+4
-8
lines changed

ports/stm32/i2c.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,10 +279,6 @@ int i2c_write(i2c_t *i2c, const uint8_t *src, size_t len, size_t next_len) {
279279
#elif defined(STM32L4)
280280
#define APB1ENR APB1ENR1
281281
#define RCC_APB1ENR_I2C1EN RCC_APB1ENR1_I2C1EN
282-
#if defined(STM32L432xx)
283-
// Not a real peripheral, only needed for i2c_id calculation in i2c_init.
284-
#define I2C2_BASE (APB1PERIPH_BASE + 0x5800UL)
285-
#endif
286282
#endif
287283

288284
static uint16_t i2c_timeout_ms[MICROPY_HW_MAX_I2C];

ports/stm32/i2cslave.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ void i2c_slave_irq_handler(i2c_slave_t *i2c) {
7676
}
7777
}
7878

79-
#elif defined(STM32F7) || defined(STM32H7) || defined(STM32WB)
79+
#elif defined(STM32F7) || defined(STM32H7) || defined(STM32L4) || defined(STM32WB)
8080

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

ports/stm32/i2cslave.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
#include STM32_HAL_H
3030

31-
#if defined(STM32F4) || defined(STM32F7) || defined(STM32H7) || defined(STM32WB)
31+
#if defined(STM32F4) || defined(STM32F7) || defined(STM32H7) || defined(STM32L4) || defined(STM32WB)
3232

3333
#if !defined(I2C2_BASE)
3434
// This MCU doesn't have I2C2_BASE, define it so that the i2c_idx calculation works.
@@ -63,7 +63,7 @@ static inline void i2c_slave_init(i2c_slave_t *i2c, int irqn, int irq_pri, int a
6363
volatile uint32_t tmp = RCC->APB1ENR1; // Delay after enabling clock
6464
(void)tmp;
6565
}
66-
#elif defined(STM32WB)
66+
#elif defined(STM32L4) || defined(STM32WB)
6767
RCC->APB1ENR1 |= 1 << (RCC_APB1ENR1_I2C1EN_Pos + i2c_idx);
6868
volatile uint32_t tmp = RCC->APB1ENR1; // Delay after enabling clock
6969
(void)tmp;

ports/stm32/mpconfigboard_common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@
640640
|| defined(MICROPY_HW_I2C3_SCL) || defined(MICROPY_HW_I2C4_SCL)
641641
#define MICROPY_HW_ENABLE_HW_I2C (1)
642642
#ifndef MICROPY_HW_ENABLE_HW_I2C_TARGET
643-
#if defined(STM32F4) || defined(STM32F7) || defined(STM32H7) || defined(STM32WB)
643+
#if defined(STM32F4) || defined(STM32F7) || defined(STM32H7) || defined(STM32L4) || defined(STM32WB)
644644
#define MICROPY_HW_ENABLE_HW_I2C_TARGET (1)
645645
#else
646646
#define MICROPY_HW_ENABLE_HW_I2C_TARGET (0)

0 commit comments

Comments
 (0)