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)]
|
#[rtic::app(device = dk, peripherals = false)]
|
||||||
mod app {
|
mod app {
|
||||||
|
use cortex_m::asm;
|
||||||
use dk::{
|
use dk::{
|
||||||
peripheral::USBD,
|
peripheral::USBD,
|
||||||
usbd::{self, Event},
|
usbd::{self, Event},
|
||||||
Peripherals,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#[local]
|
#[local]
|
||||||
|
@ -46,19 +46,19 @@ mod app {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_event(_usbd: &USBD, event: Event) {
|
fn on_event(_usbd: &USBD, event: Event) {
|
||||||
defmt::println("USB: {:?}", event);
|
defmt::println!("USB: {:?}", event);
|
||||||
|
|
||||||
match event {
|
match event {
|
||||||
Event::UsbReset => {
|
Event::UsbReset => {
|
||||||
// going from the Default state to the Default state is a no-operation
|
// 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::UsbEp0DataDone => todo!(),
|
||||||
|
|
||||||
Event::UsbEp0Setup => {
|
Event::UsbEp0Setup => {
|
||||||
defmt::println("goal reached; move to the next section");
|
defmt::println!("goal reached; move to the next section");
|
||||||
dk::exit()
|
asm::bkpt();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +1,15 @@
|
||||||
#![no_main]
|
#![no_main]
|
||||||
#![no_std]
|
#![no_std]
|
||||||
|
|
||||||
use dk::{
|
|
||||||
peripheral::USBD,
|
|
||||||
usbd::{self, Event},
|
|
||||||
};
|
|
||||||
// this imports `beginner/apps/lib.rs` to retrieve our global logger + panicking-behavior
|
// this imports `beginner/apps/lib.rs` to retrieve our global logger + panicking-behavior
|
||||||
use firmware as _;
|
use firmware as _;
|
||||||
|
|
||||||
#[rtic::app(device = dk, peripherals = false)]
|
#[rtic::app(device = dk, peripherals = false)]
|
||||||
mod app {
|
mod app {
|
||||||
|
use cortex_m::asm;
|
||||||
use dk::{
|
use dk::{
|
||||||
peripheral::USBD,
|
peripheral::USBD,
|
||||||
usbd::{self, Event},
|
usbd::{self, Event},
|
||||||
Peripherals,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#[local]
|
#[local]
|
||||||
|
@ -23,7 +19,6 @@ mod app {
|
||||||
|
|
||||||
#[shared]
|
#[shared]
|
||||||
struct MySharedResources {
|
struct MySharedResources {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[init]
|
#[init]
|
||||||
|
@ -58,7 +53,7 @@ mod app {
|
||||||
// leave this at it is for now.
|
// leave this at it is for now.
|
||||||
Event::UsbEp0Setup => {
|
Event::UsbEp0Setup => {
|
||||||
defmt::println!("goal reached; move to the next section");
|
defmt::println!("goal reached; move to the next section");
|
||||||
dk::exit()
|
asm::bkpt()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,6 @@ mod app {
|
||||||
|
|
||||||
#[shared]
|
#[shared]
|
||||||
struct MySharedResources {
|
struct MySharedResources {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[init]
|
#[init]
|
||||||
|
@ -41,6 +40,7 @@ mod app {
|
||||||
on_event(usbd, event)
|
on_event(usbd, event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_event(usbd: &USBD, event: Event) {
|
fn on_event(usbd: &USBD, event: Event) {
|
||||||
defmt::println!("USB: {:?} @ {:?}", event, dk::uptime());
|
defmt::println!("USB: {:?} @ {:?}", event, dk::uptime());
|
||||||
|
|
||||||
|
@ -107,6 +107,5 @@ mod app {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
# USB Enumeration
|
# 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.
|
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.
|
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:
|
✅ 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
|
``` console
|
||||||
INFO:usb_1 -- USB: UsbReset
|
USBD initialized
|
||||||
INFO:usb_1 -- returning to the Default state
|
USB: UsbReset
|
||||||
INFO:usb_1 -- USB: UsbEp0Setup
|
returning to the Default state
|
||||||
INFO:usb_1 -- goal reached; move to the next section
|
USB: UsbEp0Setup
|
||||||
INFO:dk -- `dk::exit() called; exiting ...
|
goal reached; move to the next section
|
||||||
```
|
```
|
||||||
|
|
||||||
## Help
|
## Help
|
||||||
|
|
Loading…
Reference in a new issue