aboutsummaryrefslogtreecommitdiff
path: root/examples/stm32f0
diff options
context:
space:
mode:
Diffstat (limited to 'examples/stm32f0')
-rw-r--r--examples/stm32f0/Cargo.toml20
-rw-r--r--examples/stm32f0/src/bin/adc-watchdog.rs34
-rw-r--r--examples/stm32f0/src/bin/button_controlled_blink.rs2
-rw-r--r--examples/stm32f0/src/bin/multiprio.rs6
4 files changed, 51 insertions, 11 deletions
diff --git a/examples/stm32f0/Cargo.toml b/examples/stm32f0/Cargo.toml
index 932a97dc8..11ecbe3c2 100644
--- a/examples/stm32f0/Cargo.toml
+++ b/examples/stm32f0/Cargo.toml
@@ -3,20 +3,26 @@ name = "embassy-stm32f0-examples"
3version = "0.1.0" 3version = "0.1.0"
4edition = "2021" 4edition = "2021"
5license = "MIT OR Apache-2.0" 5license = "MIT OR Apache-2.0"
6publish = false
6 7
7[dependencies] 8[dependencies]
8# Change stm32f091rc to your chip name, if necessary. 9# Change stm32f091rc to your chip name, if necessary.
9embassy-stm32 = { version = "0.2.0", path = "../../embassy-stm32", features = [ "defmt", "memory-x", "stm32f091rc", "time-driver-tim2", "exti", "unstable-pac"] } 10embassy-stm32 = { version = "0.4.0", path = "../../embassy-stm32", features = [ "defmt", "memory-x", "stm32f091rc", "time-driver-tim2", "exti", "unstable-pac"] }
10cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } 11cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] }
11cortex-m-rt = "0.7.0" 12cortex-m-rt = "0.7.0"
12defmt = "0.3" 13defmt = "1.0.1"
13defmt-rtt = "0.4" 14defmt-rtt = "1.0.0"
14panic-probe = { version = "0.3", features = ["print-defmt"] } 15panic-probe = { version = "1.0.0", features = ["print-defmt"] }
15embassy-sync = { version = "0.6.2", path = "../../embassy-sync", features = ["defmt"] } 16embassy-sync = { version = "0.7.2", path = "../../embassy-sync", features = ["defmt"] }
16embassy-executor = { version = "0.7.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "executor-interrupt", "defmt"] } 17embassy-executor = { version = "0.9.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "executor-interrupt", "defmt"] }
17embassy-time = { version = "0.4.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } 18embassy-time = { version = "0.5.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
18static_cell = "2" 19static_cell = "2"
19portable-atomic = { version = "1.5", features = ["unsafe-assume-single-core"] } 20portable-atomic = { version = "1.5", features = ["unsafe-assume-single-core"] }
20 21
21[profile.release] 22[profile.release]
22debug = 2 23debug = 2
24
25[package.metadata.embassy]
26build = [
27 { target = "thumbv6m-none-eabi", artifact-dir = "out/examples/stm32f0" }
28]
diff --git a/examples/stm32f0/src/bin/adc-watchdog.rs b/examples/stm32f0/src/bin/adc-watchdog.rs
new file mode 100644
index 000000000..ff98aac8e
--- /dev/null
+++ b/examples/stm32f0/src/bin/adc-watchdog.rs
@@ -0,0 +1,34 @@
1#![no_std]
2#![no_main]
3
4use defmt::*;
5use embassy_executor::Spawner;
6use embassy_stm32::adc::{self, Adc, WatchdogChannels};
7use embassy_stm32::bind_interrupts;
8use embassy_stm32::peripherals::ADC1;
9use {defmt_rtt as _, panic_probe as _};
10
11bind_interrupts!(struct Irqs {
12 ADC1_COMP => adc::InterruptHandler<ADC1>;
13});
14
15#[embassy_executor::main]
16async fn main(_spawner: Spawner) {
17 let p = embassy_stm32::init(Default::default());
18 info!("ADC watchdog example");
19
20 let mut adc = Adc::new(p.ADC1, Irqs);
21 let pin = p.PC1;
22
23 loop {
24 // Wait for pin to go high
25 adc.init_watchdog(WatchdogChannels::from_channel(&pin), 0, 0x07F);
26 let v_high = adc.monitor_watchdog().await;
27 info!("ADC sample is high {}", v_high);
28
29 // Wait for pin to go low
30 adc.init_watchdog(WatchdogChannels::from_channel(&pin), 0x01f, 0xFFF);
31 let v_low = adc.monitor_watchdog().await;
32 info!("ADC sample is low {}", v_low);
33 }
34}
diff --git a/examples/stm32f0/src/bin/button_controlled_blink.rs b/examples/stm32f0/src/bin/button_controlled_blink.rs
index 744df3e3b..f232e3290 100644
--- a/examples/stm32f0/src/bin/button_controlled_blink.rs
+++ b/examples/stm32f0/src/bin/button_controlled_blink.rs
@@ -46,7 +46,7 @@ async fn main(spawner: Spawner) {
46 BLINK_MS.store(del_var, Ordering::Relaxed); 46 BLINK_MS.store(del_var, Ordering::Relaxed);
47 47
48 // Spawn LED blinking task 48 // Spawn LED blinking task
49 spawner.spawn(led_task(p.PA5.into())).unwrap(); 49 spawner.spawn(led_task(p.PA5.into()).unwrap());
50 50
51 loop { 51 loop {
52 // Check if button got pressed 52 // Check if button got pressed
diff --git a/examples/stm32f0/src/bin/multiprio.rs b/examples/stm32f0/src/bin/multiprio.rs
index 84e4077ef..b5244afc8 100644
--- a/examples/stm32f0/src/bin/multiprio.rs
+++ b/examples/stm32f0/src/bin/multiprio.rs
@@ -134,16 +134,16 @@ fn main() -> ! {
134 // High-priority executor: USART1, priority level 6 134 // High-priority executor: USART1, priority level 6
135 interrupt::USART1.set_priority(Priority::P6); 135 interrupt::USART1.set_priority(Priority::P6);
136 let spawner = EXECUTOR_HIGH.start(interrupt::USART1); 136 let spawner = EXECUTOR_HIGH.start(interrupt::USART1);
137 unwrap!(spawner.spawn(run_high())); 137 spawner.spawn(unwrap!(run_high()));
138 138
139 // Medium-priority executor: USART2, priority level 7 139 // Medium-priority executor: USART2, priority level 7
140 interrupt::USART2.set_priority(Priority::P7); 140 interrupt::USART2.set_priority(Priority::P7);
141 let spawner = EXECUTOR_MED.start(interrupt::USART2); 141 let spawner = EXECUTOR_MED.start(interrupt::USART2);
142 unwrap!(spawner.spawn(run_med())); 142 spawner.spawn(unwrap!(run_med()));
143 143
144 // Low priority executor: runs in thread mode, using WFE/SEV 144 // Low priority executor: runs in thread mode, using WFE/SEV
145 let executor = EXECUTOR_LOW.init(Executor::new()); 145 let executor = EXECUTOR_LOW.init(Executor::new());
146 executor.run(|spawner| { 146 executor.run(|spawner| {
147 unwrap!(spawner.spawn(run_low())); 147 spawner.spawn(unwrap!(run_low()));
148 }); 148 });
149} 149}