From cd44e736db7f1b6f235a42435ad085df15bc4abc Mon Sep 17 00:00:00 2001 From: Jakob Lechner Date: Thu, 6 Mar 2025 23:41:58 +0100 Subject: [PATCH 01/10] Use RP2350 --- .cargo/config.toml | 19 ++--- Cargo.lock | 199 +++++++++++++++++++++++++-------------------- Cargo.toml | 29 ++----- Makefile | 12 --- build.rs | 13 +++ memory.x | 80 ++++++++++++++++-- shell.nix | 3 +- src/main.rs | 54 ++++++++---- 8 files changed, 252 insertions(+), 157 deletions(-) delete mode 100644 Makefile create mode 100644 build.rs diff --git a/.cargo/config.toml b/.cargo/config.toml index 01c7fca..9b886b5 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,15 +1,12 @@ -[target.'cfg(all(target_arch = "arm", target_os = "none"))'] -runner = "probe-rs run --chip RP2040 --protocol swd" -# runner = "elf2uf2-rs -d" +[build] +target = "thumbv8m.main-none-eabihf" +[target.thumbv8m.main-none-eabihf] rustflags = [ - "-C", "linker=flip-link", - "-C", "link-arg=--nmagic", - "-C", "link-arg=-Tlink.x", - "-C", "link-arg=-Tdefmt.x", - "-Z", "trap-unreachable=no", - "-C", "no-vectorize-loops", + "-C", "link-arg=--nmagic", + "-C", "link-arg=-Tlink.x", + "-C", "link-arg=-Tdefmt.x", + "-C", "target-cpu=cortex-m33", ] -[build] -target = "thumbv6m-none-eabi" +runner = "picotool load -u -v -x -t elf" diff --git a/Cargo.lock b/Cargo.lock index ddcb754..56ed097 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -70,16 +70,7 @@ checksum = "e37549a379a9e0e6e576fd208ee60394ccb8be963889eebba3ffe0980364f472" dependencies = [ "proc-macro2", "quote", - "syn 2.0.89", -] - -[[package]] -name = "crc-any" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a62ec9ff5f7965e4d7280bd5482acd20aadb50d632cf6c1d74493856b011fa73" -dependencies = [ - "debug-helper", + "syn 2.0.100", ] [[package]] @@ -88,12 +79,6 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "790eea4361631c5e7d22598ecd5723ff611904e3344ce8720784c93e3d83d40b" -[[package]] -name = "debug-helper" -version = "0.3.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f578e8e2c440e7297e008bb5486a3a8a194775224bbc23729b0dbdfaeebf162e" - [[package]] name = "defmt" version = "0.3.10" @@ -114,7 +99,7 @@ dependencies = [ "proc-macro-error2", "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.100", ] [[package]] @@ -138,9 +123,9 @@ dependencies = [ [[package]] name = "either" -version = "1.13.0" +version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" +checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" [[package]] name = "embedded-dma" @@ -216,7 +201,7 @@ checksum = "e99b8b3c28ae0e84b604c75f721c21dc77afb3706076af5e8216d15fd1deaae3" dependencies = [ "frunk_proc_macro_helpers", "quote", - "syn 2.0.89", + "syn 2.0.100", ] [[package]] @@ -228,7 +213,7 @@ dependencies = [ "frunk_core", "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.100", ] [[package]] @@ -267,9 +252,9 @@ dependencies = [ [[package]] name = "itertools" -version = "0.10.5" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" dependencies = [ "either", ] @@ -326,9 +311,15 @@ checksum = "96667db765a921f7b295ffee8b60472b686a51d4f21c2ee4ffdb94c7013b65a6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.100", ] +[[package]] +name = "panic-halt" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a513e167849a384b7f9b746e517604398518590a9142f4846a32e3c2a4de7b11" + [[package]] name = "panic-probe" version = "0.3.2" @@ -336,7 +327,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4047d9235d1423d66cc97da7d07eddb54d4f154d6c13805c6d0793956f4f25b0" dependencies = [ "cortex-m", - "defmt", ] [[package]] @@ -358,9 +348,9 @@ dependencies = [ [[package]] name = "portable-atomic" -version = "1.10.0" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "280dc24453071f1b63954171985a0b0d30058d287960968b9b2aca264c8d4ee6" +checksum = "350e9b48cbc6b0e028b0473b114454c6316e57336ee184ceab6e53f72c178b3e" [[package]] name = "proc-macro-error-attr2" @@ -381,23 +371,23 @@ dependencies = [ "proc-macro-error-attr2", "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.100", ] [[package]] name = "proc-macro2" -version = "1.0.92" +version = "1.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0" +checksum = "a31971752e70b8b2686d7e46ec17fb38dad4051d94024c88df49b667caea9c84" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.37" +version = "1.0.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +checksum = "c1f1914ce909e1658d9907913b4b91947430c7d9be598b15a1912935b8c04801" dependencies = [ "proc-macro2", ] @@ -409,36 +399,79 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" [[package]] -name = "rp-pico" -version = "0.9.0" +name = "riscv" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9342d3ac7011ac688300979e9b52a81f0add1d05feb02868cf94bfee0705b28" +checksum = "2f5c1b8bf41ea746266cdee443d1d1e9125c86ce1447e1a2615abd34330d33a9" dependencies = [ - "cortex-m-rt", - "fugit", - "rp2040-boot2", - "rp2040-hal", - "usb-device", + "critical-section", + "embedded-hal 1.0.0", ] [[package]] -name = "rp2040-boot2" +name = "riscv-rt" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0d35e32cf1383183e8885d8a9aa4402a087fd094dc34c2cb6df6687d0229dfe" +dependencies = [ + "riscv", + "riscv-rt-macros", +] + +[[package]] +name = "riscv-rt-macros" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30f19a85fe107b65031e0ba8ec60c34c2494069fe910d6c297f5e7cb5a6f76d0" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.100", +] + +[[package]] +name = "rp-binary-info" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534e2a451671116f5b9391cb15fae43b9abdc56817bcaca9a95ed32c3e4c6b38" + +[[package]] +name = "rp-hal-common" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8288358786b1458fb2caac8c4b40fb529ef4200d6c46467e2695b7a8ba573ae8" +dependencies = [ + "fugit", +] + +[[package]] +name = "rp2350-usb-ramdisk" +version = "0.1.0" +dependencies = [ + "cortex-m", + "cortex-m-rt", + "critical-section", + "defmt", + "defmt-rtt", + "embedded-hal 1.0.0", + "panic-halt", + "panic-probe", + "rp235x-hal", + "usb-device", + "usbd-storage", +] + +[[package]] +name = "rp235x-hal" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c92f344f63f950ee36cf4080050e4dce850839b9175da38f9d2ffb69b4dbb21" -dependencies = [ - "crc-any", -] - -[[package]] -name = "rp2040-hal" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d11e711940087f2cdff8aeae9f4b902e2014c06a00b39a1092686b81ec973d6f" +checksum = "e2939c82776b0b4ae110168b4298b5adf831e6cff249b057bf2a2187453b959c" dependencies = [ "bitfield 0.14.0", "cortex-m", + "cortex-m-rt", "critical-section", + "defmt", "embedded-dma", "embedded-hal 0.2.7", "embedded-hal 1.0.0", @@ -447,35 +480,40 @@ dependencies = [ "embedded-io", "frunk", "fugit", + "gcd", "itertools", "nb 1.1.0", "paste", "pio", "rand_core", - "rp2040-hal-macros", - "rp2040-pac", + "riscv", + "riscv-rt", + "rp-binary-info", + "rp-hal-common", + "rp235x-hal-macros", + "rp235x-pac", + "sha2-const-stable", "usb-device", "vcell", "void", ] [[package]] -name = "rp2040-hal-macros" +name = "rp235x-hal-macros" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86479063e497efe1ae81995ef9071f54fd1c7427e04d6c5b84cde545ff672a5e" +checksum = "74edd7a5979e9763bbb98e9746e711bac7464ee3397af7288e6c288ff0d3c764" dependencies = [ - "cortex-m-rt", "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.100", ] [[package]] -name = "rp2040-pac" -version = "0.6.0" +name = "rp235x-pac" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83cbcd3f7a0ca7bbe61dc4eb7e202842bee4e27b769a7bf3a4a72fa399d6e404" +checksum = "5ffcb6931deee4242886b5a1df62db5e2555b0eb6ae1e8be101f3ea3e58e65c6" dependencies = [ "cortex-m", "cortex-m-rt", @@ -483,23 +521,6 @@ dependencies = [ "vcell", ] -[[package]] -name = "rp2040-usb-ramdisk" -version = "0.1.0" -dependencies = [ - "cortex-m", - "cortex-m-rt", - "defmt", - "defmt-rtt", - "embedded-hal 1.0.0", - "panic-probe", - "rp-pico", - "rp2040-boot2", - "rp2040-hal", - "usb-device", - "usbd-storage", -] - [[package]] name = "rustc_version" version = "0.2.3" @@ -524,6 +545,12 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" +[[package]] +name = "sha2-const-stable" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f179d4e11094a893b82fff208f74d448a7512f99f5a0acbd5c679b705f83ed9" + [[package]] name = "stable_deref_trait" version = "1.2.0" @@ -543,9 +570,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.89" +version = "2.0.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44d46482f1c1c87acd84dea20c1bf5ebff4c757009ed6bf19cfd36fb10e92c4e" +checksum = "b09a44accad81e1ba1cd74a32461ba89dee89095ba17b32f5d03683b1b1fc2a0" dependencies = [ "proc-macro2", "quote", @@ -554,29 +581,29 @@ dependencies = [ [[package]] name = "thiserror" -version = "2.0.3" +version = "2.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c006c85c7651b3cf2ada4584faa36773bd07bac24acfb39f3c431b36d7e667aa" +checksum = "567b8a2dae586314f7be2a752ec7474332959c6460e02bde30d702a66d488708" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "2.0.3" +version = "2.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f077553d607adc1caf65430528a576c757a71ed73944b66ebb58ef2bbd243568" +checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d" dependencies = [ "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.100", ] [[package]] name = "unicode-ident" -version = "1.0.14" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83" +checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" [[package]] name = "usb-device" diff --git a/Cargo.toml b/Cargo.toml index 0799c3b..9f4b78e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,30 +1,17 @@ [package] -name = "rp2040-usb-ramdisk" +name = "rp2350-usb-ramdisk" version = "0.1.0" -edition = "2024" +edition = "2021" [dependencies] cortex-m = "0.7.7" -cortex-m-rt = { version = "0.7.5", optional = true } +cortex-m-rt = "0.7.5" +critical-section = "1.2.0" defmt = "0.3.10" defmt-rtt = "0.4.1" embedded-hal = "1.0.0" -panic-probe = { version = "0.3.2", features = ["print-defmt"] } -rp-pico = "0.9.0" -rp2040-boot2 = { version = "0.3.0", optional = true } -rp2040-hal = "0.10.2" +panic-halt = "1.0.0" +panic-probe = "0.3.2" +rp235x-hal = { version = "0.3.0", features = ["binary-info", "critical-section-impl", "rt", "defmt"] } usb-device = "0.3.2" -usbd-storage = { version = "1.0.0", features = ["scsi", "bbb", "defmt"] } - -[features] -default = ["boot2", "rt", "critical-section-impl"] -boot2 = ["rp2040-boot2"] -rt = ["cortex-m-rt","rp2040-hal/rt"] -critical-section-impl = ["rp2040-hal/critical-section-impl"] -cortex-m-rt = ["dep:cortex-m-rt"] - -[profile.dev] -panic = "abort" - -[profile.release] -panic = "abort" +usbd-storage = { version = "1.0.0", features = ["bbb", "defmt", "scsi"] } diff --git a/Makefile b/Makefile deleted file mode 100644 index de09fbc..0000000 --- a/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -BIN=rp2040-usb-ramdisk - -.PHONY: flash -flash: target/thumbv6m-none-eabi/release/$(BIN) - elf2uf2-rs --deploy $< - -target/thumbv6m-none-eabi/release/$(BIN): src/main.rs src/serial_number.rs Cargo.toml - cargo build --target thumbv6m-none-eabi --release - -target/thumbv6m-none-eabi/release/$(BIN).uf2: target/thumbv6m-none-eabi/release/$(BIN) - elf2uf2-rs $< $@ - diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..90bade9 --- /dev/null +++ b/build.rs @@ -0,0 +1,13 @@ +use std::{fs::File, io::Write, path::PathBuf}; + +fn main() { + let out = PathBuf::from(std::env::var("OUT_DIR").unwrap()); + println!("cargo:rustc-link-search={}", out.display()); + + let memory_x = include_bytes!("memory.x"); + let mut f = File::create(out.join("memory.x")).unwrap(); + f.write_all(memory_x).unwrap(); + println!("cargo:rerun-if-changed=memory.x"); + + println!("cargo:rerun-if-changed=build.rs"); +} diff --git a/memory.x b/memory.x index 070eac7..7d409ba 100644 --- a/memory.x +++ b/memory.x @@ -1,15 +1,77 @@ MEMORY { - BOOT2 : ORIGIN = 0x10000000, LENGTH = 0x100 - FLASH : ORIGIN = 0x10000100, LENGTH = 2048K - 0x100 - RAM : ORIGIN = 0x20000000, LENGTH = 256K + /* + * The RP2350 has either external or internal flash. + * + * 2 MiB is a safe default here, although a Pico 2 has 4 MiB. + */ + FLASH : ORIGIN = 0x10000000, LENGTH = 2048K + /* + * RAM consists of 8 banks, SRAM0-SRAM7, with a striped mapping. + * This is usually good for performance, as it distributes load on + * those banks evenly. + */ + RAM : ORIGIN = 0x20000000, LENGTH = 512K + /* + * RAM banks 8 and 9 use a direct mapping. They can be used to have + * memory areas dedicated for some specific job, improving predictability + * of access times. + * Example: Separate stacks for core0 and core1. + */ + SRAM4 : ORIGIN = 0x20080000, LENGTH = 4K + SRAM5 : ORIGIN = 0x20081000, LENGTH = 4K } -EXTERN(BOOT2_FIRMWARE) +SECTIONS { + /* ### Boot ROM info + * + * Goes after .vector_table, to keep it in the first 4K of flash + * where the Boot ROM (and picotool) can find it + */ + .start_block : ALIGN(4) + { + __start_block_addr = .; + KEEP(*(.start_block)); + KEEP(*(.boot_info)); + } > FLASH + +} INSERT AFTER .vector_table; + +/* move .text to start /after/ the boot info */ +_stext = ADDR(.start_block) + SIZEOF(.start_block); SECTIONS { - /* ### Boot loader */ - .boot2 ORIGIN(BOOT2) : + /* ### Picotool 'Binary Info' Entries + * + * Picotool looks through this block (as we have pointers to it in our + * header) to find interesting information. + */ + .bi_entries : ALIGN(4) { - KEEP(*(.boot2)); - } > BOOT2 -} INSERT BEFORE .text; \ No newline at end of file + /* We put this in the header */ + __bi_entries_start = .; + /* Here are the entries */ + KEEP(*(.bi_entries)); + /* Keep this block a nice round size */ + . = ALIGN(4); + /* We put this in the header */ + __bi_entries_end = .; + } > FLASH +} INSERT AFTER .text; + +SECTIONS { + /* ### Boot ROM extra info + * + * Goes after everything in our program, so it can contain a signature. + */ + .end_block : ALIGN(4) + { + __end_block_addr = .; + KEEP(*(.end_block)); + } > FLASH + +} INSERT AFTER .uninit; + +PROVIDE(start_to_end = __end_block_addr - __start_block_addr); +PROVIDE(end_to_start = __start_block_addr - __end_block_addr); + + diff --git a/shell.nix b/shell.nix index d866bbc..882a501 100644 --- a/shell.nix +++ b/shell.nix @@ -1,10 +1,9 @@ { pkgs ? import {} }: pkgs.mkShell { nativeBuildInputs = with pkgs; [ - elf2uf2-rs + picotool gcc gnumake - probe-rs rustup ]; } diff --git a/src/main.rs b/src/main.rs index 42a1cb9..9168152 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,18 +1,14 @@ #![no_std] #![no_main] -use rp_pico::entry; - use defmt as _; use defmt_rtt as _; use panic_probe as _; +use rp235x_hal as hal; + use embedded_hal::digital::StatefulOutputPin; -use rp_pico::hal::pac; - -use rp_pico::hal; - use usb_device::{class_prelude::*, prelude::*}; use usbd_storage::subclass::scsi::{Scsi, ScsiCommand}; @@ -22,8 +18,14 @@ use usbd_storage::transport::TransportError; mod serial_number; +#[link_section = ".start_block"] +#[used] +pub static IMAGE_DEF: hal::block::ImageDef = hal::block::ImageDef::secure_exe(); + +const XTAL_FREQ_HZ: u32 = 12_000_000u32; + const DISK_BLOCK_SIZE: u32 = 512; -const DISK_BLOCK_NUM: u32 = 256; +const DISK_BLOCK_NUM: u32 = 1000; const USB_PACKET_SIZE: u16 = 64; // 8,16,32,64 const MAX_LUN: u8 = 0; // max 0x0F @@ -68,14 +70,14 @@ impl State { } } -#[entry] +#[hal::entry] fn main() -> ! { - let mut pac = pac::Peripherals::take().unwrap(); + let mut pac = hal::pac::Peripherals::take().unwrap(); let mut watchdog = hal::Watchdog::new(pac.WATCHDOG); let clocks = hal::clocks::init_clocks_and_plls( - rp_pico::XOSC_CRYSTAL_FREQ, + XTAL_FREQ_HZ, pac.XOSC, pac.CLOCKS, pac.PLL_SYS, @@ -83,24 +85,36 @@ fn main() -> ! { &mut pac.RESETS, &mut watchdog, ) - .ok() .unwrap(); - let timer = hal::timer::Timer::new(pac.TIMER, &mut pac.RESETS, &clocks); + let timer = hal::Timer::new_timer0(pac.TIMER0, &mut pac.RESETS, &clocks); let sio = hal::Sio::new(pac.SIO); - let pins = rp_pico::Pins::new( + let pins = hal::gpio::Pins::new( pac.IO_BANK0, pac.PADS_BANK0, sio.gpio_bank0, &mut pac.RESETS, ); - let mut led_pin = pins.led.into_push_pull_output(); + let mut led_pin = pins.gpio25.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( - pac.USBCTRL_REGS, - pac.USBCTRL_DPRAM, + pac.USB, + pac.USB_DPRAM, clocks.usb_clock, true, &mut pac.RESETS, @@ -344,3 +358,11 @@ fn process_command( Ok(()) } + +#[link_section = ".bi_entries"] +#[used] +pub static PICOTOOL_ENTRIES: [hal::binary_info::EntryAddr; 3] = [ + hal::binary_info::rp_program_name!(c"rp2350-usb-ramdisk"), + hal::binary_info::rp_cargo_version!(), + hal::binary_info::rp_program_build_attribute!(), +]; From b7209dd33110b702155ca0bdab086cc2d1a910af Mon Sep 17 00:00:00 2001 From: Jakob Lechner Date: Thu, 3 Apr 2025 01:00:12 +0200 Subject: [PATCH 02/10] 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. --- .gitignore | 1 - src/main.rs | 5 +---- src/serial_number.rs.example | 1 - 3 files changed, 1 insertion(+), 6 deletions(-) delete mode 100644 src/serial_number.rs.example diff --git a/.gitignore b/.gitignore index 2105e7c..6abfe1b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ /target /.direnv -/src/serial_number.rs diff --git a/src/main.rs b/src/main.rs index 42a1cb9..0c6e6ba 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,8 +20,6 @@ use usbd_storage::subclass::Command; use usbd_storage::transport::bbb::{BulkOnly, BulkOnlyError}; use usbd_storage::transport::TransportError; -mod serial_number; - const DISK_BLOCK_SIZE: u32 = 512; const DISK_BLOCK_NUM: u32 = 256; @@ -112,8 +110,7 @@ fn main() -> ! { let mut usb_device = UsbDeviceBuilder::new(&usb_bus, UsbVidPid(0xcafe, 0x4002)) .strings(&[StringDescriptors::new(LangID::EN) .manufacturer("jalr") - .product("RAM Mass Storage") - .serial_number(serial_number::SERIAL)]) + .product("RAM Mass Storage")]) .unwrap() .device_class(0x08) .self_powered(false) diff --git a/src/serial_number.rs.example b/src/serial_number.rs.example deleted file mode 100644 index e61eae8..0000000 --- a/src/serial_number.rs.example +++ /dev/null @@ -1 +0,0 @@ -pub const SERIAL: &str = "example-4711"; From a9db8eeb4f1c932e46226aad545777b071195383 Mon Sep 17 00:00:00 2001 From: Jakob Lechner Date: Thu, 3 Apr 2025 01:01:49 +0200 Subject: [PATCH 03/10] Fix partition table --- src/main.rs | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/main.rs b/src/main.rs index 0c6e6ba..20d6c98 100644 --- a/src/main.rs +++ b/src/main.rs @@ -133,10 +133,10 @@ fn main() -> ! { const OEM: [u8; 8] = *b"mkfs.fat"; 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 "; - storage[0x1B8..0x1BC].copy_from_slice(&[0xEF, 0xBE, 0xAD, 0xDE]); - storage[0x1BE..0x1C3].copy_from_slice(&[0x00, 0x00, 0x02, 0x00, 0x01]); + storage[0x1B9] = 0x10; + storage[0x1BE..0x1C3].copy_from_slice(&[0x00, 0x00, 0x02, 0x00, 0x0c]); storage[0x1C3] = last_head as u8; storage[0x1C4] = ((last_cyl >> 8) & 0xc0) as u8 | ((last_sect as u8) & 0x3f); storage[0x1C5] = last_cyl as u8; @@ -150,22 +150,23 @@ fn main() -> ! { // FAT12 Partition storage[0x200..0x203].copy_from_slice(&[0xEB, 0x3C, 0x90]); storage[0x203..0x20B].copy_from_slice(&OEM); - storage[0x20B..0x227].copy_from_slice(&[0x00, 0x02, 0x04, 0x01, 0x00, - 0x02, 0x00, 0x02, (DISK_BLOCK_NUM & 0xff) as u8, - (DISK_BLOCK_NUM >> 8) as u8, - 0xF8, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x29]); + storage[0x20B..0x21d].copy_from_slice(&[0x00, 0x02, 0x04, 0x01, 0x00, + 0x02, 0x00, 0x02, (LBA & 0xff) as u8, + (LBA >> 8) as u8, + 0xF8, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01]); + storage[0x224..0x227].copy_from_slice(&[0x80, 0x00, 0x29]); 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[0x3FE..0x400].copy_from_slice(&[0x55, 0xAA]); - + storage[0x400..0x403].copy_from_slice(&[0xF8, 0xFF, 0xFF]); storage[0x600..0x603].copy_from_slice(&[0xF8, 0xFF, 0xFF]); - storage[0x800..0x80B].copy_from_slice(&FILESYSTEM_NAME); - storage[0x80B..0x81A].copy_from_slice(&[0x08, 0x00, 0x00, 0xF9, 0x98, - 0x3A, 0x58, 0x3A, 0x58, 0x00, 0x00, 0xF9, 0x98, 0x3A, 0x58 - ]); + storage[0x800..0x80B].copy_from_slice(&FILESYSTEM_LABEL); + storage[0x80B] = 0x08; // file attribute 0x08 = volume label + + // https://de.wikipedia.org/wiki/File_Allocation_Table + // Remove bootloader code: dd if=/dev/zero conv=notrunc of=foo bs=1 count=420 seek=602 let mut state: State = State { storage_offset: 0, From b9a37ff54d117f108c0de8fe32557e62cc675ae4 Mon Sep 17 00:00:00 2001 From: Jakob Lechner Date: Thu, 3 Apr 2025 01:00:12 +0200 Subject: [PATCH 04/10] 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. --- .gitignore | 1 - src/main.rs | 4 +--- src/serial_number.rs.example | 1 - 3 files changed, 1 insertion(+), 5 deletions(-) delete mode 100644 src/serial_number.rs.example diff --git a/.gitignore b/.gitignore index 2105e7c..6abfe1b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ /target /.direnv -/src/serial_number.rs diff --git a/src/main.rs b/src/main.rs index 9168152..8092a79 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,7 +16,6 @@ use usbd_storage::subclass::Command; use usbd_storage::transport::bbb::{BulkOnly, BulkOnlyError}; use usbd_storage::transport::TransportError; -mod serial_number; #[link_section = ".start_block"] #[used] @@ -126,8 +125,7 @@ fn main() -> ! { let mut usb_device = UsbDeviceBuilder::new(&usb_bus, UsbVidPid(0xcafe, 0x4002)) .strings(&[StringDescriptors::new(LangID::EN) .manufacturer("jalr") - .product("RAM Mass Storage") - .serial_number(serial_number::SERIAL)]) + .product("RAM Mass Storage")]) .unwrap() .device_class(0x08) .self_powered(false) diff --git a/src/serial_number.rs.example b/src/serial_number.rs.example deleted file mode 100644 index e61eae8..0000000 --- a/src/serial_number.rs.example +++ /dev/null @@ -1 +0,0 @@ -pub const SERIAL: &str = "example-4711"; From 8dd4913dbaa287b0a61c18b377dec7c5293e413c Mon Sep 17 00:00:00 2001 From: Jakob Lechner Date: Thu, 3 Apr 2025 01:01:49 +0200 Subject: [PATCH 05/10] Fix partition table --- src/main.rs | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/main.rs b/src/main.rs index 8092a79..5230f7c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -148,10 +148,10 @@ fn main() -> ! { const OEM: [u8; 8] = *b"mkfs.fat"; 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 "; - storage[0x1B8..0x1BC].copy_from_slice(&[0xEF, 0xBE, 0xAD, 0xDE]); - storage[0x1BE..0x1C3].copy_from_slice(&[0x00, 0x00, 0x02, 0x00, 0x01]); + storage[0x1B9] = 0x10; + storage[0x1BE..0x1C3].copy_from_slice(&[0x00, 0x00, 0x02, 0x00, 0x0c]); storage[0x1C3] = last_head as u8; storage[0x1C4] = ((last_cyl >> 8) & 0xc0) as u8 | ((last_sect as u8) & 0x3f); storage[0x1C5] = last_cyl as u8; @@ -165,22 +165,23 @@ fn main() -> ! { // FAT12 Partition storage[0x200..0x203].copy_from_slice(&[0xEB, 0x3C, 0x90]); storage[0x203..0x20B].copy_from_slice(&OEM); - storage[0x20B..0x227].copy_from_slice(&[0x00, 0x02, 0x04, 0x01, 0x00, - 0x02, 0x00, 0x02, (DISK_BLOCK_NUM & 0xff) as u8, - (DISK_BLOCK_NUM >> 8) as u8, - 0xF8, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x29]); + storage[0x20B..0x21d].copy_from_slice(&[0x00, 0x02, 0x04, 0x01, 0x00, + 0x02, 0x00, 0x02, (LBA & 0xff) as u8, + (LBA >> 8) as u8, + 0xF8, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01]); + storage[0x224..0x227].copy_from_slice(&[0x80, 0x00, 0x29]); 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[0x3FE..0x400].copy_from_slice(&[0x55, 0xAA]); - + storage[0x400..0x403].copy_from_slice(&[0xF8, 0xFF, 0xFF]); storage[0x600..0x603].copy_from_slice(&[0xF8, 0xFF, 0xFF]); - storage[0x800..0x80B].copy_from_slice(&FILESYSTEM_NAME); - storage[0x80B..0x81A].copy_from_slice(&[0x08, 0x00, 0x00, 0xF9, 0x98, - 0x3A, 0x58, 0x3A, 0x58, 0x00, 0x00, 0xF9, 0x98, 0x3A, 0x58 - ]); + storage[0x800..0x80B].copy_from_slice(&FILESYSTEM_LABEL); + storage[0x80B] = 0x08; // file attribute 0x08 = volume label + + // https://de.wikipedia.org/wiki/File_Allocation_Table + // Remove bootloader code: dd if=/dev/zero conv=notrunc of=foo bs=1 count=420 seek=602 let mut state: State = State { storage_offset: 0, From eb4921afce00157960df0b52183188c04f281ae1 Mon Sep 17 00:00:00 2001 From: Jakob Lechner Date: Tue, 23 Sep 2025 20:19:22 +0200 Subject: [PATCH 06/10] Change LED Pin and flash timing --- src/main.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 5230f7c..25bd191 100644 --- a/src/main.rs +++ b/src/main.rs @@ -96,7 +96,7 @@ fn main() -> ! { &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; @@ -201,10 +201,10 @@ fn main() -> ! { (UsbDeviceState::Addressed, true) => 250_000, (UsbDeviceState::Addressed, false) => 250_000, // The USB device has been configured and is fully functional. - (UsbDeviceState::Configured, true) => 1_000_000, - (UsbDeviceState::Configured, false) => 0, + (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) => 25_000, + (UsbDeviceState::Suspend, true) => 10_000, (UsbDeviceState::Suspend, false) => 2_000_000, }; if timer.get_counter().ticks() - start_time > interval { From 574b0cb4fe90ca862af4bf8aae65b2082cf2d469 Mon Sep 17 00:00:00 2001 From: Jakob Lechner Date: Tue, 23 Sep 2025 20:30:34 +0200 Subject: [PATCH 07/10] Add fast blinking after reset --- src/main.rs | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/main.rs b/src/main.rs index 20d6c98..0136bce 100644 --- a/src/main.rs +++ b/src/main.rs @@ -116,8 +116,6 @@ fn main() -> ! { .self_powered(false) .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]; const LBA: u32 = DISK_BLOCK_NUM - 1; @@ -177,20 +175,26 @@ fn main() -> ! { defmt::info!("entering main loop"); + let mut start_time: u64 = 0; loop { - let interval = match (usb_device.state(), led_pin.is_set_high().unwrap_or_else(|_| false)) { - // The USB device has just been created or reset. - (UsbDeviceState::Default, true) => 100_000, - (UsbDeviceState::Default, false) => 100_000, - // The USB device has received an address from the host. - (UsbDeviceState::Addressed, true) => 250_000, - (UsbDeviceState::Addressed, false) => 250_000, - // The USB device has been configured and is fully functional. - (UsbDeviceState::Configured, true) => 1_000_000, - (UsbDeviceState::Configured, false) => 0, - // The USB device has been suspended by the host or it has been unplugged from the USB bus. - (UsbDeviceState::Suspend, true) => 25_000, - (UsbDeviceState::Suspend, false) => 2_000_000, + let interval = if timer.get_counter().ticks() < 2_000_000 { + 25_000 + } + else { + match (usb_device.state(), led_pin.is_set_high().unwrap_or_else(|_| false)) { + // The USB device has just been created or reset. + (UsbDeviceState::Default, true) => 100_000, + (UsbDeviceState::Default, false) => 100_000, + // The USB device has received an address from the host. + (UsbDeviceState::Addressed, true) => 250_000, + (UsbDeviceState::Addressed, false) => 250_000, + // The USB device has been configured and is fully functional. + (UsbDeviceState::Configured, true) => 1_000_000, + (UsbDeviceState::Configured, false) => 0, + // The USB device has been suspended by the host or it has been unplugged from the USB bus. + (UsbDeviceState::Suspend, true) => 25_000, + (UsbDeviceState::Suspend, false) => 2_000_000, + } }; if timer.get_counter().ticks() - start_time > interval { let _ = led_pin.toggle(); From cd9c304370e586173bab1d71920a0943ea4d94d5 Mon Sep 17 00:00:00 2001 From: Jakob Lechner Date: Tue, 23 Sep 2025 20:51:10 +0200 Subject: [PATCH 08/10] Use picotool --- .cargo/config.toml | 3 +-- shell.nix | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index 01c7fca..0b32db2 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,6 +1,5 @@ [target.'cfg(all(target_arch = "arm", target_os = "none"))'] -runner = "probe-rs run --chip RP2040 --protocol swd" -# runner = "elf2uf2-rs -d" +runner = "picotool load -u -v -x -t elf" rustflags = [ "-C", "linker=flip-link", diff --git a/shell.nix b/shell.nix index d866bbc..882a501 100644 --- a/shell.nix +++ b/shell.nix @@ -1,10 +1,9 @@ { pkgs ? import {} }: pkgs.mkShell { nativeBuildInputs = with pkgs; [ - elf2uf2-rs + picotool gcc gnumake - probe-rs rustup ]; } From 96a08061ee91ff8a406b86de69cbb183e55b848a Mon Sep 17 00:00:00 2001 From: Jakob Lechner Date: Tue, 23 Sep 2025 20:51:19 +0200 Subject: [PATCH 09/10] Update dependencies --- Cargo.lock | 97 +++++++++++++++++++++++++++++------------------------- 1 file changed, 53 insertions(+), 44 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ddcb754..6dadf0c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -70,7 +70,7 @@ checksum = "e37549a379a9e0e6e576fd208ee60394ccb8be963889eebba3ffe0980364f472" dependencies = [ "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.106", ] [[package]] @@ -96,9 +96,18 @@ checksum = "f578e8e2c440e7297e008bb5486a3a8a194775224bbc23729b0dbdfaeebf162e" [[package]] name = "defmt" -version = "0.3.10" +version = "0.3.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86f6162c53f659f65d00619fe31f14556a6e9f8752ccc4a41bd177ffcf3d6130" +checksum = "f0963443817029b2024136fc4dd07a5107eb8f977eaf18fcd1fdeb11306b64ad" +dependencies = [ + "defmt 1.0.1", +] + +[[package]] +name = "defmt" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "548d977b6da32fa1d1fda2876453da1e7df63ad0304c8b3dae4dbe7b96f39b78" dependencies = [ "bitflags", "defmt-macros", @@ -106,41 +115,41 @@ dependencies = [ [[package]] name = "defmt-macros" -version = "0.4.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d135dd939bad62d7490b0002602d35b358dce5fd9233a709d3c1ef467d4bde6" +checksum = "3d4fc12a85bcf441cfe44344c4b72d58493178ce635338a3f3b78943aceb258e" dependencies = [ "defmt-parser", "proc-macro-error2", "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.106", ] [[package]] name = "defmt-parser" -version = "0.4.1" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3983b127f13995e68c1e29071e5d115cd96f215ccb5e6812e3728cd6f92653b3" +checksum = "10d60334b3b2e7c9d91ef8150abfb6fa4c1c39ebbcf4a81c2e346aad939fee3e" dependencies = [ "thiserror", ] [[package]] name = "defmt-rtt" -version = "0.4.1" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bab697b3dbbc1750b7c8b821aa6f6e7f2480b47a99bc057a2ed7b170ebef0c51" +checksum = "c6eca0aae8aa2cf8333200ecbd236274697bc0a394765c858b3d9372eb1abcfa" dependencies = [ "critical-section", - "defmt", + "defmt 0.3.100", ] [[package]] name = "either" -version = "1.13.0" +version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" +checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" [[package]] name = "embedded-dma" @@ -194,9 +203,9 @@ checksum = "edd0f118536f44f5ccd48bcb8b111bdc3de888b58c74639dfb034a357d0f206d" [[package]] name = "frunk" -version = "0.4.3" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "874b6a17738fc273ec753618bac60ddaeac48cb1d7684c3e7bd472e57a28b817" +checksum = "28aef0f9aa070bce60767c12ba9cb41efeaf1a2bc6427f87b7d83f11239a16d7" dependencies = [ "frunk_core", "frunk_derives", @@ -204,31 +213,31 @@ dependencies = [ [[package]] name = "frunk_core" -version = "0.4.3" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3529a07095650187788833d585c219761114005d5976185760cf794d265b6a5c" +checksum = "476eeaa382e3462b84da5d6ba3da97b5786823c2d0d3a0d04ef088d073da225c" [[package]] name = "frunk_derives" -version = "0.4.3" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e99b8b3c28ae0e84b604c75f721c21dc77afb3706076af5e8216d15fd1deaae3" +checksum = "a0b4095fc99e1d858e5b8c7125d2638372ec85aa0fe6c807105cf10b0265ca6c" dependencies = [ "frunk_proc_macro_helpers", "quote", - "syn 2.0.89", + "syn 2.0.106", ] [[package]] name = "frunk_proc_macro_helpers" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05a956ef36c377977e512e227dcad20f68c2786ac7a54dacece3746046fea5ce" +checksum = "1952b802269f2db12ab7c0bd328d0ae8feaabf19f352a7b0af7bb0c5693abfce" dependencies = [ "frunk_core", "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.106", ] [[package]] @@ -326,7 +335,7 @@ checksum = "96667db765a921f7b295ffee8b60472b686a51d4f21c2ee4ffdb94c7013b65a6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.106", ] [[package]] @@ -336,7 +345,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4047d9235d1423d66cc97da7d07eddb54d4f154d6c13805c6d0793956f4f25b0" dependencies = [ "cortex-m", - "defmt", + "defmt 0.3.100", ] [[package]] @@ -358,9 +367,9 @@ dependencies = [ [[package]] name = "portable-atomic" -version = "1.10.0" +version = "1.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "280dc24453071f1b63954171985a0b0d30058d287960968b9b2aca264c8d4ee6" +checksum = "f84267b20a16ea918e43c6a88433c2d54fa145c92a811b5b047ccbe153674483" [[package]] name = "proc-macro-error-attr2" @@ -381,23 +390,23 @@ dependencies = [ "proc-macro-error-attr2", "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.106", ] [[package]] name = "proc-macro2" -version = "1.0.92" +version = "1.0.101" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0" +checksum = "89ae43fd86e4158d6db51ad8e2b80f313af9cc74f5c0e03ccb87de09998732de" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.37" +version = "1.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" dependencies = [ "proc-macro2", ] @@ -489,7 +498,7 @@ version = "0.1.0" dependencies = [ "cortex-m", "cortex-m-rt", - "defmt", + "defmt 0.3.100", "defmt-rtt", "embedded-hal 1.0.0", "panic-probe", @@ -543,9 +552,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.89" +version = "2.0.106" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44d46482f1c1c87acd84dea20c1bf5ebff4c757009ed6bf19cfd36fb10e92c4e" +checksum = "ede7c438028d4436d71104916910f5bb611972c5cfd7f89b8300a8186e6fada6" dependencies = [ "proc-macro2", "quote", @@ -554,29 +563,29 @@ dependencies = [ [[package]] name = "thiserror" -version = "2.0.3" +version = "2.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c006c85c7651b3cf2ada4584faa36773bd07bac24acfb39f3c431b36d7e667aa" +checksum = "3467d614147380f2e4e374161426ff399c91084acd2363eaf549172b3d5e60c0" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "2.0.3" +version = "2.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f077553d607adc1caf65430528a576c757a71ed73944b66ebb58ef2bbd243568" +checksum = "6c5e1be1c48b9172ee610da68fd9cd2770e7a4056cb3fc98710ee6906f0c7960" dependencies = [ "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.106", ] [[package]] name = "unicode-ident" -version = "1.0.14" +version = "1.0.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83" +checksum = "f63a545481291138910575129486daeaf8ac54aee4387fe7906919f7830c7d9d" [[package]] name = "usb-device" @@ -584,7 +593,7 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "98816b1accafbb09085168b90f27e93d790b4bfa19d883466b5e53315b5f06a6" dependencies = [ - "defmt", + "defmt 0.3.100", "heapless", "portable-atomic", ] @@ -595,7 +604,7 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ee23ab04c7d76b63c417cf2fa672d720477d2e71c6822ac6e5ceaf526f48f394" dependencies = [ - "defmt", + "defmt 0.3.100", "num_enum 0.6.1", "usb-device", ] From 43bec436eb5272594f61710e59717e772486f975 Mon Sep 17 00:00:00 2001 From: Jakob Lechner Date: Wed, 24 Sep 2025 10:46:11 +0200 Subject: [PATCH 10/10] Rework fast blinking after reset --- src/main.rs | 47 +++++++++++++++++++---------------------------- 1 file changed, 19 insertions(+), 28 deletions(-) diff --git a/src/main.rs b/src/main.rs index 25bd191..91e7c2a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -98,19 +98,6 @@ fn main() -> ! { 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( pac.USB, pac.USB_DPRAM, @@ -131,8 +118,6 @@ fn main() -> ! { .self_powered(false) .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]; const LBA: u32 = DISK_BLOCK_NUM - 1; @@ -192,20 +177,26 @@ fn main() -> ! { defmt::info!("entering main loop"); + let mut start_time: u64 = 0; loop { - let interval = match (usb_device.state(), led_pin.is_set_high().unwrap_or_else(|_| false)) { - // The USB device has just been created or reset. - (UsbDeviceState::Default, true) => 100_000, - (UsbDeviceState::Default, false) => 100_000, - // The USB device has received an address from the host. - (UsbDeviceState::Addressed, true) => 250_000, - (UsbDeviceState::Addressed, false) => 250_000, - // The USB device has been configured and is fully functional. - (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, + let interval = if timer.get_counter().ticks() < 2_000_000 { + 25_000 + } + else { + match (usb_device.state(), led_pin.is_set_high().unwrap_or_else(|_| false)) { + // The USB device has just been created or reset. + (UsbDeviceState::Default, true) => 100_000, + (UsbDeviceState::Default, false) => 100_000, + // The USB device has received an address from the host. + (UsbDeviceState::Addressed, true) => 250_000, + (UsbDeviceState::Addressed, false) => 250_000, + // The USB device has been configured and is fully functional. + (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 { let _ = led_pin.toggle();