From b3ca9eeabf0443a3775824fca8fa8d508dab4d08 Mon Sep 17 00:00:00 2001 From: cscherr Date: Wed, 9 Jul 2025 15:02:17 +0200 Subject: [PATCH] feat: create crc crate --- .cargo/config.toml | 6 +++++- Cargo.lock | 4 ++++ Cargo.toml | 3 +++ crates/crc/.gitignore | 1 + crates/crc/Cargo.toml | 6 ++++++ crates/crc/src/crc_32.rs | 0 crates/crc/src/crc_dev.rs | 9 +++++++++ crates/crc/src/lib.rs | 14 ++++++++++++++ scripts/flash.sh | 6 ++++++ 9 files changed, 48 insertions(+), 1 deletion(-) create mode 100755 crates/crc/.gitignore create mode 100755 crates/crc/Cargo.toml create mode 100755 crates/crc/src/crc_32.rs create mode 100755 crates/crc/src/crc_dev.rs create mode 100755 crates/crc/src/lib.rs create mode 100755 scripts/flash.sh diff --git a/.cargo/config.toml b/.cargo/config.toml index 2aafa28..b280dc1 100755 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,11 +1,15 @@ [build] -target = "thumbv6m-none-eabi" +# target = "thumbv6m-none-eabi" + +[test] +target = "x86_64-unknown-linux-gnu" [target.thumbv6m-none-eabi] runner = 'probe-rs run --chip STM32L053R8' [alias] +target = "thumbv6m-none-eabi" cflash = "flash --chip STM32L053R8" [env] diff --git a/Cargo.lock b/Cargo.lock index afdb2df..d094e9f 100755 --- a/Cargo.lock +++ b/Cargo.lock @@ -92,6 +92,10 @@ dependencies = [ "syn", ] +[[package]] +name = "crc" +version = "0.1.0" + [[package]] name = "critical-section" version = "1.2.0" diff --git a/Cargo.toml b/Cargo.toml index 3c51828..ff3db82 100755 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,3 +17,6 @@ panic-probe = { version = "0.3", features = ["print-defmt"] } [profile.release] debug = "full" # those are not on the board + +[workspace] +members = ["", "crates/crc"] diff --git a/crates/crc/.gitignore b/crates/crc/.gitignore new file mode 100755 index 0000000..ea8c4bf --- /dev/null +++ b/crates/crc/.gitignore @@ -0,0 +1 @@ +/target diff --git a/crates/crc/Cargo.toml b/crates/crc/Cargo.toml new file mode 100755 index 0000000..585d3ea --- /dev/null +++ b/crates/crc/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "crc" +version = "0.1.0" +edition = "2024" + +[dependencies] diff --git a/crates/crc/src/crc_32.rs b/crates/crc/src/crc_32.rs new file mode 100755 index 0000000..e69de29 diff --git a/crates/crc/src/crc_dev.rs b/crates/crc/src/crc_dev.rs new file mode 100755 index 0000000..4d75d4b --- /dev/null +++ b/crates/crc/src/crc_dev.rs @@ -0,0 +1,9 @@ +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn it_works() { + assert_eq!(2 + 2, 4); + } +} diff --git a/crates/crc/src/lib.rs b/crates/crc/src/lib.rs new file mode 100755 index 0000000..91b6a76 --- /dev/null +++ b/crates/crc/src/lib.rs @@ -0,0 +1,14 @@ +mod crc_32; +pub use crc_32::*; + +// for testing purposes +mod crc_dev; +pub use crc_dev::*; + +pub trait Crc { + type Input: ?Sized; + type Checksum: Eq; + const CHECKSUM_LEN: usize; + + fn process(data: &Self::Input) -> Self::Checksum; +} diff --git a/scripts/flash.sh b/scripts/flash.sh new file mode 100755 index 0000000..2f24e45 --- /dev/null +++ b/scripts/flash.sh @@ -0,0 +1,6 @@ +#!/bin/bash +# I'm using a bash script because if i set the target in .cargo/config.toml +# i can't build for x86_64 anymore, which means I can't run the unit tests. +TARGET="thumbv6m-none-eabi" +cargo build --target $TARGET +cargo run --target $TARGET