Skip to content

Commit c087024

Browse files
committed
Add macros for setting correct F7 and H7 I2C timing
1 parent bf3a5af commit c087024

File tree

6 files changed

+29
-1
lines changed

6 files changed

+29
-1
lines changed

ports/stm/boards/nucleo_f746zg/mpconfigboard.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,9 @@
4646
#define BOARD_HSE_SOURCE (RCC_HSE_BYPASS) // ST boards use the STLink clock signal
4747
#define BOARD_HAS_LOW_SPEED_CRYSTAL (1)
4848

49+
// Obtain I2C timing values for F7 and H7 boards from ST CubeMX
50+
#define CPY_I2CFAST_TIMINGR 0x6000030D
51+
#define CPY_I2CSTANDARD_TIMINGR 0x20404768
52+
4953
#define DEBUG_UART_TX (&pin_PD08)
5054
#define DEBUG_UART_RX (&pin_PD09)

ports/stm/boards/nucleo_f767zi/mpconfigboard.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@
4040
#define CPY_SRAM_SUBMASK 0xFC // Mask 512 to 384
4141
#define CPY_SRAM_START_ADDR 0x20020000
4242

43+
// Obtain I2C timing values for F7 and H7 boards from ST CubeMX
44+
#define CPY_I2CFAST_TIMINGR 0x6000030D
45+
#define CPY_I2CSTANDARD_TIMINGR 0x20404768
46+
4347
#define HSE_VALUE ((uint32_t)8000000)
4448
#define LSE_VALUE ((uint32_t)32768)
4549
#define BOARD_HSE_SOURCE (RCC_HSE_BYPASS) // ST boards use the STLink clock signal

ports/stm/boards/nucleo_h743zi_2/mpconfigboard.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@
3939
#define CPY_SRAM_SUBMASK 0x00
4040
#define CPY_SRAM_START_ADDR 0x24000000
4141

42+
// Obtain I2C timing values for F7 and H7 boards from ST CubeMX
43+
#define CPY_I2CFAST_TIMINGR 0x00B03FDB
44+
#define CPY_I2CSTANDARD_TIMINGR 0x307075B1
45+
46+
47+
4248
#define HSE_VALUE ((uint32_t)8000000)
4349
#define LSE_VALUE ((uint32_t)32768)
4450
#define BOARD_HSE_SOURCE (RCC_HSE_BYPASS) // ST boards use the STLink clock signal

ports/stm/boards/openmv_h7/mpconfigboard.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,9 @@
3939
#define CPY_SRAM_SUBMASK 0x00
4040
#define CPY_SRAM_START_ADDR 0x24000000
4141

42+
// Obtain I2C timing values for F7 and H7 boards from ST CubeMX
43+
#define CPY_I2CFAST_TIMINGR 0x00B03FDB
44+
#define CPY_I2CSTANDARD_TIMINGR 0x307075B1
45+
4246
#define HSE_VALUE ((uint32_t)12000000)
4347
#define BOARD_HAS_LOW_SPEED_CRYSTAL (0)

ports/stm/boards/stm32f746g_discovery/mpconfigboard.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@
5050
#define CPY_CLK_FLASH_LATENCY (FLASH_LATENCY_6)
5151
#define CPY_CLK_USB_USES_AUDIOPLL (1)
5252

53+
// Obtain I2C timing values for F7 and H7 boards from ST CubeMX
54+
#define CPY_I2CFAST_TIMINGR 0x00401959
55+
#define CPY_I2CSTANDARD_TIMINGR 0x00C0EAFF
56+
5357
#define BOARD_HSE_SOURCE (RCC_HSE_BYPASS) // ST boards use the STLink clock signal
5458
#define BOARD_HAS_LOW_SPEED_CRYSTAL (1)
5559

ports/stm/common-hal/busio/I2C.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,13 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
120120

121121
// Handle the HAL handle differences
122122
#if (CPY_STM32H7 || CPY_STM32F7)
123-
self->handle.Init.Timing = 0x40604E73; //Taken from STCube examples
123+
if (frequency == 400000) {
124+
self->handle.Init.Timing = CPY_I2CFAST_TIMINGR;
125+
} else if (frequency == 100000) {
126+
self->handle.Init.Timing = CPY_I2CSTANDARD_TIMINGR;
127+
} else {
128+
mp_raise_ValueError(translate("MCU supports only I2C Standard and Fast modes"));
129+
}
124130
#else
125131
self->handle.Init.ClockSpeed = frequency;
126132
self->handle.Init.DutyCycle = I2C_DUTYCYCLE_2;

0 commit comments

Comments
 (0)