-
Notifications
You must be signed in to change notification settings - Fork 39
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
Possible miscompilation error? #164
Comments
Tried on ESP32-WROOM-32 and got |
I've updated the comment with my configuration |
Tried with both versions from https://wokwi.com/projects/345876589283639891 and also with pub fn calculate(data: &[u8]) -> u8 {
const CRC8_POLYNOMIAL: u8 = 0x31;
let mut crc: u8 = 0xff;
for byte in data {
crc ^= byte;
println!("crc tmp: {:02x}", crc);
for _ in 0..8 {
if (crc & 0x80) > 0 {
println!("top bit is high");
//crc = (crc.overflowing_shl(1)).0 ^ CRC8_POLYNOMIAL;
crc = (crc << 1) ^ CRC8_POLYNOMIAL;
} else {
println!("top bit is low");
//crc = crc.overflowing_shl(1).0;
crc <<= 1;
}
}
}
crc
}
pub fn calculate2(data: &[u8]) -> u8 {
const CRC8_POLYNOMIAL: u8 = 0x31;
let mut crc: u8 = 0xff;
for byte in data {
crc ^= byte;
for _ in 0..8 {
if (crc & 0x80) > 0 {
//crc = (crc.overflowing_shl(1)).0 ^ CRC8_POLYNOMIAL;
crc = (crc << 1) ^ CRC8_POLYNOMIAL;
} else {
//crc = crc.overflowing_shl(1).0;
crc <<= 1;
}
}
}
crc
} |
Hi @vojty, sorry you've been running into this issue. Fortunately, its a duplicate of #134 which we already have a fix for! It will be released in the next 2 weeks with the 1.65 Rust toolchain. I tested your code with the new LLVM version locally and it works correctly with your input data :). I'll close this for now, in favour of the tracking issue here: #134. |
@MabezDev Thank you! |
@MabezDev I've upgraded the toolchain to 1.65 using https://github.com/esp-rs/espup
Unfortunately, the calculation is still wrong. For given The program executed on the ESP chip outputs Code: pub fn calculate(data: &[u8]) -> u8 {
const CRC8_POLYNOMIAL: u8 = 0x31;
let mut crc: u8 = 0xff;
for byte in data {
crc ^= byte;
for _ in 0..8 {
if (crc & 0x80) > 0 {
crc = (crc << 1) ^ CRC8_POLYNOMIAL;
} else {
crc <<= 1;
}
}
}
crc
}
fn main() -> Result<()> {
// Temporary. Will disappear once ESP-IDF 4.4 is released, but for now it is necessary to call this function once,
// or else some patches to the runtime implemented by esp-idf-sys might not link properly.
esp_idf_sys::link_patches();
// Bind the log crate to the ESP Logging facilities
esp_idf_svc::log::EspLogger::initialize_default();
println!("dec={}", calculate(&[171, 13]));
Ok(())
} Log
Also the previous example EDIT:
then the result is correct:
|
Thanks for the update, it seems like it's not entirely fixed. For me, it works on all opt-levels apart from when |
I can confirm that |
With the 1.69 release, this should now be fixed. Please let me know if you still run into issues! |
Hello, I've found a strange error and I'm not sure what the problem might be. I've been trying to use ESP32 + SCD41 with no luck. I tracked down the problem to this piece of code:
For the given example data
[9, 94]
the correct result should be35
but I'm getting55
. It works correctly on the blank Rust project usingcargo new
but it fails when I deploy the code to my ESP32.I've created an example here https://wokwi.com/projects/345876589283639891 with 2 identical
calculate
functions, the only difference is that one of them hasprintln!
macros inside. However, the result differs.Does anyone know what's going on? What am I missing?
Configuration:
Chip: Espressif ESP32-WROOM-32 (https://www.laskakit.cz/laskakit-esp-vindriktning-esp-32-i2c/)
The text was updated successfully, but these errors were encountered: