aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--docs/Config_Reference.md5
-rw-r--r--src/stm32/stm32f0_i2c.c7
2 files changed, 10 insertions, 2 deletions
diff --git a/docs/Config_Reference.md b/docs/Config_Reference.md
index e4c70937..bc4dbe32 100644
--- a/docs/Config_Reference.md
+++ b/docs/Config_Reference.md
@@ -5001,8 +5001,9 @@ Most Klipper micro-controller implementations only support an
micro-controller supports a 400000 speed (*fast mode*, 400kbit/s), but it must be
[set in the operating system](RPi_microcontroller.md#optional-enabling-i2c)
and the `i2c_speed` parameter is otherwise ignored. The Klipper
-"RP2040" micro-controller and ATmega AVR family support a rate of 400000
-via the `i2c_speed` parameter. All other Klipper micro-controllers use a
+"RP2040" micro-controller and ATmega AVR family and some STM32
+(F0, G0, G4, L4, F7, H7) support a rate of 400000 via the `i2c_speed` parameter.
+All other Klipper micro-controllers use a
100000 rate and ignore the `i2c_speed` parameter.
```
diff --git a/src/stm32/stm32f0_i2c.c b/src/stm32/stm32f0_i2c.c
index a45aa34b..b83ceb0f 100644
--- a/src/stm32/stm32f0_i2c.c
+++ b/src/stm32/stm32f0_i2c.c
@@ -153,6 +153,13 @@ i2c_setup(uint32_t bus, uint32_t rate, uint8_t addr)
uint32_t sclh = 32; // 32 * 125ns = 4us
uint32_t sdadel = 4; // 4 * 125ns = 500ns
uint32_t scldel = 10; // 10 * 125ns = 1250ns
+ // Clamp the rate to 400Khz
+ if (rate >= 400000) {
+ scll = 10; // 10 * 125ns = 1250ns
+ sclh = 4; // 4 * 125 = 500ns
+ sdadel = 3; // 3 * 125 = 375ns
+ scldel = 4; // 4 * 125 = 500ns
+ }
uint32_t pclk = get_pclock_frequency((uint32_t)i2c);
uint32_t presc = DIV_ROUND_UP(pclk, nom_i2c_clock);