3737#include "dma.h"
3838#include "i2c.h"
3939
40- #if !defined(MICROPY_HW_I2C_BAUDRATE_DEFAULT )
41- #define MICROPY_HW_I2C_BAUDRATE_DEFAULT 400000
42- #endif
43-
44- #if !defined(MICROPY_HW_I2C_BAUDRATE_MAX )
45- #define MICROPY_HW_I2C_BAUDRATE_MAX 400000
46- #endif
47-
4840/// \moduleref pyb
4941/// \class I2C - a two-wire serial protocol
5042///
@@ -134,10 +126,42 @@ const pyb_i2c_obj_t pyb_i2c_obj[] = {
134126 #endif
135127};
136128
137- #if defined(MICROPY_HW_I2C_BAUDRATE_TIMING )
129+ #if defined(MCU_SERIES_F7 ) || defined(MCU_SERIES_L4 )
130+
138131// The STM32F0, F3, F7 and L4 use a TIMINGR register rather than ClockSpeed and
139132// DutyCycle.
140133
134+ #if defined(STM32F746xx )
135+
136+ // The value 0x40912732 was obtained from the DISCOVERY_I2Cx_TIMING constant
137+ // defined in the STM32F7Cube file Drivers/BSP/STM32F746G-Discovery/stm32f7456g_discovery.h
138+ #define MICROPY_HW_I2C_BAUDRATE_TIMING {{100000, 0x40912732}}
139+ #define MICROPY_HW_I2C_BAUDRATE_DEFAULT (100000)
140+ #define MICROPY_HW_I2C_BAUDRATE_MAX (100000)
141+
142+ #elif defined(STM32F767xx ) || defined(STM32F769xx )
143+
144+ // These timing values are for f_I2CCLK=54MHz and are only approximate
145+ #define MICROPY_HW_I2C_BAUDRATE_TIMING { \
146+ {100000, 0xb0420f13}, \
147+ {400000, 0x70330309}, \
148+ {1000000, 0x50100103}, \
149+ }
150+ #define MICROPY_HW_I2C_BAUDRATE_DEFAULT (400000)
151+ #define MICROPY_HW_I2C_BAUDRATE_MAX (1000000)
152+
153+ #elif defined(MCU_SERIES_L4 )
154+
155+ // The value 0x90112626 was obtained from the DISCOVERY_I2C1_TIMING constant
156+ // defined in the STM32L4Cube file Drivers/BSP/STM32L476G-Discovery/stm32l476g_discovery.h
157+ #define MICROPY_HW_I2C_BAUDRATE_TIMING {{100000, 0x90112626}}
158+ #define MICROPY_HW_I2C_BAUDRATE_DEFAULT (100000)
159+ #define MICROPY_HW_I2C_BAUDRATE_MAX (100000)
160+
161+ #else
162+ #error "no I2C timings for this MCU"
163+ #endif
164+
141165STATIC const struct {
142166 uint32_t baudrate ;
143167 uint32_t timing ;
@@ -167,6 +191,9 @@ uint32_t i2c_get_baudrate(I2C_InitTypeDef *init) {
167191
168192#else
169193
194+ #define MICROPY_HW_I2C_BAUDRATE_DEFAULT (400000)
195+ #define MICROPY_HW_I2C_BAUDRATE_MAX (400000)
196+
170197STATIC void i2c_set_baudrate (I2C_InitTypeDef * init , uint32_t baudrate ) {
171198 init -> ClockSpeed = baudrate ;
172199 init -> DutyCycle = I2C_DUTYCYCLE_16_9 ;
@@ -176,7 +203,7 @@ uint32_t i2c_get_baudrate(I2C_InitTypeDef *init) {
176203 return init -> ClockSpeed ;
177204}
178205
179- #endif // MICROPY_HW_I2C_BAUDRATE_TIMING
206+ #endif
180207
181208void i2c_init0 (void ) {
182209 // reset the I2C1 handles
0 commit comments