aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2023-07-28 22:44:03 +0000
committerGitHub <[email protected]>2023-07-28 22:44:03 +0000
commitbdc4aa4a3beeeecb9860644f8421bba6c8ab0cf2 (patch)
tree593ede68752ae7bae4ccf2302c3082622bf74d06 /examples
parentcc414e63d3b7aec7da07d9097cf8a78b5d55a73a (diff)
parent5bb5654d847b8d7a15f242d4b4078369a1b7285f (diff)
Merge pull request #1582 from xoviat/hrtim
Add the high resolution timer
Diffstat (limited to 'examples')
-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/button.rs27
-rw-r--r--examples/stm32f334/src/bin/hello.rs23
-rw-r--r--examples/stm32f334/src/bin/pwm.rs71
6 files changed, 161 insertions, 0 deletions
diff --git a/examples/stm32f334/.cargo/config.toml b/examples/stm32f334/.cargo/config.toml
new file mode 100644
index 000000000..caf947be6
--- /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-run --chip STM32F334R8"
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/button.rs b/examples/stm32f334/src/bin/button.rs
new file mode 100644
index 000000000..599c0f27d
--- /dev/null
+++ b/examples/stm32f334/src/bin/button.rs
@@ -0,0 +1,27 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5use defmt::*;
6use embassy_executor::Spawner;
7use embassy_stm32::gpio::{Level, Output, Speed};
8use embassy_time::{Duration, Timer};
9use {defmt_rtt as _, panic_probe as _};
10
11#[embassy_executor::main]
12async fn main(_spawner: Spawner) {
13 info!("Hello World!");
14
15 let p = embassy_stm32::init(Default::default());
16
17 let mut out1 = Output::new(p.PA8, Level::Low, Speed::High);
18
19 out1.set_high();
20 Timer::after(Duration::from_millis(500)).await;
21 out1.set_low();
22
23 Timer::after(Duration::from_millis(500)).await;
24 info!("end program");
25
26 cortex_m::asm::bkpt();
27}
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..2660b10c5
--- /dev/null
+++ b/examples/stm32f334/src/bin/pwm.rs
@@ -0,0 +1,71 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5use defmt::*;
6use embassy_executor::Spawner;
7use embassy_stm32::hrtim::*;
8use embassy_stm32::time::{khz, mhz};
9use embassy_stm32::Config;
10use embassy_time::{Duration, Timer};
11use {defmt_rtt as _, panic_probe as _};
12
13#[embassy_executor::main]
14async fn main(_spawner: Spawner) {
15 let mut config: Config = Default::default();
16 config.rcc.sysclk = Some(mhz(64));
17 config.rcc.hclk = Some(mhz(64));
18 config.rcc.pclk1 = Some(mhz(32));
19 config.rcc.pclk2 = Some(mhz(64));
20
21 let p = embassy_stm32::init(config);
22 info!("Hello World!");
23
24 let ch1 = PwmPin::new_cha(p.PA8);
25 let ch1n = ComplementaryPwmPin::new_cha(p.PA9);
26 let pwm = AdvancedPwm::new(
27 p.HRTIM1,
28 Some(ch1),
29 Some(ch1n),
30 None,
31 None,
32 None,
33 None,
34 None,
35 None,
36 None,
37 None,
38 );
39
40 info!("pwm constructed");
41
42 let mut buck_converter = BridgeConverter::new(pwm.ch_a, khz(5));
43
44 // embassy_stm32::pac::HRTIM1
45 // .tim(0)
46 // .setr(0)
47 // .modify(|w| w.set_sst(Activeeffect::SETACTIVE));
48 //
49 // Timer::after(Duration::from_millis(500)).await;
50 //
51 // embassy_stm32::pac::HRTIM1
52 // .tim(0)
53 // .rstr(0)
54 // .modify(|w| w.set_srt(Inactiveeffect::SETINACTIVE));
55
56 let max_duty = buck_converter.get_max_compare_value();
57
58 info!("max compare value: {}", max_duty);
59
60 buck_converter.set_dead_time(max_duty / 20);
61 buck_converter.set_primary_duty(max_duty / 2);
62 buck_converter.set_secondary_duty(3 * max_duty / 4);
63
64 buck_converter.start();
65
66 Timer::after(Duration::from_millis(500)).await;
67
68 info!("end program");
69
70 cortex_m::asm::bkpt();
71}