File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change
1
+ //This example puts the timer in PWM mode using the specified pin with a frequency of 100Hz and a duty cycle of 50%.
2
+ #![ no_main]
3
+ #![ no_std]
4
+
5
+ use cortex_m_rt:: entry;
6
+ use hal:: gpio:: gpioa:: PA8 ;
7
+ use hal:: gpio:: Alternate ;
8
+ use hal:: gpio:: AF6 ;
9
+ use hal:: prelude:: * ;
10
+ use hal:: stm32;
11
+ use stm32g4xx_hal as hal;
12
+ mod utils;
13
+ extern crate cortex_m_rt as rt;
14
+
15
+ #[ entry]
16
+ fn main ( ) -> ! {
17
+ let dp = stm32:: Peripherals :: take ( ) . expect ( "cannot take peripherals" ) ;
18
+ let mut rcc = dp. RCC . constrain ( ) ;
19
+ let gpioa = dp. GPIOA . split ( & mut rcc) ;
20
+ let pin: PA8 < Alternate < AF6 > > = gpioa. pa8 . into_alternate ( ) ;
21
+
22
+ let mut pwm = dp. TIM1 . pwm ( pin, 100 . hz ( ) , & mut rcc) ;
23
+
24
+ pwm. set_duty ( pwm. get_max_duty ( ) / 2 ) ;
25
+ pwm. enable ( ) ;
26
+
27
+ loop {
28
+ cortex_m:: asm:: nop ( )
29
+ }
30
+ }
You can’t perform that action at this time.
0 commit comments