Initial commit
This commit is contained in:
commit
e6d5d84304
|
@ -0,0 +1,17 @@
|
||||||
|
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
|
||||||
|
runner = "probe-run --chip STM32F103CB"
|
||||||
|
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,66 @@
|
||||||
|
[package]
|
||||||
|
authors = ["{{authors}}"]
|
||||||
|
name = "{{project-name}}"
|
||||||
|
edition = "2018"
|
||||||
|
version = "0.1.0"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
cortex-m = "0.7.1"
|
||||||
|
cortex-m-rt = "0.6.13"
|
||||||
|
defmt = "0.2.0"
|
||||||
|
defmt-rtt = "0.2.0"
|
||||||
|
panic-probe = { version = "0.2.0", features = ["print-defmt"] }
|
||||||
|
stm32f1xx-hal = { version = "0.7.0", features = ["stm32f103", "rt"] }
|
||||||
|
embedded-hal = {version = "0.2.6"}
|
||||||
|
|
||||||
|
[features]
|
||||||
|
# set logging levels here
|
||||||
|
default = [
|
||||||
|
"defmt-default",
|
||||||
|
]
|
||||||
|
|
||||||
|
# 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 = 3 # <-
|
||||||
|
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 # <-
|
|
@ -0,0 +1,48 @@
|
||||||
|
# `stm32f103-template`
|
||||||
|
|
||||||
|
> Quickly set up a [`probe-run`] + [`defmt`] + [`flip-link`] embedded project
|
||||||
|
|
||||||
|
[`probe-run`]: https://crates.io/crates/probe-run
|
||||||
|
[`defmt`]: https://github.com/knurling-rs/defmt
|
||||||
|
[`flip-link`]: https://github.com/knurling-rs/flip-link
|
||||||
|
|
||||||
|
## Dependencies
|
||||||
|
|
||||||
|
#### 1. `flip-link`:
|
||||||
|
|
||||||
|
```console
|
||||||
|
$ cargo install flip-link
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 2. `probe-run`:
|
||||||
|
|
||||||
|
``` console
|
||||||
|
$ # make sure to install v0.2.0 or later
|
||||||
|
$ cargo install probe-run
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 3. [`cargo-generate`]:
|
||||||
|
|
||||||
|
``` console
|
||||||
|
$ cargo install cargo-generate
|
||||||
|
```
|
||||||
|
|
||||||
|
[`cargo-generate`]: https://crates.io/crates/cargo-generate
|
||||||
|
|
||||||
|
|
||||||
|
## Setup
|
||||||
|
|
||||||
|
#### 1. Initialize the project template
|
||||||
|
|
||||||
|
``` console
|
||||||
|
$ cargo generate \
|
||||||
|
--git ssh://git@gitea.zenerdio.de:2202/sebastian/stm32f103-template.git \
|
||||||
|
--branch main \
|
||||||
|
--name my-app
|
||||||
|
```
|
||||||
|
|
||||||
|
## License
|
||||||
|
- MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
|
||||||
|
|
||||||
|
## Original Work
|
||||||
|
Based on the awsome [app-template](https://github.com/knurling-rs/app-template) by knurling-rs.
|
|
@ -0,0 +1,2 @@
|
||||||
|
[template]
|
||||||
|
exclude = ["README.md"]
|
|
@ -0,0 +1,6 @@
|
||||||
|
/* Linker script for the STM32F103C8T6 */
|
||||||
|
MEMORY
|
||||||
|
{
|
||||||
|
FLASH : ORIGIN = 0x08000000, LENGTH = 64K
|
||||||
|
RAM : ORIGIN = 0x20000000, LENGTH = 20K
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
use cortex_m::prelude::*;
|
||||||
|
use embedded_hal::digital::v2::ToggleableOutputPin;
|
||||||
|
use stm32f1xx_hal::{
|
||||||
|
delay::Delay,
|
||||||
|
gpio::{gpioc, Output, PushPull},
|
||||||
|
};
|
||||||
|
|
||||||
|
mod setup;
|
||||||
|
|
||||||
|
//use crate::exit;
|
||||||
|
pub use setup::setup;
|
||||||
|
|
||||||
|
pub struct App {
|
||||||
|
delay: Delay,
|
||||||
|
board_led: gpioc::PC13<Output<PushPull>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl App {
|
||||||
|
pub fn run(mut self) -> ! {
|
||||||
|
defmt::info!("Application Startup!");
|
||||||
|
|
||||||
|
loop {
|
||||||
|
self.board_led.toggle().unwrap();
|
||||||
|
defmt::info!("Blink...");
|
||||||
|
self.delay.delay_ms(500u16);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
use stm32f1xx_hal::{delay::Delay, prelude::*, stm32};
|
||||||
|
|
||||||
|
use crate::application::App;
|
||||||
|
|
||||||
|
pub fn setup(cp: cortex_m::peripheral::Peripherals, dp: stm32::Peripherals) -> App {
|
||||||
|
// Take ownership over the raw flash and rcc devices and convert them into the corresponding
|
||||||
|
// HAL structs
|
||||||
|
let mut flash = dp.FLASH.constrain();
|
||||||
|
|
||||||
|
let mut rcc = dp.RCC.constrain();
|
||||||
|
|
||||||
|
// Freeze the configuration of all the clocks in the system and store the frozen frequencies in
|
||||||
|
// `clocks`
|
||||||
|
let clocks = rcc
|
||||||
|
.cfgr
|
||||||
|
.use_hse(8.mhz())
|
||||||
|
.sysclk(72.mhz())
|
||||||
|
.pclk1(36.mhz())
|
||||||
|
.freeze(&mut flash.acr);
|
||||||
|
|
||||||
|
defmt::info!("Clock Setup done");
|
||||||
|
|
||||||
|
// Acquire the GPIOC peripheral
|
||||||
|
let mut gpioc = dp.GPIOC.split(&mut rcc.apb2);
|
||||||
|
|
||||||
|
let board_led = gpioc.pc13.into_push_pull_output(&mut gpioc.crh);
|
||||||
|
|
||||||
|
let delay = Delay::new(cp.SYST, clocks);
|
||||||
|
|
||||||
|
App { delay, board_led }
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
#![no_std]
|
||||||
|
use defmt_rtt as _; // global logger
|
||||||
|
|
||||||
|
use panic_probe as _;
|
||||||
|
use stm32f1xx_hal as _;
|
||||||
|
|
||||||
|
use core::sync::atomic::{AtomicU32, Ordering};
|
||||||
|
|
||||||
|
pub mod application;
|
||||||
|
|
||||||
|
// 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()
|
||||||
|
}
|
||||||
|
|
||||||
|
static COUNT: AtomicU32 = AtomicU32::new(0);
|
||||||
|
defmt::timestamp!("{=u32}", COUNT.fetch_add(1, Ordering::Relaxed));
|
||||||
|
|
||||||
|
/// Terminates the application and makes `probe-run` exit with exit-code = 0
|
||||||
|
pub fn exit() -> ! {
|
||||||
|
loop {
|
||||||
|
cortex_m::asm::bkpt();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue