diff options
| author | David Haig <[email protected]> | 2024-06-28 18:11:34 +0100 |
|---|---|---|
| committer | David Haig <[email protected]> | 2024-06-28 18:11:34 +0100 |
| commit | 79f00e54cc4d13a28c7ccc9a13345bf2f3730f42 (patch) | |
| tree | f84018216825751ae22401bda35ccc2490efd602 /examples | |
| parent | 1123e3fd41e7b23dd0507816f1ff67fc0de6b5d1 (diff) | |
Moved ltdc example to its own crate
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/stm32h7/Cargo.toml | 2 | ||||
| -rw-r--r-- | examples/stm32h735/.cargo/config.toml | 8 | ||||
| -rw-r--r-- | examples/stm32h735/Cargo.toml | 61 | ||||
| -rw-r--r-- | examples/stm32h735/build.rs | 35 | ||||
| -rw-r--r-- | examples/stm32h735/memory.x | 5 | ||||
| -rw-r--r-- | examples/stm32h735/src/bin/ferris.bmp (renamed from examples/stm32h7/src/bin/ferris.bmp) | bin | 6794 -> 6794 bytes | |||
| -rw-r--r-- | examples/stm32h735/src/bin/ltdc.rs (renamed from examples/stm32h7/src/bin/ltdc.rs) | 15 |
7 files changed, 111 insertions, 15 deletions
diff --git a/examples/stm32h7/Cargo.toml b/examples/stm32h7/Cargo.toml index 6f3007492..0584f3916 100644 --- a/examples/stm32h7/Cargo.toml +++ b/examples/stm32h7/Cargo.toml | |||
| @@ -34,8 +34,6 @@ stm32-fmc = "0.3.0" | |||
| 34 | embedded-storage = "0.3.1" | 34 | embedded-storage = "0.3.1" |
| 35 | static_cell = "2" | 35 | static_cell = "2" |
| 36 | chrono = { version = "^0.4", default-features = false } | 36 | chrono = { version = "^0.4", default-features = false } |
| 37 | embedded-graphics = { version = "0.8.1" } | ||
| 38 | tinybmp = { version = "0.5" } | ||
| 39 | 37 | ||
| 40 | # cargo build/run | 38 | # cargo build/run |
| 41 | [profile.dev] | 39 | [profile.dev] |
diff --git a/examples/stm32h735/.cargo/config.toml b/examples/stm32h735/.cargo/config.toml new file mode 100644 index 000000000..95536c6a8 --- /dev/null +++ b/examples/stm32h735/.cargo/config.toml | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | [target.thumbv7em-none-eabihf] | ||
| 2 | runner = 'probe-rs run --chip STM32H735IGKx' | ||
| 3 | |||
| 4 | [build] | ||
| 5 | target = "thumbv7em-none-eabihf" # Cortex-M4F and Cortex-M7F (with FPU) | ||
| 6 | |||
| 7 | [env] | ||
| 8 | DEFMT_LOG = "trace" | ||
diff --git a/examples/stm32h735/Cargo.toml b/examples/stm32h735/Cargo.toml new file mode 100644 index 000000000..fc21cc894 --- /dev/null +++ b/examples/stm32h735/Cargo.toml | |||
| @@ -0,0 +1,61 @@ | |||
| 1 | [package] | ||
| 2 | edition = "2021" | ||
| 3 | name = "embassy-stm32h735-examples" | ||
| 4 | version = "0.1.0" | ||
| 5 | license = "MIT OR Apache-2.0" | ||
| 6 | |||
| 7 | [dependencies] | ||
| 8 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32h735ig", "time-driver-tim2", "exti", "memory-x", "unstable-pac", "chrono"] } | ||
| 9 | embassy-sync = { version = "0.6.0", path = "../../embassy-sync", features = ["defmt"] } | ||
| 10 | embassy-embedded-hal = { version = "0.1.0", path = "../../embassy-embedded-hal" } | ||
| 11 | embassy-executor = { version = "0.5.0", path = "../../embassy-executor", features = ["task-arena-size-32768", "arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] } | ||
| 12 | embassy-time = { version = "0.3.1", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } | ||
| 13 | embassy-futures = { version = "0.1.0", path = "../../embassy-futures" } | ||
| 14 | |||
| 15 | defmt = "0.3" | ||
| 16 | defmt-rtt = "0.4" | ||
| 17 | |||
| 18 | cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } | ||
| 19 | cortex-m-rt = "0.7.0" | ||
| 20 | panic-probe = { version = "0.3", features = ["print-defmt"] } | ||
| 21 | heapless = { version = "0.8", default-features = false } | ||
| 22 | embedded-graphics = { version = "0.8.1" } | ||
| 23 | tinybmp = { version = "0.5" } | ||
| 24 | |||
| 25 | # cargo build/run | ||
| 26 | [profile.dev] | ||
| 27 | codegen-units = 1 | ||
| 28 | debug = 2 | ||
| 29 | debug-assertions = true # <- | ||
| 30 | incremental = false | ||
| 31 | opt-level = 3 # <- | ||
| 32 | overflow-checks = true # <- | ||
| 33 | |||
| 34 | # cargo test | ||
| 35 | [profile.test] | ||
| 36 | codegen-units = 1 | ||
| 37 | debug = 2 | ||
| 38 | debug-assertions = true # <- | ||
| 39 | incremental = false | ||
| 40 | opt-level = 3 # <- | ||
| 41 | overflow-checks = true # <- | ||
| 42 | |||
| 43 | # cargo build/run --release | ||
| 44 | [profile.release] | ||
| 45 | codegen-units = 1 | ||
| 46 | debug = 2 | ||
| 47 | debug-assertions = false # <- | ||
| 48 | incremental = false | ||
| 49 | lto = 'fat' | ||
| 50 | opt-level = 3 # <- | ||
| 51 | overflow-checks = false # <- | ||
| 52 | |||
| 53 | # cargo test --release | ||
| 54 | [profile.bench] | ||
| 55 | codegen-units = 1 | ||
| 56 | debug = 2 | ||
| 57 | debug-assertions = false # <- | ||
| 58 | incremental = false | ||
| 59 | lto = 'fat' | ||
| 60 | opt-level = 3 # <- | ||
| 61 | overflow-checks = false # <- | ||
diff --git a/examples/stm32h735/build.rs b/examples/stm32h735/build.rs new file mode 100644 index 000000000..30691aa97 --- /dev/null +++ b/examples/stm32h735/build.rs | |||
| @@ -0,0 +1,35 @@ | |||
| 1 | //! This build script copies the `memory.x` file from the crate root into | ||
| 2 | //! a directory where the linker can always find it at build time. | ||
| 3 | //! For many projects this is optional, as the linker always searches the | ||
| 4 | //! project root directory -- wherever `Cargo.toml` is. However, if you | ||
| 5 | //! are using a workspace or have a more complicated build setup, this | ||
| 6 | //! build script becomes required. Additionally, by requesting that | ||
| 7 | //! Cargo re-run the build script whenever `memory.x` is changed, | ||
| 8 | //! updating `memory.x` ensures a rebuild of the application with the | ||
| 9 | //! new memory settings. | ||
| 10 | |||
| 11 | use std::env; | ||
| 12 | use std::fs::File; | ||
| 13 | use std::io::Write; | ||
| 14 | use std::path::PathBuf; | ||
| 15 | |||
| 16 | fn main() { | ||
| 17 | // Put `memory.x` in our output directory and ensure it's | ||
| 18 | // on the linker search path. | ||
| 19 | let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); | ||
| 20 | File::create(out.join("memory.x")) | ||
| 21 | .unwrap() | ||
| 22 | .write_all(include_bytes!("memory.x")) | ||
| 23 | .unwrap(); | ||
| 24 | println!("cargo:rustc-link-search={}", out.display()); | ||
| 25 | |||
| 26 | // By default, Cargo will re-run a build script whenever | ||
| 27 | // any file in the project changes. By specifying `memory.x` | ||
| 28 | // here, we ensure the build script is only re-run when | ||
| 29 | // `memory.x` is changed. | ||
| 30 | println!("cargo:rerun-if-changed=memory.x"); | ||
| 31 | |||
| 32 | println!("cargo:rustc-link-arg-bins=--nmagic"); | ||
| 33 | println!("cargo:rustc-link-arg-bins=-Tlink.x"); | ||
| 34 | println!("cargo:rustc-link-arg-bins=-Tdefmt.x"); | ||
| 35 | } | ||
diff --git a/examples/stm32h735/memory.x b/examples/stm32h735/memory.x new file mode 100644 index 000000000..3a70d24d2 --- /dev/null +++ b/examples/stm32h735/memory.x | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | MEMORY | ||
| 2 | { | ||
| 3 | FLASH : ORIGIN = 0x08000000, LENGTH = 1024K | ||
| 4 | RAM : ORIGIN = 0x24000000, LENGTH = 320K | ||
| 5 | } \ No newline at end of file | ||
diff --git a/examples/stm32h7/src/bin/ferris.bmp b/examples/stm32h735/src/bin/ferris.bmp index 7a222ab84..7a222ab84 100644 --- a/examples/stm32h7/src/bin/ferris.bmp +++ b/examples/stm32h735/src/bin/ferris.bmp | |||
| Binary files differ | |||
diff --git a/examples/stm32h7/src/bin/ltdc.rs b/examples/stm32h735/src/bin/ltdc.rs index 3b56bbb6c..5c75a7db1 100644 --- a/examples/stm32h7/src/bin/ltdc.rs +++ b/examples/stm32h735/src/bin/ltdc.rs | |||
| @@ -36,19 +36,9 @@ const DISPLAY_HEIGHT: usize = 272; | |||
| 36 | const MY_TASK_POOL_SIZE: usize = 2; | 36 | const MY_TASK_POOL_SIZE: usize = 2; |
| 37 | 37 | ||
| 38 | // the following two display buffers consume 261120 bytes that just about fits into axis ram found on the mcu | 38 | // the following two display buffers consume 261120 bytes that just about fits into axis ram found on the mcu |
| 39 | // see memory.x linker script | ||
| 40 | pub static mut FB1: [TargetPixelType; DISPLAY_WIDTH * DISPLAY_HEIGHT] = [0; DISPLAY_WIDTH * DISPLAY_HEIGHT]; | 39 | pub static mut FB1: [TargetPixelType; DISPLAY_WIDTH * DISPLAY_HEIGHT] = [0; DISPLAY_WIDTH * DISPLAY_HEIGHT]; |
| 41 | pub static mut FB2: [TargetPixelType; DISPLAY_WIDTH * DISPLAY_HEIGHT] = [0; DISPLAY_WIDTH * DISPLAY_HEIGHT]; | 40 | pub static mut FB2: [TargetPixelType; DISPLAY_WIDTH * DISPLAY_HEIGHT] = [0; DISPLAY_WIDTH * DISPLAY_HEIGHT]; |
| 42 | 41 | ||
| 43 | // a basic memory.x linker script for the stm32h735g-dk is as follows: | ||
| 44 | /* | ||
| 45 | MEMORY | ||
| 46 | { | ||
| 47 | FLASH : ORIGIN = 0x08000000, LENGTH = 1024K | ||
| 48 | RAM : ORIGIN = 0x24000000, LENGTH = 320K | ||
| 49 | } | ||
| 50 | */ | ||
| 51 | |||
| 52 | bind_interrupts!(struct Irqs { | 42 | bind_interrupts!(struct Irqs { |
| 53 | LTDC => ltdc::InterruptHandler<peripherals::LTDC>; | 43 | LTDC => ltdc::InterruptHandler<peripherals::LTDC>; |
| 54 | }); | 44 | }); |
| @@ -110,7 +100,7 @@ async fn main(spawner: Spawner) { | |||
| 110 | 100 | ||
| 111 | // enable the bottom layer with a 256 color lookup table | 101 | // enable the bottom layer with a 256 color lookup table |
| 112 | ltdc.init_layer(&layer_config, Some(&clut)); | 102 | ltdc.init_layer(&layer_config, Some(&clut)); |
| 113 | 103 | ||
| 114 | // Safety: the DoubleBuffer controls access to the statically allocated frame buffers | 104 | // Safety: the DoubleBuffer controls access to the statically allocated frame buffers |
| 115 | // and it is the only thing that mutates their content | 105 | // and it is the only thing that mutates their content |
| 116 | let mut double_buffer = DoubleBuffer::new( | 106 | let mut double_buffer = DoubleBuffer::new( |
| @@ -369,8 +359,7 @@ mod rcc_setup { | |||
| 369 | config.rcc.apb2_pre = APBPrescaler::DIV2; | 359 | config.rcc.apb2_pre = APBPrescaler::DIV2; |
| 370 | config.rcc.apb3_pre = APBPrescaler::DIV2; | 360 | config.rcc.apb3_pre = APBPrescaler::DIV2; |
| 371 | config.rcc.apb4_pre = APBPrescaler::DIV2; | 361 | config.rcc.apb4_pre = APBPrescaler::DIV2; |
| 372 | let p = embassy_stm32::init(config); | 362 | embassy_stm32::init(config) |
| 373 | p | ||
| 374 | } | 363 | } |
| 375 | } | 364 | } |
| 376 | 365 | ||
