22// command build: cargo build --example adc_ext_trig_double_dma_serial --features stm32g031
33// command run: cargo run --example adc_ext_trig_double_dma_serial --features stm32g031
44
5- #![ deny( warnings) ]
65#![ no_main]
76#![ no_std]
87
@@ -24,14 +23,12 @@ use rt::entry;
2423use core:: cell:: RefCell ;
2524use cortex_m:: interrupt:: Mutex ;
2625
26+ use crate :: hal:: analog:: adc:: DmaMode ;
27+ use crate :: hal:: analog:: adc:: InjectMode ;
2728use crate :: hal:: stm32:: { interrupt, Interrupt } ;
2829use hal:: analog:: adc:: { InjTrigSource , Precision , SampleTime } ; //, VTemp
29-
3030use hal:: dma:: { self , Channel , Target } ;
3131
32- use crate :: hal:: analog:: adc:: DmaMode ;
33- use crate :: hal:: analog:: adc:: InjectMode ;
34-
3532// Make dma globally available
3633static G_DMA : Mutex < RefCell < Option < hal:: dma:: Channels > > > = Mutex :: new ( RefCell :: new ( None ) ) ;
3734
@@ -120,10 +117,10 @@ fn main() -> ! {
120117 . set_peripheral_address ( adc_data_register_addr, false ) ;
121118 dma. ch1 . set_transfer_length ( adc_buffer1. len ( ) as u16 ) ;
122119
123- hprintln ! ( "adc_data_register_addr {:?}" , adc_buffer1_addr) . unwrap ( ) ; // will output addr in dec
124- // in gdb read the data bytes with: x /32xh 0x??????? (last is addr in hex)
125- // or put addr in dec format: x /32xh 536878092
126- // https://sourceware.org/gdb/current/onlinedocs/gdb/Memory.html
120+ hprintln ! ( "adc_data_register_addr {:?}" , adc_buffer1_addr) ; // will output addr in dec
121+ // in gdb read the data bytes with: x /32xh 0x??????? (last is addr in hex)
122+ // or put addr in dec format: x /32xh 536878092
123+ // https://sourceware.org/gdb/current/onlinedocs/gdb/Memory.html
127124
128125 // dma ch1 reads from ADC register into memory
129126 dma. ch1 . select_peripheral ( hal:: dmamux:: DmaMuxIndex :: ADC ) ;
@@ -162,9 +159,9 @@ fn main() -> ! {
162159 adc. set_sample_time ( SampleTime :: T_80 ) ;
163160 adc. set_precision ( Precision :: B_12 ) ;
164161 let mut pa3 = gpioa. pa5 . into_analog ( ) ;
165- let u_raw: u32 = adc. read ( & mut pa3) . expect ( "adc read failed" ) ;
162+ let u_raw = adc. read ( & mut pa3) . expect ( "adc read failed" ) ;
166163 let u = u_raw. saturating_sub ( 32 ) as f32 / 4_096_f32 * 3.3 ;
167- hprintln ! ( "u: {:.4} V " , u) . unwrap ( ) ;
164+ hprintln ! ( "u: {:.4} V " , u) ;
168165
169166 adc. set_oversampling_ratio ( adc:: OversamplingRatio :: X_16 ) ;
170167 adc. set_oversampling_shift ( 4 ) ;
0 commit comments