Skip to content

Commit

Permalink
Route sources of panics to the crate's fmt macros
Browse files Browse the repository at this point in the history
  • Loading branch information
dflemstr committed Jun 28, 2024
1 parent 26e6607 commit cbc6746
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
8 changes: 7 additions & 1 deletion embassy-boot-nrf/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ impl<const BUFFER_SIZE: usize> BootLoader<BUFFER_SIZE> {
pub fn prepare<ACTIVE: NorFlash, DFU: NorFlash, STATE: NorFlash>(
config: BootLoaderConfig<ACTIVE, DFU, STATE>,
) -> Self {
Self::try_prepare::<ACTIVE, DFU, STATE>(config).expect("Boot prepare error")
if let Ok(loader) = Self::try_prepare::<ACTIVE, DFU, STATE>(config) {
loader
} else {
// Use explicit panic instead of .expect() to ensure this gets routed via defmt/etc.
// properly
panic!("Boot prepare error")
}
}

/// Inspect the bootloader state and perform actions required before booting, such as swapping firmware
Expand Down
8 changes: 7 additions & 1 deletion embassy-boot-rp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ impl<const BUFFER_SIZE: usize> BootLoader<BUFFER_SIZE> {
pub fn prepare<ACTIVE: NorFlash, DFU: NorFlash, STATE: NorFlash>(
config: BootLoaderConfig<ACTIVE, DFU, STATE>,
) -> Self {
Self::try_prepare::<ACTIVE, DFU, STATE>(config).expect("Boot prepare error")
if let Ok(loader) = Self::try_prepare::<ACTIVE, DFU, STATE>(config) {
loader
} else {
// Use explicit panic instead of .expect() to ensure this gets routed via defmt/etc.
// properly
panic!("Boot prepare error")
}
}

/// Inspect the bootloader state and perform actions required before booting, such as swapping firmware
Expand Down
8 changes: 7 additions & 1 deletion embassy-boot-stm32/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ impl BootLoader {
pub fn prepare<ACTIVE: NorFlash, DFU: NorFlash, STATE: NorFlash, const BUFFER_SIZE: usize>(
config: BootLoaderConfig<ACTIVE, DFU, STATE>,
) -> Self {
Self::try_prepare::<ACTIVE, DFU, STATE, BUFFER_SIZE>(config).expect("Boot prepare error")
if let Ok(loader) = Self::try_prepare::<ACTIVE, DFU, STATE, BUFFER_SIZE>(config) {
loader
} else {
// Use explicit panic instead of .expect() to ensure this gets routed via defmt/etc.
// properly
panic!("Boot prepare error")
}
}

/// Inspect the bootloader state and perform actions required before booting, such as swapping firmware
Expand Down
2 changes: 1 addition & 1 deletion embassy-boot/src/test_flash/asynch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ where
}

fn create_partition<T: NorFlash>(mutex: &Mutex<NoopRawMutex, T>) -> Partition<NoopRawMutex, T> {
Partition::new(mutex, 0, mutex.try_lock().unwrap().capacity() as u32)
Partition::new(mutex, 0, unwrap!(mutex.try_lock()).capacity() as u32)
}
}

Expand Down

0 comments on commit cbc6746

Please sign in to comment.