From 50fdc339083a34d91ada1c462c67978e58f87f11 Mon Sep 17 00:00:00 2001 From: Lotte Steenbrink Date: Mon, 19 Apr 2021 11:21:21 +0200 Subject: [PATCH 1/4] point out parts of a embedded program in helo.rs, Cargo.toml --- beginner/apps/.cargo/config.toml | 1 + beginner/apps/src/bin/hello.rs | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/beginner/apps/.cargo/config.toml b/beginner/apps/.cargo/config.toml index be9aeec..7a1c918 100644 --- a/beginner/apps/.cargo/config.toml +++ b/beginner/apps/.cargo/config.toml @@ -12,4 +12,5 @@ rustflags = [ ] [build] +# cross-compile to this target target = "thumbv7em-none-eabihf" # = ARM Cortex-M4 \ No newline at end of file diff --git a/beginner/apps/src/bin/hello.rs b/beginner/apps/src/bin/hello.rs index 62a8ad0..9d20aa2 100644 --- a/beginner/apps/src/bin/hello.rs +++ b/beginner/apps/src/bin/hello.rs @@ -1,12 +1,20 @@ -#![no_main] +// 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; use panic_log as _; // the panicking behavior + #[entry] +// ˆˆˆˆ the custom entry point fn main() -> ! { + // ˆˆˆ + // ! is the 'never' type: this function never returns + // initializes the peripherals dk::init().unwrap(); From adaca12a61adb5d4e334b70b2096ef903af790d4 Mon Sep 17 00:00:00 2001 From: Lotte Steenbrink Date: Mon, 19 Apr 2021 11:55:11 +0200 Subject: [PATCH 2/4] appeal to the rustfmt gods --- beginner/apps/src/bin/hello.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/beginner/apps/src/bin/hello.rs b/beginner/apps/src/bin/hello.rs index 9d20aa2..f7734b8 100644 --- a/beginner/apps/src/bin/hello.rs +++ b/beginner/apps/src/bin/hello.rs @@ -9,11 +9,12 @@ use cortex_m_rt::entry; use panic_log as _; // the panicking behavior +// the custom entry point +// vvvvv #[entry] -// ˆˆˆˆ the custom entry point fn main() -> ! { // ˆˆˆ - // ! is the 'never' type: this function never returns + // ! is the 'never' type: this function never returns // initializes the peripherals dk::init().unwrap(); From 3e54af411b1fec4e49afd07c8e55ed6140eb4ee0 Mon Sep 17 00:00:00 2001 From: Lotte Steenbrink Date: Mon, 19 Apr 2021 11:56:28 +0200 Subject: [PATCH 3/4] add probe-run explanation --- beginner/apps/.cargo/config.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/beginner/apps/.cargo/config.toml b/beginner/apps/.cargo/config.toml index 7a1c918..4b518a8 100644 --- a/beginner/apps/.cargo/config.toml +++ b/beginner/apps/.cargo/config.toml @@ -6,6 +6,8 @@ rustflags = [ ] [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", From 49a5d9e898c367602782c663b873a5bb4b7bf431 Mon Sep 17 00:00:00 2001 From: Lotte Steenbrink Date: Fri, 23 Apr 2021 19:13:11 +0200 Subject: [PATCH 4/4] cargo fmt --- beginner/apps/src/bin/hello.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/beginner/apps/src/bin/hello.rs b/beginner/apps/src/bin/hello.rs index f7734b8..8a5605d 100644 --- a/beginner/apps/src/bin/hello.rs +++ b/beginner/apps/src/bin/hello.rs @@ -8,7 +8,6 @@ use cortex_m::asm; use cortex_m_rt::entry; use panic_log as _; // the panicking behavior - // the custom entry point // vvvvv #[entry]