From bd48f68a3345d0f568dc43ba3fe8b16b1587de07 Mon Sep 17 00:00:00 2001 From: Codetector Date: Sat, 2 Nov 2024 17:42:22 -0700 Subject: [PATCH] feat: introduce compile error if using atomic This change introduce a compile error if the toolchain is using a target with atomics. It looks like at least on the the QingKe V4 atomics are suspiciously broken. There is also a feature you can enable `i-understand-that-atomics-are-likely-broken` you can enable to remove this compile error See issue: https://github.com/ch32-rs/ch32-hal/issues/59 --- Cargo.toml | 3 ++- qingke-rt/Cargo.toml | 4 ++-- src/lib.rs | 17 +++++++++++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2bf6c60..1619e44 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ documentation = "https://docs.rs/qingke" homepage = "https://github.com/ch32-rs/qingke" categories = ["embedded", "no-std", "hardware-support"] license = "MIT/Apache-2.0" -version = "0.4.0" # for rt and macros +version = "0.5.0" # for rt and macros edition = "2021" [package] @@ -37,6 +37,7 @@ defmt = { version = "0.3.8", optional = true } critical-section-impl = ["dep:critical-section"] defmt = ["dep:defmt"] v3 = [] +unsafe-trust-wch-atomics = [] [package.metadata.docs.rs] targets = ["riscv32imac-unknown-none-elf"] diff --git a/qingke-rt/Cargo.toml b/qingke-rt/Cargo.toml index cb83435..dd54c73 100644 --- a/qingke-rt/Cargo.toml +++ b/qingke-rt/Cargo.toml @@ -25,8 +25,8 @@ u-mode = [] highcode = [] [dependencies] -qingke-rt-macros = { path = "./macros", version = "0.4" } -qingke = { path = "../", version = "0.4", features = ["critical-section-impl"] } +qingke-rt-macros = { path = "./macros" } +qingke = { path = "../", features = ["critical-section-impl"] } [package.metadata.docs.rs] targets = ["riscv32imac-unknown-none-elf"] diff --git a/src/lib.rs b/src/lib.rs index 016770e..39eb191 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,5 +11,22 @@ pub mod register; // re-export pub use riscv; +#[cfg(all( + any( + target_has_atomic = "8", + // target_has_atomic = "16", + // target_has_atomic = "32", + // target_has_atomic = "64", + // target_has_atomic = "128", + // target_has_atomic = "ptr" + ), + not(feature = "unsafe-trust-wch-atomics") +))] +compile_error!( + "As tested on QingKe V4, most likely the atomics are broken, +please validate the atomic instruction on the hardware using +something like litmus test suite before trusting them." +); + #[cfg(feature = "critical-section-impl")] mod critical_section_impl;