diff options
| author | Aaron Griffith <[email protected]> | 2025-02-27 06:50:01 -0500 |
|---|---|---|
| committer | Aaron Griffith <[email protected]> | 2025-02-27 06:50:01 -0500 |
| commit | 03f73ce339c31b2cd222a7e96e66ee78f37e2ce3 (patch) | |
| tree | b9717502d0dd6bd6cf9c2a6daba9d24afabc8527 | |
| parent | 17301c00e986c5b8536435ea31ebf5aaf13aed17 (diff) | |
stm32/i2c: disable peripheral when changing timings
| -rw-r--r-- | embassy-stm32/src/i2c/v2.rs | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/embassy-stm32/src/i2c/v2.rs b/embassy-stm32/src/i2c/v2.rs index 71769bbc1..1f53a995d 100644 --- a/embassy-stm32/src/i2c/v2.rs +++ b/embassy-stm32/src/i2c/v2.rs | |||
| @@ -855,7 +855,12 @@ impl<'d, M: Mode> SetConfig for I2c<'d, M> { | |||
| 855 | type Config = Hertz; | 855 | type Config = Hertz; |
| 856 | type ConfigError = (); | 856 | type ConfigError = (); |
| 857 | fn set_config(&mut self, config: &Self::Config) -> Result<(), ()> { | 857 | fn set_config(&mut self, config: &Self::Config) -> Result<(), ()> { |
| 858 | self.info.regs.cr1().modify(|reg| { | ||
| 859 | reg.set_pe(false); | ||
| 860 | }); | ||
| 861 | |||
| 858 | let timings = Timings::new(self.kernel_clock, *config); | 862 | let timings = Timings::new(self.kernel_clock, *config); |
| 863 | |||
| 859 | self.info.regs.timingr().write(|reg| { | 864 | self.info.regs.timingr().write(|reg| { |
| 860 | reg.set_presc(timings.prescale); | 865 | reg.set_presc(timings.prescale); |
| 861 | reg.set_scll(timings.scll); | 866 | reg.set_scll(timings.scll); |
| @@ -864,6 +869,10 @@ impl<'d, M: Mode> SetConfig for I2c<'d, M> { | |||
| 864 | reg.set_scldel(timings.scldel); | 869 | reg.set_scldel(timings.scldel); |
| 865 | }); | 870 | }); |
| 866 | 871 | ||
| 872 | self.info.regs.cr1().modify(|reg| { | ||
| 873 | reg.set_pe(true); | ||
| 874 | }); | ||
| 875 | |||
| 867 | Ok(()) | 876 | Ok(()) |
| 868 | } | 877 | } |
| 869 | } | 878 | } |
