Skip to content

Commit

Permalink
bunch of debugging work, can't figure it out
Browse files Browse the repository at this point in the history
  • Loading branch information
bradjc committed Aug 21, 2023
1 parent 11ba4da commit 30accc6
Show file tree
Hide file tree
Showing 6 changed files with 370 additions and 103 deletions.
83 changes: 47 additions & 36 deletions boards/nano33ble/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,47 +86,52 @@ impl IoWrite for Writer {
// and not much we can do. Don't want to double fault,
// so just return.
super::CDC_REF_FOR_PANIC.map(|cdc| {
// Lots of unsafe dereferencing of global static mut objects here.
// However, this should be okay, because it all happens within
// a single thread, and:
// - This is the only place the global CDC_REF_FOR_PANIC is used, the logic is the same
// as applies for the global CHIP variable used in the panic handler.
// - We do create multiple mutable references to the STATIC_PANIC_BUF, but we never
// access the STATIC_PANIC_BUF after a slice of it is passed to transmit_buffer
// until the slice has been returned in the uart callback.
// - Similarly, only this function uses the global DUMMY variable, and we do not
// mutate it.
let usb = &mut cdc.controller();
STATIC_PANIC_BUF[..max].copy_from_slice(&buf[..max]);
let static_buf = &mut STATIC_PANIC_BUF;
cdc.set_transmit_client(&DUMMY);
match cdc.transmit_buffer(static_buf, max) {
Ok(()) => {}
_ => {}
}
let mut interrupt_count = 0;
loop {
if let Some(interrupt) = cortexm4::nvic::next_pending() {
if interrupt == 39 {
interrupt_count += 1;
if interrupt_count >= 2 {
super::NRF52_RTC.map(|rtc| {
// Lots of unsafe dereferencing of global static mut objects here.
// However, this should be okay, because it all happens within
// a single thread, and:
// - This is the only place the global CDC_REF_FOR_PANIC is used, the logic is the same
// as applies for the global CHIP variable used in the panic handler.
// - We do create multiple mutable references to the STATIC_PANIC_BUF, but we never
// access the STATIC_PANIC_BUF after a slice of it is passed to transmit_buffer
// until the slice has been returned in the uart callback.
// - Similarly, only this function uses the global DUMMY variable, and we do not
// mutate it.
let usb = &mut cdc.controller();
STATIC_PANIC_BUF[..max].copy_from_slice(&buf[..max]);
let static_buf = &mut STATIC_PANIC_BUF;
cdc.set_transmit_client(&DUMMY);
match cdc.transmit_buffer(static_buf, max) {
Ok(()) => {}
_ => {}
}
let mut interrupt_count = 0;
loop {
if let Some(interrupt) = cortexm4::nvic::next_pending() {
if interrupt == 39 {
interrupt_count += 1;
if interrupt_count >= 2 {}
led.on();
usb.handle_interrupt();
// } else if interrupt < 25 {
} else {
// led.on();
// rtc.handle_interrupt();
}
usb.handle_interrupt();
let n = cortexm4::nvic::Nvic::new(interrupt);
n.clear_pending();
n.enable();
}
let n = cortexm4::nvic::Nvic::new(interrupt);
n.clear_pending();
n.enable();
}

if DUMMY.fired.get() == true {
// buffer finished transmitting, return so we can output additional
// messages when requested by the panic handler.
// led.on();
break;
if DUMMY.fired.get() == true {
// buffer finished transmitting, return so we can output additional
// messages when requested by the panic handler.
// led.on();
break;
}
}
}
DUMMY.fired.set(false);
DUMMY.fired.set(false);
});
});
}
buf.len()
Expand All @@ -147,6 +152,12 @@ pub unsafe extern "C" fn panic_fmt(pi: &PanicInfo) -> ! {

// debug::panic_blink_forever(&mut [led])

cortexm4::nvic::disable_all();
cortexm4::nvic::clear_all_pending();

let n = cortexm4::nvic::Nvic::new(39);
n.enable();

// loop {}
let writer = &mut WRITER;
debug::panic_print(
Expand Down
2 changes: 2 additions & 0 deletions boards/nano33ble/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ static mut CDC_REF_FOR_PANIC: Option<
>,
> = None;
static mut NRF52_POWER: Option<&'static nrf52840::power::Power> = None;
static mut NRF52_RTC: Option<&'static nrf52840::rtc::Rtc> = None;

/// Dummy buffer that causes the linker to reserve enough space for the stack.
#[no_mangle]
Expand Down Expand Up @@ -246,6 +247,7 @@ pub unsafe fn start() -> (
// Save a reference to the power module for resetting the board into the
// bootloader.
NRF52_POWER = Some(&base_peripherals.pwr_clk);
NRF52_RTC = Some(&base_peripherals.rtc);

let board_kernel = static_init!(kernel::Kernel, kernel::Kernel::new(&PROCESSES));

Expand Down
Loading

0 comments on commit 30accc6

Please sign in to comment.