-
Notifications
You must be signed in to change notification settings - Fork 51
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
i2c infinite loop when building with optimizations #5
Comments
Just tested 9697aef and it is not fixed yet. For now I need to add a 'timeout' to the ($i2c:expr) => {
let mut count = 0;
loop {
let isr = $i2c.isr.read();
if isr.berr().bit_is_set() {
$i2c.icr.write(|w| w.berrcf().set_bit());
return Err(Error::BusError);
} else if isr.arlo().bit_is_set() {
$i2c.icr.write(|w| w.arlocf().set_bit());
return Err(Error::ArbitrationLost);
} else if isr.nackf().bit_is_set() {
$i2c.icr.write(|w| w.nackcf().set_bit());
return Err(Error::Nack);
} else if isr.busy().bit_is_clear() {
break;
}
count += 1;
if count > 1000 {
break;
}
}
}; I'll try to look into it further soon |
Yes, I have the same problem. At some point stuff from L0 https://github.com/stm32-rs/stm32l0xx-hal/blob/master/src/i2c.rs should be merged. |
`write_read` is also now fixed - before this fix stop was added after write
`write_read` is also now fixed - before this fix stop was added after write
I was just getting ready to tackle this issue, so I did a git pull and turns out it is already fixed 😃 |
When I build with optimizations (1 or 2) enabled
Then i2c
read
operations can get into an infinite loop in thebusy_wait
macro.Bus speed =
=100khz
.Here the intention is to wait until the peripheral is not busy anymore and then break out of the loop.
However, the busy flag is
1
if busy and will be cleared when not busy anymore. So the check should actually check forbit_is_cleared()
.But I guess that's not true for all
$flags
that can be passed in.Because optimization is on, the code is faster, the bit is already cleared so it ends up in an infinite loop.
The text was updated successfully, but these errors were encountered: