mirror of
https://github.com/ferrous-systems/embedded-trainings-2020.git
synced 2024-11-10 18:51:02 +00:00
update book
This commit is contained in:
parent
bea6eb0b21
commit
901c0f7d2c
5 changed files with 17 additions and 21 deletions
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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]
|
||||
|
@ -23,7 +19,6 @@ mod app {
|
|||
|
||||
#[shared]
|
||||
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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
|
||||
|
@ -107,6 +107,5 @@ mod app {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue