-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New embedded assignment #195
base: main
Are you sure you want to change the base?
Changes from 4 commits
eaab435
e98ddd2
028a850
3f56cd6
a9293e6
923b850
9e46b57
c4cc515
aa907e9
6529d50
5f8e4b1
f21124a
8b31518
fd51794
ad7f9db
1891f17
25cd0fa
14d76fb
3afc29c
c1825d1
bf87279
dffa5d4
453eb95
a142d15
16fbd1c
1665506
cd345aa
373e791
a1e990b
b2adf4a
3465441
71ad8b0
59a08c6
37930c3
5b11a4d
38c963e
3b72b1b
9a354f2
30fe350
bfcb572
ab2d908
5f079cd
2505e00
e7eef7a
f0bf2ec
5fc64c5
b5c3480
a3f653d
89ee72e
274767b
d647036
dc9232f
81b6657
4fb7415
8de826d
1db5935
08654a5
ee29b74
f981189
debd765
7701ae8
5e5ccb5
b09dd73
ee0f7b1
70ce745
e55713f
7a8e94e
11bd35e
6606472
8518686
eda4261
53a7c72
bb86aed
1424c7d
ed973e7
b4de9b3
b8f34e4
13b90e1
4eb0ac3
2c2358a
3e1dca1
c097fcf
15302d1
55b40e8
3e62747
da3ef09
14247f5
747edc5
ab0e106
baa572a
8b58405
c7576cf
00c20e6
f93eb74
7e9bf1b
2355def
a80583f
6c513bd
d84cc58
19cf5c2
de261dc
a74ae1a
aa93c99
e85a98b
8900ace
ef6f61c
3689d0d
a5f4ebe
3a4acd3
fbda1d9
971ec39
9ec556b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
[target.'cfg(all(target_arch = "arm", target_os = "none"))'] | ||
# (..) | ||
rustflags = [ | ||
"-C", "linker=flip-link", # adds stack overflow protection | ||
"-C", "link-arg=-Tdefmt.x", # defmt support | ||
# (..) | ||
] | ||
|
||
[target.thumbv7em-none-eabihf] | ||
# set custom cargo runner to flash & run on embedded target when we call `cargo run` | ||
# for more information, check out https://github.com/knurling-rs/probe-run | ||
runner = "probe-run --chip nRF52840_xxAA" | ||
rustflags = [ | ||
"-C", "link-arg=-Tlink.x", | ||
] | ||
|
||
[build] | ||
# cross-compile to this target | ||
target = "thumbv7em-none-eabihf" # = ARM Cortex-M4 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
[package] | ||
authors = ["Tanks Transfeld <[email protected]>"] | ||
edition = "2018" | ||
license = "MIT OR Apache-2.0" | ||
name = "apps" | ||
version = "0.0.0" | ||
|
||
[dependencies] | ||
cortex-m = {version = "0.7.6", features = ["critical-section-single-core"]} | ||
cortex-m-rt = "0.7.2" | ||
dk_template = { path = "../dk_template" } | ||
heapless = "0.7.16" | ||
panic-probe = { version = "0.3.0", features = ["print-defmt"] } | ||
defmt = "0.3.2" | ||
defmt-rtt = "0.3.2" | ||
|
||
# optimize code in both profiles | ||
[profile.dev] | ||
codegen-units = 1 | ||
debug = 2 | ||
debug-assertions = true # ! | ||
incremental = false | ||
lto = "fat" | ||
opt-level = 'z' # ! | ||
overflow-checks = false | ||
|
||
[profile.release] | ||
codegen-units = 1 | ||
debug = 1 | ||
debug-assertions = false | ||
incremental = false | ||
lto = "fat" | ||
opt-level = 3 | ||
overflow-checks = false | ||
|
||
[features] | ||
|
||
default = [ | ||
"other-feature" | ||
] | ||
other-feature = [] | ||
# do NOT modify these features | ||
defmt-default = [] | ||
defmt-trace = [] | ||
defmt-debug = [] | ||
defmt-info = [] | ||
defmt-warn = [] | ||
defmt-error = [] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#![no_main] | ||
#![no_std] | ||
|
||
use cortex_m::asm; | ||
use cortex_m_rt::entry; | ||
use core::fmt::Write; | ||
// this imports `beginner/apps/lib.rs` to retrieve our global logger + panicking-behavior | ||
use apps as _; | ||
|
||
#[entry] | ||
fn main() -> ! { | ||
// to enable more verbose logs, go to your `Cargo.toml` and set defmt logging levels | ||
// to `defmt-trace` by changing the `default = []` entry in `[features]` | ||
|
||
let board = dk_template::init().unwrap(); | ||
|
||
let mut led = board.leds; | ||
let button_1 = board.buttons.b_1; | ||
|
||
loop { | ||
if button_1.is_pushed() { | ||
led.led_1.on(); | ||
} else { | ||
led.led_1.off(); | ||
} | ||
} | ||
|
||
// this program does not `exit`; use Ctrl+C to terminate it | ||
loop { | ||
asm::nop(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// this program does not use the standard library to avoid heap allocations. | ||
// only the `core` library functions are available. | ||
#![no_std] | ||
// this program uses a custom entry point instead of `fn main()` | ||
#![no_main] | ||
|
||
use cortex_m::asm; | ||
use cortex_m_rt::entry; | ||
// this imports `beginner/apps/lib.rs` to retrieve our global logger + panicking-behavior | ||
use apps as _; | ||
|
||
// the custom entry point | ||
// vvvvv | ||
#[entry] | ||
fn main() -> ! { | ||
// ˆˆˆ | ||
// ! is the 'never' type: this function never returns | ||
|
||
// initializes the peripherals | ||
dk::init().unwrap(); | ||
|
||
defmt::println!("Hello, world!"); // :wave: | ||
|
||
loop { | ||
// breakpoint: halts the program's execution | ||
asm::bkpt(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#![no_main] | ||
#![no_std] | ||
|
||
use cortex_m::asm; | ||
use cortex_m_rt::entry; | ||
use core::fmt::Write; | ||
// this imports `beginner/apps/lib.rs` to retrieve our global logger + panicking-behavior | ||
use apps as _; | ||
|
||
#[entry] | ||
fn main() -> ! { | ||
// to enable more verbose logs, go to your `Cargo.toml` and set defmt logging levels | ||
// to `defmt-trace` by changing the `default = []` entry in `[features]` | ||
|
||
let board = dk_template::init().unwrap(); | ||
|
||
let button_1 = board.buttons.b_1; | ||
let mut uarte = board.uarte; | ||
|
||
|
||
let tx_buffer = "Hello\n"; | ||
|
||
|
||
loop { | ||
if button_1.is_pushed() { | ||
uarte.write_str(tx_buffer).unwrap(); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#![no_std] | ||
|
||
use panic_probe as _; | ||
|
||
// same panicking *behavior* as `panic-probe` but doesn't print a panic message | ||
// this prevents the panic message being printed *twice* when `defmt::panic` is invoked | ||
#[defmt::panic_handler] | ||
fn panic() -> ! { | ||
cortex_m::asm::udf() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
[package] | ||
authors = ["Jorge Aparicio <[email protected]>", "Tanks Transfeld <[email protected]"] | ||
edition = "2018" | ||
license = "MIT OR Apache-2.0" | ||
name = "dk_template" | ||
version = "0.0.0" | ||
|
||
[dependencies] | ||
cortex-m = {version = "0.7.6", features = ["critical-section-single-core"]} | ||
cortex-m-rt = "0.7.2" | ||
embedded-hal = "0.2.7" | ||
hal = { package = "nrf52840-hal", version = "0.14.0" } | ||
panic-probe = { version = "0.3.0", features = ["print-defmt"] } | ||
defmt = "0.3.2" | ||
defmt-rtt = "0.3.2" | ||
|
||
[features] | ||
advanced = [] | ||
beginner = [] | ||
|
||
default = [ | ||
"other-feature" | ||
] | ||
other-feature = [] | ||
|
||
# do NOT modify these features | ||
defmt-default = [] | ||
defmt-trace = [] | ||
defmt-debug = [] | ||
defmt-info = [] | ||
defmt-warn = [] | ||
defmt-error = [] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# `dk` | ||
|
||
Board Support Crate for the nRF52840 Development Kit (DK) | ||
|
||
## Getting familiar with the hardware | ||
|
||
TODO |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
use std::{env, error::Error, fs, path::PathBuf}; | ||
|
||
fn main() -> Result<(), Box<dyn Error>> { | ||
let out_dir = PathBuf::from(env::var("OUT_DIR")?); | ||
|
||
// put memory layout (linker script) in the linker search path | ||
fs::copy("memory.x", out_dir.join("memory.x"))?; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add rerun-if-changed on |
||
println!("cargo:rustc-link-search={}", out_dir.display()); | ||
|
||
Ok(()) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
MEMORY | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Worth a note here as to which chip we're running on, and a link to the Manufacturer's data sheet / product page, so you can easily verify that these numbers are correct. |
||
{ | ||
FLASH : ORIGIN = 0x00000000, LENGTH = 1024K | ||
RAM : ORIGIN = 0x20000000, LENGTH = 256K | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/// USBD cannot be enabled | ||
pub unsafe fn e187a() { | ||
(0x4006_EC00 as *mut u32).write_volatile(0x9375); | ||
(0x4006_ED14 as *mut u32).write_volatile(3); | ||
(0x4006_EC00 as *mut u32).write_volatile(0x9375); | ||
} | ||
|
||
/// USBD cannot be enabled | ||
pub unsafe fn e187b() { | ||
(0x4006_EC00 as *mut u32).write_volatile(0x9375); | ||
(0x4006_ED14 as *mut u32).write_volatile(0); | ||
(0x4006_EC00 as *mut u32).write_volatile(0x9375); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you need these any more?
See https://defmt.ferrous-systems.com/migration-02-03.html