File tree Expand file tree Collapse file tree 1 file changed +25
-1
lines changed
ports/stm/common-hal/busio Expand file tree Collapse file tree 1 file changed +25
-1
lines changed Original file line number Diff line number Diff line change 34
34
#include "supervisor/shared/translate.h"
35
35
#include "common-hal/microcontroller/Pin.h"
36
36
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
+
37
55
// Arrays use 0 based numbering: I2C1 is stored at index 0
38
56
#define MAX_I2C 4
39
57
@@ -120,7 +138,13 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
120
138
121
139
// Handle the HAL handle differences
122
140
#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
+ }
124
148
#else
125
149
self -> handle .Init .ClockSpeed = frequency ;
126
150
self -> handle .Init .DutyCycle = I2C_DUTYCYCLE_2 ;
You can’t perform that action at this time.
0 commit comments