aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.vscode/settings.json1
-rwxr-xr-xci.sh1
-rw-r--r--embassy-stm32/src/pwm/advanced_pwm.rs2
-rw-r--r--examples/stm32f334/.cargo/config.toml9
-rw-r--r--examples/stm32f334/Cargo.toml26
-rw-r--r--examples/stm32f334/build.rs5
-rw-r--r--examples/stm32f334/src/bin/hello.rs23
-rw-r--r--examples/stm32f334/src/bin/pwm.rs63
8 files changed, 129 insertions, 1 deletions
diff --git a/.vscode/settings.json b/.vscode/settings.json
index 9ef7fe1ce..fdfafafa9 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -25,6 +25,7 @@
25 // "examples/stm32f1/Cargo.toml", 25 // "examples/stm32f1/Cargo.toml",
26 // "examples/stm32f2/Cargo.toml", 26 // "examples/stm32f2/Cargo.toml",
27 // "examples/stm32f3/Cargo.toml", 27 // "examples/stm32f3/Cargo.toml",
28 // "examples/stm32f334/Cargo.toml",
28 // "examples/stm32f4/Cargo.toml", 29 // "examples/stm32f4/Cargo.toml",
29 // "examples/stm32f7/Cargo.toml", 30 // "examples/stm32f7/Cargo.toml",
30 // "examples/stm32g0/Cargo.toml", 31 // "examples/stm32g0/Cargo.toml",
diff --git a/ci.sh b/ci.sh
index a03efb856..ec6304f16 100755
--- a/ci.sh
+++ b/ci.sh
@@ -119,6 +119,7 @@ cargo batch \
119 --- build --release --manifest-path examples/stm32f1/Cargo.toml --target thumbv7m-none-eabi --out-dir out/examples/stm32f1 \ 119 --- build --release --manifest-path examples/stm32f1/Cargo.toml --target thumbv7m-none-eabi --out-dir out/examples/stm32f1 \
120 --- build --release --manifest-path examples/stm32f2/Cargo.toml --target thumbv7m-none-eabi --out-dir out/examples/stm32f2 \ 120 --- build --release --manifest-path examples/stm32f2/Cargo.toml --target thumbv7m-none-eabi --out-dir out/examples/stm32f2 \
121 --- build --release --manifest-path examples/stm32f3/Cargo.toml --target thumbv7em-none-eabihf --out-dir out/examples/stm32f3 \ 121 --- build --release --manifest-path examples/stm32f3/Cargo.toml --target thumbv7em-none-eabihf --out-dir out/examples/stm32f3 \
122 --- build --release --manifest-path examples/stm32f334/Cargo.toml --target thumbv7em-none-eabihf --out-dir out/examples/stm32f334 \
122 --- build --release --manifest-path examples/stm32f4/Cargo.toml --target thumbv7em-none-eabi --out-dir out/examples/stm32f4 \ 123 --- build --release --manifest-path examples/stm32f4/Cargo.toml --target thumbv7em-none-eabi --out-dir out/examples/stm32f4 \
123 --- build --release --manifest-path examples/stm32f7/Cargo.toml --target thumbv7em-none-eabihf --out-dir out/examples/stm32f7 \ 124 --- build --release --manifest-path examples/stm32f7/Cargo.toml --target thumbv7em-none-eabihf --out-dir out/examples/stm32f7 \
124 --- build --release --manifest-path examples/stm32c0/Cargo.toml --target thumbv6m-none-eabi --out-dir out/examples/stm32c0 \ 125 --- build --release --manifest-path examples/stm32c0/Cargo.toml --target thumbv6m-none-eabi --out-dir out/examples/stm32c0 \
diff --git a/embassy-stm32/src/pwm/advanced_pwm.rs b/embassy-stm32/src/pwm/advanced_pwm.rs
index c7b5f7482..bb0e06ad5 100644
--- a/embassy-stm32/src/pwm/advanced_pwm.rs
+++ b/embassy-stm32/src/pwm/advanced_pwm.rs
@@ -52,7 +52,7 @@ pub struct ComplementaryPwmPin<'d, Perip, Channel> {
52macro_rules! advanced_channel_impl { 52macro_rules! advanced_channel_impl {
53 ($new_chx:ident, $channel:tt, $ch_num:expr, $pin_trait:ident, $complementary_pin_trait:ident) => { 53 ($new_chx:ident, $channel:tt, $ch_num:expr, $pin_trait:ident, $complementary_pin_trait:ident) => {
54 impl<'d, Perip: AdvancedCaptureCompare16bitInstance> PwmPin<'d, Perip, $channel<Perip>> { 54 impl<'d, Perip: AdvancedCaptureCompare16bitInstance> PwmPin<'d, Perip, $channel<Perip>> {
55 pub fn $new_chx(pin: impl Peripheral<P = impl $complementary_pin_trait<Perip>> + 'd) -> Self { 55 pub fn $new_chx(pin: impl Peripheral<P = impl $pin_trait<Perip>> + 'd) -> Self {
56 into_ref!(pin); 56 into_ref!(pin);
57 critical_section::with(|_| { 57 critical_section::with(|_| {
58 pin.set_low(); 58 pin.set_low();
diff --git a/examples/stm32f334/.cargo/config.toml b/examples/stm32f334/.cargo/config.toml
new file mode 100644
index 000000000..7f3fda529
--- /dev/null
+++ b/examples/stm32f334/.cargo/config.toml
@@ -0,0 +1,9 @@
1[target.'cfg(all(target_arch = "arm", target_os = "none"))']
2# replace STM32F429ZITx with your chip as listed in `probe-rs-cli chip list`
3runner = "probe-rs-cli run --chip STM32F303ZETx"
4
5[build]
6target = "thumbv7em-none-eabihf"
7
8[env]
9DEFMT_LOG = "trace"
diff --git a/examples/stm32f334/Cargo.toml b/examples/stm32f334/Cargo.toml
new file mode 100644
index 000000000..6410891a1
--- /dev/null
+++ b/examples/stm32f334/Cargo.toml
@@ -0,0 +1,26 @@
1[package]
2edition = "2021"
3name = "embassy-stm32f3-examples"
4version = "0.1.0"
5license = "MIT OR Apache-2.0"
6
7[dependencies]
8embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
9embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] }
10embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
11embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f334r8", "unstable-pac", "memory-x", "time-driver-any", "exti"] }
12embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] }
13embassy-futures = { version = "0.1.0", path = "../../embassy-futures" }
14
15defmt = "0.3"
16defmt-rtt = "0.4"
17
18cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] }
19cortex-m-rt = "0.7.0"
20embedded-hal = "0.2.6"
21panic-probe = { version = "0.3", features = ["print-defmt"] }
22futures = { version = "0.3.17", default-features = false, features = ["async-await"] }
23heapless = { version = "0.7.5", default-features = false }
24nb = "1.0.0"
25embedded-storage = "0.3.0"
26static_cell = { version = "1.1", features = ["nightly"]}
diff --git a/examples/stm32f334/build.rs b/examples/stm32f334/build.rs
new file mode 100644
index 000000000..8cd32d7ed
--- /dev/null
+++ b/examples/stm32f334/build.rs
@@ -0,0 +1,5 @@
1fn main() {
2 println!("cargo:rustc-link-arg-bins=--nmagic");
3 println!("cargo:rustc-link-arg-bins=-Tlink.x");
4 println!("cargo:rustc-link-arg-bins=-Tdefmt.x");
5}
diff --git a/examples/stm32f334/src/bin/hello.rs b/examples/stm32f334/src/bin/hello.rs
new file mode 100644
index 000000000..65773210d
--- /dev/null
+++ b/examples/stm32f334/src/bin/hello.rs
@@ -0,0 +1,23 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5use defmt::info;
6use embassy_executor::Spawner;
7use embassy_stm32::time::Hertz;
8use embassy_stm32::Config;
9use embassy_time::{Duration, Timer};
10use {defmt_rtt as _, panic_probe as _};
11
12#[embassy_executor::main]
13async fn main(_spawner: Spawner) -> ! {
14 let mut config = Config::default();
15 config.rcc.hse = Some(Hertz(8_000_000));
16 config.rcc.sysclk = Some(Hertz(16_000_000));
17 let _p = embassy_stm32::init(config);
18
19 loop {
20 info!("Hello World!");
21 Timer::after(Duration::from_secs(1)).await;
22 }
23}
diff --git a/examples/stm32f334/src/bin/pwm.rs b/examples/stm32f334/src/bin/pwm.rs
new file mode 100644
index 000000000..cc2ea8617
--- /dev/null
+++ b/examples/stm32f334/src/bin/pwm.rs
@@ -0,0 +1,63 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5use defmt::*;
6use embassy_executor::Spawner;
7use embassy_stm32::pwm::advanced_pwm::*;
8use embassy_stm32::pwm::Channel;
9use embassy_stm32::time::khz;
10use embassy_time::{Duration, Timer};
11use {defmt_rtt as _, panic_probe as _};
12
13#[embassy_executor::main]
14async fn main(_spawner: Spawner) {
15 let p = embassy_stm32::init(Default::default());
16 info!("Hello World!");
17
18 let ch1 = PwmPin::new_cha(p.PA8);
19 let ch1n = ComplementaryPwmPin::new_cha(p.PA9);
20 let mut pwm = AdvancedPwm::new(
21 p.HRTIM1,
22 Some(ch1),
23 Some(ch1n),
24 None,
25 None,
26 None,
27 None,
28 None,
29 None,
30 None,
31 None,
32 );
33
34 pwm.set_dead_time(0);
35
36 let mut buck_converter = BridgeConverter::new(pwm.ch_a, khz(100));
37
38 buck_converter.set_duty(0, u16::MAX);
39
40 // note: if the pins are not passed into the advanced pwm struct, they will not be output
41 let mut boost_converter = BridgeConverter::new(pwm.ch_b, khz(100));
42
43 boost_converter.set_duty(0, 0);
44
45 // let max = pwm.get_max_duty();
46 // pwm.set_dead_time(max / 1024);
47 //
48 // pwm.enable(Channel::Ch1);
49 //
50 // info!("PWM initialized");
51 // info!("PWM max duty {}", max);
52 //
53 // loop {
54 // pwm.set_duty(Channel::Ch1, 0);
55 // Timer::after(Duration::from_millis(300)).await;
56 // pwm.set_duty(Channel::Ch1, max / 4);
57 // Timer::after(Duration::from_millis(300)).await;
58 // pwm.set_duty(Channel::Ch1, max / 2);
59 // Timer::after(Duration::from_millis(300)).await;
60 // pwm.set_duty(Channel::Ch1, max - 1);
61 // Timer::after(Duration::from_millis(300)).await;
62 // }
63}