feat: try to integrate algorithms into the stm32 main code to calc crc's

This commit is contained in:
cscherr 2025-07-10 17:54:07 +02:00
parent 84a7fc294b
commit 28611efedb
Signed by: cscherrNT
GPG key ID: 8E2B45BC51A27EA7
4 changed files with 22 additions and 9 deletions

17
Cargo.lock generated
View file

@ -11,6 +11,14 @@ dependencies = [
"memchr",
]
[[package]]
name = "algorithms"
version = "0.1.0"
dependencies = [
"criterion",
"iai",
]
[[package]]
name = "as-slice"
version = "0.2.1"
@ -52,14 +60,6 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8fe8f5a8a398345e52358e18ff07cc17a568fbca5c6f73873d3a62056309603"
[[package]]
name = "benches"
version = "0.1.0"
dependencies = [
"criterion",
"iai",
]
[[package]]
name = "bitfield"
version = "0.13.2"
@ -396,6 +396,7 @@ checksum = "8d5439c4ad607c3c23abf66de8c8bf57ba8adcd1f129e699851a6e43935d339d"
name = "nucleo-l053r8-benches"
version = "0.1.0"
dependencies = [
"algorithms",
"cortex-m",
"cortex-m-rt",
"defmt 1.0.1",

View file

@ -14,6 +14,7 @@ cortex-m-rt = "0.7.5"
defmt = { version = "1.0.1" }
defmt-rtt = { version = "1.0.0" }
panic-probe = { version = "0.3", features = ["print-defmt"] }
algorithms = { path = "./crates/algorithms" }
[features]
default = ["buildscript"]

View file

@ -1,5 +1,5 @@
[package]
name = "benches"
name = "algorithms"
version = "0.1.0"
edition = "2024"

View file

@ -1,6 +1,8 @@
#![no_main]
#![no_std]
use algorithms::crc::{Crc, Crc32 as Crc32Rust, ffi::Crc32 as Crc32C};
use defmt::{debug, error, info, println, trace, warn};
use panic_probe as _;
@ -16,6 +18,8 @@ fn panic() -> ! {
cortex_m::asm::udf()
}
const DATA: &[u8] = b"hello world AAAAAAAAAAAAAAAAAAAAAAA";
#[entry]
fn main() -> ! {
let dp = pac::Peripherals::take().unwrap();
@ -34,6 +38,8 @@ fn main() -> ! {
// Get the delay provider.
let mut delay = cp.SYST.delay(rcc.clocks);
let mut crc;
#[allow(clippy::never_loop)]
loop {
println!("Hello World!");
@ -46,6 +52,11 @@ fn main() -> ! {
led.set_high().unwrap();
delay.delay_ms(500_u16);
crc = Crc32Rust::checksum(DATA);
info!("CRC (Rust): {:08x}", crc);
crc = Crc32C::checksum(DATA);
info!("CRC (C) : {:08x}", crc);
led.set_low().unwrap();
delay.delay_ms(500_u16);
}