aboutsummaryrefslogtreecommitdiff
path: root/tests/stm32/src/bin
diff options
context:
space:
mode:
Diffstat (limited to 'tests/stm32/src/bin')
-rw-r--r--tests/stm32/src/bin/hsem.rs47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/stm32/src/bin/hsem.rs b/tests/stm32/src/bin/hsem.rs
new file mode 100644
index 000000000..19648997c
--- /dev/null
+++ b/tests/stm32/src/bin/hsem.rs
@@ -0,0 +1,47 @@
1// required-features: hsem
2#![no_std]
3#![no_main]
4
5#[path = "../common.rs"]
6mod common;
7
8use common::*;
9use embassy_executor::Spawner;
10use embassy_stm32::bind_interrupts;
11use embassy_stm32::hsem::{HardwareSemaphore, HardwareSemaphoreInterruptHandler};
12use embassy_stm32::peripherals::HSEM;
13
14bind_interrupts!(struct Irqs{
15 HSEM => HardwareSemaphoreInterruptHandler<HSEM>;
16});
17
18#[embassy_executor::main]
19async fn main(_spawner: Spawner) {
20 let p: embassy_stm32::Peripherals = init();
21
22 let hsem = HardwareSemaphore::new(p.HSEM, Irqs);
23
24 // if hsem.channel_for(SemaphoreNumber::Channel5).is_semaphore_locked() {
25 // defmt::panic!("Semaphore 5 already locked!")
26 // }
27 //
28 // hsem.channel_for(SemaphoreNumber::Channel5).one_step_lock().unwrap();
29 // hsem.channel_for(SemaphoreNumber::Channel1).two_step_lock(0).unwrap();
30 //
31 // hsem.channel_for(SemaphoreNumber::Channel5).unlock(0);
32
33 let [_channel1, _channel2, _channel3, _channel4, mut channel5, _channel6] = hsem.split();
34
35 info!("Locking channel 5");
36
37 let mutex = channel5.lock(0).await;
38
39 info!("Locked channel 5");
40
41 drop(mutex);
42
43 info!("Unlocked channel 5");
44
45 info!("Test OK");
46 cortex_m::asm::bkpt();
47}