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

Add Custom halt feature #58

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,7 @@ exception-handler = []
panic-handler = []
halt-cores = []
colors = []
custom-halt = []

[lints.rust]
unexpected_cfgs = "allow"
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
18 changes: 14 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,14 +279,24 @@ 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")]
fn halt() -> ! {
extern "Rust" {
fn custom_halt() -> !;
}
unsafe { custom_halt() }
}

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