Compare commits

..

4 commits

Author SHA1 Message Date
Jakob Lechner
43bec436eb Rework fast blinking after reset 2025-09-24 10:46:11 +02:00
Jakob Lechner
eb4921afce Change LED Pin and flash timing 2025-09-23 20:19:22 +02:00
Jakob Lechner
8dd4913dba Fix partition table 2025-04-11 02:47:38 +02:00
Jakob Lechner
b9a37ff54d Remove serial number
It doesn't work with windows. It seems that the USB device goes into low
power state and then the serial number string descriptor cannot be read.
2025-04-11 02:47:29 +02:00

View file

@ -16,6 +16,7 @@ use usbd_storage::subclass::Command;
use usbd_storage::transport::bbb::{BulkOnly, BulkOnlyError}; use usbd_storage::transport::bbb::{BulkOnly, BulkOnlyError};
use usbd_storage::transport::TransportError; use usbd_storage::transport::TransportError;
#[link_section = ".start_block"] #[link_section = ".start_block"]
#[used] #[used]
pub static IMAGE_DEF: hal::block::ImageDef = hal::block::ImageDef::secure_exe(); pub static IMAGE_DEF: hal::block::ImageDef = hal::block::ImageDef::secure_exe();
@ -95,20 +96,7 @@ fn main() -> ! {
&mut pac.RESETS, &mut pac.RESETS,
); );
let mut led_pin = pins.gpio25.into_push_pull_output(); let mut led_pin = pins.gpio12.into_push_pull_output();
let mut start_time: u64 = 0;
let mut count: u64 = 0;
loop {
if timer.get_counter().ticks() - start_time > 25_000 {
count += 1;
let _ = led_pin.toggle();
start_time = timer.get_counter().ticks();
if count == 125 {
break;
}
}
}
let usb_bus = UsbBusAllocator::new(hal::usb::UsbBus::new( let usb_bus = UsbBusAllocator::new(hal::usb::UsbBus::new(
pac.USB, pac.USB,
@ -130,8 +118,6 @@ fn main() -> ! {
.self_powered(false) .self_powered(false)
.build(); .build();
let mut start_time: u64 = 0;
let mut storage: [u8; (DISK_BLOCK_SIZE * DISK_BLOCK_NUM) as usize] = [0u8; (DISK_BLOCK_SIZE * DISK_BLOCK_NUM) as usize]; let mut storage: [u8; (DISK_BLOCK_SIZE * DISK_BLOCK_NUM) as usize] = [0u8; (DISK_BLOCK_SIZE * DISK_BLOCK_NUM) as usize];
const LBA: u32 = DISK_BLOCK_NUM - 1; const LBA: u32 = DISK_BLOCK_NUM - 1;
@ -147,8 +133,7 @@ fn main() -> ! {
const OEM: [u8; 8] = *b"mkfs.fat"; const OEM: [u8; 8] = *b"mkfs.fat";
const FILESYSTEM_ID: [u8; 4] = [0xDE, 0xAD, 0xBE, 0xEF]; const FILESYSTEM_ID: [u8; 4] = [0xDE, 0xAD, 0xBE, 0xEF];
const FILESYSTEM_NAME: [u8; 11] = *b"RAM_USB\0\0\0\0"; const FILESYSTEM_LABEL: [u8; 11] = *b"RAM_USB ";
const MEDIA_SECTORS: u32 = DISK_BLOCK_NUM - 256;
storage[0x1B9] = 0x10; storage[0x1B9] = 0x10;
storage[0x1BE..0x1C3].copy_from_slice(&[0x00, 0x00, 0x02, 0x00, 0x0c]); storage[0x1BE..0x1C3].copy_from_slice(&[0x00, 0x00, 0x02, 0x00, 0x0c]);
@ -165,26 +150,23 @@ fn main() -> ! {
// FAT12 Partition // FAT12 Partition
storage[0x200..0x203].copy_from_slice(&[0xEB, 0x3C, 0x90]); storage[0x200..0x203].copy_from_slice(&[0xEB, 0x3C, 0x90]);
storage[0x203..0x20B].copy_from_slice(&OEM); storage[0x203..0x20B].copy_from_slice(&OEM);
storage[0x20B..0x227].copy_from_slice(&[0x00, 0x02, 0x04, 0x01, 0x00, storage[0x20B..0x21d].copy_from_slice(&[0x00, 0x02, 0x04, 0x01, 0x00,
0x02, 0x00, 0x02, (MEDIA_SECTORS & 0xff) as u8, 0x02, 0x00, 0x02, (LBA & 0xff) as u8,
(MEDIA_SECTORS >> 8) as u8, (LBA >> 8) as u8,
0xF8, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01]);
0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x29]); storage[0x224..0x227].copy_from_slice(&[0x80, 0x00, 0x29]);
storage[0x227..0x22B].copy_from_slice(&FILESYSTEM_ID); storage[0x227..0x22B].copy_from_slice(&FILESYSTEM_ID);
storage[0x22B..0x236].copy_from_slice(&FILESYSTEM_NAME); storage[0x22B..0x236].copy_from_slice(&FILESYSTEM_LABEL);
storage[0x236..0x23E].copy_from_slice(b"FAT12 "); storage[0x236..0x23E].copy_from_slice(b"FAT12 ");
storage[0x3FE..0x400].copy_from_slice(&[0x55, 0xAA]); storage[0x3FE..0x400].copy_from_slice(&[0x55, 0xAA]);
storage[0x400..0x403].copy_from_slice(&[0xF8, 0xFF, 0xFF]); storage[0x400..0x403].copy_from_slice(&[0xF8, 0xFF, 0xFF]);
storage[0x600..0x603].copy_from_slice(&[0xF8, 0xFF, 0xFF]); storage[0x600..0x603].copy_from_slice(&[0xF8, 0xFF, 0xFF]);
storage[0x800..0x80B].copy_from_slice(&FILESYSTEM_NAME); storage[0x800..0x80B].copy_from_slice(&FILESYSTEM_LABEL);
storage[0x80B..0x81A].copy_from_slice(&[0x08, 0x00, 0x00, 0x00, 0x00, storage[0x80B] = 0x08; // file attribute 0x08 = volume label
0x21, 0x00, 0x21, 0x00, 0x00, 0x00, 0xFA, 0x01, 0x83, 0x5A
]); // https://de.wikipedia.org/wiki/File_Allocation_Table
storage[0x5000..0x5010].copy_from_slice(&[ // Remove bootloader code: dd if=/dev/zero conv=notrunc of=foo bs=1 count=420 seek=602
0x2E, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x10, 0x00, 0x00, 0xA5, 0xBD
]);
let mut state: State = State { let mut state: State = State {
storage_offset: 0, storage_offset: 0,
@ -195,20 +177,26 @@ fn main() -> ! {
defmt::info!("entering main loop"); defmt::info!("entering main loop");
let mut start_time: u64 = 0;
loop { loop {
let interval = match (usb_device.state(), led_pin.is_set_high().unwrap_or_else(|_| false)) { let interval = if timer.get_counter().ticks() < 2_000_000 {
// The USB device has just been created or reset. 25_000
(UsbDeviceState::Default, true) => 100_000, }
(UsbDeviceState::Default, false) => 100_000, else {
// The USB device has received an address from the host. match (usb_device.state(), led_pin.is_set_high().unwrap_or_else(|_| false)) {
(UsbDeviceState::Addressed, true) => 250_000, // The USB device has just been created or reset.
(UsbDeviceState::Addressed, false) => 250_000, (UsbDeviceState::Default, true) => 100_000,
// The USB device has been configured and is fully functional. (UsbDeviceState::Default, false) => 100_000,
(UsbDeviceState::Configured, true) => 1_000_000, // The USB device has received an address from the host.
(UsbDeviceState::Configured, false) => 0, (UsbDeviceState::Addressed, true) => 250_000,
// The USB device has been suspended by the host or it has been unplugged from the USB bus. (UsbDeviceState::Addressed, false) => 250_000,
(UsbDeviceState::Suspend, true) => 25_000, // The USB device has been configured and is fully functional.
(UsbDeviceState::Suspend, false) => 2_000_000, (UsbDeviceState::Configured, true) => 8,
(UsbDeviceState::Configured, false) => 16,
// The USB device has been suspended by the host or it has been unplugged from the USB bus.
(UsbDeviceState::Suspend, true) => 10_000,
(UsbDeviceState::Suspend, false) => 2_000_000,
}
}; };
if timer.get_counter().ticks() - start_time > interval { if timer.get_counter().ticks() - start_time > interval {
let _ = led_pin.toggle(); let _ = led_pin.toggle();