Skip to content

Commit 29e1630

Browse files
committed
update package
- Add embassy example - improve timer API - restructure examples
1 parent 405cc08 commit 29e1630

File tree

24 files changed

+781
-181
lines changed

24 files changed

+781
-181
lines changed

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ members = [
55
"va108xx",
66
"va108xx-hal",
77
"examples/simple",
8+
"examples/rtic",
9+
"examples/embassy",
810
"board-tests",
911
]
1012

README.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,13 @@ This workspace contains the following released crates:
1919

2020
It also contains the following helper crates:
2121

22-
- The `board-tests` contains an application which can be used to test the libraries on the
23-
board.
24-
- The `examples` crates contains various example applications for the HAL and the PAC.
22+
- The [`board-tests`](https://egit.irs.uni-stuttgart.de/rust/va108xx-rs/src/branch/main/board-tests)
23+
contains an application which can be used to test the libraries on the board.
24+
- The [`examples`](https://egit.irs.uni-stuttgart.de/rust/va108xx-rs/src/branch/main/examples)
25+
folder contains various example applications crates using the HAL and the PAC.
26+
This folder also contains dedicated example applications using the
27+
[`RTIC`](https://rtic.rs/2/book/en/) and [`embassy`](https://github.com/embassy-rs/embassy)
28+
native Rust RTOSes.
2529

2630
## Using the `.cargo/config.toml` file
2731

@@ -94,6 +98,8 @@ example.
9498

9599
Assuming a working debug connection to your VA108xx board, you can debug using VS Code with
96100
the [`Cortex-Debug` plugin](https://marketplace.visualstudio.com/items?itemName=marus25.cortex-debug).
101+
Please make sure that [`objdump-multiarch` and `nm-multiarch`](https://forums.raspberrypi.com/viewtopic.php?t=333146)
102+
are installed as well.
97103

98104
Some sample configuration files for VS code were provided and can be used by running
99105
`cp -rT vscode .vscode` like specified above. After that, you can use `Run and Debug`
@@ -108,4 +114,5 @@ configuration variables in your `settings.json`:
108114
- `"cortex-debug.gdbPath.osx"`
109115

110116
The provided VS Code configurations also provide an integrated RTT logger, which you can access
111-
via the terminal at `RTT Ch:0 console`.
117+
via the terminal at `RTT Ch:0 console`. In order for the RTT block address detection to
118+
work properly, `objdump-multiarch` and `nm-multiarch` need to be installed.

board-tests/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ version = "0.1.0"
44
edition = "2021"
55

66
[dependencies]
7-
cortex-m-rtic = "1"
8-
panic-halt = "0.2"
97
cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }
108
cortex-m-rt = "0.7"
9+
panic-halt = "0.2"
1110
rtt-target = "0.5"
1211
panic-rtt-target = "0.1.3"
1312
embedded-hal = "1"

examples/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
VA108xx Example Applications
2+
========
3+
4+
This folder contains various examples
5+
Consult the main README first for setup of the repository.
6+
7+
## Simple examples
8+
9+
```rs
10+
cargo run --example blinky
11+
```
12+
13+
You can have a look at the `simple/examples` folder to see all available simple examples
14+
15+
## RTIC example
16+
17+
```rs
18+
cargo run --bin rtic-example
19+
```
20+
21+
## Embassy example
22+
23+
```rs
24+
cargo run --bin embassy-example
25+
```

examples/embassy/Cargo.toml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
[package]
2+
name = "embassy-example"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
cortex-m = { version = "0.7", features = ["critical-section-single-core"] }
8+
cortex-m-rt = "0.7"
9+
embedded-hal = "1"
10+
11+
rtt-target = { version = "0.5" }
12+
panic-rtt-target = { version = "0.1" }
13+
critical-section = "1"
14+
portable-atomic = { version = "1", features = ["unsafe-assume-single-core"]}
15+
16+
embassy-sync = { version = "0.6.0" }
17+
embassy-time = { version = "0.3.2" }
18+
embassy-time-driver = { version = "0.1" }
19+
20+
[dependencies.once_cell]
21+
version = "1"
22+
default-features = false
23+
features = ["critical-section"]
24+
25+
[dependencies.embassy-executor]
26+
version = "0.6.0"
27+
features = [
28+
"arch-cortex-m",
29+
"executor-thread",
30+
"executor-interrupt",
31+
"integrated-timers",
32+
]
33+
34+
[dependencies.va108xx-hal]
35+
path = "../../va108xx-hal"
36+
37+
[features]
38+
default = ["ticks-hz-1_000"]
39+
ticks-hz-1_000 = ["embassy-time/tick-hz-1_000"]
40+
ticks-hz-32_768 = ["embassy-time/tick-hz-32_768"]

examples/embassy/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#![no_std]
2+
pub mod time_driver;
3+
4+
pub use time_driver::init;

examples/embassy/src/main.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#![no_std]
2+
#![no_main]
3+
use embassy_executor::Spawner;
4+
use embassy_time::{Duration, Instant, Ticker};
5+
use embedded_hal::digital::StatefulOutputPin;
6+
use panic_rtt_target as _;
7+
use rtt_target::{rprintln, rtt_init_print};
8+
use va108xx_hal::{gpio::PinsA, pac, prelude::*};
9+
10+
const SYSCLK_FREQ: Hertz = Hertz::from_raw(50_000_000);
11+
12+
// main is itself an async function.
13+
#[embassy_executor::main]
14+
async fn main(_spawner: Spawner) {
15+
rtt_init_print!();
16+
rprintln!("-- VA108xx Embassy Demo --");
17+
18+
let mut dp = pac::Peripherals::take().unwrap();
19+
20+
// Safety: Only called once here.
21+
unsafe {
22+
embassy_example::init(
23+
&mut dp.sysconfig,
24+
&dp.irqsel,
25+
SYSCLK_FREQ,
26+
dp.tim23,
27+
dp.tim22,
28+
)
29+
};
30+
31+
let porta = PinsA::new(&mut dp.sysconfig, Some(dp.ioconfig), dp.porta);
32+
let mut led0 = porta.pa10.into_readable_push_pull_output();
33+
let mut led1 = porta.pa7.into_readable_push_pull_output();
34+
let mut led2 = porta.pa6.into_readable_push_pull_output();
35+
let mut ticker = Ticker::every(Duration::from_secs(1));
36+
loop {
37+
ticker.next().await;
38+
rprintln!("Current time: {}", Instant::now().as_secs());
39+
led0.toggle().ok();
40+
led1.toggle().ok();
41+
led2.toggle().ok();
42+
}
43+
}

0 commit comments

Comments
 (0)