From 618358ece41a1e45f496f74afe9cf6ea5a2859a2 Mon Sep 17 00:00:00 2001 From: Mirabellensaft Date: Fri, 7 Jan 2022 19:01:58 +0100 Subject: [PATCH] update book --- advanced/firmware/src/bin/usb-1-solution.rs | 10 +++++----- advanced/firmware/src/bin/usb-1.rs | 11 +++-------- advanced/firmware/src/bin/usb-2-solution.rs | 5 ++--- embedded-workshop-book/src/usb-enumeration.md | 2 ++ embedded-workshop-book/src/usb-events.md | 10 +++++----- 5 files changed, 17 insertions(+), 21 deletions(-) diff --git a/advanced/firmware/src/bin/usb-1-solution.rs b/advanced/firmware/src/bin/usb-1-solution.rs index 91ef9d1..94e8231 100644 --- a/advanced/firmware/src/bin/usb-1-solution.rs +++ b/advanced/firmware/src/bin/usb-1-solution.rs @@ -7,10 +7,10 @@ use firmware as _; #[rtic::app(device = dk, peripherals = false)] mod app { + use cortex_m::asm; use dk::{ peripheral::USBD, usbd::{self, Event}, - Peripherals, }; #[local] @@ -46,19 +46,19 @@ mod app { } fn on_event(_usbd: &USBD, event: Event) { - defmt::println("USB: {:?}", event); + defmt::println!("USB: {:?}", event); match event { Event::UsbReset => { // going from the Default state to the Default state is a no-operation - defmt::println("returning to the Default state"); + defmt::println!("returning to the Default state"); } Event::UsbEp0DataDone => todo!(), Event::UsbEp0Setup => { - defmt::println("goal reached; move to the next section"); - dk::exit() + defmt::println!("goal reached; move to the next section"); + asm::bkpt(); } } } diff --git a/advanced/firmware/src/bin/usb-1.rs b/advanced/firmware/src/bin/usb-1.rs index a5293e1..82ed77c 100644 --- a/advanced/firmware/src/bin/usb-1.rs +++ b/advanced/firmware/src/bin/usb-1.rs @@ -1,19 +1,15 @@ #![no_main] #![no_std] -use dk::{ - peripheral::USBD, - usbd::{self, Event}, -}; // this imports `beginner/apps/lib.rs` to retrieve our global logger + panicking-behavior use firmware as _; #[rtic::app(device = dk, peripherals = false)] mod app { + use cortex_m::asm; use dk::{ peripheral::USBD, usbd::{self, Event}, - Peripherals, }; #[local] @@ -22,8 +18,7 @@ mod app { } #[shared] - struct MySharedResources { - + struct MySharedResources { } #[init] @@ -58,7 +53,7 @@ mod app { // leave this at it is for now. Event::UsbEp0Setup => { defmt::println!("goal reached; move to the next section"); - dk::exit() + asm::bkpt() } } } diff --git a/advanced/firmware/src/bin/usb-2-solution.rs b/advanced/firmware/src/bin/usb-2-solution.rs index 323a004..e0eb463 100644 --- a/advanced/firmware/src/bin/usb-2-solution.rs +++ b/advanced/firmware/src/bin/usb-2-solution.rs @@ -21,7 +21,6 @@ mod app { #[shared] struct MySharedResources { - } #[init] @@ -41,6 +40,7 @@ mod app { on_event(usbd, event) } } + fn on_event(usbd: &USBD, event: Event) { defmt::println!("USB: {:?} @ {:?}", event, dk::uptime()); @@ -106,7 +106,6 @@ mod app { } } } - } - + } } diff --git a/embedded-workshop-book/src/usb-enumeration.md b/embedded-workshop-book/src/usb-enumeration.md index dbb7c00..8f0802d 100644 --- a/embedded-workshop-book/src/usb-enumeration.md +++ b/embedded-workshop-book/src/usb-enumeration.md @@ -1,5 +1,7 @@ # USB Enumeration +Check this miro board for an [overview](https://miro.com/app/board/uXjVObcQhcc=/?invite_link_id=467100096053). + A USB device, like the nRF52840, can be one of these three states: the Default state, the Address state or the Configured state. After being powered the device will start in the Default state. The enumeration process will take the device from the Default state to the Address state. As a result of the enumeration process the device will be assigned an address, in the range `1..=127`, by the host. The USB protocol is complex so we'll leave out many details and focus only on the concepts required to get enumeration and configuration working. There are also several USB specific terms so we recommend checking chapter 2, "Terms and Abbreviations", of the USB specification (linked at the bottom of this document) every now and then. diff --git a/embedded-workshop-book/src/usb-events.md b/embedded-workshop-book/src/usb-events.md index 5761bb1..a575901 100644 --- a/embedded-workshop-book/src/usb-events.md +++ b/embedded-workshop-book/src/usb-events.md @@ -15,11 +15,11 @@ This code will panic because `USBRESET` is not implemented yet. ✅ Go to `fn on_event`, line 39. In this section you'll need to implement the following USB events `USBRESET` and `EP0SETUP` so that your log output will look like this: ``` console -INFO:usb_1 -- USB: UsbReset -INFO:usb_1 -- returning to the Default state -INFO:usb_1 -- USB: UsbEp0Setup -INFO:usb_1 -- goal reached; move to the next section -INFO:dk -- `dk::exit() called; exiting ... +USBD initialized +USB: UsbReset +returning to the Default state +USB: UsbEp0Setup +goal reached; move to the next section ``` ## Help