From a6efc670647193cab3fd2b84253960f5304e0bdd Mon Sep 17 00:00:00 2001 From: Yuuki NAGAO Date: Mon, 15 Sep 2025 08:09:01 +0900 Subject: [PATCH] stm32/i2c: Add hardware I2C implementation for STM32G4. For STM32G4, hardware I2C can implement same as STM32L4 for machine.I2C. This commit makes to be able to use of hardware I2C in machine.I2C. Tested on NUCLEO-G474RE. Signed-off-by: Yuuki NAGAO --- ports/stm32/i2c.c | 4 ++-- ports/stm32/machine_i2c.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ports/stm32/i2c.c b/ports/stm32/i2c.c index 778885eac8..2460a36cb1 100644 --- a/ports/stm32/i2c.c +++ b/ports/stm32/i2c.c @@ -271,12 +271,12 @@ int i2c_write(i2c_t *i2c, const uint8_t *src, size_t len, size_t next_len) { return num_acks; } -#elif defined(STM32F0) || defined(STM32F7) || defined(STM32H7) || defined(STM32L4) +#elif defined(STM32F0) || defined(STM32F7) || defined(STM32G4) || defined(STM32H7) || defined(STM32L4) #if defined(STM32H7) #define APB1ENR APB1LENR #define RCC_APB1ENR_I2C1EN RCC_APB1LENR_I2C1EN -#elif defined(STM32L4) +#elif defined(STM32G4) || defined(STM32L4) #define APB1ENR APB1ENR1 #define RCC_APB1ENR_I2C1EN RCC_APB1ENR1_I2C1EN #endif diff --git a/ports/stm32/machine_i2c.c b/ports/stm32/machine_i2c.c index ca2170e32d..0fb9cf83c9 100644 --- a/ports/stm32/machine_i2c.c +++ b/ports/stm32/machine_i2c.c @@ -34,7 +34,7 @@ #define I2C_POLL_DEFAULT_TIMEOUT_US (50000) // 50ms -#if defined(STM32F0) || defined(STM32F4) || defined(STM32F7) || defined(STM32H7) || defined(STM32L1) || defined(STM32L4) +#if defined(STM32F0) || defined(STM32F4) || defined(STM32F7) || defined(STM32G4) || defined(STM32H7) || defined(STM32L1) || defined(STM32L4) typedef struct _machine_hard_i2c_obj_t { mp_obj_base_t base;