11#![ no_std]
22#![ no_main]
33
4+ #[ path = "../utils/mod.rs" ]
5+ mod utils;
6+ use utils:: logger:: info;
7+
48/// Example showcasing the use of the HRTIM peripheral to trigger the ADC at various points of the switch cycle off HRTIM_TIMA
59use cortex_m_rt:: entry;
6- use panic_probe as _;
710use stm32_hrtim:: {
811 compare_register:: HrCompareRegister , output:: HrOutput , timer:: HrTimer , HrParts , HrPwmAdvExt ,
912 Pscl4 ,
@@ -23,14 +26,14 @@ use stm32g4xx_hal::{
2326fn main ( ) -> ! {
2427 const VREF : f32 = 3.3 ;
2528
26- defmt :: info!( "start" ) ;
29+ info ! ( "start" ) ;
2730
2831 let dp = Peripherals :: take ( ) . unwrap ( ) ;
2932 let cp = CorePeripherals :: take ( ) . expect ( "cannot take core peripherals" ) ;
3033
3134 // Set system frequency to 16MHz * 15/1/2 = 120MHz
3235 // This would lead to HrTim running at 120MHz * 32 = 3.84...
33- defmt :: info!( "rcc" ) ;
36+ info ! ( "rcc" ) ;
3437 let pwr = dp. PWR . constrain ( ) . freeze ( ) ;
3538 let mut rcc = dp. RCC . freeze (
3639 rcc:: Config :: pll ( ) . pll_cfg ( rcc:: PllConfig {
@@ -52,7 +55,7 @@ fn main() -> ! {
5255 . circular_buffer ( true )
5356 . memory_increment ( true ) ;
5457
55- defmt :: info!( "Setup Gpio" ) ;
58+ info ! ( "Setup Gpio" ) ;
5659 let gpioa = dp. GPIOA . split ( & mut rcc) ;
5760 let pa0 = gpioa. pa0 . into_analog ( ) ;
5861
@@ -102,7 +105,7 @@ fn main() -> ! {
102105 out1. enable_set_event ( & timer) ; // Set high at new period
103106 out2. enable_set_event ( & timer) ;
104107
105- defmt :: info!( "Setup Adc1" ) ;
108+ info ! ( "Setup Adc1" ) ;
106109 let mut adc12_common = dp. ADC12_COMMON . claim ( Default :: default ( ) , & mut rcc) ;
107110 let mut adc = adc12_common. claim ( dp. ADC1 , & mut delay) ;
108111
@@ -124,7 +127,7 @@ fn main() -> ! {
124127 adc:: config:: SampleTime :: Cycles_640_5 ,
125128 ) ;
126129
127- defmt :: info!( "Setup DMA" ) ;
130+ info ! ( "Setup DMA" ) ;
128131 let first_buffer = cortex_m:: singleton!( : [ u16 ; 10 ] = [ 0 ; 10 ] ) . unwrap ( ) ;
129132
130133 let mut transfer = dma1ch1. into_circ_peripheral_to_memory_transfer (
@@ -144,16 +147,16 @@ fn main() -> ! {
144147 let mut b = [ 0_u16 ; 4 ] ;
145148 let r = transfer. read_exact ( & mut b) ;
146149
147- defmt :: info!( "read: {}" , r) ;
150+ info ! ( "read: {}" , r) ;
148151 assert ! ( r == b. len( ) ) ;
149152
150153 let millivolts = Vref :: sample_to_millivolts ( ( b[ 0 ] + b[ 2 ] ) / 2 ) ;
151- defmt :: info!( "pa3: {}mV" , millivolts) ;
154+ info ! ( "pa3: {}mV" , millivolts) ;
152155 let temp = Temperature :: temperature_to_degrees_centigrade (
153156 ( b[ 1 ] + b[ 3 ] ) / 2 ,
154157 VREF ,
155158 adc:: config:: Resolution :: Twelve ,
156159 ) ;
157- defmt :: info!( "temp: {}℃C" , temp) ;
160+ info ! ( "temp: {}℃C" , temp) ;
158161 }
159162}
0 commit comments