Initial commit
This commit is contained in:
commit
d5c12e27e6
|
@ -0,0 +1,19 @@
|
||||||
|
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
|
||||||
|
# TODO(2) replace `$CHIP` with your chip's name (see `probe-run --list-chips` output)
|
||||||
|
runner = "probe-run --chip STM32F103C6"
|
||||||
|
rustflags = [
|
||||||
|
"-C", "linker=flip-link",
|
||||||
|
"-C", "link-arg=-Tlink.x",
|
||||||
|
"-C", "link-arg=-Tdefmt.x",
|
||||||
|
# This is needed if your flash or ram addresses are not aligned to 0x10000 in memory.x
|
||||||
|
# See https://github.com/rust-embedded/cortex-m-quickstart/pull/95
|
||||||
|
"-C", "link-arg=--nmagic",
|
||||||
|
]
|
||||||
|
|
||||||
|
[build]
|
||||||
|
target = "thumbv7m-none-eabi" # Cortex-M3
|
||||||
|
|
||||||
|
|
||||||
|
[alias]
|
||||||
|
rb = "run --bin"
|
||||||
|
rrb = "run --release --bin"
|
|
@ -0,0 +1,2 @@
|
||||||
|
/target
|
||||||
|
Cargo.lock
|
|
@ -0,0 +1,78 @@
|
||||||
|
[package]
|
||||||
|
authors = ["LongHairedHacker <sebastian@sebastians-site.de>"]
|
||||||
|
name = "rtic-bluepill-blinky"
|
||||||
|
edition = "2018"
|
||||||
|
version = "0.1.0"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
cortex-m = "0.7.6"
|
||||||
|
cortex-m-rt = "0.7.2"
|
||||||
|
cortex-m-rtic = "1.1.3"
|
||||||
|
defmt = "0.3.2"
|
||||||
|
defmt-rtt = "0.3.2"
|
||||||
|
panic-probe = { version = "0.3.0", features = ["print-defmt"] }
|
||||||
|
stm32f1xx-hal = { version = "0.9.0", features = ["stm32f103", "rt"] }
|
||||||
|
embedded-hal = {version = "0.2.3"}
|
||||||
|
systick-monotonic = "1.0.0"
|
||||||
|
|
||||||
|
|
||||||
|
[features]
|
||||||
|
# set logging levels here
|
||||||
|
default = [
|
||||||
|
"defmt-default",
|
||||||
|
# "dependency-a/defmt-trace",
|
||||||
|
]
|
||||||
|
|
||||||
|
# do NOT modify these features
|
||||||
|
defmt-default = []
|
||||||
|
defmt-trace = []
|
||||||
|
defmt-debug = []
|
||||||
|
defmt-info = []
|
||||||
|
defmt-warn = []
|
||||||
|
defmt-error = []
|
||||||
|
|
||||||
|
# cargo build/run
|
||||||
|
[profile.dev]
|
||||||
|
codegen-units = 1
|
||||||
|
debug = 2
|
||||||
|
debug-assertions = true # <-
|
||||||
|
incremental = false
|
||||||
|
opt-level = 'z' # <-
|
||||||
|
overflow-checks = true # <-
|
||||||
|
|
||||||
|
# cargo test
|
||||||
|
[profile.test]
|
||||||
|
codegen-units = 1
|
||||||
|
debug = 2
|
||||||
|
debug-assertions = true # <-
|
||||||
|
incremental = false
|
||||||
|
opt-level = 3 # <-
|
||||||
|
overflow-checks = true # <-
|
||||||
|
|
||||||
|
# cargo build/run --release
|
||||||
|
[profile.release]
|
||||||
|
codegen-units = 1
|
||||||
|
debug = 2
|
||||||
|
debug-assertions = false # <-
|
||||||
|
incremental = false
|
||||||
|
lto = 'fat'
|
||||||
|
opt-level = 3 # <-
|
||||||
|
overflow-checks = false # <-
|
||||||
|
|
||||||
|
# cargo test --release
|
||||||
|
[profile.bench]
|
||||||
|
codegen-units = 1
|
||||||
|
debug = 2
|
||||||
|
debug-assertions = false # <-
|
||||||
|
incremental = false
|
||||||
|
lto = 'fat'
|
||||||
|
opt-level = 3 # <-
|
||||||
|
overflow-checks = false # <-
|
||||||
|
|
||||||
|
# uncomment this to switch from the crates.io version of defmt to its git version
|
||||||
|
# check app-template's README for instructions
|
||||||
|
# [patch.crates-io]
|
||||||
|
# defmt = { git = "https://github.com/knurling-rs/defmt", rev = "use defmt version reported by `probe-run --version`" }
|
||||||
|
# defmt-rtt = { git = "https://github.com/knurling-rs/defmt", rev = "use defmt version reported by `probe-run --version`" }
|
||||||
|
# defmt-test = { git = "https://github.com/knurling-rs/defmt", rev = "use defmt version reported by `probe-run --version`" }
|
||||||
|
# panic-probe = { git = "https://github.com/knurling-rs/defmt", rev = "use defmt version reported by `probe-run --version`" }
|
|
@ -0,0 +1,6 @@
|
||||||
|
/* Fake bluepill using STM32F103C6T6 */
|
||||||
|
MEMORY
|
||||||
|
{
|
||||||
|
FLASH : ORIGIN = 0x08000000, LENGTH = 32K
|
||||||
|
RAM : ORIGIN = 0x20000000, LENGTH = 10K
|
||||||
|
}
|
|
@ -0,0 +1,83 @@
|
||||||
|
#![deny(unsafe_code)]
|
||||||
|
#![no_main]
|
||||||
|
#![no_std]
|
||||||
|
|
||||||
|
use defmt_rtt as _; // global logger
|
||||||
|
use panic_probe as _;
|
||||||
|
use rtic::app;
|
||||||
|
use stm32f1xx_hal::gpio::PinState;
|
||||||
|
use stm32f1xx_hal::gpio::{gpioc::PC13, Output, PushPull};
|
||||||
|
use stm32f1xx_hal::prelude::*;
|
||||||
|
use systick_monotonic::Systick;
|
||||||
|
|
||||||
|
// same panicking *behavior* as `panic-probe` but doesn't print a panic message
|
||||||
|
// this prevents the panic message being printed *twice* when `defmt::panic` is invoked
|
||||||
|
#[defmt::panic_handler]
|
||||||
|
fn panic() -> ! {
|
||||||
|
cortex_m::asm::udf()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[app(device = stm32f1xx_hal::pac, peripherals = true, dispatchers = [TIM3])]
|
||||||
|
mod app {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[shared]
|
||||||
|
struct Shared {}
|
||||||
|
|
||||||
|
#[local]
|
||||||
|
struct Local {
|
||||||
|
led: PC13<Output<PushPull>>,
|
||||||
|
state: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[monotonic(binds = SysTick, default = true)]
|
||||||
|
type MonoTimer = Systick<1000>;
|
||||||
|
|
||||||
|
#[init]
|
||||||
|
fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||||
|
// Setup clocks
|
||||||
|
let mut flash = cx.device.FLASH.constrain();
|
||||||
|
let rcc = cx.device.RCC.constrain();
|
||||||
|
|
||||||
|
defmt::info!("init");
|
||||||
|
|
||||||
|
let clocks = rcc
|
||||||
|
.cfgr
|
||||||
|
.use_hse(8.MHz())
|
||||||
|
.sysclk(36.MHz())
|
||||||
|
.pclk1(36.MHz())
|
||||||
|
.freeze(&mut flash.acr);
|
||||||
|
|
||||||
|
let mono = Systick::new(cx.core.SYST, clocks.pclk1().to_Hz());
|
||||||
|
|
||||||
|
// Setup LED
|
||||||
|
let mut gpioc = cx.device.GPIOC.split();
|
||||||
|
let led = gpioc
|
||||||
|
.pc13
|
||||||
|
.into_push_pull_output_with_state(&mut gpioc.crh, PinState::Low);
|
||||||
|
|
||||||
|
// Schedule the blinking task
|
||||||
|
blink::spawn_after(1.secs().into()).unwrap();
|
||||||
|
|
||||||
|
(
|
||||||
|
Shared {},
|
||||||
|
Local { led, state: false },
|
||||||
|
init::Monotonics(mono),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[task(local = [led, state])]
|
||||||
|
fn blink(cx: blink::Context) {
|
||||||
|
if *cx.local.state {
|
||||||
|
defmt::info!("blink");
|
||||||
|
cx.local.led.set_high();
|
||||||
|
*cx.local.state = false;
|
||||||
|
} else {
|
||||||
|
defmt::info!("blonk");
|
||||||
|
cx.local.led.set_low();
|
||||||
|
*cx.local.state = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
blink::spawn_after(1.secs().into()).unwrap();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue