@@ -7,13 +7,13 @@ use stm32_hrtim::{
7
7
compare_register:: HrCompareRegister , control:: HrControltExt , output:: HrOutput , timer:: HrTimer ,
8
8
HrParts , HrPwmAdvExt , Pscl4 ,
9
9
} ;
10
- use stm32g4xx_hal:: {
11
- delay:: { DelayExt , SYSTDelayExt } ,
10
+ use stm32f3xx_hal:: {
11
+ delay:: Delay ,
12
+ flash:: FlashExt as _,
12
13
gpio:: GpioExt ,
13
- pwr:: PwrExt ,
14
- rcc:: { self , RccExt } ,
15
- stm32:: { CorePeripherals , Peripherals } ,
16
- time:: ExtU32 ,
14
+ pac:: { CorePeripherals , Peripherals } ,
15
+ prelude:: { _embedded_hal_blocking_delay_DelayMs, _stm32f3xx_hal_time_rate_Extensions} ,
16
+ rcc:: RccExt ,
17
17
} ;
18
18
19
19
#[ entry]
@@ -22,18 +22,28 @@ fn main() -> ! {
22
22
23
23
let dp = Peripherals :: take ( ) . expect ( "cannot take peripherals" ) ;
24
24
let cp = CorePeripherals :: take ( ) . expect ( "cannot take core" ) ;
25
- // Set system frequency to 16MHz * 15/1/2 = 120MHz
26
- // This would lead to HrTim running at 120MHz * 32 = 3.84...
27
- let pwr = dp. PWR . constrain ( ) . freeze ( ) ;
28
- let mut rcc = Input to hrtim needs to be 128 MHz when using HSI , 128 -144 with HSE
29
25
30
- let mut delay = cp. SYST . delay ( & rcc. clocks ) ;
26
+ let mut flash = dp. FLASH . constrain ( ) ;
27
+ let mut rcc = dp. RCC . constrain ( ) ;
28
+ let mut gpioa = dp. GPIOA . split ( & mut rcc. ahb ) ;
29
+
30
+ //let mut rcc = Input to hrtim needs to be 128MHz when using HSI, 128-144 with HSE
31
+
32
+ // Set system frequency to 64MHz using PLL, PLLCLKx2 will thus be 128MHz which
33
+ // feeds into the HRTIM. This and the HRTIM's DLL would lead to an effective
34
+ // HRTIM frequency of 128MHz * 32 = 4.096GHz...
35
+ let clocks = rcc
36
+ . cfgr
37
+ . sysclk ( 64_u32 . MHz ( ) )
38
+ . use_pll ( )
39
+ . freeze ( & mut flash. acr ) ;
40
+
41
+ let mut delay = Delay :: new ( cp. SYST , clocks) ;
31
42
32
43
// ...with a prescaler of 4 this gives us a HrTimer with a tick rate of 960MHz
33
44
// With max the max period set, this would be 960MHz/2^16 ~= 15kHz...
34
45
let prescaler = Pscl4 ;
35
46
36
- let gpioa = dp. GPIOA . split ( & mut rcc) ;
37
47
let pin_a = gpioa. pa8 ;
38
48
let pin_b = gpioa. pa9 ;
39
49
@@ -49,7 +59,10 @@ fn main() -> ! {
49
59
// ------------------------ ---------------------------- ----
50
60
// . . . .
51
61
// . . . .
52
- let ( hr_control, ..) = dp. HRTIM_COMMON . hr_control ( & mut rcc) . wait_for_calibration ( ) ;
62
+ let ( hr_control, ..) = dp
63
+ . HRTIM_COMMON
64
+ . hr_control ( & clocks, & mut rcc. apb2 )
65
+ . wait_for_calibration ( ) ;
53
66
let mut hr_control = hr_control. constrain ( ) ;
54
67
55
68
let HrParts {
@@ -59,14 +72,19 @@ fn main() -> ! {
59
72
..
60
73
} = dp
61
74
. HRTIM_TIMA
62
- . pwm_advanced ( ( pin_a, pin_b) , & mut rcc )
75
+ . pwm_advanced ( ( pin_a, pin_b) )
63
76
. prescaler ( prescaler)
64
77
. period ( 0xFFFF )
65
78
. push_pull_mode ( true ) // Set push pull mode, out1 and out2 are
66
79
// alternated every period with one being
67
80
// inactive and the other getting to output its wave form
68
81
// as normal
69
- . finalize ( & mut hr_control) ;
82
+ . finalize (
83
+ & mut hr_control,
84
+ & mut gpioa. moder ,
85
+ & mut gpioa. otyper ,
86
+ & mut gpioa. afrh ,
87
+ ) ;
70
88
71
89
out1. enable_rst_event ( & cr1) ; // Set low on compare match with cr1
72
90
out2. enable_rst_event ( & cr1) ;
@@ -85,7 +103,7 @@ fn main() -> ! {
85
103
cr1. set_duty ( new_period / 3 ) ;
86
104
timer. set_period ( new_period) ;
87
105
88
- delay. delay ( 500_u32 . millis ( ) ) ;
106
+ delay. delay_ms ( 500_u16 ) ;
89
107
}
90
108
}
91
109
}
0 commit comments