#cortex-m #arm #teensy-4

no-std teensy4-panic

Panic handler for the Teensy 4. Part of the teensy4-rs project

5 releases

0.2.3 Sep 15, 2023
0.2.2 Jan 6, 2023
0.2.1 Dec 19, 2021
0.2.0 Apr 24, 2021
0.1.0 Dec 26, 2020

#1513 in Embedded development

Download history 47/week @ 2024-07-24 41/week @ 2024-07-31 33/week @ 2024-08-07 71/week @ 2024-08-14 28/week @ 2024-08-21 28/week @ 2024-08-28 61/week @ 2024-09-04 67/week @ 2024-09-11 51/week @ 2024-09-18 95/week @ 2024-09-25 122/week @ 2024-10-02 99/week @ 2024-10-09 122/week @ 2024-10-16 63/week @ 2024-10-23 79/week @ 2024-10-30 25/week @ 2024-11-06

302 downloads per month
Used in 3 crates

MIT/Apache

11KB
100 lines

teensy4-panic

Panic handler for the Teensy 4.

When you link teensy4-panic into your program, any panic!() will cause your Teensy's LED to blink S.O.S. in Morse code. Supports both Teensy 4.0 and 4.1 boards.

Usage

Depend on teensy4-panic:

[dependencies]
teensy4-panic = "0.2"

Then, include the crate in your final program:

use teensy4_panic as _;

Finally, use panic!() to stop the program and blink the LED.

Features

The table below summarizes this crate's features. Each subsection details the feature.

Feature Description Default feature?
panic-handler Define the Teensy 4's panic handler in this crate
log Log the panic message using log::error!

It does not make sense to disable panic-handler and enable log, since logging can only happen when panic-handler is enabled.

Custom panic handlers

By default, teensy4-panic enables the panic-handler feature. If you want to use the S.O.S. routine in your own panic handler, disable the default features, and call sos():

[dependencies]
teensy4-panic = "0.2"
default-features = false
use teensy4_panic::sos;

#[panic_handler]
fn panic(_: &core::panic::PanicInfo) -> ! {
    // Your panic handler here...
    sos()
}

Log the panic message

If the log feature is enabled, the crate links with the log crate. Before blinking, the panic handler logs the panic message and source location at the error priority, using log::error!. The logging target is teensy4_panic.

The example below shows a panic! and an example of its corresponding log message:

const DELAY_MS: u32 = 5_000;
panic!("This is a panic message written after {}ms", DELAY_MS);
[ERROR teensy4_panic]: panicked at 'This is a panic message written after 5000ms', examples/panic_log.rs:22:5

The panic handler only emits the log message once. You're responsible for making sure that the log message can reach its destination while a panic! is active.

License: MIT OR Apache-2.0

Dependencies

~22KB