feat(example): move ospi memory mapped example for stm32h7b0 to separate folder

Signed-off-by: Haobo Gu <haobogu@outlook.com>
This commit is contained in:
Haobo Gu 2024-10-26 23:50:16 +08:00
parent ca6bcb4250
commit 04c9130d32
5 changed files with 124 additions and 3 deletions

View File

@ -0,0 +1,8 @@
[target.thumbv7em-none-eabihf]
runner = 'probe-rs run --chip STM32H7B0VBTx'
[build]
target = "thumbv7em-none-eabihf" # Cortex-M4F and Cortex-M7F (with FPU)
[env]
DEFMT_LOG = "trace"

View File

@ -0,0 +1,74 @@
[package]
edition = "2021"
name = "embassy-stm32h7b0-examples"
version = "0.1.0"
license = "MIT OR Apache-2.0"
[dependencies]
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32h7b0vb", "time-driver-tim2", "exti", "memory-x", "unstable-pac", "chrono"] }
embassy-sync = { version = "0.6.0", path = "../../embassy-sync", features = ["defmt"] }
embassy-embedded-hal = { version = "0.2.0", path = "../../embassy-embedded-hal" }
embassy-executor = { version = "0.6.1", path = "../../embassy-executor", features = ["task-arena-size-32768", "arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] }
embassy-time = { version = "0.3.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
embassy-net = { version = "0.4.0", path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet", "proto-ipv6", "dns"] }
embassy-usb = { version = "0.3.0", path = "../../embassy-usb", features = ["defmt"] }
embassy-futures = { version = "0.1.0", path = "../../embassy-futures" }
defmt = "0.3"
defmt-rtt = "0.4"
cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] }
cortex-m-rt = "0.7.0"
embedded-hal = "0.2.6"
embedded-hal-1 = { package = "embedded-hal", version = "1.0" }
embedded-hal-async = { version = "1.0" }
embedded-nal-async = "0.8.0"
embedded-io-async = { version = "0.6.1" }
panic-probe = { version = "0.3", features = ["print-defmt"] }
heapless = { version = "0.8", default-features = false }
rand_core = "0.6.3"
critical-section = "1.1"
micromath = "2.0.0"
stm32-fmc = "0.3.0"
embedded-storage = "0.3.1"
static_cell = "2"
chrono = { version = "^0.4", default-features = false }
grounded = "0.2.0"
# 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 # <-

View File

@ -0,0 +1,35 @@
//! 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");
println!("cargo:rustc-link-arg-bins=--nmagic");
println!("cargo:rustc-link-arg-bins=-Tlink.x");
println!("cargo:rustc-link-arg-bins=-Tdefmt.x");
}

View File

@ -0,0 +1,5 @@
MEMORY
{
FLASH : ORIGIN = 0x08000000, LENGTH = 128K /* BANK_1 */
RAM : ORIGIN = 0x24000000, LENGTH = 512K /* SRAM */
}

View File

@ -61,7 +61,7 @@ async fn main(_spawner: Spawner) {
free_running_clock: false, free_running_clock: false,
clock_mode: false, clock_mode: false,
wrap_size: WrapSize::None, wrap_size: WrapSize::None,
clock_prescaler: 2, clock_prescaler: 4,
sample_shifting: true, sample_shifting: true,
delay_hold_quarter_cycle: false, delay_hold_quarter_cycle: false,
chip_select_boundary: 0, chip_select_boundary: 0,
@ -94,8 +94,8 @@ async fn main(_spawner: Spawner) {
flash.read_memory(0, &mut rd_buf, true); flash.read_memory(0, &mut rd_buf, true);
info!("WRITE BUF: {=[u8]:#X}", wr_buf); info!("WRITE BUF: {=[u8]:#X}", wr_buf);
info!("READ BUF: {=[u8]:#X}", rd_buf); info!("READ BUF: {=[u8]:#X}", rd_buf);
info!("Enabling memory mapped mode");
flash.enable_mm().await; flash.enable_mm().await;
info!("Enabled memory mapped mode");
let first_u32 = unsafe { *(0x90000000 as *const u32) }; let first_u32 = unsafe { *(0x90000000 as *const u32) };
assert_eq!(first_u32, 0x03020100); assert_eq!(first_u32, 0x03020100);
@ -121,7 +121,6 @@ const CMD_QUAD_READ: u8 = 0x6B;
const CMD_QUAD_WRITE_PG: u8 = 0x32; const CMD_QUAD_WRITE_PG: u8 = 0x32;
const CMD_READ_ID: u8 = 0x9F; const CMD_READ_ID: u8 = 0x9F;
const CMD_READ_UUID: u8 = 0x4B;
const CMD_ENABLE_RESET: u8 = 0x66; const CMD_ENABLE_RESET: u8 = 0x66;
const CMD_RESET: u8 = 0x99; const CMD_RESET: u8 = 0x99;