commit 7a12a39bd3e9b2b027a042e4d36b058034d517d1 Author: hodasemi Date: Mon Mar 11 21:58:53 2024 +0100 Inital commit diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..7986e53 --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,16 @@ +[target.'cfg(all(target_arch = "arm", target_os = "none"))'] +# Choose a default "cargo run" tool: +# - probe-run provides flashing and defmt via a hardware debugger +# - cargo embed offers flashing, rtt, defmt and a gdb server via a hardware debugger +# it is configured via the Embed.toml in the root of this project +# - elf2uf2-rs loads firmware over USB when the rp2040 is in boot mode +# runner = "probe-run --chip RP2040" +# runner = "cargo embed" +runner = "elf2uf2-rs -d" + +[build] +# Cortex-M0 and Cortex-M0+ +target = "thumbv6m-none-eabi" + +[env] +# DEFMT_LOG = "debug" \ No newline at end of file diff --git a/.gitea/workflows/pull_request.yaml b/.gitea/workflows/pull_request.yaml new file mode 100644 index 0000000..1bc0838 --- /dev/null +++ b/.gitea/workflows/pull_request.yaml @@ -0,0 +1,16 @@ +name: Terrarium Controller Merge Build +run_name: Test successful terrarium controller build on merge request + +on: + pull_request: + types: [opened, reopened, edited, review_requested, synchronize] + +jobs: + Build: + steps: + - uses: https://github.com/actions/checkout@v3 + + - uses: https://github.com/dtolnay/rust-toolchain@stable + + - name: Build + run: cargo build \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..869df07 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/target +Cargo.lock \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..e671987 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "rust-analyzer.check.allTargets": false +} \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..5b98ced --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "rust-embassy-template" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +embassy-executor = { version = "0.5.0", features = ["task-arena-size-32768", "arch-cortex-m", "executor-thread", "executor-interrupt", "integrated-timers"] } +embassy-rp = { version = "0.1.0", features = ["unstable-pac", "time-driver", "critical-section-impl"] } +embassy-futures = { version = "0.1.1" } + +cortex-m-rt = "0.7.0" diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..113c72e --- /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=-Tlink-rp.x"); + // println!("cargo:rustc-link-arg-bins=-Tdefmt.x"); +} diff --git a/memory.x b/memory.x new file mode 100644 index 0000000..771b8fa --- /dev/null +++ b/memory.x @@ -0,0 +1,17 @@ +MEMORY { + BOOT2 : ORIGIN = 0x10000000, LENGTH = 0x100 + FLASH : ORIGIN = 0x10000100, LENGTH = 2048K - 0x100 + + /* Pick one of the two options for RAM layout */ + + /* OPTION A: Use all RAM banks as one big block */ + /* Reasonable, unless you are doing something */ + /* really particular with DMA or other concurrent */ + /* access that would benefit from striping */ + RAM : ORIGIN = 0x20000000, LENGTH = 264K + + /* OPTION B: Keep the unstriped sections separate */ + /* RAM: ORIGIN = 0x20000000, LENGTH = 256K */ + /* SCRATCH_A: ORIGIN = 0x20040000, LENGTH = 4K */ + /* SCRATCH_B: ORIGIN = 0x20041000, LENGTH = 4K */ +} \ No newline at end of file diff --git a/renovate.json b/renovate.json new file mode 100644 index 0000000..c24cd7a --- /dev/null +++ b/renovate.json @@ -0,0 +1,15 @@ +{ + "$schema": "https://docs.renovatebot.com/renovate-schema.json", + "extends": [ + "config:base" + ], + "packageRules": [ + { + "matchUpdateTypes": [ + "minor", + "patch" + ], + "automerge": true + } + ] +} \ No newline at end of file diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..dfac03c --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,3 @@ +[toolchain] +components = [ "rust-src", "rustfmt", "llvm-tools" ] +targets = ["thumbv6m-none-eabi"] \ No newline at end of file diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..87ed5d5 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,27 @@ +#![no_std] +#![no_main] + +use core::panic::PanicInfo; + +use embassy_executor::Spawner; +use embassy_rp::gpio::{Level, Output}; + +#[panic_handler] +fn panic(_info: &PanicInfo) -> ! { + loop {} +} + +#[embassy_executor::main] +async fn main(_spawner: Spawner) { + let p = embassy_rp::init(Default::default()); + + let mut pin = Output::new(p.PIN_25, Level::High); + + let toggle_led = async { + loop { + pin.toggle(); + } + }; + + toggle_led.await; +}