Initial support for STM32F767ZI.
This commit is contained in:
committed by
Dario Nieuwenhuis
parent
7cb34760c4
commit
015cad84dd
18
examples/stm32f7/.cargo/config.toml
Normal file
18
examples/stm32f7/.cargo/config.toml
Normal file
@ -0,0 +1,18 @@
|
||||
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
|
||||
# replace STM32F429ZITx with your chip as listed in `probe-run --list-chips`
|
||||
runner = "probe-run --chip STM32F767ZITx"
|
||||
|
||||
rustflags = [
|
||||
# LLD (shipped with the Rust toolchain) is used as the default linker
|
||||
"-C", "link-arg=--nmagic",
|
||||
"-C", "link-arg=-Tlink.x",
|
||||
"-C", "link-arg=-Tdefmt.x",
|
||||
|
||||
# Code-size optimizations.
|
||||
"-Z", "trap-unreachable=no",
|
||||
"-C", "inline-threshold=5",
|
||||
"-C", "no-vectorize-loops",
|
||||
]
|
||||
|
||||
[build]
|
||||
target = "thumbv7em-none-eabihf"
|
35
examples/stm32f7/Cargo.toml
Normal file
35
examples/stm32f7/Cargo.toml
Normal file
@ -0,0 +1,35 @@
|
||||
[package]
|
||||
authors = ["Dario Nieuwenhuis <dirbaio@dirbaio.net>"]
|
||||
edition = "2018"
|
||||
name = "embassy-stm32f7-examples"
|
||||
version = "0.1.0"
|
||||
resolver = "2"
|
||||
|
||||
[features]
|
||||
default = [
|
||||
"defmt-default",
|
||||
]
|
||||
defmt-default = []
|
||||
defmt-trace = []
|
||||
defmt-debug = []
|
||||
defmt-info = []
|
||||
defmt-warn = []
|
||||
defmt-error = []
|
||||
|
||||
[dependencies]
|
||||
embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt", "defmt-trace"] }
|
||||
embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] }
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "defmt-trace", "stm32f767zi", "unstable-pac", "time-driver-tim2"] }
|
||||
embassy-hal-common = {version = "0.1.0", path = "../../embassy-hal-common" }
|
||||
|
||||
defmt = "0.2.3"
|
||||
defmt-rtt = "0.2.0"
|
||||
|
||||
cortex-m = "0.7.3"
|
||||
cortex-m-rt = "0.7.0"
|
||||
embedded-hal = "0.2.6"
|
||||
panic-probe = { version = "0.2.0", features = ["print-defmt"] }
|
||||
futures = { version = "0.3.17", default-features = false, features = ["async-await"] }
|
||||
rtt-target = { version = "0.3.1", features = ["cortex-m"] }
|
||||
heapless = { version = "0.7.5", default-features = false }
|
||||
nb = "1.0.0"
|
39
examples/stm32f7/build.rs
Normal file
39
examples/stm32f7/build.rs
Normal file
@ -0,0 +1,39 @@
|
||||
//! adapted from https://github.com/stm32-rs/stm32f7xx-hal/blob/master/build.rs
|
||||
use std::env;
|
||||
use std::fs::File;
|
||||
use std::io::{self, prelude::*};
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[derive(Debug)]
|
||||
enum Error {
|
||||
Env(env::VarError),
|
||||
Io(io::Error),
|
||||
}
|
||||
|
||||
impl From<env::VarError> for Error {
|
||||
fn from(error: env::VarError) -> Self {
|
||||
Self::Env(error)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<io::Error> for Error {
|
||||
fn from(error: io::Error) -> Self {
|
||||
Self::Io(error)
|
||||
}
|
||||
}
|
||||
|
||||
fn main() -> Result<(), Error> {
|
||||
println!("cargo:rerun-if-changed=build.rs");
|
||||
println!("cargo:rerun-if-changed=memory.x");
|
||||
|
||||
let out_dir = env::var("OUT_DIR")?;
|
||||
let out_dir = PathBuf::from(out_dir);
|
||||
|
||||
let memory_x = include_bytes!("memory.x").as_ref();
|
||||
File::create(out_dir.join("memory.x"))?.write_all(memory_x)?;
|
||||
|
||||
// Tell Cargo where to find the file.
|
||||
println!("cargo:rustc-link-search={}", out_dir.display());
|
||||
|
||||
Ok(())
|
||||
}
|
12
examples/stm32f7/memory.x
Normal file
12
examples/stm32f7/memory.x
Normal file
@ -0,0 +1,12 @@
|
||||
/* For STM32F765,767,768,769,777,778,779 devices */
|
||||
MEMORY
|
||||
{
|
||||
/* NOTE K = KiBi = 1024 bytes */
|
||||
FLASH : ORIGIN = 0x08000000, LENGTH = 2M
|
||||
RAM : ORIGIN = 0x20000000, LENGTH = 368K + 16K
|
||||
}
|
||||
|
||||
/* This is where the call stack will be allocated. */
|
||||
/* The stack is of the full descending type. */
|
||||
/* NOTE Do NOT modify `_stack_start` unless you know what you are doing */
|
||||
_stack_start = ORIGIN(RAM) + LENGTH(RAM);
|
29
examples/stm32f7/src/bin/blinky.rs
Normal file
29
examples/stm32f7/src/bin/blinky.rs
Normal file
@ -0,0 +1,29 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
#[path = "../example_common.rs"]
|
||||
mod example_common;
|
||||
use embassy::executor::Spawner;
|
||||
use embassy::time::{Duration, Timer};
|
||||
use embassy_stm32::gpio::{Level, Output, Speed};
|
||||
use embassy_stm32::Peripherals;
|
||||
use embedded_hal::digital::v2::OutputPin;
|
||||
use example_common::*;
|
||||
|
||||
#[embassy::main]
|
||||
async fn main(_spawner: Spawner, p: Peripherals) {
|
||||
info!("Hello World!");
|
||||
|
||||
let mut led = Output::new(p.PB7, Level::High, Speed::Low);
|
||||
|
||||
loop {
|
||||
info!("high");
|
||||
unwrap!(led.set_high());
|
||||
Timer::after(Duration::from_millis(300)).await;
|
||||
|
||||
info!("low");
|
||||
unwrap!(led.set_low());
|
||||
Timer::after(Duration::from_millis(300)).await;
|
||||
}
|
||||
}
|
34
examples/stm32f7/src/bin/button.rs
Normal file
34
examples/stm32f7/src/bin/button.rs
Normal file
@ -0,0 +1,34 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
#[path = "../example_common.rs"]
|
||||
mod example_common;
|
||||
use cortex_m_rt::entry;
|
||||
use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
|
||||
use embedded_hal::digital::v2::{InputPin, OutputPin};
|
||||
use example_common::*;
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
info!("Hello World!");
|
||||
|
||||
let p = embassy_stm32::init(Default::default());
|
||||
|
||||
let button = Input::new(p.PC13, Pull::Down);
|
||||
let mut led1 = Output::new(p.PB0, Level::High, Speed::Low);
|
||||
let _led2 = Output::new(p.PB7, Level::High, Speed::Low);
|
||||
let mut led3 = Output::new(p.PB14, Level::High, Speed::Low);
|
||||
|
||||
loop {
|
||||
if unwrap!(button.is_high()) {
|
||||
info!("high");
|
||||
unwrap!(led1.set_high());
|
||||
unwrap!(led3.set_low());
|
||||
} else {
|
||||
info!("low");
|
||||
unwrap!(led1.set_low());
|
||||
unwrap!(led3.set_high());
|
||||
}
|
||||
}
|
||||
}
|
29
examples/stm32f7/src/bin/button_exti.rs
Normal file
29
examples/stm32f7/src/bin/button_exti.rs
Normal file
@ -0,0 +1,29 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
#[path = "../example_common.rs"]
|
||||
mod example_common;
|
||||
use embassy::executor::Spawner;
|
||||
use embassy_stm32::exti::ExtiInput;
|
||||
use embassy_stm32::gpio::{Input, Pull};
|
||||
use embassy_stm32::Peripherals;
|
||||
use embassy_traits::gpio::{WaitForFallingEdge, WaitForRisingEdge};
|
||||
use example_common::*;
|
||||
|
||||
#[embassy::main]
|
||||
async fn main(_spawner: Spawner, p: Peripherals) {
|
||||
info!("Hello World!");
|
||||
|
||||
let button = Input::new(p.PC13, Pull::Down);
|
||||
let mut button = ExtiInput::new(button, p.EXTI13);
|
||||
|
||||
info!("Press the USER button...");
|
||||
|
||||
loop {
|
||||
button.wait_for_rising_edge().await;
|
||||
info!("Pressed!");
|
||||
button.wait_for_falling_edge().await;
|
||||
info!("Released!");
|
||||
}
|
||||
}
|
27
examples/stm32f7/src/bin/hello.rs
Normal file
27
examples/stm32f7/src/bin/hello.rs
Normal file
@ -0,0 +1,27 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use defmt::info;
|
||||
use embassy::executor::Spawner;
|
||||
use embassy::time::{Duration, Timer};
|
||||
use embassy_stm32::time::Hertz;
|
||||
use embassy_stm32::Config;
|
||||
use embassy_stm32::Peripherals;
|
||||
|
||||
#[path = "../example_common.rs"]
|
||||
mod example_common;
|
||||
|
||||
fn config() -> Config {
|
||||
let mut config = Config::default();
|
||||
config.rcc.sys_ck = Some(Hertz(84_000_000));
|
||||
config
|
||||
}
|
||||
|
||||
#[embassy::main(config = "config()")]
|
||||
async fn main(_spawner: Spawner, _p: Peripherals) -> ! {
|
||||
loop {
|
||||
info!("Hello World!");
|
||||
Timer::after(Duration::from_secs(1)).await;
|
||||
}
|
||||
}
|
17
examples/stm32f7/src/example_common.rs
Normal file
17
examples/stm32f7/src/example_common.rs
Normal 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
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user