update book

This commit is contained in:
Mirabellensaft 2022-01-07 19:01:58 +01:00
parent ae36a3c578
commit 618358ece4
5 changed files with 17 additions and 21 deletions

View File

@ -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();
}
}
}

View File

@ -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()
}
}
}

View File

@ -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 {
}
}
}
}
}
}

View File

@ -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.

View File

@ -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