@@ -5,12 +5,12 @@ use cortex_m_rt::entry;
55use panic_probe as _;
66use stm32_hrtim:: {
77 compare_register:: HrCompareRegister , control:: HrControltExt , output:: HrOutput , timer:: HrTimer ,
8- HrParts , HrPwmAdvExt , Pscl4 ,
8+ HrParts , HrPwmAdvExt , Pscl1 ,
99} ;
1010use stm32h7xx_hal:: {
11- prelude:: _embedded_hal_blocking_delay_DelayMs,
1211 delay:: DelayExt ,
1312 gpio:: GpioExt ,
13+ prelude:: _embedded_hal_blocking_delay_DelayMs,
1414 pwr:: PwrExt ,
1515 rcc:: RccExt ,
1616 stm32:: { CorePeripherals , Peripherals } ,
@@ -31,7 +31,14 @@ fn main() -> ! {
3131
3232 // Constrain and Freeze clock
3333 let rcc = dp. RCC . constrain ( ) ;
34- let ccdr = rcc. sys_ck ( 320 . MHz ( ) ) . freeze ( pwrcfg, & dp. SYSCFG ) ;
34+
35+ // With a sys_ck of 240MHz and d1cpre of 1 if the HRTIM will be fed by 240MHz/1 = 240MHz
36+ // since HRTIMSEL is set to take the HRTIM's clock directly from the core clock. The
37+ // stm32h7 devices' HRTIM does not have a DLL, also leading to an effective HRTIM
38+ // frequency of 240MHz...
39+ let ccdr = rcc
40+ . sys_ck ( 240 . MHz ( ) )
41+ . freeze ( pwrcfg, & dp. SYSCFG ) ;
3542
3643 // Acquire the GPIO peripherals. This also enables the clock for
3744 // the GPIOs in the RCC register.
@@ -40,9 +47,9 @@ fn main() -> ! {
4047 // Get the delay provider.
4148 let mut delay = cp. SYST . delay ( ccdr. clocks ) ;
4249
43- // ...with a prescaler of 4 this gives us a HrTimer with a tick rate of 960MHz
44- // With max the max period set, this would be 960MHz /2^16 ~= 15kHz ...
45- let prescaler = Pscl4 ;
50+ // ...with a prescaler of 1 this gives us a HrTimer with a tick rate of 240MHz
51+ // With max the max period set, this would be 240MHz /2^16 ~= 3.7kHz ...
52+ let prescaler = Pscl1 ;
4653
4754 let pin_a = gpioc. pc6 . into_input ( ) ;
4855 let pin_b = gpioc. pc7 . into_input ( ) ;
@@ -61,7 +68,7 @@ fn main() -> ! {
6168 // . . . .
6269 let ( hr_control, ..) = dp
6370 . HRTIM_COMMON
64- . hr_control ( ccdr. peripheral . HRTIM )
71+ . hr_control ( & ccdr . clocks , ccdr. peripheral . HRTIM )
6572 . wait_for_calibration ( ) ;
6673 let mut hr_control = hr_control. constrain ( ) ;
6774
@@ -91,7 +98,7 @@ fn main() -> ! {
9198 out2. enable ( ) ;
9299
93100 loop {
94- // Step frequency from 18kHz to about 180kHz (half of that when only looking at one pin)
101+ // Step frequency from 3.7kHz to about 36.6kHz (half of that when only looking at one pin)
95102 for i in 1 ..10 {
96103 let new_period = u16:: MAX / i;
97104
0 commit comments