Skip to content

Instantly share code, notes, and snippets.

@hikilaka
Created March 13, 2022 02:21
Show Gist options
  • Save hikilaka/28ec0290cc89649c2a940e8a4af24de4 to your computer and use it in GitHub Desktop.
Save hikilaka/28ec0290cc89649c2a940e8a4af24de4 to your computer and use it in GitHub Desktop.
.program panic
set pindirs, 1
pull block
out y, 32
.wrap_target
mov x, y
set pins, 1
loop_on:
jmp x--, loop_on
mov x, y
set pins, 0
loop_off:
jmp x--, loop_off
.wrap
use core::panic::PanicInfo;
use pio_proc::pio_file;
use rp_pico::hal::{
pac::Peripherals,
pio::{PIOBuilder, PIOExt},
};
// Our panic handler LED lives on Gpio22
pub const PANIC_PIN: u8 = 22;
#[inline(never)]
#[panic_handler]
fn custom_panic(_info: &PanicInfo) -> ! {
let program = pio_file!(
"pio/panic.pio",
select_program("panic")
);
let mut pac = unsafe { Peripherals::steal() };
let (mut pio, sm0, _sm1, _sm2, _sm3) = pac.PIO0.split(&mut pac.RESETS);
let installed = pio.install(&program.program).unwrap();
let (sm, _rx, mut tx) = PIOBuilder::from_program(installed)
.set_pins(PANIC_PIN, 1)
.clock_divisor(0f32)
.build(sm0);
tx.write(1024);
sm.start();
loop {
cortex_m::asm::nop();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment