-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
138: PWM support r=therealprof a=jonfin Add PWM support based on the stm32f4xx_hal implementation. It is mostly a copy from stm32f4xx_hal with some modification. Only change to stm32f4xx_hal: it uses the recommended order for setting the register from DM00042534 I did some testing based on a stm32f030c8 chip. fixes #26 Co-authored-by: Jonas <jonas@finger-ling.de>
- Loading branch information
Showing
5 changed files
with
816 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#![deny(unsafe_code)] | ||
#![no_main] | ||
#![no_std] | ||
|
||
// Halt on panic | ||
use panic_halt as _; | ||
|
||
use cortex_m_rt::entry; | ||
|
||
use stm32f0xx_hal as hal; | ||
|
||
use hal::{pac, prelude::*, pwm}; | ||
|
||
#[entry] | ||
fn main() -> ! { | ||
if let Some(mut dp) = pac::Peripherals::take() { | ||
// Set up the system clock. | ||
let mut rcc = dp.RCC.configure().sysclk(8.mhz()).freeze(&mut dp.FLASH); | ||
|
||
let gpioa = dp.GPIOA.split(&mut rcc); | ||
let channels = cortex_m::interrupt::free(move |cs| { | ||
( | ||
gpioa.pa8.into_alternate_af2(cs), | ||
gpioa.pa9.into_alternate_af2(cs), | ||
) | ||
}); | ||
|
||
let pwm = pwm::tim1(dp.TIM1, channels, &mut rcc, 20u32.khz()); | ||
let (mut ch1, _ch2) = pwm; | ||
let max_duty = ch1.get_max_duty(); | ||
ch1.set_duty(max_duty / 2); | ||
ch1.enable(); | ||
} | ||
|
||
loop { | ||
cortex_m::asm::nop(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.