aboutsummaryrefslogtreecommitdiff
path: root/examples/stm32f1
diff options
context:
space:
mode:
authorBruno Bousquet <[email protected]>2024-05-28 23:12:08 -0400
committerBruno Bousquet <[email protected]>2024-05-28 23:12:08 -0400
commita6c419d096bf2a4d14243fe90a7e2c1881b33fdf (patch)
treea962fe7bb634672efa854188b06c0f69a156add9 /examples/stm32f1
parentf1d5f4ca21629036f510e52aeee617ffb70db51b (diff)
add f103 example for input_capture
Diffstat (limited to 'examples/stm32f1')
-rw-r--r--examples/stm32f1/.vscode/launch.json33
-rw-r--r--examples/stm32f1/.vscode/tasks.json21
-rw-r--r--examples/stm32f1/openocd.cfg5
-rw-r--r--examples/stm32f1/openocd.gdb40
-rw-r--r--examples/stm32f1/src/bin/input_capture.rs52
5 files changed, 151 insertions, 0 deletions
diff --git a/examples/stm32f1/.vscode/launch.json b/examples/stm32f1/.vscode/launch.json
new file mode 100644
index 000000000..7d1504a39
--- /dev/null
+++ b/examples/stm32f1/.vscode/launch.json
@@ -0,0 +1,33 @@
1{
2 /*
3 * Requires the Rust Language Server (rust-analyzer) and Cortex-Debug extensions
4 * https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer
5 * https://marketplace.visualstudio.com/items?itemName=marus25.cortex-debug
6 */
7 "version": "0.2.0",
8 "configurations": [
9 {
10 /* Configuration for the STM32F446 Discovery board */
11 "type": "cortex-debug",
12 "request": "launch",
13 "name": "Debug (OpenOCD)",
14 "servertype": "openocd",
15 "cwd": "${workspaceRoot}",
16 "preLaunchTask": "Cargo Build (debug)",
17 "runToEntryPoint": "main",
18 "executable": "./target/thumbv7m-none-eabi/debug/input_capture",
19 /* Run `cargo build --example itm` and uncomment this line to run itm example */
20 // "executable": "./target/thumbv7em-none-eabihf/debug/examples/itm",
21 "device": "STM32F103TB",
22 "configFiles": [
23 "interface/stlink.cfg",
24 "target/stm32f1x.cfg"
25 ],
26 "postLaunchCommands": [
27 "monitor arm semihosting enable"
28 ],
29 "postRestartCommands": [],
30 "postResetCommands": [],
31 }
32 ]
33} \ No newline at end of file
diff --git a/examples/stm32f1/.vscode/tasks.json b/examples/stm32f1/.vscode/tasks.json
new file mode 100644
index 000000000..e153722da
--- /dev/null
+++ b/examples/stm32f1/.vscode/tasks.json
@@ -0,0 +1,21 @@
1{
2 "version": "2.0.0",
3 "tasks": [
4 {
5 "type": "cargo",
6 "command": "build",
7 "problemMatcher": [
8 "$rustc"
9 ],
10 "args": [
11 "--bin",
12 "input_capture"
13 ],
14 "group": {
15 "kind": "build",
16 "isDefault": true
17 },
18 "label": "Cargo Build (debug)",
19 }
20 ]
21} \ No newline at end of file
diff --git a/examples/stm32f1/openocd.cfg b/examples/stm32f1/openocd.cfg
new file mode 100644
index 000000000..0325cd651
--- /dev/null
+++ b/examples/stm32f1/openocd.cfg
@@ -0,0 +1,5 @@
1# Sample OpenOCD configuration for the STM32F3DISCOVERY development board
2
3source [find interface/stlink.cfg]
4
5source [find target/stm32f1x.cfg]
diff --git a/examples/stm32f1/openocd.gdb b/examples/stm32f1/openocd.gdb
new file mode 100644
index 000000000..7795319fb
--- /dev/null
+++ b/examples/stm32f1/openocd.gdb
@@ -0,0 +1,40 @@
1target extended-remote :3333
2
3# print demangled symbols
4set print asm-demangle on
5
6# set backtrace limit to not have infinite backtrace loops
7set backtrace limit 32
8
9# detect unhandled exceptions, hard faults and panics
10break DefaultHandler
11break HardFault
12break rust_begin_unwind
13# # run the next few lines so the panic message is printed immediately
14# # the number needs to be adjusted for your panic handler
15# commands $bpnum
16# next 4
17# end
18
19# *try* to stop at the user entry point (it might be gone due to inlining)
20break main
21
22monitor arm semihosting enable
23
24# # send captured ITM to the file itm.fifo
25# # (the microcontroller SWO pin must be connected to the programmer SWO pin)
26# # 8000000 must match the core clock frequency
27# monitor tpiu config internal itm.txt uart off 8000000
28
29# # OR: make the microcontroller SWO pin output compatible with UART (8N1)
30# # 8000000 must match the core clock frequency
31# # 2000000 is the frequency of the SWO pin
32# monitor tpiu config external uart off 8000000 2000000
33
34# # enable ITM port 0
35# monitor itm port 0 on
36
37load
38
39# start the process but immediately halt the processor
40stepi
diff --git a/examples/stm32f1/src/bin/input_capture.rs b/examples/stm32f1/src/bin/input_capture.rs
new file mode 100644
index 000000000..417830231
--- /dev/null
+++ b/examples/stm32f1/src/bin/input_capture.rs
@@ -0,0 +1,52 @@
1#![no_std]
2#![no_main]
3
4use defmt::*;
5use embassy_executor::Spawner;
6use embassy_stm32::gpio::{Level, Output, Pull, Speed};
7use embassy_stm32::time::khz;
8use embassy_stm32::timer::input_capture::{CapturePin, InputCapture};
9use embassy_stm32::timer::{self, Channel};
10use embassy_stm32::{bind_interrupts, peripherals};
11use embassy_time::Timer;
12use {defmt_rtt as _, panic_probe as _};
13
14/// Connect PA2 and PC13 with a 1k Ohm resistor
15
16#[embassy_executor::task]
17async fn blinky(led: peripherals::PC13) {
18 let mut led = Output::new(led, Level::High, Speed::Low);
19
20 loop {
21 info!("high");
22 led.set_high();
23 Timer::after_millis(300).await;
24
25 info!("low");
26 led.set_low();
27 Timer::after_millis(300).await;
28 }
29}
30
31bind_interrupts!(struct Irqs {
32 TIM2 => timer::CaptureCompareInterruptHandler<peripherals::TIM2>;
33});
34
35#[embassy_executor::main]
36async fn main(spawner: Spawner) {
37 let p = embassy_stm32::init(Default::default());
38 info!("Hello World!");
39
40 unwrap!(spawner.spawn(blinky(p.PC13)));
41
42 let ch3 = CapturePin::new_ch3(p.PA2, Pull::None);
43 let mut ic = InputCapture::new(p.TIM2, None, None, Some(ch3), None, Irqs, khz(1000), Default::default());
44
45 loop {
46 info!("wait for risign edge");
47 ic.wait_for_rising_edge(Channel::Ch3).await;
48
49 let capture_value = ic.get_capture_value(Channel::Ch3);
50 info!("new capture! {}", capture_value);
51 }
52}