diff options
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/stm32g4/Cargo.toml | 2 | ||||
| -rw-r--r-- | examples/stm32g4/src/bin/pwm.rs | 36 |
2 files changed, 37 insertions, 1 deletions
diff --git a/examples/stm32g4/Cargo.toml b/examples/stm32g4/Cargo.toml index 0f9d77f5e..f4378309a 100644 --- a/examples/stm32g4/Cargo.toml +++ b/examples/stm32g4/Cargo.toml | |||
| @@ -8,7 +8,7 @@ resolver = "2" | |||
| 8 | [dependencies] | 8 | [dependencies] |
| 9 | embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt"] } | 9 | embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt"] } |
| 10 | embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] } | 10 | embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] } |
| 11 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "time-driver-tim2", "stm32g491re", "memory-x", "unstable-pac"] } | 11 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "time-driver-tim3", "stm32g491re", "memory-x", "unstable-pac"] } |
| 12 | embassy-hal-common = {version = "0.1.0", path = "../../embassy-hal-common" } | 12 | embassy-hal-common = {version = "0.1.0", path = "../../embassy-hal-common" } |
| 13 | 13 | ||
| 14 | defmt = "0.3" | 14 | defmt = "0.3" |
diff --git a/examples/stm32g4/src/bin/pwm.rs b/examples/stm32g4/src/bin/pwm.rs new file mode 100644 index 000000000..1aa7b85f3 --- /dev/null +++ b/examples/stm32g4/src/bin/pwm.rs | |||
| @@ -0,0 +1,36 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | #[path = "../example_common.rs"] | ||
| 6 | mod example_common; | ||
| 7 | use embassy::executor::Spawner; | ||
| 8 | use embassy::time::{Duration, Timer}; | ||
| 9 | use embassy_stm32::gpio::NoPin; | ||
| 10 | use embassy_stm32::pwm::{Channel, Pwm}; | ||
| 11 | use embassy_stm32::time::U32Ext; | ||
| 12 | use embassy_stm32::Peripherals; | ||
| 13 | use example_common::*; | ||
| 14 | |||
| 15 | #[embassy::main] | ||
| 16 | async fn main(_spawner: Spawner, p: Peripherals) { | ||
| 17 | info!("Hello World!"); | ||
| 18 | |||
| 19 | let mut pwm = Pwm::new(p.TIM2, p.PA5, NoPin, NoPin, NoPin, 10000.hz()); | ||
| 20 | let max = pwm.get_max_duty(); | ||
| 21 | pwm.enable(Channel::Ch1); | ||
| 22 | |||
| 23 | info!("PWM initialized"); | ||
| 24 | info!("PWM max duty {}", max); | ||
| 25 | |||
| 26 | loop { | ||
| 27 | pwm.set_duty(Channel::Ch1, 0); | ||
| 28 | Timer::after(Duration::from_millis(300)).await; | ||
| 29 | pwm.set_duty(Channel::Ch1, max / 4); | ||
| 30 | Timer::after(Duration::from_millis(300)).await; | ||
| 31 | pwm.set_duty(Channel::Ch1, max / 2); | ||
| 32 | Timer::after(Duration::from_millis(300)).await; | ||
| 33 | pwm.set_duty(Channel::Ch1, max - 1); | ||
| 34 | Timer::after(Duration::from_millis(300)).await; | ||
| 35 | } | ||
| 36 | } | ||
