mirror of
https://github.com/ferrous-systems/embedded-trainings-2020.git
synced 2025-01-25 07:18:08 +00:00
finish advanced defmt port
This commit is contained in:
parent
9c22c61c67
commit
9c1a7e5ee1
11 changed files with 82 additions and 69 deletions
|
@ -3,15 +3,15 @@
|
||||||
|
|
||||||
use cortex_m::asm;
|
use cortex_m::asm;
|
||||||
use cortex_m_rt::entry;
|
use cortex_m_rt::entry;
|
||||||
use panic_log as _; // panic handler
|
// this imports `beginner/apps/lib.rs` to retrieve our global logger + panicking-behavior
|
||||||
|
use firmware as _;
|
||||||
|
|
||||||
#[entry]
|
#[entry]
|
||||||
fn main() -> ! {
|
fn main() -> ! {
|
||||||
// board initialization
|
// board initialization
|
||||||
dk::init().unwrap();
|
dk::init().unwrap();
|
||||||
|
|
||||||
log::info!("provoking stack overflow...");
|
defmt::info!("fib(100) = {:?}", fib(100));
|
||||||
spam(0);
|
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
asm::bkpt();
|
asm::bkpt();
|
||||||
|
@ -19,16 +19,13 @@ fn main() -> ! {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(never)]
|
#[inline(never)]
|
||||||
fn spam(n: u32) {
|
fn fib(n: u32) -> u32 {
|
||||||
// allocate and initialize 4 kilobytes of stack memory to provoke stack overflow
|
// allocate and initialize one kilobyte of stack memory to provoke stack overflow
|
||||||
let use_stack = [n; 1024];
|
let _use_stack = [0xAA; 1024];
|
||||||
|
|
||||||
log::info!(
|
if n < 2 {
|
||||||
"address of current `use_stack` at recursion depth {:?}: {:?}",
|
1
|
||||||
use_stack[1023], // "use" use_stack to prevent it from being optimized out
|
} else {
|
||||||
&use_stack as *const u32
|
fib(n - 1) + fib(n - 2) // recursion
|
||||||
);
|
}
|
||||||
|
|
||||||
let next = n + 1;
|
|
||||||
spam(next); // infinite recursion
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,8 @@ use dk::{
|
||||||
peripheral::USBD,
|
peripheral::USBD,
|
||||||
usbd::{self, Event},
|
usbd::{self, Event},
|
||||||
};
|
};
|
||||||
use panic_log as _; // panic handler
|
// this imports `beginner/apps/lib.rs` to retrieve our global logger + panicking-behavior
|
||||||
|
use firmware as _;
|
||||||
|
|
||||||
#[rtic::app(device = dk)]
|
#[rtic::app(device = dk)]
|
||||||
const APP: () = {
|
const APP: () = {
|
||||||
|
@ -33,18 +34,18 @@ const APP: () = {
|
||||||
};
|
};
|
||||||
|
|
||||||
fn on_event(_usbd: &USBD, event: Event) {
|
fn on_event(_usbd: &USBD, event: Event) {
|
||||||
log::info!("USB: {:?}", event);
|
defmt::info!("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
|
||||||
log::info!("returning to the Default state");
|
defmt::info!("returning to the Default state");
|
||||||
}
|
}
|
||||||
|
|
||||||
Event::UsbEp0DataDone => todo!(),
|
Event::UsbEp0DataDone => todo!(),
|
||||||
|
|
||||||
Event::UsbEp0Setup => {
|
Event::UsbEp0Setup => {
|
||||||
log::info!("goal reached; move to the next section");
|
defmt::info!("goal reached; move to the next section");
|
||||||
dk::exit()
|
dk::exit()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,8 @@ use dk::{
|
||||||
peripheral::USBD,
|
peripheral::USBD,
|
||||||
usbd::{self, Event},
|
usbd::{self, Event},
|
||||||
};
|
};
|
||||||
use panic_log as _; // panic handler
|
// this imports `beginner/apps/lib.rs` to retrieve our global logger + panicking-behavior
|
||||||
|
use firmware as _;
|
||||||
|
|
||||||
#[rtic::app(device = dk)]
|
#[rtic::app(device = dk)]
|
||||||
const APP: () = {
|
const APP: () = {
|
||||||
|
@ -21,7 +22,7 @@ const APP: () = {
|
||||||
// NOTE this will block if the USB cable is not connected to port J3
|
// NOTE this will block if the USB cable is not connected to port J3
|
||||||
usbd::init(board.power, &board.usbd);
|
usbd::init(board.power, &board.usbd);
|
||||||
|
|
||||||
log::info!("USBD initialized");
|
defmt::info!("USBD initialized");
|
||||||
|
|
||||||
init::LateResources { usbd: board.usbd }
|
init::LateResources { usbd: board.usbd }
|
||||||
}
|
}
|
||||||
|
@ -37,7 +38,7 @@ const APP: () = {
|
||||||
};
|
};
|
||||||
|
|
||||||
fn on_event(_usbd: &USBD, event: Event) {
|
fn on_event(_usbd: &USBD, event: Event) {
|
||||||
log::info!("USB: {:?} @ {:?}", event, dk::uptime());
|
defmt::info!("USB: {:?} @ {:?}", event, dk::uptime());
|
||||||
|
|
||||||
match event {
|
match event {
|
||||||
Event::UsbReset => todo!(),
|
Event::UsbReset => todo!(),
|
||||||
|
@ -45,7 +46,7 @@ fn on_event(_usbd: &USBD, event: Event) {
|
||||||
Event::UsbEp0DataDone => todo!(),
|
Event::UsbEp0DataDone => todo!(),
|
||||||
// leave this at it is for now.
|
// leave this at it is for now.
|
||||||
Event::UsbEp0Setup => {
|
Event::UsbEp0Setup => {
|
||||||
log::info!("goal reached; move to the next section");
|
defmt::info!("goal reached; move to the next section");
|
||||||
dk::exit()
|
dk::exit()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,8 @@ use dk::{
|
||||||
peripheral::USBD,
|
peripheral::USBD,
|
||||||
usbd::{self, Event},
|
usbd::{self, Event},
|
||||||
};
|
};
|
||||||
use panic_log as _; // panic handler
|
// this imports `beginner/apps/lib.rs` to retrieve our global logger + panicking-behavior
|
||||||
|
use firmware as _;
|
||||||
use usb::{Descriptor, Request};
|
use usb::{Descriptor, Request};
|
||||||
|
|
||||||
#[rtic::app(device = dk)]
|
#[rtic::app(device = dk)]
|
||||||
|
@ -34,7 +35,7 @@ const APP: () = {
|
||||||
};
|
};
|
||||||
|
|
||||||
fn on_event(usbd: &USBD, event: Event) {
|
fn on_event(usbd: &USBD, event: Event) {
|
||||||
log::info!("USB: {:?} @ {:?}", event, dk::uptime());
|
defmt::info!("USB: {:?} @ {:?}", event, dk::uptime());
|
||||||
|
|
||||||
match event {
|
match event {
|
||||||
Event::UsbReset => {
|
Event::UsbReset => {
|
||||||
|
@ -69,7 +70,7 @@ fn on_event(usbd: &USBD, event: Event) {
|
||||||
// let windex = usbd::windex(usbd);
|
// let windex = usbd::windex(usbd);
|
||||||
// let wvalue = usbd::wvalue(usbd);
|
// let wvalue = usbd::wvalue(usbd);
|
||||||
|
|
||||||
log::info!(
|
defmt::info!(
|
||||||
"SETUP: bmrequesttype: {}, brequest: {}, wlength: {}, windex: {}, wvalue: {}",
|
"SETUP: bmrequesttype: {}, brequest: {}, wlength: {}, windex: {}, wvalue: {}",
|
||||||
bmrequesttype,
|
bmrequesttype,
|
||||||
brequest,
|
brequest,
|
||||||
|
@ -84,9 +85,9 @@ fn on_event(usbd: &USBD, event: Event) {
|
||||||
Request::GetDescriptor { descriptor, length }
|
Request::GetDescriptor { descriptor, length }
|
||||||
if descriptor == Descriptor::Device =>
|
if descriptor == Descriptor::Device =>
|
||||||
{
|
{
|
||||||
log::info!("GET_DESCRIPTOR Device [length={}]", length);
|
defmt::info!("GET_DESCRIPTOR Device [length={}]", length);
|
||||||
|
|
||||||
log::info!("Goal reached; move to the next section");
|
defmt::info!("Goal reached; move to the next section");
|
||||||
dk::exit()
|
dk::exit()
|
||||||
}
|
}
|
||||||
Request::SetAddress { .. } => {
|
Request::SetAddress { .. } => {
|
||||||
|
|
|
@ -5,7 +5,9 @@ use dk::{
|
||||||
peripheral::USBD,
|
peripheral::USBD,
|
||||||
usbd::{self, Event},
|
usbd::{self, Event},
|
||||||
};
|
};
|
||||||
use panic_log as _; // panic handler
|
// this imports `beginner/apps/lib.rs` to retrieve our global logger + panicking-behavior
|
||||||
|
use firmware as _;
|
||||||
|
|
||||||
use usb::{Descriptor, Request};
|
use usb::{Descriptor, Request};
|
||||||
|
|
||||||
#[rtic::app(device = dk)]
|
#[rtic::app(device = dk)]
|
||||||
|
@ -34,7 +36,7 @@ const APP: () = {
|
||||||
};
|
};
|
||||||
|
|
||||||
fn on_event(_usbd: &USBD, event: Event) {
|
fn on_event(_usbd: &USBD, event: Event) {
|
||||||
log::info!("USB: {:?} @ {:?}", event, dk::uptime());
|
defmt::info!("USB: {:?} @ {:?}", event, dk::uptime());
|
||||||
|
|
||||||
match event {
|
match event {
|
||||||
Event::UsbReset => {
|
Event::UsbReset => {
|
||||||
|
@ -61,7 +63,7 @@ fn on_event(_usbd: &USBD, event: Event) {
|
||||||
// composed of a high register (WVALUEH) and a low register (WVALUEL)
|
// composed of a high register (WVALUEH) and a low register (WVALUEL)
|
||||||
let wvalue: u16 = 0;
|
let wvalue: u16 = 0;
|
||||||
|
|
||||||
log::info!(
|
defmt::info!(
|
||||||
"SETUP: bmrequesttype: {}, brequest: {}, wlength: {}, windex: {}, wvalue: {}",
|
"SETUP: bmrequesttype: {}, brequest: {}, wlength: {}, windex: {}, wvalue: {}",
|
||||||
bmrequesttype,
|
bmrequesttype,
|
||||||
brequest,
|
brequest,
|
||||||
|
@ -79,9 +81,9 @@ fn on_event(_usbd: &USBD, event: Event) {
|
||||||
// TODO modify `Request::parse()` in `advanced/common/usb/lib.rs`
|
// TODO modify `Request::parse()` in `advanced/common/usb/lib.rs`
|
||||||
// so that this branch is reached
|
// so that this branch is reached
|
||||||
|
|
||||||
log::info!("GET_DESCRIPTOR Device [length={}]", length);
|
defmt::info!("GET_DESCRIPTOR Device [length={}]", length);
|
||||||
|
|
||||||
log::info!("Goal reached; move to the next section");
|
defmt::info!("Goal reached; move to the next section");
|
||||||
dk::exit()
|
dk::exit()
|
||||||
}
|
}
|
||||||
Request::SetAddress { .. } => {
|
Request::SetAddress { .. } => {
|
||||||
|
|
|
@ -5,7 +5,8 @@ use dk::{
|
||||||
peripheral::USBD,
|
peripheral::USBD,
|
||||||
usbd::{self, Ep0In, Event},
|
usbd::{self, Ep0In, Event},
|
||||||
};
|
};
|
||||||
use panic_log as _; // panic handler
|
// this imports `beginner/apps/lib.rs` to retrieve our global logger + panicking-behavior
|
||||||
|
use firmware as _;
|
||||||
use usb::{Descriptor, Request};
|
use usb::{Descriptor, Request};
|
||||||
|
|
||||||
#[rtic::app(device = dk)]
|
#[rtic::app(device = dk)]
|
||||||
|
@ -39,7 +40,7 @@ const APP: () = {
|
||||||
};
|
};
|
||||||
|
|
||||||
fn on_event(usbd: &USBD, ep0in: &mut Ep0In, event: Event) {
|
fn on_event(usbd: &USBD, ep0in: &mut Ep0In, event: Event) {
|
||||||
log::info!("USB: {:?} @ {:?}", event, dk::uptime());
|
defmt::info!("USB: {:?} @ {:?}", event, dk::uptime());
|
||||||
|
|
||||||
match event {
|
match event {
|
||||||
Event::UsbReset => {
|
Event::UsbReset => {
|
||||||
|
@ -55,7 +56,7 @@ fn on_event(usbd: &USBD, ep0in: &mut Ep0In, event: Event) {
|
||||||
let windex = usbd::windex(usbd);
|
let windex = usbd::windex(usbd);
|
||||||
let wvalue = usbd::wvalue(usbd);
|
let wvalue = usbd::wvalue(usbd);
|
||||||
|
|
||||||
log::info!(
|
defmt::info!(
|
||||||
"SETUP: bmrequesttype: {}, brequest: {}, wlength: {}, windex: {}, wvalue: {}",
|
"SETUP: bmrequesttype: {}, brequest: {}, wlength: {}, windex: {}, wvalue: {}",
|
||||||
bmrequesttype,
|
bmrequesttype,
|
||||||
brequest,
|
brequest,
|
||||||
|
@ -71,7 +72,7 @@ fn on_event(usbd: &USBD, ep0in: &mut Ep0In, event: Event) {
|
||||||
Request::GetDescriptor { descriptor, length }
|
Request::GetDescriptor { descriptor, length }
|
||||||
if descriptor == Descriptor::Device =>
|
if descriptor == Descriptor::Device =>
|
||||||
{
|
{
|
||||||
log::info!("GET_DESCRIPTOR Device [length={}]", length);
|
defmt::info!("GET_DESCRIPTOR Device [length={}]", length);
|
||||||
|
|
||||||
let desc = usb2::device::Descriptor {
|
let desc = usb2::device::Descriptor {
|
||||||
bDeviceClass: 0,
|
bDeviceClass: 0,
|
||||||
|
@ -96,7 +97,7 @@ fn on_event(usbd: &USBD, ep0in: &mut Ep0In, event: Event) {
|
||||||
// but for now it's OK to do nothing.
|
// but for now it's OK to do nothing.
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
log::error!(
|
defmt::error!(
|
||||||
"unknown request (goal achieved if GET_DESCRIPTOR Device was handled before)"
|
"unknown request (goal achieved if GET_DESCRIPTOR Device was handled before)"
|
||||||
);
|
);
|
||||||
dk::exit()
|
dk::exit()
|
||||||
|
|
|
@ -5,7 +5,8 @@ use dk::{
|
||||||
peripheral::USBD,
|
peripheral::USBD,
|
||||||
usbd::{self, Ep0In, Event},
|
usbd::{self, Ep0In, Event},
|
||||||
};
|
};
|
||||||
use panic_log as _; // panic handler
|
// this imports `beginner/apps/lib.rs` to retrieve our global logger + panicking-behavior
|
||||||
|
use firmware as _;
|
||||||
use usb::{Descriptor, Request};
|
use usb::{Descriptor, Request};
|
||||||
|
|
||||||
#[rtic::app(device = dk)]
|
#[rtic::app(device = dk)]
|
||||||
|
@ -39,7 +40,7 @@ const APP: () = {
|
||||||
};
|
};
|
||||||
|
|
||||||
fn on_event(usbd: &USBD, ep0in: &mut Ep0In, event: Event) {
|
fn on_event(usbd: &USBD, ep0in: &mut Ep0In, event: Event) {
|
||||||
log::info!("USB: {:?} @ {:?}", event, dk::uptime());
|
defmt::info!("USB: {:?} @ {:?}", event, dk::uptime());
|
||||||
|
|
||||||
match event {
|
match event {
|
||||||
Event::UsbReset => {
|
Event::UsbReset => {
|
||||||
|
@ -55,7 +56,7 @@ fn on_event(usbd: &USBD, ep0in: &mut Ep0In, event: Event) {
|
||||||
let windex = usbd::windex(usbd);
|
let windex = usbd::windex(usbd);
|
||||||
let wvalue = usbd::wvalue(usbd);
|
let wvalue = usbd::wvalue(usbd);
|
||||||
|
|
||||||
log::info!(
|
defmt::info!(
|
||||||
"SETUP: bmrequesttype: {}, brequest: {}, wlength: {}, windex: {}, wvalue: {}",
|
"SETUP: bmrequesttype: {}, brequest: {}, wlength: {}, windex: {}, wvalue: {}",
|
||||||
bmrequesttype,
|
bmrequesttype,
|
||||||
brequest,
|
brequest,
|
||||||
|
@ -71,7 +72,7 @@ fn on_event(usbd: &USBD, ep0in: &mut Ep0In, event: Event) {
|
||||||
Request::GetDescriptor { descriptor, length }
|
Request::GetDescriptor { descriptor, length }
|
||||||
if descriptor == Descriptor::Device =>
|
if descriptor == Descriptor::Device =>
|
||||||
{
|
{
|
||||||
log::info!("GET_DESCRIPTOR Device [length={}]", length);
|
defmt::info!("GET_DESCRIPTOR Device [length={}]", length);
|
||||||
|
|
||||||
// TODO send back a valid device descriptor, truncated to `length` bytes
|
// TODO send back a valid device descriptor, truncated to `length` bytes
|
||||||
// let desc = usb2::device::Descriptor { .. };
|
// let desc = usb2::device::Descriptor { .. };
|
||||||
|
@ -87,7 +88,7 @@ fn on_event(usbd: &USBD, ep0in: &mut Ep0In, event: Event) {
|
||||||
// but for now it's OK to do nothing.
|
// but for now it's OK to do nothing.
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
log::error!(
|
defmt::error!(
|
||||||
"unknown request (goal achieved if GET_DESCRIPTOR Device was handled before)"
|
"unknown request (goal achieved if GET_DESCRIPTOR Device was handled before)"
|
||||||
);
|
);
|
||||||
dk::exit()
|
dk::exit()
|
||||||
|
|
|
@ -7,7 +7,8 @@ use dk::{
|
||||||
peripheral::USBD,
|
peripheral::USBD,
|
||||||
usbd::{self, Ep0In, Event},
|
usbd::{self, Ep0In, Event},
|
||||||
};
|
};
|
||||||
use panic_log as _; // panic handler
|
// this imports `beginner/apps/lib.rs` to retrieve our global logger + panicking-behavior
|
||||||
|
use firmware as _;
|
||||||
use usb2::{GetDescriptor as Descriptor, StandardRequest as Request, State};
|
use usb2::{GetDescriptor as Descriptor, StandardRequest as Request, State};
|
||||||
|
|
||||||
#[rtic::app(device = dk)]
|
#[rtic::app(device = dk)]
|
||||||
|
@ -44,22 +45,22 @@ const APP: () = {
|
||||||
};
|
};
|
||||||
|
|
||||||
fn on_event(usbd: &USBD, ep0in: &mut Ep0In, state: &mut State, event: Event) {
|
fn on_event(usbd: &USBD, ep0in: &mut Ep0In, state: &mut State, event: Event) {
|
||||||
log::info!("USB: {:?} @ {:?}", event, dk::uptime());
|
defmt::info!("USB: {:?} @ {:?}", event, dk::uptime());
|
||||||
|
|
||||||
match event {
|
match event {
|
||||||
Event::UsbReset => {
|
Event::UsbReset => {
|
||||||
log::info!("USB reset condition detected");
|
defmt::info!("USB reset condition detected");
|
||||||
*state = State::Default;
|
*state = State::Default;
|
||||||
}
|
}
|
||||||
|
|
||||||
Event::UsbEp0DataDone => {
|
Event::UsbEp0DataDone => {
|
||||||
log::info!("EP0IN: transfer complete");
|
defmt::info!("EP0IN: transfer complete");
|
||||||
ep0in.end(usbd);
|
ep0in.end(usbd);
|
||||||
}
|
}
|
||||||
|
|
||||||
Event::UsbEp0Setup => {
|
Event::UsbEp0Setup => {
|
||||||
if ep0setup(usbd, ep0in, state).is_err() {
|
if ep0setup(usbd, ep0in, state).is_err() {
|
||||||
log::warn!("EP0IN: unexpected request; stalling the endpoint");
|
defmt::warn!("EP0IN: unexpected request; stalling the endpoint");
|
||||||
usbd::ep0stall(usbd);
|
usbd::ep0stall(usbd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -76,7 +77,7 @@ fn ep0setup(usbd: &USBD, ep0in: &mut Ep0In, state: &mut State) -> Result<(), ()>
|
||||||
let windex = usbd::windex(usbd);
|
let windex = usbd::windex(usbd);
|
||||||
let wvalue = usbd::wvalue(usbd);
|
let wvalue = usbd::wvalue(usbd);
|
||||||
|
|
||||||
log::info!(
|
defmt::info!(
|
||||||
"bmrequesttype: {}, brequest: {}, wlength: {}, windex: {}, wvalue: {}",
|
"bmrequesttype: {}, brequest: {}, wlength: {}, windex: {}, wvalue: {}",
|
||||||
bmrequesttype,
|
bmrequesttype,
|
||||||
brequest,
|
brequest,
|
||||||
|
@ -87,7 +88,9 @@ fn ep0setup(usbd: &USBD, ep0in: &mut Ep0In, state: &mut State) -> Result<(), ()>
|
||||||
|
|
||||||
let request = Request::parse(bmrequesttype, brequest, wvalue, windex, wlength)
|
let request = Request::parse(bmrequesttype, brequest, wvalue, windex, wlength)
|
||||||
.expect("Error parsing request");
|
.expect("Error parsing request");
|
||||||
log::info!("EP0: {:?}", request);
|
defmt::info!("EP0: {:?}", defmt::Debug2Format(&request));
|
||||||
|
// ^^^^^^^^^^^^^^^^^^^ this adapter iscurrently needed to log
|
||||||
|
// `StandardRequest` with `defmt`
|
||||||
|
|
||||||
match request {
|
match request {
|
||||||
// section 9.4.3
|
// section 9.4.3
|
||||||
|
|
|
@ -5,7 +5,8 @@ use dk::{
|
||||||
peripheral::USBD,
|
peripheral::USBD,
|
||||||
usbd::{self, Ep0In, Event},
|
usbd::{self, Ep0In, Event},
|
||||||
};
|
};
|
||||||
use panic_log as _; // panic handler
|
// this imports `beginner/apps/lib.rs` to retrieve our global logger + panicking-behavior
|
||||||
|
use firmware as _;
|
||||||
|
|
||||||
use usb2::State;
|
use usb2::State;
|
||||||
// HEADS UP to use *your* USB packet parser uncomment line 12 and remove line 13
|
// HEADS UP to use *your* USB packet parser uncomment line 12 and remove line 13
|
||||||
|
@ -46,17 +47,17 @@ const APP: () = {
|
||||||
};
|
};
|
||||||
|
|
||||||
fn on_event(usbd: &USBD, ep0in: &mut Ep0In, state: &mut State, event: Event) {
|
fn on_event(usbd: &USBD, ep0in: &mut Ep0In, state: &mut State, event: Event) {
|
||||||
log::info!("USB: {:?} @ {:?}", event, dk::uptime());
|
defmt::info!("USB: {:?} @ {:?}", event, dk::uptime());
|
||||||
|
|
||||||
match event {
|
match event {
|
||||||
// TODO change `state` as specified in chapter 9.1 USB Device States, of the USB specification
|
// TODO change `state` as specified in chapter 9.1 USB Device States, of the USB specification
|
||||||
Event::UsbReset => {
|
Event::UsbReset => {
|
||||||
log::info!("USB reset condition detected");
|
defmt::info!("USB reset condition detected");
|
||||||
todo!();
|
todo!();
|
||||||
}
|
}
|
||||||
|
|
||||||
Event::UsbEp0DataDone => {
|
Event::UsbEp0DataDone => {
|
||||||
log::info!("EP0IN: transfer complete");
|
defmt::info!("EP0IN: transfer complete");
|
||||||
ep0in.end(usbd);
|
ep0in.end(usbd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,7 +65,7 @@ fn on_event(usbd: &USBD, ep0in: &mut Ep0In, state: &mut State, event: Event) {
|
||||||
if ep0setup(usbd, ep0in, state).is_err() {
|
if ep0setup(usbd, ep0in, state).is_err() {
|
||||||
// unsupported or invalid request:
|
// unsupported or invalid request:
|
||||||
// TODO: add code to stall the endpoint
|
// TODO: add code to stall the endpoint
|
||||||
log::warn!("EP0IN: unexpected request; stalling the endpoint");
|
defmt::warn!("EP0IN: unexpected request; stalling the endpoint");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -77,7 +78,7 @@ fn ep0setup(usbd: &USBD, ep0in: &mut Ep0In, _state: &mut State) -> Result<(), ()
|
||||||
let windex = usbd::windex(usbd);
|
let windex = usbd::windex(usbd);
|
||||||
let wvalue = usbd::wvalue(usbd);
|
let wvalue = usbd::wvalue(usbd);
|
||||||
|
|
||||||
log::info!(
|
defmt::info!(
|
||||||
"bmrequesttype: {}, brequest: {}, wlength: {}, windex: {}, wvalue: {}",
|
"bmrequesttype: {}, brequest: {}, wlength: {}, windex: {}, wvalue: {}",
|
||||||
bmrequesttype,
|
bmrequesttype,
|
||||||
brequest,
|
brequest,
|
||||||
|
@ -88,7 +89,9 @@ fn ep0setup(usbd: &USBD, ep0in: &mut Ep0In, _state: &mut State) -> Result<(), ()
|
||||||
|
|
||||||
let request = Request::parse(bmrequesttype, brequest, wvalue, windex, wlength)
|
let request = Request::parse(bmrequesttype, brequest, wvalue, windex, wlength)
|
||||||
.expect("Error parsing request");
|
.expect("Error parsing request");
|
||||||
log::info!("EP0: {:?}", request);
|
defmt::info!("EP0: {:?}", defmt::Debug2Format(&request));
|
||||||
|
// ^^^^^^^^^^^^^^^^^^^ this adapter iscurrently needed to log
|
||||||
|
// `StandardRequest` with `defmt`
|
||||||
|
|
||||||
match request {
|
match request {
|
||||||
Request::GetDescriptor { descriptor, length } => match descriptor {
|
Request::GetDescriptor { descriptor, length } => match descriptor {
|
||||||
|
|
|
@ -7,7 +7,8 @@ use dk::{
|
||||||
peripheral::USBD,
|
peripheral::USBD,
|
||||||
usbd::{self, Ep0In, Event},
|
usbd::{self, Ep0In, Event},
|
||||||
};
|
};
|
||||||
use panic_log as _; // panic handler
|
// this imports `beginner/apps/lib.rs` to retrieve our global logger + panicking-behavior
|
||||||
|
use firmware as _;
|
||||||
use usb2::{GetDescriptor as Descriptor, StandardRequest as Request, State};
|
use usb2::{GetDescriptor as Descriptor, StandardRequest as Request, State};
|
||||||
|
|
||||||
#[rtic::app(device = dk)]
|
#[rtic::app(device = dk)]
|
||||||
|
@ -44,22 +45,22 @@ const APP: () = {
|
||||||
};
|
};
|
||||||
|
|
||||||
fn on_event(usbd: &USBD, ep0in: &mut Ep0In, state: &mut State, event: Event) {
|
fn on_event(usbd: &USBD, ep0in: &mut Ep0In, state: &mut State, event: Event) {
|
||||||
log::info!("USB: {:?} @ {:?}", event, dk::uptime());
|
defmt::info!("USB: {:?} @ {:?}", event, dk::uptime());
|
||||||
|
|
||||||
match event {
|
match event {
|
||||||
Event::UsbReset => {
|
Event::UsbReset => {
|
||||||
log::info!("USB reset condition detected");
|
defmt::info!("USB reset condition detected");
|
||||||
*state = State::Default;
|
*state = State::Default;
|
||||||
}
|
}
|
||||||
|
|
||||||
Event::UsbEp0DataDone => {
|
Event::UsbEp0DataDone => {
|
||||||
log::info!("EP0IN: transfer complete");
|
defmt::info!("EP0IN: transfer complete");
|
||||||
ep0in.end(usbd);
|
ep0in.end(usbd);
|
||||||
}
|
}
|
||||||
|
|
||||||
Event::UsbEp0Setup => {
|
Event::UsbEp0Setup => {
|
||||||
if ep0setup(usbd, ep0in, state).is_err() {
|
if ep0setup(usbd, ep0in, state).is_err() {
|
||||||
log::warn!("EP0IN: unexpected request; stalling the endpoint");
|
defmt::warn!("EP0IN: unexpected request; stalling the endpoint");
|
||||||
usbd::ep0stall(usbd);
|
usbd::ep0stall(usbd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -76,7 +77,7 @@ fn ep0setup(usbd: &USBD, ep0in: &mut Ep0In, state: &mut State) -> Result<(), ()>
|
||||||
let windex = usbd::windex(usbd);
|
let windex = usbd::windex(usbd);
|
||||||
let wvalue = usbd::wvalue(usbd);
|
let wvalue = usbd::wvalue(usbd);
|
||||||
|
|
||||||
log::info!(
|
defmt::info!(
|
||||||
"bmrequesttype: {}, brequest: {}, wlength: {}, windex: {}, wvalue: {}",
|
"bmrequesttype: {}, brequest: {}, wlength: {}, windex: {}, wvalue: {}",
|
||||||
bmrequesttype,
|
bmrequesttype,
|
||||||
brequest,
|
brequest,
|
||||||
|
@ -87,7 +88,9 @@ fn ep0setup(usbd: &USBD, ep0in: &mut Ep0In, state: &mut State) -> Result<(), ()>
|
||||||
|
|
||||||
let request = Request::parse(bmrequesttype, brequest, wvalue, windex, wlength)
|
let request = Request::parse(bmrequesttype, brequest, wvalue, windex, wlength)
|
||||||
.expect("Error parsing request");
|
.expect("Error parsing request");
|
||||||
log::info!("EP0: {:?}", request);
|
defmt::info!("EP0: {:?}", defmt::Debug2Format(&request));
|
||||||
|
// ^^^^^^^^^^^^^^^^^^^ this adapter iscurrently needed to log
|
||||||
|
// `StandardRequest` with `defmt`
|
||||||
|
|
||||||
match request {
|
match request {
|
||||||
// section 9.4.3
|
// section 9.4.3
|
||||||
|
@ -185,10 +188,10 @@ fn ep0setup(usbd: &USBD, ep0in: &mut Ep0In, state: &mut State) -> Result<(), ()>
|
||||||
State::Address(address) => {
|
State::Address(address) => {
|
||||||
if let Some(value) = value {
|
if let Some(value) = value {
|
||||||
if value.get() == CONFIG_VAL {
|
if value.get() == CONFIG_VAL {
|
||||||
log::info!("entering the configured state");
|
defmt::info!("entering the configured state");
|
||||||
*state = State::Configured { address, value };
|
*state = State::Configured { address, value };
|
||||||
} else {
|
} else {
|
||||||
log::error!("unsupported configuration value");
|
defmt::error!("unsupported configuration value");
|
||||||
return Err(());
|
return Err(());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -203,18 +206,18 @@ fn ep0setup(usbd: &USBD, ep0in: &mut Ep0In, state: &mut State) -> Result<(), ()>
|
||||||
if let Some(new_value) = value {
|
if let Some(new_value) = value {
|
||||||
if new_value.get() == CONFIG_VAL {
|
if new_value.get() == CONFIG_VAL {
|
||||||
if new_value != curr_value {
|
if new_value != curr_value {
|
||||||
log::info!("changing configuration");
|
defmt::info!("changing configuration");
|
||||||
*state = State::Configured {
|
*state = State::Configured {
|
||||||
address,
|
address,
|
||||||
value: new_value,
|
value: new_value,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log::error!("unsupported configuration value");
|
defmt::error!("unsupported configuration value");
|
||||||
return Err(());
|
return Err(());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log::info!("returned to the address state");
|
defmt::info!("returned to the address state");
|
||||||
*state = State::Address(address);
|
*state = State::Address(address);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -161,7 +161,7 @@ pub fn ep0stall(usbd: &USBD) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// USBD.EVENTS registers mapped to an enum
|
/// USBD.EVENTS registers mapped to an enum
|
||||||
#[derive(Debug)]
|
#[derive(Debug, defmt::Format)]
|
||||||
pub enum Event {
|
pub enum Event {
|
||||||
/// `EVENTS_USBRESET` register was active
|
/// `EVENTS_USBRESET` register was active
|
||||||
UsbReset,
|
UsbReset,
|
||||||
|
|
Loading…
Reference in a new issue