From 84dcc9e907c3fead800334db37be62ae5ae779b3 Mon Sep 17 00:00:00 2001 From: Lotte Steenbrink Date: Mon, 13 Jul 2020 14:47:36 +0200 Subject: [PATCH] usb-2: remove the need for 6.35.13.* PS tables --- advanced/firmware/src/bin/usb-2-solution.rs | 10 ++++++++++ advanced/firmware/src/bin/usb-2.rs | 10 ++++++++++ embedded-workshop-book/src/setup-stage.md | 2 +- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/advanced/firmware/src/bin/usb-2-solution.rs b/advanced/firmware/src/bin/usb-2-solution.rs index a49c948..3f8cfe4 100644 --- a/advanced/firmware/src/bin/usb-2-solution.rs +++ b/advanced/firmware/src/bin/usb-2-solution.rs @@ -44,12 +44,22 @@ fn on_event(usbd: &USBD, event: Event) { Event::UsbEp0DataDone => todo!(), Event::UsbEp0Setup => { + + // the BMREQUESTTYPE register contains information about data recipient, transfer type and direction let bmrequesttype = usbd.bmrequesttype.read().bits() as u8; + // the BREQUEST register stores the type of the current request (e.g. SET_ADDRESS, GET_DESCRIPTOR, ...) let brequest = usbd.brequest.read().brequest().bits(); + // wLength denotes the number of bytes to transfer (if any) + // composed of a high register (WLENGTHH) and a low register (WLENGTHL) let wlength = (u16::from(usbd.wlengthh.read().wlengthh().bits()) << 8) | u16::from(usbd.wlengthl.read().wlengthl().bits()); + // wIndex is a generic index field whose meaning depends on the request type + // composed of a high register (WINDEXH) and a low register (WINDEXL) let windex = (u16::from(usbd.windexh.read().windexh().bits()) << 8) | u16::from(usbd.windexl.read().windexl().bits()); + // wValue is a generic paremeter field meaning depends on the request type (e.g. contains the device + // address in SET_ADRESS requests) + // composed of a high register (WVALUEH) and a low register (WVALUEL) let wvalue = (u16::from(usbd.wvalueh.read().wvalueh().bits()) << 8) | u16::from(usbd.wvaluel.read().wvaluel().bits()); diff --git a/advanced/firmware/src/bin/usb-2.rs b/advanced/firmware/src/bin/usb-2.rs index 8e64acc..c8b07f2 100644 --- a/advanced/firmware/src/bin/usb-2.rs +++ b/advanced/firmware/src/bin/usb-2.rs @@ -45,10 +45,20 @@ fn on_event(_usbd: &USBD, event: Event) { Event::UsbEp0Setup => { // TODO read USBD registers + + // the BMREQUESTTYPE register contains information about data recipient, transfer type and direction let bmrequesttype: u8 = 0; + // the BREQUEST register stores the type of the current request (e.g. SET_ADDRESS, GET_DESCRIPTOR, ...) let brequest: u8 = 0; + // wLength denotes the number of bytes to transfer (if any) + // composed of a high register (WLENGTHH) and a low register (WLENGTHL) let wlength: u16 = 0; + // wIndex is a generic index field whose meaning depends on the request type + // composed of a high register (WINDEXH) and a low register (WINDEXL) let windex: u16 = 0; + // wValue is a generic paremeter field meaning depends on the request type (e.g. contains the device + // address in SET_ADRESS requests) + // composed of a high register (WVALUEH) and a low register (WVALUEL) let wvalue: u16 = 0; log::info!( diff --git a/embedded-workshop-book/src/setup-stage.md b/embedded-workshop-book/src/setup-stage.md index 6cdcf25..44ddc4f 100644 --- a/embedded-workshop-book/src/setup-stage.md +++ b/embedded-workshop-book/src/setup-stage.md @@ -1,6 +1,6 @@ # USB-2: SETUP Stage -At the end of program `usb-1` we received a EP0SETUP event. This event signals the *end* of the SETUP stage of a control transfer. The nRF52840 USBD peripheral will automatically receive the SETUP data and store it in the following registers: BMREQUESTTYPE, BREQUEST, WVALUE{L,H}, WINDEX{L,H} and WLENGTH{L,H}. These registers are documented in sections 6.35.13.31 to 6.35.13.38 of the [nRF52840 Product Specification][nrf product spec]. +At the end of program `usb-1` we received a EP0SETUP event. This event signals the *end* of the SETUP stage of a control transfer. The nRF52840 USBD peripheral will automatically receive the SETUP data and store it in the following registers: BMREQUESTTYPE, BREQUEST, WVALUE{L,H}, WINDEX{L,H} and WLENGTH{L,H}. These registers are documented in sections 6.35.13.31 to 6.35.13.38 of the [nRF52840 Product Specification][nrf product spec]. In `usb-2.rs`, you will find a short description of each register above the variable into which it should be read. [nrf product spec]: https://infocenter.nordicsemi.com/pdf/nRF52840_PS_v1.1.pdf