Compare commits

..

No commits in common. "96a08061ee91ff8a406b86de69cbb183e55b848a" and "1f8a8ff81ac5383d61e0a07e5bb8aeb52874c2df" have entirely different histories.

6 changed files with 83 additions and 90 deletions

View file

@ -1,5 +1,6 @@
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
runner = "picotool load -u -v -x -t elf"
runner = "probe-rs run --chip RP2040 --protocol swd"
# runner = "elf2uf2-rs -d"
rustflags = [
"-C", "linker=flip-link",

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
/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.106",
"syn 2.0.89",
]
[[package]]
@ -96,18 +96,9 @@ checksum = "f578e8e2c440e7297e008bb5486a3a8a194775224bbc23729b0dbdfaeebf162e"
[[package]]
name = "defmt"
version = "0.3.100"
version = "0.3.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
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"
checksum = "86f6162c53f659f65d00619fe31f14556a6e9f8752ccc4a41bd177ffcf3d6130"
dependencies = [
"bitflags",
"defmt-macros",
@ -115,41 +106,41 @@ dependencies = [
[[package]]
name = "defmt-macros"
version = "1.0.1"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3d4fc12a85bcf441cfe44344c4b72d58493178ce635338a3f3b78943aceb258e"
checksum = "9d135dd939bad62d7490b0002602d35b358dce5fd9233a709d3c1ef467d4bde6"
dependencies = [
"defmt-parser",
"proc-macro-error2",
"proc-macro2",
"quote",
"syn 2.0.106",
"syn 2.0.89",
]
[[package]]
name = "defmt-parser"
version = "1.0.0"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "10d60334b3b2e7c9d91ef8150abfb6fa4c1c39ebbcf4a81c2e346aad939fee3e"
checksum = "3983b127f13995e68c1e29071e5d115cd96f215ccb5e6812e3728cd6f92653b3"
dependencies = [
"thiserror",
]
[[package]]
name = "defmt-rtt"
version = "0.4.2"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c6eca0aae8aa2cf8333200ecbd236274697bc0a394765c858b3d9372eb1abcfa"
checksum = "bab697b3dbbc1750b7c8b821aa6f6e7f2480b47a99bc057a2ed7b170ebef0c51"
dependencies = [
"critical-section",
"defmt 0.3.100",
"defmt",
]
[[package]]
name = "either"
version = "1.15.0"
version = "1.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719"
checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0"
[[package]]
name = "embedded-dma"
@ -203,9 +194,9 @@ checksum = "edd0f118536f44f5ccd48bcb8b111bdc3de888b58c74639dfb034a357d0f206d"
[[package]]
name = "frunk"
version = "0.4.4"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28aef0f9aa070bce60767c12ba9cb41efeaf1a2bc6427f87b7d83f11239a16d7"
checksum = "874b6a17738fc273ec753618bac60ddaeac48cb1d7684c3e7bd472e57a28b817"
dependencies = [
"frunk_core",
"frunk_derives",
@ -213,31 +204,31 @@ dependencies = [
[[package]]
name = "frunk_core"
version = "0.4.4"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "476eeaa382e3462b84da5d6ba3da97b5786823c2d0d3a0d04ef088d073da225c"
checksum = "3529a07095650187788833d585c219761114005d5976185760cf794d265b6a5c"
[[package]]
name = "frunk_derives"
version = "0.4.4"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a0b4095fc99e1d858e5b8c7125d2638372ec85aa0fe6c807105cf10b0265ca6c"
checksum = "e99b8b3c28ae0e84b604c75f721c21dc77afb3706076af5e8216d15fd1deaae3"
dependencies = [
"frunk_proc_macro_helpers",
"quote",
"syn 2.0.106",
"syn 2.0.89",
]
[[package]]
name = "frunk_proc_macro_helpers"
version = "0.1.4"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1952b802269f2db12ab7c0bd328d0ae8feaabf19f352a7b0af7bb0c5693abfce"
checksum = "05a956ef36c377977e512e227dcad20f68c2786ac7a54dacece3746046fea5ce"
dependencies = [
"frunk_core",
"proc-macro2",
"quote",
"syn 2.0.106",
"syn 2.0.89",
]
[[package]]
@ -335,7 +326,7 @@ checksum = "96667db765a921f7b295ffee8b60472b686a51d4f21c2ee4ffdb94c7013b65a6"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.106",
"syn 2.0.89",
]
[[package]]
@ -345,7 +336,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4047d9235d1423d66cc97da7d07eddb54d4f154d6c13805c6d0793956f4f25b0"
dependencies = [
"cortex-m",
"defmt 0.3.100",
"defmt",
]
[[package]]
@ -367,9 +358,9 @@ dependencies = [
[[package]]
name = "portable-atomic"
version = "1.11.1"
version = "1.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f84267b20a16ea918e43c6a88433c2d54fa145c92a811b5b047ccbe153674483"
checksum = "280dc24453071f1b63954171985a0b0d30058d287960968b9b2aca264c8d4ee6"
[[package]]
name = "proc-macro-error-attr2"
@ -390,23 +381,23 @@ dependencies = [
"proc-macro-error-attr2",
"proc-macro2",
"quote",
"syn 2.0.106",
"syn 2.0.89",
]
[[package]]
name = "proc-macro2"
version = "1.0.101"
version = "1.0.92"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89ae43fd86e4158d6db51ad8e2b80f313af9cc74f5c0e03ccb87de09998732de"
checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.40"
version = "1.0.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d"
checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af"
dependencies = [
"proc-macro2",
]
@ -498,7 +489,7 @@ version = "0.1.0"
dependencies = [
"cortex-m",
"cortex-m-rt",
"defmt 0.3.100",
"defmt",
"defmt-rtt",
"embedded-hal 1.0.0",
"panic-probe",
@ -552,9 +543,9 @@ dependencies = [
[[package]]
name = "syn"
version = "2.0.106"
version = "2.0.89"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ede7c438028d4436d71104916910f5bb611972c5cfd7f89b8300a8186e6fada6"
checksum = "44d46482f1c1c87acd84dea20c1bf5ebff4c757009ed6bf19cfd36fb10e92c4e"
dependencies = [
"proc-macro2",
"quote",
@ -563,29 +554,29 @@ dependencies = [
[[package]]
name = "thiserror"
version = "2.0.16"
version = "2.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3467d614147380f2e4e374161426ff399c91084acd2363eaf549172b3d5e60c0"
checksum = "c006c85c7651b3cf2ada4584faa36773bd07bac24acfb39f3c431b36d7e667aa"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "2.0.16"
version = "2.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c5e1be1c48b9172ee610da68fd9cd2770e7a4056cb3fc98710ee6906f0c7960"
checksum = "f077553d607adc1caf65430528a576c757a71ed73944b66ebb58ef2bbd243568"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.106",
"syn 2.0.89",
]
[[package]]
name = "unicode-ident"
version = "1.0.19"
version = "1.0.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f63a545481291138910575129486daeaf8ac54aee4387fe7906919f7830c7d9d"
checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83"
[[package]]
name = "usb-device"
@ -593,7 +584,7 @@ version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "98816b1accafbb09085168b90f27e93d790b4bfa19d883466b5e53315b5f06a6"
dependencies = [
"defmt 0.3.100",
"defmt",
"heapless",
"portable-atomic",
]
@ -604,7 +595,7 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee23ab04c7d76b63c417cf2fa672d720477d2e71c6822ac6e5ceaf526f48f394"
dependencies = [
"defmt 0.3.100",
"defmt",
"num_enum 0.6.1",
"usb-device",
]

View file

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

View file

@ -20,6 +20,8 @@ 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;
@ -110,12 +112,15 @@ fn main() -> ! {
let mut usb_device = UsbDeviceBuilder::new(&usb_bus, UsbVidPid(0xcafe, 0x4002))
.strings(&[StringDescriptors::new(LangID::EN)
.manufacturer("jalr")
.product("RAM Mass Storage")])
.product("RAM Mass Storage")
.serial_number(serial_number::SERIAL)])
.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;
@ -131,10 +136,10 @@ fn main() -> ! {
const OEM: [u8; 8] = *b"mkfs.fat";
const FILESYSTEM_ID: [u8; 4] = [0xDE, 0xAD, 0xBE, 0xEF];
const FILESYSTEM_LABEL: [u8; 11] = *b"RAM_USB ";
const FILESYSTEM_NAME: [u8; 11] = *b"RAM_USB\0\0\0\0";
storage[0x1B9] = 0x10;
storage[0x1BE..0x1C3].copy_from_slice(&[0x00, 0x00, 0x02, 0x00, 0x0c]);
storage[0x1B8..0x1BC].copy_from_slice(&[0xEF, 0xBE, 0xAD, 0xDE]);
storage[0x1BE..0x1C3].copy_from_slice(&[0x00, 0x00, 0x02, 0x00, 0x01]);
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;
@ -148,23 +153,22 @@ fn main() -> ! {
// FAT12 Partition
storage[0x200..0x203].copy_from_slice(&[0xEB, 0x3C, 0x90]);
storage[0x203..0x20B].copy_from_slice(&OEM);
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[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[0x227..0x22B].copy_from_slice(&FILESYSTEM_ID);
storage[0x22B..0x236].copy_from_slice(&FILESYSTEM_LABEL);
storage[0x22B..0x236].copy_from_slice(&FILESYSTEM_NAME);
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_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
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
]);
let mut state: State = State {
storage_offset: 0,
@ -175,26 +179,20 @@ fn main() -> ! {
defmt::info!("entering main loop");
let mut start_time: u64 = 0;
loop {
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,
}
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,
};
if timer.get_counter().ticks() - start_time > interval {
let _ = led_pin.toggle();

View file

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