Skip to content

Commit

Permalink
stm32/i2c: disable peripheral when changing timings
Browse files Browse the repository at this point in the history
  • Loading branch information
agrif committed Feb 27, 2025
1 parent 17301c0 commit 03f73ce
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions embassy-stm32/src/i2c/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,12 @@ impl<'d, M: Mode> SetConfig for I2c<'d, M> {
type Config = Hertz;
type ConfigError = ();
fn set_config(&mut self, config: &Self::Config) -> Result<(), ()> {
self.info.regs.cr1().modify(|reg| {
reg.set_pe(false);
});

let timings = Timings::new(self.kernel_clock, *config);

self.info.regs.timingr().write(|reg| {
reg.set_presc(timings.prescale);
reg.set_scll(timings.scll);
Expand All @@ -864,6 +869,10 @@ impl<'d, M: Mode> SetConfig for I2c<'d, M> {
reg.set_scldel(timings.scldel);
});

self.info.regs.cr1().modify(|reg| {
reg.set_pe(true);
});

Ok(())
}
}

0 comments on commit 03f73ce

Please sign in to comment.