From 5caf329f4779fa49fb6815f9a75873613fd88dba Mon Sep 17 00:00:00 2001 From: Lukrecja Date: Fri, 12 Dec 2025 20:15:55 +0100 Subject: [PATCH] init --- .cargo/config.toml | 7 +++++++ .gitignore | 3 +++ Cargo.toml | 39 +++++++++++++++++++++++++++++++++++++++ build.rs | 36 ++++++++++++++++++++++++++++++++++++ memory.x | 7 +++++++ rust-toolchain.toml | 11 +++++++++++ src/main.rs | 15 +++++++++++++++ 7 files changed, 118 insertions(+) create mode 100644 .cargo/config.toml create mode 100644 .gitignore create mode 100644 Cargo.toml create mode 100644 build.rs create mode 100644 memory.x create mode 100644 rust-toolchain.toml create mode 100644 src/main.rs diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..ced406b --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,7 @@ +[target.'cfg(all(target_arch = "arm", target_os = "none"))'] +runner = "probe-rs run --chip RP2040" +[build] +target = "thumbv6m-none-eabi" + +[env] +DEFMT_LOG = "info" diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a1f3e00 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +# Cargo build artifacts +/target/ +**/.idea \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..1227f48 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,39 @@ +[package] +edition = "2024" +name = "kb-firmware" +version = "0.1.0" +authors = ["Lukrecja "] +resolver = "2" + +[[bin]] +name = "kb-firmware" +test = false +bench = false + +[dependencies] +defmt = "0.3" +defmt-rtt = "0.4" +panic-probe = { version = "0.3", features = ["print-defmt"] } + +embedded-hal = "1.0.0" +embedded-hal-async = "1.0.0" +embedded-io = "0.6.1" +embedded-io-async = "0.6.1" +embedded-storage = "0.3.1" + +cortex-m-rt = "0.7.3" + +embassy-executor = { version = "0.7", features = ["task-arena-size-1024", "arch-cortex-m", "executor-thread", "defmt", "executor-interrupt"] } +embassy-sync = { version = "0.6" } +embassy-time = { version = "0.4", features = ["defmt", "defmt-timestamp-uptime"] } +cortex-m = { version = "0.7.7" } +embassy-rp = { version = "0.4", features = ["defmt", "unstable-pac", "time-driver", "critical-section-impl", "rp2040"] } +[profile.release] +debug = 2 +lto = true +opt-level = 'z' + +[profile.dev] +debug = 2 +lto = true +opt-level = "z" diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..318688b --- /dev/null +++ b/build.rs @@ -0,0 +1,36 @@ +//! This build script copies the `memory.x` file from the crate root into +//! a directory where the linker can always find it at build time. +//! For many projects this is optional, as the linker always searches the +//! project root directory -- wherever `Cargo.toml` is. However, if you +//! are using a workspace or have a more complicated build setup, this +//! build script becomes required. Additionally, by requesting that +//! Cargo re-run the build script whenever `memory.x` is changed, +//! updating `memory.x` ensures a rebuild of the application with the +//! new memory settings. + +use std::env; +use std::fs::File; +use std::io::Write; +use std::path::PathBuf; + +fn main() { + // Put `memory.x` in our output directory and ensure it's + // on the linker search path. + let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); + File::create(out.join("memory.x")) + .unwrap() + .write_all(include_bytes!("memory.x")) + .unwrap(); + println!("cargo:rustc-link-search={}", out.display()); + + // By default, Cargo will re-run a build script whenever + // any file in the project changes. By specifying `memory.x` + // here, we ensure the build script is only re-run when + // `memory.x` is changed. + println!("cargo:rerun-if-changed=memory.x"); + + println!("cargo:rustc-link-arg-bins=--nmagic"); + println!("cargo:rustc-link-arg-bins=-Tlink.x"); + println!("cargo:rustc-link-arg-bins=-Tdefmt.x"); +println!("cargo:rustc-link-arg-bins=-Tlink-rp.x"); +} diff --git a/memory.x b/memory.x new file mode 100644 index 0000000..411416b --- /dev/null +++ b/memory.x @@ -0,0 +1,7 @@ +MEMORY +{ +BOOT2 : ORIGIN = 0x10000000, LENGTH = 0x100 +FLASH : ORIGIN = 0x10000100, LENGTH = 2048K - 0x100 +RAM : ORIGIN = 0x20000000, LENGTH = 264K +} + diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..c42fb4a --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,11 @@ +# Before upgrading check that everything is available on all tier1 targets here: +# https://rust-lang.github.io/rustup-components-history +[toolchain] +channel = "stable" +components = [ "rustfmt" ] +targets = [ + "thumbv6m-none-eabi", + "thumbv7em-none-eabihf", + "thumbv8m.main-none-eabihf", + "riscv32imac-unknown-none-elf", +] diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..1c0716f --- /dev/null +++ b/src/main.rs @@ -0,0 +1,15 @@ +#![no_std] +#![no_main] + +use embassy_executor::Spawner; +use embassy_time::{Duration, Timer}; +use {defmt_rtt as _, panic_probe as _}; + +#[embassy_executor::main] +async fn main(_spawner: Spawner) -> ! { + let _p = embassy_rp::init(Default::default()); + loop { + defmt::info!("Blink"); + Timer::after(Duration::from_millis(100)).await; + } +}