Compare commits

...

5 commits

Author SHA1 Message Date
Jakob Lechner
96a08061ee Update dependencies 2025-09-23 20:51:19 +02:00
Jakob Lechner
cd9c304370 Use picotool 2025-09-23 20:51:10 +02:00
Jakob Lechner
574b0cb4fe Add fast blinking after reset 2025-09-23 20:48:57 +02:00
Jakob Lechner
a9db8eeb4f Fix partition table 2025-04-03 18:23:56 +02:00
Jakob Lechner
b7209dd331 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-03 11:02:08 +02:00
6 changed files with 90 additions and 83 deletions

View file

@ -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",

1
.gitignore vendored
View file

@ -1,3 +1,2 @@
/target
/.direnv
/src/serial_number.rs

97
Cargo.lock generated
View file

@ -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",
]

View file

@ -1,10 +1,9 @@
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
nativeBuildInputs = with pkgs; [
elf2uf2-rs
picotool
gcc
gnumake
probe-rs
rustup
];
}

View file

@ -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,15 +110,12 @@ 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)
.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;
@ -136,10 +131,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;
@ -153,22 +148,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,
@ -179,8 +175,13 @@ 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)) {
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,
@ -193,6 +194,7 @@ fn main() -> ! {
// 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();

View file

@ -1 +0,0 @@
pub const SERIAL: &str = "example-4711";