@@ -11,15 +11,16 @@ use bsp::RgbLed;
1111#[ rtic:: app( device = bsp, peripherals = false , dispatchers = [ QSPI , CRYPTOCELL ] ) ]
1212mod app {
1313 use bsp:: hal:: { self , usb:: vbus_detect:: HardwareVbusDetect } ;
14+ use embedded_hal_async:: delay:: DelayNs as _;
1415 use core:: fmt:: Write as _;
1516 use defmt_rtt as _;
1617 use embassy_sync:: blocking_mutex:: raw:: CriticalSectionRawMutex ;
18+ use embassy_time:: Delay ;
19+ use embassy_time:: Duration ;
1720 use embassy_usb:: class:: cdc_acm;
1821 use embassy_usb:: class:: hid;
1922 use embedded_io_async:: Write as _;
20- use rtic_monotonics:: fugit:: ExtU32 ;
2123
22- use rtic_monotonics:: systick:: prelude:: * ;
2324 use static_cell:: StaticCell ;
2425
2526 const SERIAL_BUFFER_SIZE : usize = 512 ;
@@ -34,8 +35,6 @@ mod app {
3435 RADIO => hal:: radio:: InterruptHandler <hal:: peripherals:: RADIO >;
3536 } ) ;
3637
37- systick_monotonic ! ( Mono ) ;
38-
3938 /// An adapter that simplifies asynchronously writing to the USB ACM by buffering writes.
4039 ///
4140 /// All writes are buffered until `flush` is called, which performs the async write.
@@ -125,9 +124,8 @@ mod app {
125124 struct MySharedResources { }
126125
127126 #[ init]
128- fn init ( ctx : init:: Context ) -> ( MySharedResources , MyLocalResources ) {
127+ fn init ( mut ctx : init:: Context ) -> ( MySharedResources , MyLocalResources ) {
129128 let board = bsp:: init ( ) . unwrap ( ) ;
130- Mono :: start ( ctx. core . SYST , 64_000_000 ) ;
131129 defmt:: println!( "-- Radio Loopback firmware --" ) ;
132130
133131 #[ cfg( feature = "dk" ) ]
@@ -280,9 +278,7 @@ mod app {
280278
281279 // Set the ARM SLEEPONEXIT bit to go to sleep after handling interrupts
282280 // See https://developer.arm.com/docs/100737/0100/power-management/sleep-mode/sleep-on-exit-bit
283- // TODO: Unfortunately, this does not work yet. Radio packets are not
284- // arriving properly.
285- //ctx.core.SCB.set_sleepdeep();
281+ ctx. core . SCB . set_sleepdeep ( ) ;
286282
287283 ( shared, local)
288284 }
@@ -293,11 +289,7 @@ mod app {
293289 // Now Wait For Interrupt is used instead of a busy-wait loop
294290 // to allow MCU to sleep between interrupts
295291 // https://developer.arm.com/documentation/ddi0406/c/Application-Level-Architecture/Instruction-Details/Alphabetical-list-of-instructions/WFI
296- //
297- // TODO: Unfortunately, this does not work yet. Radio packets are not
298- // arriving properly.
299- // rtic::export::wfi()
300- cortex_m:: asm:: nop ( ) ;
292+ rtic:: export:: wfi ( )
301293 }
302294 }
303295
@@ -326,7 +318,12 @@ mod app {
326318 async fn usb_acm ( mut ctx : usb_acm:: Context ) {
327319 loop {
328320 // Wait for up to 200 ms for a connection, discard ACM data otherwise.
329- match Mono :: timeout_after ( 200 . millis ( ) , ctx. local . usb_acm . wait_connection ( ) ) . await {
321+ match embassy_time:: with_timeout (
322+ Duration :: from_millis ( 200 ) ,
323+ ctx. local . usb_acm . wait_connection ( ) ,
324+ )
325+ . await
326+ {
330327 Ok ( _) => {
331328 defmt:: info!( "ACM Connected" ) ;
332329 connected_usb_acm ( & mut ctx) . await ;
@@ -349,8 +346,11 @@ mod app {
349346 let mut buffer = [ 0u8 ; 64 ] ;
350347 loop {
351348 // Poll for a frame for up to 50 milliseconds.
352- if let Ok ( result) =
353- Mono :: timeout_after ( 50 . millis ( ) , ctx. local . usb_acm . read_packet ( & mut buffer) ) . await
349+ if let Ok ( result) = embassy_time:: with_timeout (
350+ Duration :: from_millis ( 50 ) ,
351+ ctx. local . usb_acm . read_packet ( & mut buffer) ,
352+ )
353+ . await
354354 {
355355 match result {
356356 Ok ( n) => {
@@ -377,8 +377,8 @@ mod app {
377377 . usb_acm_reader
378378 . try_read ( & mut buffer[ 0 ..MAX_ACM_PACKET_SIZE - 1 ] )
379379 {
380- match Mono :: timeout_after (
381- 20 . millis ( ) ,
380+ match embassy_time :: with_timeout (
381+ Duration :: from_millis ( 20 ) ,
382382 ctx. local . usb_acm . write_packet ( & buffer[ 0 ..bytes_read] ) ,
383383 )
384384 . await
@@ -463,8 +463,11 @@ mod app {
463463 defmt:: debug!( "Waiting for packet.." ) ;
464464
465465 // Poll for a frame for up to 200 milliseconds.
466- if let Ok ( result) =
467- Mono :: timeout_after ( 200 . millis ( ) , ctx. local . radio . receive ( ctx. local . packet ) ) . await
466+ if let Ok ( result) = embassy_time:: with_timeout (
467+ Duration :: from_millis ( 200 ) ,
468+ ctx. local . radio . receive ( ctx. local . packet ) ,
469+ )
470+ . await
468471 {
469472 match result {
470473 Ok ( _) => {
@@ -481,7 +484,7 @@ mod app {
481484 // send packet after 5ms (we know the client waits for 10ms and
482485 // we want to ensure they are definitely in receive mode by the
483486 // time we send this reply)
484- Mono :: delay ( 5 . millis ( ) ) . await ;
487+ Delay . delay_ms ( 5 ) . await ;
485488 if let Err ( e) = ctx. local . radio . try_send ( ctx. local . packet ) . await {
486489 let _ = writeln ! (
487490 & mut ctx. local. usb_acm_write_adapter,
@@ -528,5 +531,3 @@ fn panic(info: &core::panic::PanicInfo) -> ! {
528531 core:: hint:: spin_loop ( ) ;
529532 }
530533}
531-
532- defmt:: timestamp!( "{=u64:tus}" , bsp:: uptime_us( ) ) ;
0 commit comments