start tutorial
This commit is contained in:
20
tutorial/05-led-blink/README.md
Normal file
20
tutorial/05-led-blink/README.md
Normal file
@@ -0,0 +1,20 @@
|
||||
# 05 - LED Blink (8 min)
|
||||
|
||||
## Goal
|
||||
|
||||
Onboard-LED (PC13, active-low) per Timer toggeln.
|
||||
|
||||
## Run
|
||||
|
||||
- `bash scripts/run-step.sh 05 task`
|
||||
|
||||
## Tasks
|
||||
|
||||
1. Prüfe in `task/src/main.rs`, welche Pegel "LED an/aus" bedeuten.
|
||||
2. Passe Blinkfrequenz an.
|
||||
3. Verifiziere LED und Logs.
|
||||
|
||||
## Done when
|
||||
|
||||
1. LED blinkt sichtbar.
|
||||
2. Logs zeigen den Schaltzustand.
|
||||
12
tutorial/05-led-blink/solution/.cargo/config.toml
Normal file
12
tutorial/05-led-blink/solution/.cargo/config.toml
Normal file
@@ -0,0 +1,12 @@
|
||||
[target.thumbv7m-none-eabi]
|
||||
runner = "probe-rs run --chip STM32F103C8"
|
||||
rustflags = [
|
||||
"-C", "link-arg=-Tlink.x",
|
||||
"-C", "link-arg=-Tdefmt.x",
|
||||
]
|
||||
|
||||
[build]
|
||||
target = "thumbv7m-none-eabi"
|
||||
|
||||
[env]
|
||||
DEFMT_LOG = "info"
|
||||
22
tutorial/05-led-blink/solution/Cargo.toml
Normal file
22
tutorial/05-led-blink/solution/Cargo.toml
Normal file
@@ -0,0 +1,22 @@
|
||||
[package]
|
||||
name = "step05_led_blink_solution"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
cortex-m = "0.7.7"
|
||||
cortex-m-rt = "0.7.5"
|
||||
defmt = "0.3.10"
|
||||
defmt-rtt = "0.4.2"
|
||||
panic-probe = { version = "0.3.2", features = ["print-defmt"] }
|
||||
nb = "1.1.0"
|
||||
|
||||
[dependencies.stm32f1xx-hal]
|
||||
version = "0.11.0"
|
||||
features = ["rt", "stm32f103", "medium"]
|
||||
|
||||
[profile.release]
|
||||
codegen-units = 1
|
||||
debug = 2
|
||||
lto = true
|
||||
opt-level = "z"
|
||||
5
tutorial/05-led-blink/solution/memory.x
Normal file
5
tutorial/05-led-blink/solution/memory.x
Normal file
@@ -0,0 +1,5 @@
|
||||
MEMORY
|
||||
{
|
||||
FLASH : ORIGIN = 0x08000000, LENGTH = 64K
|
||||
RAM : ORIGIN = 0x20000000, LENGTH = 20K
|
||||
}
|
||||
4
tutorial/05-led-blink/solution/rust-toolchain.toml
Normal file
4
tutorial/05-led-blink/solution/rust-toolchain.toml
Normal file
@@ -0,0 +1,4 @@
|
||||
[toolchain]
|
||||
channel = "stable"
|
||||
components = ["rustfmt"]
|
||||
targets = ["thumbv7m-none-eabi"]
|
||||
31
tutorial/05-led-blink/solution/src/main.rs
Normal file
31
tutorial/05-led-blink/solution/src/main.rs
Normal file
@@ -0,0 +1,31 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use cortex_m_rt::entry;
|
||||
use defmt::info;
|
||||
use nb::block;
|
||||
use stm32f1xx_hal::{pac, prelude::*, timer::Timer};
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
let cp = cortex_m::Peripherals::take().unwrap();
|
||||
let dp = pac::Peripherals::take().unwrap();
|
||||
|
||||
let mut rcc = dp.RCC.constrain();
|
||||
let mut gpioc = dp.GPIOC.split(&mut rcc);
|
||||
let mut led = gpioc.pc13.into_push_pull_output(&mut gpioc.crh);
|
||||
|
||||
let mut timer = Timer::syst(cp.SYST, &rcc.clocks).counter_hz();
|
||||
timer.start(2.Hz()).unwrap();
|
||||
|
||||
loop {
|
||||
info!("led on (pc13 low)");
|
||||
led.set_low();
|
||||
block!(timer.wait()).unwrap();
|
||||
|
||||
info!("led off (pc13 high)");
|
||||
led.set_high();
|
||||
block!(timer.wait()).unwrap();
|
||||
}
|
||||
}
|
||||
12
tutorial/05-led-blink/task/.cargo/config.toml
Normal file
12
tutorial/05-led-blink/task/.cargo/config.toml
Normal file
@@ -0,0 +1,12 @@
|
||||
[target.thumbv7m-none-eabi]
|
||||
runner = "probe-rs run --chip STM32F103C8"
|
||||
rustflags = [
|
||||
"-C", "link-arg=-Tlink.x",
|
||||
"-C", "link-arg=-Tdefmt.x",
|
||||
]
|
||||
|
||||
[build]
|
||||
target = "thumbv7m-none-eabi"
|
||||
|
||||
[env]
|
||||
DEFMT_LOG = "info"
|
||||
22
tutorial/05-led-blink/task/Cargo.toml
Normal file
22
tutorial/05-led-blink/task/Cargo.toml
Normal file
@@ -0,0 +1,22 @@
|
||||
[package]
|
||||
name = "step05_led_blink_task"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
cortex-m = "0.7.7"
|
||||
cortex-m-rt = "0.7.5"
|
||||
defmt = "0.3.10"
|
||||
defmt-rtt = "0.4.2"
|
||||
panic-probe = { version = "0.3.2", features = ["print-defmt"] }
|
||||
nb = "1.1.0"
|
||||
|
||||
[dependencies.stm32f1xx-hal]
|
||||
version = "0.11.0"
|
||||
features = ["rt", "stm32f103", "medium"]
|
||||
|
||||
[profile.release]
|
||||
codegen-units = 1
|
||||
debug = 2
|
||||
lto = true
|
||||
opt-level = "z"
|
||||
5
tutorial/05-led-blink/task/memory.x
Normal file
5
tutorial/05-led-blink/task/memory.x
Normal file
@@ -0,0 +1,5 @@
|
||||
MEMORY
|
||||
{
|
||||
FLASH : ORIGIN = 0x08000000, LENGTH = 64K
|
||||
RAM : ORIGIN = 0x20000000, LENGTH = 20K
|
||||
}
|
||||
4
tutorial/05-led-blink/task/rust-toolchain.toml
Normal file
4
tutorial/05-led-blink/task/rust-toolchain.toml
Normal file
@@ -0,0 +1,4 @@
|
||||
[toolchain]
|
||||
channel = "stable"
|
||||
components = ["rustfmt"]
|
||||
targets = ["thumbv7m-none-eabi"]
|
||||
34
tutorial/05-led-blink/task/src/main.rs
Normal file
34
tutorial/05-led-blink/task/src/main.rs
Normal file
@@ -0,0 +1,34 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use cortex_m_rt::entry;
|
||||
use defmt::info;
|
||||
use nb::block;
|
||||
use stm32f1xx_hal::{pac, prelude::*, timer::Timer};
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
let cp = cortex_m::Peripherals::take().unwrap();
|
||||
let dp = pac::Peripherals::take().unwrap();
|
||||
|
||||
let mut rcc = dp.RCC.constrain();
|
||||
let mut gpioc = dp.GPIOC.split(&mut rcc);
|
||||
|
||||
// Bluepill onboard LED on PC13 is active-low.
|
||||
let mut led = gpioc.pc13.into_push_pull_output(&mut gpioc.crh);
|
||||
|
||||
let mut timer = Timer::syst(cp.SYST, &rcc.clocks).counter_hz();
|
||||
timer.start(2.Hz()).unwrap();
|
||||
|
||||
loop {
|
||||
// TODO: swap set_high/set_low and observe behavior.
|
||||
info!("led on (pc13 low)");
|
||||
led.set_low();
|
||||
block!(timer.wait()).unwrap();
|
||||
|
||||
info!("led off (pc13 high)");
|
||||
led.set_high();
|
||||
block!(timer.wait()).unwrap();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user