From 60ec6839d340760b7f236693796b09ea7ca966e8 Mon Sep 17 00:00:00 2001 From: Matt Johnston Date: Wed, 10 Sep 2025 13:31:02 +0800 Subject: [PATCH 1/2] Use sram2 for mctp-bench buffer Signed-off-by: Matt Johnston --- src/main.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 5d02b08..07a94f7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,6 +11,8 @@ #[allow(unused)] use log::{debug, error, info, trace, warn}; +use core::mem::MaybeUninit; + use heapless::Vec; use static_cell::StaticCell; @@ -454,8 +456,12 @@ async fn bench_task( ) -> ! { debug!("mctp-bench send running"); - static BUF: StaticCell<[u8; BENCH_LEN]> = StaticCell::new(); - let buf = BUF.init_with(|| [0u8; BENCH_LEN]); + #[link_section = ".sram2_uninit"] + static mut BUF: MaybeUninit> = + MaybeUninit::uninit(); + #[allow(static_mut_refs)] + let buf = unsafe { BUF.write(StaticCell::new()) }; + let buf = buf.init_with(|| [0u8; _]); let mut bench = ccvendor::MctpBench::new(buf).unwrap(); From 796e49554dcaa622567d34be58640f0dc85b5eca Mon Sep 17 00:00:00 2001 From: Matt Johnston Date: Tue, 9 Sep 2025 16:25:01 +0800 Subject: [PATCH 2/2] Update to latest embassy This improves USB RX speed for PLDM file transfer from ~3700kB/s to ~4600kB/s, https://github.com/embassy-rs/embassy/pull/4566 Some more embassy crates are added to the patch list for consistency, it shouldn't have any functional change. Embassy requires around 512 bytes more BSS now (more DMA state was added) Signed-off-by: Matt Johnston --- Cargo.lock | 107 ++++++++++++++++++++++------------------------------ Cargo.toml | 24 +++++++----- src/main.rs | 47 ++++++++++++----------- src/usb.rs | 2 +- 4 files changed, 86 insertions(+), 94 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8cb957e..7add741 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -264,12 +264,12 @@ dependencies = [ [[package]] name = "embassy-embedded-hal" -version = "0.4.0" -source = "git+https://github.com/embassy-rs/embassy/?rev=a5cb04bdab602bc3bd056d254a9d61cad55bd967#a5cb04bdab602bc3bd056d254a9d61cad55bd967" +version = "0.5.0" +source = "git+https://github.com/embassy-rs/embassy/?rev=25e0ebf5206fa2e2906f5826c0b1587739f628d8#25e0ebf5206fa2e2906f5826c0b1587739f628d8" dependencies = [ - "embassy-futures 0.1.1 (git+https://github.com/embassy-rs/embassy/?rev=a5cb04bdab602bc3bd056d254a9d61cad55bd967)", + "embassy-futures", "embassy-hal-internal", - "embassy-sync 0.7.1", + "embassy-sync", "embassy-time", "embedded-hal 0.2.7", "embedded-hal 1.0.0", @@ -281,20 +281,21 @@ dependencies = [ [[package]] name = "embassy-executor" -version = "0.8.0" -source = "git+https://github.com/embassy-rs/embassy/?rev=a5cb04bdab602bc3bd056d254a9d61cad55bd967#a5cb04bdab602bc3bd056d254a9d61cad55bd967" +version = "0.9.0" +source = "git+https://github.com/embassy-rs/embassy/?rev=25e0ebf5206fa2e2906f5826c0b1587739f628d8#25e0ebf5206fa2e2906f5826c0b1587739f628d8" dependencies = [ "cortex-m", "critical-section", "document-features", "embassy-executor-macros", + "embassy-executor-timer-queue", "log", ] [[package]] name = "embassy-executor-macros" version = "0.7.0" -source = "git+https://github.com/embassy-rs/embassy/?rev=a5cb04bdab602bc3bd056d254a9d61cad55bd967#a5cb04bdab602bc3bd056d254a9d61cad55bd967" +source = "git+https://github.com/embassy-rs/embassy/?rev=25e0ebf5206fa2e2906f5826c0b1587739f628d8#25e0ebf5206fa2e2906f5826c0b1587739f628d8" dependencies = [ "darling", "proc-macro2", @@ -303,20 +304,19 @@ dependencies = [ ] [[package]] -name = "embassy-futures" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f878075b9794c1e4ac788c95b728f26aa6366d32eeb10c7051389f898f7d067" +name = "embassy-executor-timer-queue" +version = "0.1.0" +source = "git+https://github.com/embassy-rs/embassy/?rev=25e0ebf5206fa2e2906f5826c0b1587739f628d8#25e0ebf5206fa2e2906f5826c0b1587739f628d8" [[package]] name = "embassy-futures" -version = "0.1.1" -source = "git+https://github.com/embassy-rs/embassy/?rev=a5cb04bdab602bc3bd056d254a9d61cad55bd967#a5cb04bdab602bc3bd056d254a9d61cad55bd967" +version = "0.1.2" +source = "git+https://github.com/embassy-rs/embassy/?rev=25e0ebf5206fa2e2906f5826c0b1587739f628d8#25e0ebf5206fa2e2906f5826c0b1587739f628d8" [[package]] name = "embassy-hal-internal" version = "0.3.0" -source = "git+https://github.com/embassy-rs/embassy/?rev=a5cb04bdab602bc3bd056d254a9d61cad55bd967#a5cb04bdab602bc3bd056d254a9d61cad55bd967" +source = "git+https://github.com/embassy-rs/embassy/?rev=25e0ebf5206fa2e2906f5826c0b1587739f628d8#25e0ebf5206fa2e2906f5826c0b1587739f628d8" dependencies = [ "cortex-m", "critical-section", @@ -326,22 +326,22 @@ dependencies = [ [[package]] name = "embassy-net-driver" version = "0.2.0" -source = "git+https://github.com/embassy-rs/embassy/?rev=a5cb04bdab602bc3bd056d254a9d61cad55bd967#a5cb04bdab602bc3bd056d254a9d61cad55bd967" +source = "git+https://github.com/embassy-rs/embassy/?rev=25e0ebf5206fa2e2906f5826c0b1587739f628d8#25e0ebf5206fa2e2906f5826c0b1587739f628d8" [[package]] name = "embassy-net-driver-channel" -version = "0.3.1" -source = "git+https://github.com/embassy-rs/embassy/?rev=a5cb04bdab602bc3bd056d254a9d61cad55bd967#a5cb04bdab602bc3bd056d254a9d61cad55bd967" +version = "0.3.2" +source = "git+https://github.com/embassy-rs/embassy/?rev=25e0ebf5206fa2e2906f5826c0b1587739f628d8#25e0ebf5206fa2e2906f5826c0b1587739f628d8" dependencies = [ - "embassy-futures 0.1.1 (git+https://github.com/embassy-rs/embassy/?rev=a5cb04bdab602bc3bd056d254a9d61cad55bd967)", + "embassy-futures", "embassy-net-driver", - "embassy-sync 0.7.1", + "embassy-sync", ] [[package]] name = "embassy-stm32" -version = "0.3.0" -source = "git+https://github.com/embassy-rs/embassy/?rev=a5cb04bdab602bc3bd056d254a9d61cad55bd967#a5cb04bdab602bc3bd056d254a9d61cad55bd967" +version = "0.4.0" +source = "git+https://github.com/embassy-rs/embassy/?rev=25e0ebf5206fa2e2906f5826c0b1587739f628d8#25e0ebf5206fa2e2906f5826c0b1587739f628d8" dependencies = [ "aligned", "bit_field", @@ -353,10 +353,10 @@ dependencies = [ "critical-section", "document-features", "embassy-embedded-hal", - "embassy-futures 0.1.1 (git+https://github.com/embassy-rs/embassy/?rev=a5cb04bdab602bc3bd056d254a9d61cad55bd967)", + "embassy-futures", "embassy-hal-internal", "embassy-net-driver", - "embassy-sync 0.7.1", + "embassy-sync", "embassy-time", "embassy-time-driver", "embassy-time-queue-utils", @@ -388,22 +388,8 @@ dependencies = [ [[package]] name = "embassy-sync" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cef1a8a1ea892f9b656de0295532ac5d8067e9830d49ec75076291fd6066b136" -dependencies = [ - "cfg-if", - "critical-section", - "embedded-io-async", - "futures-sink", - "futures-util", - "heapless", -] - -[[package]] -name = "embassy-sync" -version = "0.7.1" -source = "git+https://github.com/embassy-rs/embassy/?rev=a5cb04bdab602bc3bd056d254a9d61cad55bd967#a5cb04bdab602bc3bd056d254a9d61cad55bd967" +version = "0.7.2" +source = "git+https://github.com/embassy-rs/embassy/?rev=25e0ebf5206fa2e2906f5826c0b1587739f628d8#25e0ebf5206fa2e2906f5826c0b1587739f628d8" dependencies = [ "cfg-if", "critical-section", @@ -415,8 +401,8 @@ dependencies = [ [[package]] name = "embassy-time" -version = "0.4.0" -source = "git+https://github.com/embassy-rs/embassy/?rev=a5cb04bdab602bc3bd056d254a9d61cad55bd967#a5cb04bdab602bc3bd056d254a9d61cad55bd967" +version = "0.5.0" +source = "git+https://github.com/embassy-rs/embassy/?rev=25e0ebf5206fa2e2906f5826c0b1587739f628d8#25e0ebf5206fa2e2906f5826c0b1587739f628d8" dependencies = [ "cfg-if", "critical-section", @@ -430,29 +416,29 @@ dependencies = [ [[package]] name = "embassy-time-driver" -version = "0.2.0" -source = "git+https://github.com/embassy-rs/embassy/?rev=a5cb04bdab602bc3bd056d254a9d61cad55bd967#a5cb04bdab602bc3bd056d254a9d61cad55bd967" +version = "0.2.1" +source = "git+https://github.com/embassy-rs/embassy/?rev=25e0ebf5206fa2e2906f5826c0b1587739f628d8#25e0ebf5206fa2e2906f5826c0b1587739f628d8" dependencies = [ "document-features", ] [[package]] name = "embassy-time-queue-utils" -version = "0.2.0" -source = "git+https://github.com/embassy-rs/embassy/?rev=a5cb04bdab602bc3bd056d254a9d61cad55bd967#a5cb04bdab602bc3bd056d254a9d61cad55bd967" +version = "0.3.0" +source = "git+https://github.com/embassy-rs/embassy/?rev=25e0ebf5206fa2e2906f5826c0b1587739f628d8#25e0ebf5206fa2e2906f5826c0b1587739f628d8" dependencies = [ - "embassy-executor", + "embassy-executor-timer-queue", "heapless", ] [[package]] name = "embassy-usb" -version = "0.5.0" -source = "git+https://github.com/embassy-rs/embassy/?rev=a5cb04bdab602bc3bd056d254a9d61cad55bd967#a5cb04bdab602bc3bd056d254a9d61cad55bd967" +version = "0.5.1" +source = "git+https://github.com/embassy-rs/embassy/?rev=25e0ebf5206fa2e2906f5826c0b1587739f628d8#25e0ebf5206fa2e2906f5826c0b1587739f628d8" dependencies = [ - "embassy-futures 0.1.1 (git+https://github.com/embassy-rs/embassy/?rev=a5cb04bdab602bc3bd056d254a9d61cad55bd967)", + "embassy-futures", "embassy-net-driver-channel", - "embassy-sync 0.7.1", + "embassy-sync", "embassy-usb-driver", "embedded-io-async", "heapless", @@ -461,18 +447,18 @@ dependencies = [ [[package]] name = "embassy-usb-driver" version = "0.2.0" -source = "git+https://github.com/embassy-rs/embassy/?rev=a5cb04bdab602bc3bd056d254a9d61cad55bd967#a5cb04bdab602bc3bd056d254a9d61cad55bd967" +source = "git+https://github.com/embassy-rs/embassy/?rev=25e0ebf5206fa2e2906f5826c0b1587739f628d8#25e0ebf5206fa2e2906f5826c0b1587739f628d8" dependencies = [ "embedded-io-async", ] [[package]] name = "embassy-usb-synopsys-otg" -version = "0.3.0" -source = "git+https://github.com/embassy-rs/embassy/?rev=a5cb04bdab602bc3bd056d254a9d61cad55bd967#a5cb04bdab602bc3bd056d254a9d61cad55bd967" +version = "0.3.1" +source = "git+https://github.com/embassy-rs/embassy/?rev=25e0ebf5206fa2e2906f5826c0b1587739f628d8#25e0ebf5206fa2e2906f5826c0b1587739f628d8" dependencies = [ "critical-section", - "embassy-sync 0.7.1", + "embassy-sync", "embassy-usb-driver", ] @@ -692,7 +678,7 @@ version = "0.1.0" source = "git+https://github.com/CodeConstruct/mctp-rs?rev=d8385ad5f548d0256c89bdb0c187396b29f43e41#d8385ad5f548d0256c89bdb0c187396b29f43e41" dependencies = [ "crc", - "embassy-sync 0.7.0", + "embassy-sync", "embedded-io-async", "heapless", "log", @@ -706,7 +692,7 @@ name = "mctp-usb-embassy" version = "0.1.0" source = "git+https://github.com/CodeConstruct/mctp-rs?rev=d8385ad5f548d0256c89bdb0c187396b29f43e41#d8385ad5f548d0256c89bdb0c187396b29f43e41" dependencies = [ - "embassy-futures 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "embassy-futures", "embassy-usb", "embassy-usb-driver", "heapless", @@ -1009,9 +995,8 @@ dependencies = [ [[package]] name = "stm32-metapac" -version = "17.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b44329ff285800f88ccc1666218808c6ed0e6dc570383b5f661caadb8101133" +version = "18.0.0" +source = "git+https://github.com/embassy-rs/stm32-data-generated?tag=stm32-data-d8432edd0406495adec19d31923584e80b8e03cb#c6b0010f491ba056e9b24cb45252853b3a5fc1e0" dependencies = [ "cortex-m", "cortex-m-rt", @@ -1066,9 +1051,9 @@ dependencies = [ "cortex-m-rt", "deku 0.19.1 (git+https://github.com/CodeConstruct/deku.git?tag=cc%2Fdeku-v0.19.1%2Fno-alloc-3)", "embassy-executor", - "embassy-futures 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "embassy-futures", "embassy-stm32", - "embassy-sync 0.7.0", + "embassy-sync", "embassy-time", "embassy-usb", "embassy-usb-driver", diff --git a/Cargo.toml b/Cargo.toml index d0b0004..386cbf2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ embassy-sync = { version = "0.7" } embassy-usb = { version = "0.5", default-features = false } embassy-usb-driver = { version = "0.2" } embassy-futures = { version = "0.1" } -embassy-time = "0.4" +embassy-time = "0.5" log = "0.4" rtt-target = "0.6" heapless = "0.8" @@ -23,8 +23,8 @@ cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-sing # set-vtor and set-sp necessary when using xspiloader cortex-m-rt = { version = "0.7.0", features = ["set-sp", "set-vtor"] } panic-probe = { version = "1", features = ["print-rtt"] } -embassy-executor = { version = "0.8", features = ["executor-thread"] } -embassy-stm32 = { version = "0.3", features = ["time-driver-any", "stm32h7s3l8", "unstable-pac", "log"] } +embassy-executor = { version = "0.9", features = ["executor-thread"] } +embassy-stm32 = { version = "0.4", features = ["time-driver-any", "stm32h7s3l8", "unstable-pac", "log"] } [dependencies] embassy-executor = { workspace = true, features = [ @@ -63,15 +63,19 @@ num-derive = { version = "0.4", default-features = false } num-traits = { version = "0.2", default-features = false } [patch.crates-io] +# Patches since releases: # "Fix vrefbuf trace with log" https://github.com/embassy-rs/embassy/pull/4553 -embassy-stm32 = { git = "https://github.com/embassy-rs/embassy/", rev = "a5cb04bdab602bc3bd056d254a9d61cad55bd967" } -embassy-usb-synopsys-otg = { git = "https://github.com/embassy-rs/embassy/", rev = "a5cb04bdab602bc3bd056d254a9d61cad55bd967" } +# "otg: Use chunks_exact for more efficient rx copy" https://github.com/embassy-rs/embassy/pull/4566 +embassy-stm32 = { git = "https://github.com/embassy-rs/embassy/", rev = "25e0ebf5206fa2e2906f5826c0b1587739f628d8" } +embassy-usb-synopsys-otg = { git = "https://github.com/embassy-rs/embassy/", rev = "25e0ebf5206fa2e2906f5826c0b1587739f628d8" } -embassy-time = { git = "https://github.com/embassy-rs/embassy/", rev = "a5cb04bdab602bc3bd056d254a9d61cad55bd967" } -embassy-time-driver = { git = "https://github.com/embassy-rs/embassy/", rev = "a5cb04bdab602bc3bd056d254a9d61cad55bd967" } -embassy-usb = { git = "https://github.com/embassy-rs/embassy/", rev = "a5cb04bdab602bc3bd056d254a9d61cad55bd967" } -embassy-usb-driver = { git = "https://github.com/embassy-rs/embassy/", rev = "a5cb04bdab602bc3bd056d254a9d61cad55bd967" } -embassy-executor = { git = "https://github.com/embassy-rs/embassy/", rev = "a5cb04bdab602bc3bd056d254a9d61cad55bd967" } +embassy-time = { git = "https://github.com/embassy-rs/embassy/", rev = "25e0ebf5206fa2e2906f5826c0b1587739f628d8" } +embassy-time-driver = { git = "https://github.com/embassy-rs/embassy/", rev = "25e0ebf5206fa2e2906f5826c0b1587739f628d8" } +embassy-usb = { git = "https://github.com/embassy-rs/embassy/", rev = "25e0ebf5206fa2e2906f5826c0b1587739f628d8" } +embassy-usb-driver = { git = "https://github.com/embassy-rs/embassy/", rev = "25e0ebf5206fa2e2906f5826c0b1587739f628d8" } +embassy-executor = { git = "https://github.com/embassy-rs/embassy/", rev = "25e0ebf5206fa2e2906f5826c0b1587739f628d8" } +embassy-sync = { git = "https://github.com/embassy-rs/embassy/", rev = "25e0ebf5206fa2e2906f5826c0b1587739f628d8" } +embassy-futures = { git = "https://github.com/embassy-rs/embassy/", rev = "25e0ebf5206fa2e2906f5826c0b1587739f628d8" } # Updated for embassy-usb api change diff --git a/src/main.rs b/src/main.rs index 07a94f7..a68eaf9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -253,44 +253,47 @@ fn run(low_spawner: Spawner, logger: &'static multilog::MultiLog) { let (usb_sender, usb_receiver) = mctpusb.split(); - let echo = echo_task(router, &BENCH_REQUEST); - let timeout = timeout_task(router); - let control = control_task(router, &CONTROL_NOTIFY); - let usb_send_loop = usb::usb_send_task(mctp_usb_bottom, usb_sender); + let echo = echo_task(router, &BENCH_REQUEST).unwrap(); + let timeout = timeout_task(router).unwrap(); + let control = control_task(router, &CONTROL_NOTIFY).unwrap(); + let usb_send_loop = + usb::usb_send_task(mctp_usb_bottom, usb_sender).unwrap(); let usb_recv_loop = - usb::usb_recv_task(router, usb_receiver, Routes::USB_INDEX); - let app_loop = usbnvme_app_task(&USB_NOTIFY, &CONTROL_NOTIFY, &PEER_NOTIFY); - - low_spawner.must_spawn(blink_task(led)); - medium_spawner.must_spawn(echo); - medium_spawner.must_spawn(timeout); - medium_spawner.must_spawn(usb_recv_loop); - medium_spawner.must_spawn(control); - medium_spawner.must_spawn(app_loop); + usb::usb_recv_task(router, usb_receiver, Routes::USB_INDEX).unwrap(); + let app_loop = + usbnvme_app_task(&USB_NOTIFY, &CONTROL_NOTIFY, &PEER_NOTIFY).unwrap(); + + low_spawner.spawn(blink_task(led).unwrap()); + medium_spawner.spawn(echo); + medium_spawner.spawn(timeout); + medium_spawner.spawn(usb_recv_loop); + medium_spawner.spawn(control); + medium_spawner.spawn(app_loop); // high priority for usb send - high_spawner.must_spawn(usb_send_loop); + high_spawner.spawn(usb_send_loop); #[cfg(feature = "nvme-mi")] { - let nvmemi = nvme_mi_task(router); - medium_spawner.must_spawn(nvmemi); + let nvmemi = nvme_mi_task(router).unwrap(); + medium_spawner.spawn(nvmemi); } #[cfg(feature = "pldm-file")] { - let pldm_file = pldm::pldm_file_task(router, &PEER_NOTIFY, hash); - medium_spawner.must_spawn(pldm_file); + let pldm_file = + pldm::pldm_file_task(router, &PEER_NOTIFY, hash).unwrap(); + medium_spawner.spawn(pldm_file); } #[cfg(feature = "mctp-bench")] { - let bench = bench_task(router, &BENCH_REQUEST); - low_spawner.must_spawn(bench); + let bench = bench_task(router, &BENCH_REQUEST).unwrap(); + low_spawner.spawn(bench); } let _ = logger; #[cfg(feature = "log-usbserial")] { let (sender, _) = usbserial.split(); - let seriallog = multilog::log_usbserial_task(sender, logger); - low_spawner.must_spawn(seriallog); + let seriallog = multilog::log_usbserial_task(sender, logger).unwrap(); + low_spawner.spawn(seriallog); } } diff --git a/src/usb.rs b/src/usb.rs index 1f4d786..a61368b 100644 --- a/src/usb.rs +++ b/src/usb.rs @@ -94,7 +94,7 @@ pub(crate) fn setup( let ret = (mctp,); let usb = builder.build(); - spawner.must_spawn(usb_task(usb, state_notify)); + spawner.spawn(usb_task(usb, state_notify).unwrap()); ret }