fix some lints

This commit is contained in:
2025-11-22 14:20:09 +01:00
parent 907cc908fb
commit 53d35464f5
3 changed files with 124 additions and 93 deletions

View File

@@ -11,7 +11,7 @@
mod serial;
use core::{
mem::{MaybeUninit, transmute},
mem::MaybeUninit,
sync::atomic::{AtomicU8, Ordering},
task::Poll,
};
@@ -342,12 +342,22 @@ async fn pio_task(
fn store_rom(
flash: &mut Flash<'_, FLASH, impl flash::Mode, FLASH_SIZE>,
) -> Result<(), flash::Error> {
let offset =
unsafe { (INIT_ROM_DATA.as_ptr() as *const u32).offset_from_unsigned(FLASH_BASE) as u32 };
let offset = unsafe {
u32::try_from(
INIT_ROM_DATA
.as_ptr()
.cast::<u8>()
.offset_from_unsigned(FLASH_BASE.cast::<u8>()),
)
.map_err(|_| flash::Error::OutOfBounds)?
};
let len = size_of_val(&INIT_ROM_DATA).min(ROM_DATA.len());
defmt::info!("Erasing flash at offset {:#x} with size {:#x}", offset, len);
flash.blocking_erase(offset, offset + len as u32)?;
let rom_buffer = unsafe { transmute::<&[AtomicU8], &[u8]>(&ROM_DATA[..len]) };
flash.blocking_erase(
offset,
offset + u32::try_from(len).map_err(|_| flash::Error::OutOfBounds)?,
)?;
let rom_buffer = unsafe { &*(&raw const ROM_DATA[..len] as *const [u8]) };
defmt::info!("Programming flash with buffer at {}", rom_buffer.as_ptr());
flash.blocking_write(offset, rom_buffer)?;
defmt::info!("Successfully commited rom to flash");
@@ -357,12 +367,22 @@ fn store_rom(
fn load_rom(
flash: &mut Flash<'_, FLASH, impl flash::Mode, FLASH_SIZE>,
) -> Result<(), flash::Error> {
let offset =
unsafe { (INIT_ROM_DATA.as_ptr() as *const u32).offset_from_unsigned(FLASH_BASE) as u32 };
let offset = unsafe {
u32::try_from(
INIT_ROM_DATA
.as_ptr()
.cast::<u8>()
.offset_from_unsigned(FLASH_BASE.cast::<u8>()),
)
.map_err(|_| flash::Error::OutOfBounds)?
};
let len = size_of_val(&INIT_ROM_DATA).min(ROM_DATA.len());
for (i, rom) in ROM_DATA.iter().enumerate().take(len) {
let mut init = [0u8];
flash.blocking_read(offset + i as u32, &mut init)?;
flash.blocking_read(
offset + u32::try_from(i).map_err(|_| flash::Error::OutOfBounds)?,
&mut init,
)?;
let init = init[0];
rom.store(init, Ordering::SeqCst);
}