Skip to content

Commit fcdb480

Browse files
committed
Add example and support for all timers
1 parent 9c06092 commit fcdb480

File tree

3 files changed

+555
-16
lines changed

3 files changed

+555
-16
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1414
### Added
1515

1616
- Implement `timer::Cancel` trait for `Timer<SYST>`.
17+
- Added PWM support and example.
1718

1819
## [v0.7.0] - 2020-03-07
1920

examples/pwm.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#![deny(unsafe_code)]
2+
#![no_main]
3+
#![no_std]
4+
5+
// Halt on panic
6+
use panic_halt as _;
7+
8+
use cortex_m;
9+
use cortex_m_rt::entry;
10+
use stm32f4xx_hal::{prelude::*, pwm, stm32};
11+
12+
#[entry]
13+
fn main() -> ! {
14+
if let Some(dp) = stm32::Peripherals::take() {
15+
// Set up the system clock.
16+
let rcc = dp.RCC.constrain();
17+
let clocks = rcc.cfgr.freeze();
18+
19+
let gpioa = dp.GPIOA.split();
20+
let channels = (
21+
gpioa.pa8.into_alternate_af1(),
22+
gpioa.pa9.into_alternate_af1(),
23+
);
24+
25+
let pwm = pwm::tim1(dp.TIM1, channels, clocks, 20u32.khz());
26+
let (mut ch1, _ch2) = pwm;
27+
let max_duty = ch1.get_max_duty();
28+
ch1.set_duty(max_duty / 2);
29+
ch1.enable();
30+
}
31+
32+
loop {
33+
cortex_m::asm::nop();
34+
}
35+
}

0 commit comments

Comments
 (0)