diff --git a/examples/rp/Cargo.toml b/examples/rp/Cargo.toml index 07aaa0ad2add94ca5504578b58655fb049287ab9..c79faeadba5495dec44114847cdd9b0ab2cf177d 100644 --- a/examples/rp/Cargo.toml +++ b/examples/rp/Cargo.toml @@ -33,3 +33,6 @@ embedded-hal-1 = { package = "embedded-hal", version = "1.0.0-alpha.8" } embedded-hal-async = { version = "0.1.0-alpha.1" } embedded-io = { version = "0.3.0", features = ["async", "defmt"] } static_cell = "1.0.0" + +[profile.release] +debug = 2 diff --git a/examples/rp/src/bin/usb_serial.rs b/examples/rp/src/bin/usb_serial.rs index 714fb2ce97e471422d8f44b8748a6b1ae3770eca..eb29b4e5038ba4721154dfee2ce6ddf899de8076 100644 --- a/examples/rp/src/bin/usb_serial.rs +++ b/examples/rp/src/bin/usb_serial.rs @@ -78,19 +78,22 @@ async fn main(_spawner: Spawner) { let mut gpio6 = Flex::new(p.PIN_6); - // Do stuff with the class! - let echo_fut = async { - loop { - class.wait_connection().await; - info!("Connected"); - let _ = echo(&mut class, &mut gpio6, &mut cp.SYST).await; - info!("Disconnected"); - } - }; - - // Run everything concurrently. - // If we had made everything `'static` above instead, we could do this using separate tasks instead. - join(usb_fut, echo_fut).await; + run(&mut gpio6, &mut cp.SYST).await; + + // // Do stuff with the class! + // let echo_fut = async { + // loop { + // class.wait_connection().await; + // info!("Connected"); + // let _ = usb_echo(&mut class, &mut gpio6, &mut cp.SYST).await; + // info!("Disconnected"); + // } + // }; + + + // // Run everything concurrently. + // // If we had made everything `'static` above instead, we could do this using separate tasks instead. + // join(usb_fut, echo_fut).await; } struct Disconnected {} @@ -131,7 +134,7 @@ impl core::fmt::Write for FmtBuf { } } -async fn echo<'d, P: Pin, T: Instance + 'd>(class: &mut CdcAcmClass<'d, Driver<'d, T>>, +async fn usb_echo<'d, P: Pin, T: Instance + 'd>(class: &mut CdcAcmClass<'d, Driver<'d, T>>, pin: &mut Flex<'d, P>, syst: &mut SYST) -> Result<(), Disconnected> { class.write_packet(b"hello\r\n").await?; @@ -161,6 +164,37 @@ async fn echo<'d, P: Pin, T: Instance + 'd>(class: &mut CdcAcmClass<'d, Driver<' }); let del = t1 - t2; FmtBuf::write(class, format_args!("{del}\n")).await.map_err(|_| Disconnected{})?; + } +} +async fn run<'d, P: Pin>(pin: &mut Flex<'d, P>, syst: &mut SYST) -> Result<(), Disconnected> { + info!("hello"); + + syst.set_reload(10_000_000-1); + syst.clear_current(); + syst.set_clock_source(cortex_m::peripheral::syst::SystClkSource::Core); + syst.enable_counter(); + + unsafe{ pac::ROSC.ctrl().modify(|s| s.set_enable(pac::rosc::vals::Enable::DISABLE))}; + + loop { + let (t1, t2) = critical_section::with(|_cs| { + syst.clear_current(); + + pin.set_pull(Pull::Down); + pin.set_as_output(); + pin.set_high(); + // // approx 1ms + // cortex_m::asm::delay(125_000); + cortex_m::asm::delay(900); + let t1 = SYST::get_current(); + pin.set_as_input(); + while pin.is_high() {} + + let t2 = SYST::get_current(); + (t1, t2) + }); + let del = t1 - t2; + info!("{}", del); } }