Skip to content

Commit 8ff0a3d

Browse files
authored
Merge pull request #3026 from hierophect/stm32-i2cspeed
STM32: Add I2C timing to the F7 and H7 board profile
2 parents 9285252 + 2aac3cb commit 8ff0a3d

File tree

1 file changed

+25
-1
lines changed
  • ports/stm/common-hal/busio

1 file changed

+25
-1
lines changed

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,24 @@
3434
#include "supervisor/shared/translate.h"
3535
#include "common-hal/microcontroller/Pin.h"
3636

37+
// I2C timing specs for the H7 and F7
38+
// Configured for maximum possible clock settings for the family
39+
#if (CPY_STM32F7)
40+
#ifndef CPY_I2CFAST_TIMINGR
41+
#define CPY_I2CFAST_TIMINGR 0x6000030D
42+
#endif
43+
#ifndef CPY_I2CSTANDARD_TIMINGR
44+
#define CPY_I2CSTANDARD_TIMINGR 0x20404768
45+
#endif
46+
#elif (CPY_STM32H7)
47+
#ifndef CPY_I2CFAST_TIMINGR
48+
#define CPY_I2CFAST_TIMINGR 0x00B03FDB
49+
#endif
50+
#ifndef CPY_I2CSTANDARD_TIMINGR
51+
#define CPY_I2CSTANDARD_TIMINGR 0x307075B1
52+
#endif
53+
#endif
54+
3755
// Arrays use 0 based numbering: I2C1 is stored at index 0
3856
#define MAX_I2C 4
3957

@@ -120,7 +138,13 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
120138

121139
// Handle the HAL handle differences
122140
#if (CPY_STM32H7 || CPY_STM32F7)
123-
self->handle.Init.Timing = 0x40604E73; //Taken from STCube examples
141+
if (frequency == 400000) {
142+
self->handle.Init.Timing = CPY_I2CFAST_TIMINGR;
143+
} else if (frequency == 100000) {
144+
self->handle.Init.Timing = CPY_I2CSTANDARD_TIMINGR;
145+
} else {
146+
mp_raise_ValueError(translate("Unsupported baudrate"));
147+
}
124148
#else
125149
self->handle.Init.ClockSpeed = frequency;
126150
self->handle.Init.DutyCycle = I2C_DUTYCYCLE_2;

0 commit comments

Comments
 (0)