From 08aab3e8d44becd6d47375dd89f924e27a97a157 Mon Sep 17 00:00:00 2001 From: Dion Dokter Date: Sat, 20 Apr 2024 14:16:50 +0200 Subject: [PATCH 1/4] Add risc-v support --- Cargo.toml | 2 ++ src/lib.rs | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index cecf914..aa71a95 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,3 +15,5 @@ default = ["erase-chip", "panic-handler"] erase-chip = [] panic-handler = [] verify = [] +cortex-m = [] +risc-v = [] diff --git a/src/lib.rs b/src/lib.rs index de3fffc..0570f16 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,11 +12,17 @@ #![no_main] #![macro_use] +#[cfg(not(any(feature = "cortex-m", feature = "risc-v", feature = "panic-handler")))] +compile_error!("Enable either the cortex-m or risc-v feature"); + #[cfg(all(not(test), feature = "panic-handler"))] #[panic_handler] fn panic(_info: &core::panic::PanicInfo) -> ! { unsafe { + #[cfg(feature = "cortex-m")] core::arch::asm!("udf #0"); + #[cfg(feature = "risc-v")] + core::arch::asm!("UNIMP"); core::hint::unreachable_unchecked(); } } From 4d6bee98d7973da7d6014796bee7b714a317ee75 Mon Sep 17 00:00:00 2001 From: Dion Dokter Date: Sat, 20 Apr 2024 14:21:02 +0200 Subject: [PATCH 2/4] Improve CI and cfg --- .github/workflows/ci.yml | 4 ++-- src/lib.rs | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0c7bdfb..9bb8cde 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,8 +27,8 @@ jobs: cargo install cargo-binutils rustup component add llvm-tools-preview - name: Check - run: cargo check --target thumbv7em-none-eabi + run: cargo check --features cortex-m --target thumbv7em-none-eabi - name: Clippy - run: cargo clippy --target thumbv7em-none-eabi + run: cargo clippy --features cortex-m --target thumbv7em-none-eabi - name: Format run: cargo fmt \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 0570f16..30a3247 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,7 +12,10 @@ #![no_main] #![macro_use] -#[cfg(not(any(feature = "cortex-m", feature = "risc-v", feature = "panic-handler")))] +#[cfg(all( + not(any(feature = "cortex-m", feature = "risc-v")), + all(not(test), feature = "panic-handler") +))] compile_error!("Enable either the cortex-m or risc-v feature"); #[cfg(all(not(test), feature = "panic-handler"))] From d140381a50627fcb9784437e920f4d3c7d0c8a24 Mon Sep 17 00:00:00 2001 From: Dion Dokter Date: Wed, 11 Dec 2024 14:34:02 +0100 Subject: [PATCH 3/4] Move to target_arch --- src/lib.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 30a3247..6e680b6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,19 +12,16 @@ #![no_main] #![macro_use] -#[cfg(all( - not(any(feature = "cortex-m", feature = "risc-v")), - all(not(test), feature = "panic-handler") -))] -compile_error!("Enable either the cortex-m or risc-v feature"); - #[cfg(all(not(test), feature = "panic-handler"))] #[panic_handler] fn panic(_info: &core::panic::PanicInfo) -> ! { + #[cfg(not(any(target_arch = "arm", target_arch = "riscv32")))] + compile_error!("Panic handler can only be compiled for arm and riscv32"); + unsafe { - #[cfg(feature = "cortex-m")] + #[cfg(target_arch = "arm")] core::arch::asm!("udf #0"); - #[cfg(feature = "risc-v")] + #[cfg(target_arch = "riscv32")] core::arch::asm!("UNIMP"); core::hint::unreachable_unchecked(); } From c8e3fd49e1d6b282e2695c7b723d9051e6a96195 Mon Sep 17 00:00:00 2001 From: Dion Dokter Date: Fri, 13 Dec 2024 10:35:37 +0100 Subject: [PATCH 4/4] Remove feature flags and add rv64 --- .github/workflows/ci.yml | 4 ++-- Cargo.toml | 2 -- src/lib.rs | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9bb8cde..0c7bdfb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,8 +27,8 @@ jobs: cargo install cargo-binutils rustup component add llvm-tools-preview - name: Check - run: cargo check --features cortex-m --target thumbv7em-none-eabi + run: cargo check --target thumbv7em-none-eabi - name: Clippy - run: cargo clippy --features cortex-m --target thumbv7em-none-eabi + run: cargo clippy --target thumbv7em-none-eabi - name: Format run: cargo fmt \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index aa71a95..cecf914 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,5 +15,3 @@ default = ["erase-chip", "panic-handler"] erase-chip = [] panic-handler = [] verify = [] -cortex-m = [] -risc-v = [] diff --git a/src/lib.rs b/src/lib.rs index 6e680b6..a414479 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -21,7 +21,7 @@ fn panic(_info: &core::panic::PanicInfo) -> ! { unsafe { #[cfg(target_arch = "arm")] core::arch::asm!("udf #0"); - #[cfg(target_arch = "riscv32")] + #[cfg(any(target_arch = "riscv32", target_arch = "riscv64"))] core::arch::asm!("UNIMP"); core::hint::unreachable_unchecked(); }