From a89c516ddc44dcc0548fbb607fa62a91102556d7 Mon Sep 17 00:00:00 2001 From: Mirabellensaft Date: Mon, 10 Jan 2022 14:16:14 +0100 Subject: [PATCH] update log statements --- advanced/common/usb/src/lib.rs | 40 ++++++++------------- advanced/firmware/src/bin/usb-1.rs | 2 +- advanced/firmware/src/bin/usb-2-solution.rs | 2 +- advanced/firmware/src/bin/usb-4-solution.rs | 2 +- embedded-workshop-book/src/setup-stage.md | 14 ++++---- 5 files changed, 25 insertions(+), 35 deletions(-) diff --git a/advanced/common/usb/src/lib.rs b/advanced/common/usb/src/lib.rs index e153265..e8f8157 100644 --- a/advanced/common/usb/src/lib.rs +++ b/advanced/common/usb/src/lib.rs @@ -1,5 +1,4 @@ //! Some USB 2.0 data types -// NOTE this is a partial solution to exercise `usb-2` #![deny(missing_docs)] #![deny(warnings)] @@ -51,33 +50,22 @@ impl Request { windex: u16, wlength: u16, ) -> Result { + // Request Codes // see table 9-4 (USB specification) const SET_ADDRESS: u8 = 5; - const GET_DESCRIPTOR: u8 = 6; + // TODO implement another branch handling GET_DESCRIPTOR requests: + // + // 1. get descriptor type and descriptor index from `wValue` + // + // 2. confirm that + // - the descriptor type is DEVICE, i.e. of value 1 and + // - the descriptor index is 0 (i.e. it is the first implemented descriptor for this type) and + // - `wIndex` is 0 (i.e. no language ID since it's not a string descriptor) + // + // For more details, see https://embedded-trainings.ferrous-systems.com/setup-stage.html - if bmrequesttype == 0b10000000 && brequest == GET_DESCRIPTOR { - // see table 9-5 - const DEVICE: u8 = 1; - - // 1. get descriptor type and descriptor index from wValue - let desc_ty = (wvalue >> 8) as u8; - let desc_index = wvalue as u8; - let langid = windex; - - // 2. confirm that the descriptor - // - is of type DEVICE and - // - has descriptor index 0 (i.e. it is the first implemented descriptor for this type) and - // - has wIndex 0 (i.e. no language ID since it's not a string descriptor) - if desc_ty == DEVICE && desc_index == 0 && langid == 0 { - Ok(Request::GetDescriptor { - descriptor: Descriptor::Device, - length: wlength, - }) - } else { - Err(()) - } - } else if bmrequesttype == 0b00000000 && brequest == SET_ADDRESS { + if bmrequesttype == 0b00000000 && brequest == SET_ADDRESS { // Set the device address for all future accesses. // (Needed to successfully init when conected to Apple devices) // Section 9.4.6 Set Address of the USB specification explains which values for wvalue, @@ -90,6 +78,7 @@ impl Request { Err(()) } } else { + defmt::println!("unhandled case in `Request` parser"); Err(()) } } @@ -207,5 +196,4 @@ mod tests { assert!(Request::parse(0b0000_0000, 0x09, 0x00_01, 0, 1).is_err()); // ^ } -} - +} \ No newline at end of file diff --git a/advanced/firmware/src/bin/usb-1.rs b/advanced/firmware/src/bin/usb-1.rs index 82ed77c..412933b 100644 --- a/advanced/firmware/src/bin/usb-1.rs +++ b/advanced/firmware/src/bin/usb-1.rs @@ -44,7 +44,7 @@ mod app { } fn on_event(_usbd: &USBD, event: Event) { - defmt::println!("USB: {:?} @ {:?}", event, dk::uptime()); + defmt::println!("USB: {} @ {}", event, dk::uptime()); match event { Event::UsbReset => todo!(), diff --git a/advanced/firmware/src/bin/usb-2-solution.rs b/advanced/firmware/src/bin/usb-2-solution.rs index e0eb463..a9a0cae 100644 --- a/advanced/firmware/src/bin/usb-2-solution.rs +++ b/advanced/firmware/src/bin/usb-2-solution.rs @@ -42,7 +42,7 @@ mod app { } fn on_event(usbd: &USBD, event: Event) { - defmt::println!("USB: {:?} @ {:?}", event, dk::uptime()); + defmt::println!("USB: {} @ {}", event, dk::uptime()); match event { Event::UsbReset => { diff --git a/advanced/firmware/src/bin/usb-4-solution.rs b/advanced/firmware/src/bin/usb-4-solution.rs index 51035a9..451b5c6 100644 --- a/advanced/firmware/src/bin/usb-4-solution.rs +++ b/advanced/firmware/src/bin/usb-4-solution.rs @@ -47,7 +47,7 @@ mod app { } } fn on_event(usbd: &USBD, ep0in: &mut Ep0In, state: &mut State, event: Event) { - defmt::println!("USB: {:?} @ {:?}", event, dk::uptime()); + defmt::println!("USB: {} @ {}", event, dk::uptime()); match event { Event::UsbReset => { diff --git a/embedded-workshop-book/src/setup-stage.md b/embedded-workshop-book/src/setup-stage.md index 684e522..409ae65 100644 --- a/embedded-workshop-book/src/setup-stage.md +++ b/embedded-workshop-book/src/setup-stage.md @@ -72,12 +72,14 @@ modify `usb-2.rs` to read `USBD` registers and parse the SETUP data when an EP0S When you have successfully received a GET_DESCRIPTOR request for a Device descriptor you are done. You should see an output like this: ``` console -INFO:usb_2 -- USB: UsbReset @ 438.842772ms -INFO:usb_2 -- USB: UsbEp0Setup @ 514.984128ms -... -INFO:usb_2 -- SETUP: bmrequesttype: 128, brequest: 6, wlength: 64, windex: 0, wvalue: 256 -INFO:usb_2 -- GET_DESCRIPTOR Device [length=64] -INFO:usb_2 -- Goal reached; move to the next section +USB: UsbReset @ Duration { secs: 0, nanos: 361145018 } +USB: UsbEp0Setup @ Duration { secs: 0, nanos: 402465820 } +SETUP: bmrequesttype: 0, brequest: 5, wlength: 0, windex: 0, wvalue: 10 +USB: UsbEp0Setup @ Duration { secs: 0, nanos: 404754637 } +SETUP: bmrequesttype: 128, brequest: 6, wlength: 8, windex: 0, wvalue: 256 +GET_DESCRIPTOR Device [length=8] +Goal reached; move to the next section +`dk::exit()` called; exiting ... ``` > Note: `wlength` / `length` can vary depending on the OS, USB port (USB 2.0 vs USB 3.0) or the presence of a USB hub so you may see a different value.