stm32: Add F0 example

This commit is contained in:
Thales Fragoso 2021-07-15 13:50:39 -03:00
parent 2f08c7ced5
commit 697f93ad42
7 changed files with 118 additions and 0 deletions

View file

@ -88,6 +88,8 @@ jobs:
target: thumbv6m-none-eabi
- package: examples/stm32wb55
target: thumbv7em-none-eabihf
- package: examples/stm32f0
target: thumbv6m-none-eabi
steps:
- uses: actions/checkout@v2

View file

@ -0,0 +1,10 @@
[target.thumbv6m-none-eabi]
runner = 'probe-run --chip STM32F030F4Px'
rustflags = [
# LLD (shipped with the Rust toolchain) is used as the default linker
"-C", "link-arg=-Tlink.x",
"-C", "link-arg=-Tdefmt.x",
]
[build]
target = "thumbv6m-none-eabi"

View file

@ -0,0 +1,29 @@
[package]
name = "embassy-stm32f0-examples"
version = "0.1.0"
authors = ["Thales Fragoso <thales.fragosoz@gmail.com>"]
edition = "2018"
resolver = "2"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
cortex-m = { version = "0.7.1", features = ["inline-asm"] }
cortex-m-rt = "0.6.13"
defmt = "0.2.0"
defmt-rtt = "0.2.0"
panic-probe = { version = "0.2.0" }
rtt-target = { version = "0.3", features = ["cortex-m"] }
embassy = { path = "../../embassy", features = ["defmt"] }
embassy-stm32 = { path = "../../embassy-stm32", features = ["defmt", "stm32f030f4"] }
[features]
default = [
"defmt-default",
]
defmt-default = []
defmt-trace = []
defmt-debug = []
defmt-info = []
defmt-warn = []
defmt-error = []

31
examples/stm32f0/build.rs Normal file
View file

@ -0,0 +1,31 @@
//! This build script copies the `memory.x` file from the crate root into
//! a directory where the linker can always find it at build time.
//! For many projects this is optional, as the linker always searches the
//! project root directory -- wherever `Cargo.toml` is. However, if you
//! are using a workspace or have a more complicated build setup, this
//! build script becomes required. Additionally, by requesting that
//! Cargo re-run the build script whenever `memory.x` is changed,
//! updating `memory.x` ensures a rebuild of the application with the
//! new memory settings.
use std::env;
use std::fs::File;
use std::io::Write;
use std::path::PathBuf;
fn main() {
// Put `memory.x` in our output directory and ensure it's
// on the linker search path.
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
File::create(out.join("memory.x"))
.unwrap()
.write_all(include_bytes!("memory.x"))
.unwrap();
println!("cargo:rustc-link-search={}", out.display());
// By default, Cargo will re-run a build script whenever
// any file in the project changes. By specifying `memory.x`
// here, we ensure the build script is only re-run when
// `memory.x` is changed.
println!("cargo:rerun-if-changed=memory.x");
}

View file

@ -0,0 +1,6 @@
MEMORY
{
FLASH : ORIGIN = 0x08000000, LENGTH = 16K
/* DTCM */
RAM : ORIGIN = 0x20000000, LENGTH = 4K
}

View file

@ -0,0 +1,23 @@
#![no_std]
#![no_main]
#![feature(min_type_alias_impl_trait)]
#![feature(impl_trait_in_bindings)]
#![feature(type_alias_impl_trait)]
#![allow(incomplete_features)]
use defmt::info;
use embassy::executor::Spawner;
use embassy::time::{Duration, Timer};
use embassy_stm32::Peripherals;
#[path = "../example_common.rs"]
mod example_common;
#[embassy::main]
async fn main(_spawner: Spawner, _p: Peripherals) -> ! {
loop {
Timer::after(Duration::from_secs(1)).await;
info!("Hello");
}
}

View file

@ -0,0 +1,17 @@
#![macro_use]
use defmt_rtt as _; // global logger
use panic_probe as _;
pub use defmt::*;
use core::sync::atomic::{AtomicUsize, Ordering};
defmt::timestamp! {"{=u64}", {
static COUNT: AtomicUsize = AtomicUsize::new(0);
// NOTE(no-CAS) `timestamps` runs with interrupts disabled
let n = COUNT.load(Ordering::Relaxed);
COUNT.store(n + 1, Ordering::Relaxed);
n as u64
}
}