Skip to content

Commit aef1556

Browse files
Lab03 (#8)
* add solutions lab03 and fix rust-analyzer in vscode and zed * fixes * explain derive * add MODER word * typo * fix typo Co-authored-by: Omer Genan <81963672+genan2003@users.noreply.github.com> --------- Co-authored-by: Omer Genan <81963672+genan2003@users.noreply.github.com>
1 parent d828488 commit aef1556

16 files changed

Lines changed: 863 additions & 6 deletions

File tree

.cargo/config.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[build]
2+
target = "thumbv8m.main-none-eabihf"
3+
4+
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
5+
runner = "probe-rs run --chip STM32U545RETxQ"
6+
7+
[env]
8+
DEFMT_LOG = "debug"

.helix/languages.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
[[language]]
22
name = "rust"
33

4+
[language-server.rust-analyzer.config.cargo]
5+
allTargets = false
6+
47
[language-server.rust-analyzer.config.check]
58
targets = ["thumbv8m.main-none-eabihf"]
69
allTargets = false

.vscode/settings.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"rust-analyzer.check.allTargets": false,
2+
"rust-analyzer.cargo.allTargets": false,
33
"rust-analyzer.check.workspace": false,
44
"[rust]": {
55
"editor.defaultFormatter": "rust-lang.rust-analyzer",
@@ -8,6 +8,7 @@
88
},
99
"cSpell.words": [
1010
"Boostrap",
11-
"defmt"
11+
"defmt",
12+
"MODER"
1213
]
1314
}

.zed/settings.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
"lsp": {
33
"rust-analyzer": {
44
"initialization_options": {
5+
"cargo": {
6+
"allTargets": false
7+
},
58
"check": {
6-
"target": "thumbv8m.main-none-eabihf",
7-
"allTargets": false,
89
"workspace": false
910
}
1011
}

Cargo.lock

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[workspace]
22
resolver = "3"
3-
members = ["lab01", "lab02"]
3+
members = ["lab01", "lab02", "lab03"]

codebook.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,19 @@ words = [
44
"defmt",
55
"eabihf",
66
"exti",
7+
"ish",
78
"linker's",
89
"mcu",
10+
"mille",
11+
"moder",
912
"nmagic",
13+
"pwm",
14+
"pwm's",
1015
"semihosting",
1116
"stm",
1217
"tdefmt",
1318
"thumbv",
1419
"tlink",
1520
"uptime",
21+
"vcc",
1622
]

lab03/.cargo/config.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[build]
2+
target = "thumbv8m.main-none-eabihf"
3+
4+
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
5+
runner = "probe-rs run --chip STM32U545RETxQ"
6+
7+
[env]
8+
DEFMT_LOG = "debug"

lab03/Cargo.toml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
[package]
2+
name = "lab03"
3+
version = "0.1.0"
4+
edition = "2024"
5+
6+
[dependencies]
7+
embassy-stm32 = { version = "0.4.0", git = "https://github.com/embassy-rs/embassy", rev = "3e8d8fe", features = [
8+
"defmt",
9+
"stm32u545re",
10+
"unstable-pac",
11+
"memory-x",
12+
"time-driver-tim4",
13+
"exti",
14+
# "chrono",
15+
] }
16+
17+
# Embedded HAL utilities
18+
embassy-embedded-hal = { version = "0.5.0", git = "https://github.com/embassy-rs/embassy", rev = "3e8d8fe", features = [
19+
"defmt",
20+
] }
21+
22+
# Synchronization primitives and data structures with async support
23+
embassy-sync = { version = "0.7.2", git = "https://github.com/embassy-rs/embassy", rev = "3e8d8fe", features = [
24+
"defmt",
25+
] }
26+
27+
# Async/await executor
28+
embassy-executor = { version = "0.9.0", git = "https://github.com/embassy-rs/embassy", rev = "3e8d8fe", features = [
29+
"arch-cortex-m",
30+
"executor-thread",
31+
"defmt",
32+
] }
33+
34+
# Utilities for working with futures, compatible with no_std and not using alloc
35+
embassy-futures = { version = "0.1.2", git = "https://github.com/embassy-rs/embassy", rev = "3e8d8fe" }
36+
37+
# Timekeeping, delays and timeouts
38+
embassy-time = { version = "0.5.0", git = "https://github.com/embassy-rs/embassy", rev = "3e8d8fe", features = [
39+
"defmt",
40+
"defmt-timestamp-uptime",
41+
"tick-hz-32_768",
42+
] }
43+
44+
# USB device
45+
# embassy-usb = { version = "0.5.1", git = "https://github.com/embassy-rs/embassy", rev = "3e8d8fe", features = [
46+
# "defmt",
47+
# ] }
48+
49+
# Defmt support
50+
defmt = "0.3"
51+
defmt-rtt = "0.4"
52+
53+
# Low level access to Cortex-M processors
54+
cortex-m = { version = "0.7.7", features = [
55+
"inline-asm",
56+
"critical-section-single-core",
57+
] }
58+
59+
# Boostrap crate for Cortex-M Processors
60+
cortex-m-rt = "0.7.5"
61+
62+
# Panic handler that exits `probe-run` with an error code
63+
panic-probe = { version = "1.0.0", features = ["print-defmt"] }

lab03/build.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
// This section is not needed as the `embassy-stm32` crate
18+
// provides `memory.x` and adds it to the linker's path.
19+
//
20+
// If using a crate that does not provide it, please
21+
// uncomment the this section and the related imported
22+
// items.
23+
24+
// Put `memory.x` in our output directory and ensure it's
25+
// on the linker search path.
26+
// let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
27+
// File::create(out.join("memory.x"))
28+
// .unwrap()
29+
// .write_all(include_bytes!("memory.x"))
30+
// .unwrap();
31+
// println!("cargo:rustc-link-search={}", out.display());
32+
33+
// By default, Cargo will re-run a build script whenever
34+
// any file in the project changes. By specifying `memory.x`
35+
// here, we ensure the build script is only re-run when
36+
// `memory.x` is changed.
37+
// println!("cargo:rerun-if-changed=memory.x");
38+
39+
// Prevent the linker from page aligning segments
40+
println!("cargo:rustc-link-arg-bins=--nmagic");
41+
42+
// Required for `cortex-m`
43+
println!("cargo:rustc-link-arg-bins=-Tlink.x");
44+
// Required for `defmt`
45+
println!("cargo:rustc-link-arg-bins=-Tdefmt.x");
46+
}

0 commit comments

Comments
 (0)