File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change
1
+ #![ deny( unsafe_code) ]
2
+ #![ deny( warnings) ]
3
+ #![ no_main]
4
+ #![ no_std]
5
+
6
+ // Halt on panic
7
+ use panic_halt as _; // panic handler
8
+
9
+ use cortex_m_rt:: entry;
10
+ use stm32f4xx_hal as hal;
11
+
12
+ use crate :: hal:: { pac, prelude:: * , timer:: Channel , timer:: Polarity } ;
13
+
14
+ #[ entry]
15
+ fn main ( ) -> ! {
16
+ if let Some ( dp) = pac:: Peripherals :: take ( ) {
17
+ // Set up the system clock. We want to run at 84MHz for this one.
18
+ let rcc = dp. RCC . constrain ( ) ;
19
+ let clocks = rcc. cfgr . sysclk ( 25 . MHz ( ) ) . freeze ( ) ;
20
+
21
+ let gpioa = dp. GPIOA . split ( ) ;
22
+
23
+ let channels = ( gpioa. pa8 . into_alternate ( ) , gpioa. pa7 . into_alternate ( ) ) ;
24
+
25
+ let mut pwm = dp. TIM1 . pwm_hz ( channels, 20 . kHz ( ) , & clocks) ;
26
+
27
+ let max_duty: u16 = pwm. get_max_duty ( ) ;
28
+
29
+ pwm. set_polarity ( Channel :: C1 , Polarity :: ActiveHigh ) ;
30
+ pwm. set_complementary_polarity ( Channel :: C1 , Polarity :: ActiveHigh ) ;
31
+
32
+ pwm. set_duty ( Channel :: C1 , max_duty / 2 ) ;
33
+
34
+ pwm. set_dead_time ( 200 ) ;
35
+
36
+ pwm. enable ( Channel :: C1 ) ;
37
+ pwm. enable_complementary ( Channel :: C1 ) ;
38
+
39
+ }
40
+
41
+ loop {
42
+ cortex_m:: asm:: nop ( ) ;
43
+ }
44
+ }
45
+
You can’t perform that action at this time.
0 commit comments