From 010712412d66ae21aeab0243346ba8b0c5ad9a3f Mon Sep 17 00:00:00 2001 From: cscherr Date: Thu, 17 Apr 2025 14:37:02 +0200 Subject: [PATCH] feat: flash a "does nothing" program written in rust to the board --- .cargo/config.toml | 5 ++ .gitignore | 0 Cargo.lock | 198 +++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 10 +++ build.rs | 9 +++ memory.x | 8 ++ src/main.rs | 27 ++++++- 7 files changed, 255 insertions(+), 2 deletions(-) create mode 100755 .cargo/config.toml mode change 100644 => 100755 .gitignore create mode 100755 Cargo.lock mode change 100644 => 100755 Cargo.toml create mode 100755 build.rs create mode 100755 memory.x mode change 100644 => 100755 src/main.rs diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100755 index 0000000..e65cc11 --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,5 @@ +[build] +target = "thumbv6m-none-eabi" + +[target.thumbv6m-none-eabi] +runner = 'probe-rs run --chip STM32L053R8' diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 diff --git a/Cargo.lock b/Cargo.lock new file mode 100755 index 0000000..f35b4b5 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,198 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "bare-metal" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5deb64efa5bd81e31fcd1938615a6d98c82eafcbcd787162b6f63b91d6bac5b3" +dependencies = [ + "rustc_version", +] + +[[package]] +name = "bitfield" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46afbd2983a5d5a7bd740ccb198caf5b82f45c40c09c0eed36052d91cb92e719" + +[[package]] +name = "cortex-m" +version = "0.7.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ec610d8f49840a5b376c69663b6369e71f4b34484b9b2eb29fb918d92516cb9" +dependencies = [ + "bare-metal", + "bitfield", + "critical-section", + "embedded-hal", + "volatile-register", +] + +[[package]] +name = "cortex-m-rt" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "801d4dec46b34c299ccf6b036717ae0fce602faa4f4fe816d9013b9a7c9f5ba6" +dependencies = [ + "cortex-m-rt-macros", +] + +[[package]] +name = "cortex-m-rt-macros" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e37549a379a9e0e6e576fd208ee60394ccb8be963889eebba3ffe0980364f472" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "critical-section" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "790eea4361631c5e7d22598ecd5723ff611904e3344ce8720784c93e3d83d40b" + +[[package]] +name = "embedded-hal" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35949884794ad573cf46071e41c9b60efb0cb311e3ca01f7af807af1debc66ff" +dependencies = [ + "nb 0.1.3", + "void", +] + +[[package]] +name = "nb" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "801d31da0513b6ec5214e9bf433a77966320625a37860f910be265be6e18d06f" +dependencies = [ + "nb 1.1.0", +] + +[[package]] +name = "nb" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d5439c4ad607c3c23abf66de8c8bf57ba8adcd1f129e699851a6e43935d339d" + +[[package]] +name = "nucleo-l053r8-blink" +version = "0.1.0" +dependencies = [ + "cortex-m", + "cortex-m-rt", + "panic-rtt-target", + "rtt-target", +] + +[[package]] +name = "panic-rtt-target" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "608d1d809dd8960d5e8364981279c7ab280a13d98b99eae049885a7ab2b1cbfe" +dependencies = [ + "critical-section", + "rtt-target", +] + +[[package]] +name = "proc-macro2" +version = "1.0.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rtt-target" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10b34c9e6832388e45f3c01f1bb60a016384a0a4ad80cdd7d34913bed25037f0" +dependencies = [ + "critical-section", + "ufmt-write", +] + +[[package]] +name = "rustc_version" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" +dependencies = [ + "semver", +] + +[[package]] +name = "semver" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" +dependencies = [ + "semver-parser", +] + +[[package]] +name = "semver-parser" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" + +[[package]] +name = "syn" +version = "2.0.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b09a44accad81e1ba1cd74a32461ba89dee89095ba17b32f5d03683b1b1fc2a0" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "ufmt-write" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e87a2ed6b42ec5e28cc3b94c09982969e9227600b2e3dcbc1db927a84c06bd69" + +[[package]] +name = "unicode-ident" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" + +[[package]] +name = "vcell" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77439c1b53d2303b20d9459b1ade71a83c716e3f9c34f3228c00e6f185d6c002" + +[[package]] +name = "void" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" + +[[package]] +name = "volatile-register" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de437e2a6208b014ab52972a27e59b33fa2920d3e00fe05026167a1c509d19cc" +dependencies = [ + "vcell", +] diff --git a/Cargo.toml b/Cargo.toml old mode 100644 new mode 100755 index cd80eb9..e752e1e --- a/Cargo.toml +++ b/Cargo.toml @@ -4,3 +4,13 @@ version = "0.1.0" edition = "2024" [dependencies] +cortex-m = { version = "0.7.7", features = ["critical-section-single-core"] } +cortex-m-rt = "0.7.3" +panic-rtt-target = "0.1.3" +rtt-target = "0.5.0" + + +[[bin]] +name = "nucleo-l053r8-blink" +test = false +bench = false diff --git a/build.rs b/build.rs new file mode 100755 index 0000000..549a70a --- /dev/null +++ b/build.rs @@ -0,0 +1,9 @@ +// We could do a lot of fancy build tricks here, but all we need is a linker script from +// cortext-m-rt to include our memory map, so the tools know how much RAM and flash the chip has +// and where to find them. +fn main() { + // Set the linker script to the one provided by cortex-m-rt. + println!("cargo:rustc-link-arg=-Tlink.x"); + + // Apperently, this loads the memory map provided in `memory.x` +} diff --git a/memory.x b/memory.x new file mode 100755 index 0000000..6edfca9 --- /dev/null +++ b/memory.x @@ -0,0 +1,8 @@ +# FLASH 0x08000000 - 0x0802FFFF 192K +# RAM 0x20000000 - 0x20004FFF 20K + +MEMORY +{ + FLASH : ORIGIN = 0x08000000, LENGTH = 192K + RAM : ORIGIN = 0x20000000, LENGTH = 20K +} diff --git a/src/main.rs b/src/main.rs old mode 100644 new mode 100755 index e7a11a9..de94687 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,26 @@ -fn main() { - println!("Hello, world!"); +#![no_std] +#![no_main] + +// We need to use cortex_m here so the linker can find it's critical-section, but we import is as +// an underscore since we don't directly use any of its symbols. +use cortex_m as _; + +// The entry import gives us a macro to indicate where the microcontroller should start the +// program, and also sets up the FPU on our Cortex-M4F. +use cortex_m_rt::entry; + +// Provides functions that allow printing back to probe-rs. +use panic_rtt_target as _; +use rtt_target::{rprintln, rtt_init_print}; + +// Start here, and don't ever return from this function. +#[entry] +fn main() -> ! { + // Initialise our debug printer. + rtt_init_print!(); + // Send a message back via the debugger. + rprintln!("Hello, world!"); + + // Do nothing, forever. + loop {} }