33
44use neotron_bmc as _;
55
6- use neotron_bmc:: monotonic:: { Tim6Monotonic , U16Ext } ;
6+ use neotron_bmc:: monotonic:: { Instant , Tim3Monotonic , U16Ext } ;
77
88use cortex_m_rt:: exception;
99
@@ -24,7 +24,7 @@ static VERSION: &'static str = include_str!(concat!(env!("OUT_DIR"), "/version.t
2424
2525const PERIOD_MS : u16 = 1000 ;
2626
27- #[ app( device = crate :: pac, peripherals = true , monotonic = crate :: Tim6Monotonic ) ]
27+ #[ app( device = crate :: pac, peripherals = true , monotonic = crate :: Tim3Monotonic ) ]
2828const APP : ( ) = {
2929 struct Resources {
3030 uart_cts : PA11 < Alternate < AF1 > > ,
@@ -49,8 +49,8 @@ const APP: () = {
4949 . sysclk ( 48 . mhz ( ) )
5050 . freeze ( & mut flash) ;
5151
52- defmt:: info!( "Configuring TIM6 at 7.8125 kHz..." ) ;
53- crate :: Tim6Monotonic :: initialize ( dp. TIM6 ) ;
52+ defmt:: info!( "Configuring TIM3 at 7.8125 kHz..." ) ;
53+ crate :: Tim3Monotonic :: initialize ( dp. TIM3 ) ;
5454
5555 defmt:: info!( "Creating pins..." ) ;
5656 let gpioa = dp. GPIOA . split ( & mut rcc) ;
@@ -69,7 +69,10 @@ const APP: () = {
6969
7070 defmt:: info!( "Creating UART..." ) ;
7171
72- let serial = serial:: Serial :: usart1 ( dp. USART1 , ( uart_tx, uart_rx) , 115_200 . bps ( ) , & mut rcc) ;
72+ let mut serial =
73+ serial:: Serial :: usart1 ( dp. USART1 , ( uart_tx, uart_rx) , 115_200 . bps ( ) , & mut rcc) ;
74+
75+ serial. listen ( serial:: Event :: Rxne ) ;
7376
7477 ctx. spawn . led_status_blink ( ) . unwrap ( ) ;
7578
@@ -90,29 +93,25 @@ const APP: () = {
9093 fn idle ( _: idle:: Context ) -> ! {
9194 defmt:: info!( "Idle is running..." ) ;
9295 loop {
93- cortex_m:: asm:: nop ( ) ;
94- // defmt::info!("Idle is asleep...");
95- // cortex_m::asm::wfi();
96- // defmt::info!("Idle is awake...");
96+ cortex_m:: asm:: wfi ( ) ;
97+ defmt:: info!( "It is now {}" , crate :: Instant :: now( ) . counts( ) ) ;
98+ }
99+ }
100+
101+ #[ task( binds = USART1 , resources=[ serial] ) ]
102+ fn usart1_interrupt ( ctx : usart1_interrupt:: Context ) {
103+ // Reading the register clears the RX-Not-Empty-Interrupt flag.
104+ match ctx. resources . serial . read ( ) {
105+ Ok ( b) => {
106+ defmt:: info!( "<< UART {:x}" , b) ;
107+ }
108+ Err ( _) => {
109+ defmt:: warn!( "<< UART None?" ) ;
110+ }
97111 }
98112 }
99113
100- // #[task(binds = USART1, resources=[serial])]
101- // fn usart1_interrupt(ctx: usart1_interrupt::Context) {
102- // defmt::info!("USART1 IRQ!");
103- // // Reading the register clears the RX-Not-Empty-Interrupt flag.
104- // match ctx.resources.serial.read()
105- // {
106- // Ok(b) => {
107- // defmt::info!("Read byte {:x}", b);
108- // }
109- // Err(_) => {
110- // defmt::warn!("No byte available?");
111- // }
112- // }
113- // }
114-
115- #[ task( resources = [ led_status] , schedule = [ led_status_blink] ) ]
114+ #[ task( schedule = [ led_status_blink] , resources = [ led_status] ) ]
116115 fn led_status_blink ( ctx : led_status_blink:: Context ) {
117116 // Use the safe local `static mut` of RTIC
118117 static mut LED_STATE : bool = false ;
@@ -126,9 +125,9 @@ const APP: () = {
126125 ctx. resources . led_status . set_high ( ) . unwrap ( ) ;
127126 * LED_STATE = true ;
128127 }
129- ctx. schedule
130- . led_status_blink ( ctx . scheduled + PERIOD_MS . millis ( ) )
131- . unwrap ( ) ;
128+ let next = ctx. scheduled + PERIOD_MS . millis ( ) ;
129+ defmt :: info! ( "Next blink at {}" , next . counts ( ) ) ;
130+ ctx . schedule . led_status_blink ( next ) . unwrap ( ) ;
132131 }
133132
134133 // Let it use the USB interrupt as a generic software interrupt.
0 commit comments