Skip to content

Commit 47b2774

Browse files
committed
blinky running with RTIC v2 alpha
1 parent c4a6183 commit 47b2774

File tree

6 files changed

+189
-0
lines changed

6 files changed

+189
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
[target.thumbv7m-none-eabi]
2+
# uncomment this to make `cargo run` execute programs on QEMU
3+
# runner = "qemu-system-arm -cpu cortex-m3 -machine lm3s6965evb -nographic -semihosting-config enable=on,target=native -kernel"
4+
5+
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
6+
# uncomment ONE of these three option to make `cargo run` start a GDB session
7+
# which option to pick depends on your system
8+
# runner = "arm-none-eabi-gdb -q -x openocd.gdb"
9+
# runner = "gdb-multiarch -q -x openocd.gdb"
10+
# runner = "gdb -q -x openocd.gdb"
11+
12+
rustflags = [
13+
# This is needed if your flash or ram addresses are not aligned to 0x10000 in memory.x
14+
# See https://github.com/rust-embedded/cortex-m-quickstart/pull/95
15+
"-C", "link-arg=--nmagic",
16+
17+
# LLD (shipped with the Rust toolchain) is used as the default linker
18+
"-C", "link-arg=-Tlink.x",
19+
20+
# if you run into problems with LLD switch to the GNU linker by commenting out
21+
# this line
22+
# "-C", "linker=arm-none-eabi-ld",
23+
24+
# if you need to link to pre-compiled C libraries provided by a C toolchain
25+
# use GCC as the linker by commenting out both lines above and then
26+
# uncommenting the three lines below
27+
# "-C", "linker=arm-none-eabi-gcc",
28+
# "-C", "link-arg=-Wl,-Tlink.x",
29+
# "-C", "link-arg=-nostartfiles",
30+
]
31+
32+
[build]
33+
# Pick ONE of these compilation targets
34+
# target = "thumbv6m-none-eabi" # Cortex-M0 and Cortex-M0+
35+
target = "thumbv7m-none-eabi" # Cortex-M3
36+
# target = "thumbv7em-none-eabi" # Cortex-M4 and Cortex-M7 (no FPU)
37+
# target = "thumbv7em-none-eabihf" # Cortex-M4F and Cortex-M7F (with FPU)
38+
# target = "thumbv8m.base-none-eabi" # Cortex-M23
39+
# target = "thumbv8m.main-none-eabi" # Cortex-M33 (no FPU)
40+
# target = "thumbv8m.main-none-eabihf" # Cortex-M33 (with FPU)
41+
42+
# thumbv7m-none-eabi is not coming with core and alloc, compile myself
43+
[unstable]
44+
mtime-on-use = true
45+
build-std = ["core", "alloc"]

rtic_v2/stm32f3_blinky/Cargo.toml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
[package]
2+
authors = ["Simsys <[email protected]>"]
3+
edition = "2021"
4+
readme = "README.md"
5+
name = "stm32f3-blinky"
6+
version = "0.1.0"
7+
8+
[dependencies]
9+
embedded-hal = "0.2.7"
10+
rtic = { git = "https://github.com/rtic-rs/rtic", features = ["thumbv7-backend"] }
11+
rtic-monotonics = { git = "https://github.com/rtic-rs/rtic", features = ["cortex-m-systick"] }
12+
#cortex-m-rtic = "1.1.4"
13+
systick-monotonic = "1.0.1"
14+
panic-rtt-target = { version = "0.1.2", features = ["cortex-m"] }
15+
rtt-target = { version = "0.3.1", features = ["cortex-m"] }
16+
17+
[dependencies.stm32f3xx-hal]
18+
features = ["stm32f303xc", "rt"]
19+
version = "0.9.2"
20+
21+
# this lets you use `cargo fix`!
22+
[[bin]]
23+
name = "stm32f3-blinky"
24+
test = false
25+
bench = false
26+
27+
[profile.dev]
28+
opt-level = 1
29+
codegen-units = 16
30+
debug = true
31+
lto = false
32+
33+
[profile.release]
34+
opt-level = "s" # optimize for size
35+
codegen-units = 1 # better optimizations
36+
debug = true # symbols are nice and they don't increase the size on Flash
37+
lto = true # better optimizations

rtic_v2/stm32f3_blinky/Embed.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[default.general]
2+
chip = "stm32f303re"
3+
4+
5+
[default.rtt]
6+
enabled = true
7+
8+
[default.gdb]
9+
enabled = false

rtic_v2/stm32f3_blinky/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# STM32F3 RTIC Blink example
2+
3+
Working example of simple LED blinking application for STM32 F303 Nucleo-64 board based on the STM32F303RE chip. Example uses schedule API and peripherials access. This example is based on blue-pill blinky example.
4+
5+
## How-to
6+
7+
### Build
8+
9+
Run `cargo +nightly build` to compile the code. If you run it for the first time, it will take some time to download and compile dependencies.
10+
11+
After that, you can use for example the cargo-embed tool to flash and run it
12+
13+
```bash
14+
$ cargo +nightly embed
15+
```
16+
17+
### Setup environment, flash and run program
18+
19+
In the [Discovery Book](https://rust-embedded.github.io/discovery) you find all needed informations to setup the environment, flash the controler and run the program.

rtic_v2/stm32f3_blinky/memory.x

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
MEMORY
2+
{
3+
FLASH : ORIGIN = 0x08000000, LENGTH = 256K
4+
RAM : ORIGIN = 0x20000000, LENGTH = 40K
5+
}

rtic_v2/stm32f3_blinky/src/main.rs

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#![deny(unsafe_code)]
2+
#![deny(warnings)]
3+
#![no_main]
4+
#![no_std]
5+
#![feature(type_alias_impl_trait)]
6+
7+
use panic_rtt_target as _;
8+
use rtic::app;
9+
use rtic_monotonics::systick::*;
10+
use rtt_target::{rprintln, rtt_init_print};
11+
use stm32f3xx_hal::gpio::{Output, PushPull, PA5};
12+
use stm32f3xx_hal::prelude::*;
13+
14+
#[app(device = stm32f3xx_hal::pac, peripherals = true, dispatchers = [SPI1])]
15+
mod app {
16+
use super::*;
17+
18+
rtic_monotonics::make_systick_handler!();
19+
20+
#[shared]
21+
struct Shared {}
22+
23+
#[local]
24+
struct Local {
25+
led: PA5<Output<PushPull>>,
26+
state: bool,
27+
}
28+
29+
#[init]
30+
fn init(cx: init::Context) -> (Shared, Local) {
31+
// Setup clocks
32+
let mut flash = cx.device.FLASH.constrain();
33+
let mut rcc = cx.device.RCC.constrain();
34+
35+
Systick::start(cx.core.SYST, 36_000_000); // default STM32F303 clock-rate is 36MHz
36+
37+
rtt_init_print!();
38+
rprintln!("init");
39+
40+
let _clocks = rcc
41+
.cfgr
42+
.use_hse(8.MHz())
43+
.sysclk(36.MHz())
44+
.pclk1(36.MHz())
45+
.freeze(&mut flash.acr);
46+
47+
// Setup LED
48+
let mut gpioa = cx.device.GPIOA.split(&mut rcc.ahb);
49+
let mut led = gpioa
50+
.pa5
51+
.into_push_pull_output(&mut gpioa.moder, &mut gpioa.otyper);
52+
led.set_high().unwrap();
53+
54+
// Schedule the blinking task
55+
blink::spawn().ok();
56+
57+
(Shared {}, Local { led, state: false })
58+
}
59+
60+
#[task(local = [led, state])]
61+
async fn blink(cx: blink::Context) {
62+
loop {
63+
rprintln!("blink");
64+
if *cx.local.state {
65+
cx.local.led.set_high().unwrap();
66+
*cx.local.state = false;
67+
} else {
68+
cx.local.led.set_low().unwrap();
69+
*cx.local.state = true;
70+
}
71+
Systick::delay(1000.millis()).await;
72+
}
73+
}
74+
}

0 commit comments

Comments
 (0)