Skip to content
This repository has been archived by the owner on May 23, 2024. It is now read-only.

Commit

Permalink
Add Custom halt feature
Browse files Browse the repository at this point in the history
  • Loading branch information
t-moe committed May 15, 2024
1 parent 31f54a1 commit c2cc0fc
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ exception-handler = []
panic-handler = []
halt-cores = []
colors = []
custom-halt = []
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ When using the panic and/or exception handler make sure to include `use esp_back
## Features

| Feature | Description |
| ----------------- | ------------------------------------------------------------------------------------------------------------------ |
|-------------------|--------------------------------------------------------------------------------------------------------------------|
| esp32 | Target ESP32 |
| esp32c2 | Target ESP32-C2 |
| esp32c3 | Target ESP32-C3 |
Expand All @@ -26,8 +26,9 @@ When using the panic and/or exception handler make sure to include `use esp_back
| println | Use `esp-println` to print messages |
| defmt | Use `defmt` logging to print messages\* (check [example](https://github.com/playfulFence/backtrace-defmt-example)) |
| colors | Print messages in red\* |
| halt-cores | Halt both CPUs on ESP32 / ESP32-S3 in case of a panic or exception |
| halt-cores | Halt both CPUs on ESP32 / ESP32-S3 instead of doing a `loop {}` in case of a panic or exception |
| semihosting | Call `semihosting::process::abort()` on panic. |
| custom-halt | Invoke the extern function `custom_halt()` instead of doing a `loop {}` in case of a panic or exception |

\* _only used for panic and exception handlers_

Expand Down
4 changes: 4 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ fn main() {
panic!("A backend needs to be selected");
}

if cfg!(feature = "custom-halt") && cfg!(feature = "halt-cores") {
panic!("Only one of `custom-halt` and `halt-cores` can be enabled");
}

if is_nightly() {
println!("cargo:rustc-cfg=nightly");
}
Expand Down
21 changes: 17 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ fn exception_handler(context: &arch::TrapFrame) -> ! {
if let Some(addr) = e {
#[cfg(all(feature = "colors", feature = "println"))]
println!("{}0x{:x}", RED, addr - crate::arch::RA_OFFSET);

#[cfg(not(all(feature = "colors", feature = "println")))]
println!("0x{:x}", addr - crate::arch::RA_OFFSET);
}
Expand Down Expand Up @@ -279,15 +279,28 @@ fn is_valid_ram_address(address: u32) -> bool {
true
}

#[cfg(any(
not(any(feature = "esp32", feature = "esp32p4", feature = "esp32s3")),
not(feature = "halt-cores")
#[cfg(all(
any(
not(any(feature = "esp32", feature = "esp32p4", feature = "esp32s3")),
not(feature = "halt-cores")
),
not(feature = "custom-halt")
))]
#[allow(unused)]
fn halt() -> ! {
loop {}
}

#[cfg(feature = "custom-halt")]
extern "Rust" {
fn custom_halt() -> !;
}

#[cfg(feature = "custom-halt")]
fn halt() -> ! {
unsafe { custom_halt() }
}

// TODO: Enable `halt` function for `esp32p4` feature once implemented
#[cfg(all(any(feature = "esp32", feature = "esp32s3"), feature = "halt-cores"))]
#[allow(unused)]
Expand Down

0 comments on commit c2cc0fc

Please sign in to comment.