commit 48dce4894f0d6f31060d3422b855f3ddef20e949 Author: Dario Nieuwenhuis Date: Sat Jan 23 05:02:09 2021 +0100 :tada: diff --git a/.cargo/config b/.cargo/config new file mode 100644 index 0000000..5a63ece --- /dev/null +++ b/.cargo/config @@ -0,0 +1,18 @@ +[target.'cfg(all(target_arch = "arm", target_os = "none"))'] +runner = "./probe-run.sh" + +rustflags = [ + "-C", "link-arg=--nmagic", + "-C", "link-arg=-Tlink.x", + "-C", "link-arg=-Tdefmt.x", +] + +[build] +# Pick ONE of these compilation targets +target = "thumbv6m-none-eabi" # Cortex-M0 and Cortex-M0+ +# target = "thumbv7m-none-eabi" # Cortex-M3 +# target = "thumbv7em-none-eabi" # Cortex-M4 and Cortex-M7 (no FPU) +# target = "thumbv7em-none-eabihf" # Cortex-M4F and Cortex-M7F (with FPU) +# target = "thumbv8m.base-none-eabi" # Cortex-M23 +# target = "thumbv8m.main-none-eabi" # Cortex-M33 (no FPU) +# target = "thumbv8m.main-none-eabihf" # Cortex-M33 (with FPU) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3a0e903 --- /dev/null +++ b/.gitignore @@ -0,0 +1,14 @@ +**/*.rs.bk +.#* +.gdb_history +Cargo.lock +target/ + +# editor files +.vscode/* +!.vscode/*.md +!.vscode/*.svd +!.vscode/launch.json +!.vscode/tasks.json +!.vscode/extensions.json +!.vscode/settings.json \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..23fd35f --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "editor.formatOnSave": true +} \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..62131b8 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,66 @@ +[package] +authors = ["Dario Nieuwenhuis "] +edition = "2018" +readme = "README.md" +name = "rp-test" +version = "0.1.0" + +[dependencies] +cortex-m = "0.6.0" +cortex-m-rt = "0.6.10" +cortex-m-semihosting = "0.3.3" + +defmt = "0.1.3" +defmt-rtt = "0.1.0" +panic-probe = "0.1.0" + +rp2040-pac = { git = "https://github.com/Dirbaio/rp2040-pac", branch="main" } +[features] +default = [ + "defmt-default", +] +defmt-default = [] +defmt-trace = [] +defmt-debug = [] +defmt-info = [] +defmt-warn = [] +defmt-error = [] + + +# this lets you use `cargo fix`! +[[bin]] +name = "rp-test" +test = false +bench = false + +[profile.dev] +codegen-units = 1 +debug = 2 +debug-assertions = true +incremental = false +opt-level = 3 +overflow-checks = true + +[profile.release] +codegen-units = 1 +debug = 2 +debug-assertions = false +incremental = false +lto = "fat" +opt-level = 's' +overflow-checks = false + +# do not optimize proc-macro crates = faster builds from scratch +[profile.dev.build-override] +codegen-units = 8 +debug = false +debug-assertions = false +opt-level = 0 +overflow-checks = false + +[profile.release.build-override] +codegen-units = 8 +debug = false +debug-assertions = false +opt-level = 0 +overflow-checks = false diff --git a/README.md b/README.md new file mode 100644 index 0000000..3e3c9c0 --- /dev/null +++ b/README.md @@ -0,0 +1,26 @@ +# Raspberry pico RP2040 rust test! + +How to run: + +Fist, clone these repos all in the same directory, next to each other + +- https://github.com/Dirbaio/rp2040-rust-test +- https://github.com/Dirbaio/rp2040-pac +- https://github.com/Dirbaio/probe-run +- https://github.com/Dirbaio/probe-rs + +Then you're done + + cd rp2040-rust-test + cargo run + +# License + +This thingy is licensed under either of + +- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or + http://www.apache.org/licenses/LICENSE-2.0) + +- MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) + +at your option. diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..d534cc3 --- /dev/null +++ b/build.rs @@ -0,0 +1,31 @@ +//! 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"); +} diff --git a/memory.x b/memory.x new file mode 100644 index 0000000..1857065 --- /dev/null +++ b/memory.x @@ -0,0 +1,6 @@ +MEMORY +{ + /* We set "flash" to half the RAM */ + FLASH : ORIGIN = 0x20000000, LENGTH = 128K + RAM : ORIGIN = 0x20020000, LENGTH = 128K +} diff --git a/probe-run.sh b/probe-run.sh new file mode 100755 index 0000000..006a89d --- /dev/null +++ b/probe-run.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +bin="$PWD/$1" +shift + +cd ../probe-run +cargo run -- "$bin" "$@" --chip RP2040 diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..ff8853a --- /dev/null +++ b/src/main.rs @@ -0,0 +1,45 @@ +#![no_std] +#![no_main] + +use core::sync::atomic::{AtomicUsize, Ordering}; +use cortex_m_rt::entry; +use defmt::*; +use defmt_rtt as _; // global logger +use panic_probe as _; +use rp2040_pac as pac; + +#[defmt::timestamp] +fn timestamp() -> u64 { + static COUNT: AtomicUsize = AtomicUsize::new(0); + // NOTE(no-CAS) `timestamps` runs with interrupts disabled + let n = COUNT.load(Ordering::Relaxed); + COUNT.store(n + 1, Ordering::Relaxed); + n as u64 +} + +#[entry] +fn main() -> ! { + info!("Hello World!"); + + let p = pac::Peripherals::take().unwrap(); + + loop { + info!("on!"); + p.IO_BANK0.gpio25_ctrl.write(|w| { + w.oeover().enable(); + w.outover().high(); + w + }); + + cortex_m::asm::delay(64_000_000); + + info!("off!"); + p.IO_BANK0.gpio25_ctrl.write(|w| { + w.oeover().enable(); + w.outover().low(); + w + }); + + cortex_m::asm::delay(64_000_000); + } +}