summaryrefslogtreecommitdiff
path: root/ports/stm32/i2c.c
diff options
context:
space:
mode:
Diffstat (limited to 'ports/stm32/i2c.c')
-rw-r--r--ports/stm32/i2c.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/ports/stm32/i2c.c b/ports/stm32/i2c.c
index 2460a36cb..46b55f940 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(STM32G4) || defined(STM32H7) || defined(STM32L4)
+#elif defined(STM32F0) || defined(STM32F7) || defined(STM32G4) || defined(STM32H7) || defined(STM32L4) || defined(STM32U5)
#if defined(STM32H7)
#define APB1ENR APB1LENR
#define RCC_APB1ENR_I2C1EN RCC_APB1LENR_I2C1EN
-#elif defined(STM32G4) || defined(STM32L4)
+#elif defined(STM32G4) || defined(STM32L4) || defined(STM32U5)
#define APB1ENR APB1ENR1
#define RCC_APB1ENR_I2C1EN RCC_APB1ENR1_I2C1EN
#endif
@@ -337,6 +337,16 @@ int i2c_init(i2c_t *i2c, mp_hal_pin_obj_t scl, mp_hal_pin_obj_t sda, uint32_t fr
} else {
return -MP_EINVAL;
}
+ #elif defined(STM32U5)
+ if (freq >= 1000000) {
+ i2c->TIMINGR = 0x30909DEC;
+ } else if (freq >= 400000) {
+ i2c->TIMINGR = 0x00F07BFF;
+ } else if (freq >= 100000) {
+ i2c->TIMINGR = 0x00701F6B;
+ } else {
+ return -MP_EINVAL;
+ }
#else
// These timing values are for f_I2CCLK=54MHz and are only approximate
if (freq >= 1000000) {
@@ -512,7 +522,7 @@ int i2c_write(i2c_t *i2c, const uint8_t *src, size_t len, size_t next_len) {
#endif
-#if defined(STM32F0) || defined(STM32F4) || defined(STM32F7) || defined(STM32H7)
+#if defined(STM32F0) || defined(STM32F4) || defined(STM32F7) || defined(STM32H7) || defined(STM32U5)
int i2c_readfrom(i2c_t *i2c, uint16_t addr, uint8_t *dest, size_t len, bool stop) {
int ret;