stm32/hrtim: add example impl.
This commit is contained in:
parent
348019e37f
commit
3252eaa060
1
.vscode/settings.json
vendored
1
.vscode/settings.json
vendored
@ -25,6 +25,7 @@
|
|||||||
// "examples/stm32f1/Cargo.toml",
|
// "examples/stm32f1/Cargo.toml",
|
||||||
// "examples/stm32f2/Cargo.toml",
|
// "examples/stm32f2/Cargo.toml",
|
||||||
// "examples/stm32f3/Cargo.toml",
|
// "examples/stm32f3/Cargo.toml",
|
||||||
|
// "examples/stm32f334/Cargo.toml",
|
||||||
// "examples/stm32f4/Cargo.toml",
|
// "examples/stm32f4/Cargo.toml",
|
||||||
// "examples/stm32f7/Cargo.toml",
|
// "examples/stm32f7/Cargo.toml",
|
||||||
// "examples/stm32g0/Cargo.toml",
|
// "examples/stm32g0/Cargo.toml",
|
||||||
|
1
ci.sh
1
ci.sh
@ -119,6 +119,7 @@ cargo batch \
|
|||||||
--- build --release --manifest-path examples/stm32f1/Cargo.toml --target thumbv7m-none-eabi --out-dir out/examples/stm32f1 \
|
--- build --release --manifest-path examples/stm32f1/Cargo.toml --target thumbv7m-none-eabi --out-dir out/examples/stm32f1 \
|
||||||
--- build --release --manifest-path examples/stm32f2/Cargo.toml --target thumbv7m-none-eabi --out-dir out/examples/stm32f2 \
|
--- build --release --manifest-path examples/stm32f2/Cargo.toml --target thumbv7m-none-eabi --out-dir out/examples/stm32f2 \
|
||||||
--- build --release --manifest-path examples/stm32f3/Cargo.toml --target thumbv7em-none-eabihf --out-dir out/examples/stm32f3 \
|
--- build --release --manifest-path examples/stm32f3/Cargo.toml --target thumbv7em-none-eabihf --out-dir out/examples/stm32f3 \
|
||||||
|
--- build --release --manifest-path examples/stm32f334/Cargo.toml --target thumbv7em-none-eabihf --out-dir out/examples/stm32f334 \
|
||||||
--- build --release --manifest-path examples/stm32f4/Cargo.toml --target thumbv7em-none-eabi --out-dir out/examples/stm32f4 \
|
--- build --release --manifest-path examples/stm32f4/Cargo.toml --target thumbv7em-none-eabi --out-dir out/examples/stm32f4 \
|
||||||
--- build --release --manifest-path examples/stm32f7/Cargo.toml --target thumbv7em-none-eabihf --out-dir out/examples/stm32f7 \
|
--- build --release --manifest-path examples/stm32f7/Cargo.toml --target thumbv7em-none-eabihf --out-dir out/examples/stm32f7 \
|
||||||
--- build --release --manifest-path examples/stm32c0/Cargo.toml --target thumbv6m-none-eabi --out-dir out/examples/stm32c0 \
|
--- build --release --manifest-path examples/stm32c0/Cargo.toml --target thumbv6m-none-eabi --out-dir out/examples/stm32c0 \
|
||||||
|
@ -52,7 +52,7 @@ pub struct ComplementaryPwmPin<'d, Perip, Channel> {
|
|||||||
macro_rules! advanced_channel_impl {
|
macro_rules! advanced_channel_impl {
|
||||||
($new_chx:ident, $channel:tt, $ch_num:expr, $pin_trait:ident, $complementary_pin_trait:ident) => {
|
($new_chx:ident, $channel:tt, $ch_num:expr, $pin_trait:ident, $complementary_pin_trait:ident) => {
|
||||||
impl<'d, Perip: AdvancedCaptureCompare16bitInstance> PwmPin<'d, Perip, $channel<Perip>> {
|
impl<'d, Perip: AdvancedCaptureCompare16bitInstance> PwmPin<'d, Perip, $channel<Perip>> {
|
||||||
pub fn $new_chx(pin: impl Peripheral<P = impl $complementary_pin_trait<Perip>> + 'd) -> Self {
|
pub fn $new_chx(pin: impl Peripheral<P = impl $pin_trait<Perip>> + 'd) -> Self {
|
||||||
into_ref!(pin);
|
into_ref!(pin);
|
||||||
critical_section::with(|_| {
|
critical_section::with(|_| {
|
||||||
pin.set_low();
|
pin.set_low();
|
||||||
|
9
examples/stm32f334/.cargo/config.toml
Normal file
9
examples/stm32f334/.cargo/config.toml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
|
||||||
|
# replace STM32F429ZITx with your chip as listed in `probe-rs-cli chip list`
|
||||||
|
runner = "probe-rs-cli run --chip STM32F303ZETx"
|
||||||
|
|
||||||
|
[build]
|
||||||
|
target = "thumbv7em-none-eabihf"
|
||||||
|
|
||||||
|
[env]
|
||||||
|
DEFMT_LOG = "trace"
|
26
examples/stm32f334/Cargo.toml
Normal file
26
examples/stm32f334/Cargo.toml
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
[package]
|
||||||
|
edition = "2021"
|
||||||
|
name = "embassy-stm32f3-examples"
|
||||||
|
version = "0.1.0"
|
||||||
|
license = "MIT OR Apache-2.0"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
|
||||||
|
embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] }
|
||||||
|
embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
|
||||||
|
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f334r8", "unstable-pac", "memory-x", "time-driver-any", "exti"] }
|
||||||
|
embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] }
|
||||||
|
embassy-futures = { version = "0.1.0", path = "../../embassy-futures" }
|
||||||
|
|
||||||
|
defmt = "0.3"
|
||||||
|
defmt-rtt = "0.4"
|
||||||
|
|
||||||
|
cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] }
|
||||||
|
cortex-m-rt = "0.7.0"
|
||||||
|
embedded-hal = "0.2.6"
|
||||||
|
panic-probe = { version = "0.3", features = ["print-defmt"] }
|
||||||
|
futures = { version = "0.3.17", default-features = false, features = ["async-await"] }
|
||||||
|
heapless = { version = "0.7.5", default-features = false }
|
||||||
|
nb = "1.0.0"
|
||||||
|
embedded-storage = "0.3.0"
|
||||||
|
static_cell = { version = "1.1", features = ["nightly"]}
|
5
examples/stm32f334/build.rs
Normal file
5
examples/stm32f334/build.rs
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
fn main() {
|
||||||
|
println!("cargo:rustc-link-arg-bins=--nmagic");
|
||||||
|
println!("cargo:rustc-link-arg-bins=-Tlink.x");
|
||||||
|
println!("cargo:rustc-link-arg-bins=-Tdefmt.x");
|
||||||
|
}
|
23
examples/stm32f334/src/bin/hello.rs
Normal file
23
examples/stm32f334/src/bin/hello.rs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#![no_std]
|
||||||
|
#![no_main]
|
||||||
|
#![feature(type_alias_impl_trait)]
|
||||||
|
|
||||||
|
use defmt::info;
|
||||||
|
use embassy_executor::Spawner;
|
||||||
|
use embassy_stm32::time::Hertz;
|
||||||
|
use embassy_stm32::Config;
|
||||||
|
use embassy_time::{Duration, Timer};
|
||||||
|
use {defmt_rtt as _, panic_probe as _};
|
||||||
|
|
||||||
|
#[embassy_executor::main]
|
||||||
|
async fn main(_spawner: Spawner) -> ! {
|
||||||
|
let mut config = Config::default();
|
||||||
|
config.rcc.hse = Some(Hertz(8_000_000));
|
||||||
|
config.rcc.sysclk = Some(Hertz(16_000_000));
|
||||||
|
let _p = embassy_stm32::init(config);
|
||||||
|
|
||||||
|
loop {
|
||||||
|
info!("Hello World!");
|
||||||
|
Timer::after(Duration::from_secs(1)).await;
|
||||||
|
}
|
||||||
|
}
|
63
examples/stm32f334/src/bin/pwm.rs
Normal file
63
examples/stm32f334/src/bin/pwm.rs
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
#![no_std]
|
||||||
|
#![no_main]
|
||||||
|
#![feature(type_alias_impl_trait)]
|
||||||
|
|
||||||
|
use defmt::*;
|
||||||
|
use embassy_executor::Spawner;
|
||||||
|
use embassy_stm32::pwm::advanced_pwm::*;
|
||||||
|
use embassy_stm32::pwm::Channel;
|
||||||
|
use embassy_stm32::time::khz;
|
||||||
|
use embassy_time::{Duration, Timer};
|
||||||
|
use {defmt_rtt as _, panic_probe as _};
|
||||||
|
|
||||||
|
#[embassy_executor::main]
|
||||||
|
async fn main(_spawner: Spawner) {
|
||||||
|
let p = embassy_stm32::init(Default::default());
|
||||||
|
info!("Hello World!");
|
||||||
|
|
||||||
|
let ch1 = PwmPin::new_cha(p.PA8);
|
||||||
|
let ch1n = ComplementaryPwmPin::new_cha(p.PA9);
|
||||||
|
let mut pwm = AdvancedPwm::new(
|
||||||
|
p.HRTIM1,
|
||||||
|
Some(ch1),
|
||||||
|
Some(ch1n),
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
);
|
||||||
|
|
||||||
|
pwm.set_dead_time(0);
|
||||||
|
|
||||||
|
let mut buck_converter = BridgeConverter::new(pwm.ch_a, khz(100));
|
||||||
|
|
||||||
|
buck_converter.set_duty(0, u16::MAX);
|
||||||
|
|
||||||
|
// note: if the pins are not passed into the advanced pwm struct, they will not be output
|
||||||
|
let mut boost_converter = BridgeConverter::new(pwm.ch_b, khz(100));
|
||||||
|
|
||||||
|
boost_converter.set_duty(0, 0);
|
||||||
|
|
||||||
|
// let max = pwm.get_max_duty();
|
||||||
|
// pwm.set_dead_time(max / 1024);
|
||||||
|
//
|
||||||
|
// pwm.enable(Channel::Ch1);
|
||||||
|
//
|
||||||
|
// info!("PWM initialized");
|
||||||
|
// info!("PWM max duty {}", max);
|
||||||
|
//
|
||||||
|
// loop {
|
||||||
|
// pwm.set_duty(Channel::Ch1, 0);
|
||||||
|
// Timer::after(Duration::from_millis(300)).await;
|
||||||
|
// pwm.set_duty(Channel::Ch1, max / 4);
|
||||||
|
// Timer::after(Duration::from_millis(300)).await;
|
||||||
|
// pwm.set_duty(Channel::Ch1, max / 2);
|
||||||
|
// Timer::after(Duration::from_millis(300)).await;
|
||||||
|
// pwm.set_duty(Channel::Ch1, max - 1);
|
||||||
|
// Timer::after(Duration::from_millis(300)).await;
|
||||||
|
// }
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user