1
1
#![ no_std]
2
2
#![ no_main]
3
3
4
+ #[ path = "../utils/mod.rs" ]
5
+ mod utils;
6
+ use utils:: logger:: info;
7
+
4
8
/// Example showcasing the use of the HRTIM peripheral to trigger the ADC at various points of the switch cycle off HRTIM_TIMA
5
9
use cortex_m_rt:: entry;
6
- use panic_probe as _;
7
10
use stm32_hrtim:: {
8
11
compare_register:: HrCompareRegister , output:: HrOutput , timer:: HrTimer , HrParts , HrPwmAdvExt ,
9
12
Pscl4 ,
@@ -23,14 +26,14 @@ use stm32g4xx_hal::{
23
26
fn main ( ) -> ! {
24
27
const VREF : f32 = 3.3 ;
25
28
26
- defmt :: info!( "start" ) ;
29
+ info ! ( "start" ) ;
27
30
28
31
let dp = Peripherals :: take ( ) . unwrap ( ) ;
29
32
let cp = CorePeripherals :: take ( ) . expect ( "cannot take core peripherals" ) ;
30
33
31
34
// Set system frequency to 16MHz * 15/1/2 = 120MHz
32
35
// This would lead to HrTim running at 120MHz * 32 = 3.84...
33
- defmt :: info!( "rcc" ) ;
36
+ info ! ( "rcc" ) ;
34
37
let pwr = dp. PWR . constrain ( ) . freeze ( ) ;
35
38
let mut rcc = dp. RCC . freeze (
36
39
rcc:: Config :: pll ( ) . pll_cfg ( rcc:: PllConfig {
@@ -52,7 +55,7 @@ fn main() -> ! {
52
55
. circular_buffer ( true )
53
56
. memory_increment ( true ) ;
54
57
55
- defmt :: info!( "Setup Gpio" ) ;
58
+ info ! ( "Setup Gpio" ) ;
56
59
let gpioa = dp. GPIOA . split ( & mut rcc) ;
57
60
let pa0 = gpioa. pa0 . into_analog ( ) ;
58
61
@@ -102,7 +105,7 @@ fn main() -> ! {
102
105
out1. enable_set_event ( & timer) ; // Set high at new period
103
106
out2. enable_set_event ( & timer) ;
104
107
105
- defmt :: info!( "Setup Adc1" ) ;
108
+ info ! ( "Setup Adc1" ) ;
106
109
let mut adc12_common = dp. ADC12_COMMON . claim ( Default :: default ( ) , & mut rcc) ;
107
110
let mut adc = adc12_common. claim ( dp. ADC1 , & mut delay) ;
108
111
@@ -124,7 +127,7 @@ fn main() -> ! {
124
127
adc:: config:: SampleTime :: Cycles_640_5 ,
125
128
) ;
126
129
127
- defmt :: info!( "Setup DMA" ) ;
130
+ info ! ( "Setup DMA" ) ;
128
131
let first_buffer = cortex_m:: singleton!( : [ u16 ; 10 ] = [ 0 ; 10 ] ) . unwrap ( ) ;
129
132
130
133
let mut transfer = dma1ch1. into_circ_peripheral_to_memory_transfer (
@@ -144,16 +147,16 @@ fn main() -> ! {
144
147
let mut b = [ 0_u16 ; 4 ] ;
145
148
let r = transfer. read_exact ( & mut b) ;
146
149
147
- defmt :: info!( "read: {}" , r) ;
150
+ info ! ( "read: {}" , r) ;
148
151
assert ! ( r == b. len( ) ) ;
149
152
150
153
let millivolts = Vref :: sample_to_millivolts ( ( b[ 0 ] + b[ 2 ] ) / 2 ) ;
151
- defmt :: info!( "pa3: {}mV" , millivolts) ;
154
+ info ! ( "pa3: {}mV" , millivolts) ;
152
155
let temp = Temperature :: temperature_to_degrees_centigrade (
153
156
( b[ 1 ] + b[ 3 ] ) / 2 ,
154
157
VREF ,
155
158
adc:: config:: Resolution :: Twelve ,
156
159
) ;
157
- defmt :: info!( "temp: {}℃C" , temp) ;
160
+ info ! ( "temp: {}℃C" , temp) ;
158
161
}
159
162
}
0 commit comments