Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SetConfig implementation for STM32 I2C v2 #3928

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(())
}
}