Move examples to a subdirectory
This commit is contained in:
19
examples/rp/.cargo/config.toml
Normal file
19
examples/rp/.cargo/config.toml
Normal file
@ -0,0 +1,19 @@
|
||||
[unstable]
|
||||
build-std = ["core"]
|
||||
|
||||
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
|
||||
runner = "probe-run-rp --chip RP2040"
|
||||
|
||||
rustflags = [
|
||||
# LLD (shipped with the Rust toolchain) is used as the default linker
|
||||
"-C", "link-arg=--nmagic",
|
||||
"-C", "link-arg=-Tlink.x",
|
||||
"-C", "link-arg=-Tlink-rp.x",
|
||||
"-C", "link-arg=-Tdefmt.x",
|
||||
|
||||
# Code-size optimizations.
|
||||
"-Z", "trap-unreachable=no",
|
||||
]
|
||||
|
||||
[build]
|
||||
target = "thumbv6m-none-eabi" # Cortex-M0 and Cortex-M0+
|
32
examples/rp/Cargo.toml
Normal file
32
examples/rp/Cargo.toml
Normal file
@ -0,0 +1,32 @@
|
||||
[package]
|
||||
authors = ["Dario Nieuwenhuis <dirbaio@dirbaio.net>"]
|
||||
edition = "2018"
|
||||
name = "embassy-rp-examples"
|
||||
version = "0.1.0"
|
||||
|
||||
[features]
|
||||
default = [
|
||||
"defmt-default",
|
||||
]
|
||||
defmt-default = []
|
||||
defmt-trace = []
|
||||
defmt-debug = []
|
||||
defmt-info = []
|
||||
defmt-warn = []
|
||||
defmt-error = []
|
||||
|
||||
|
||||
[dependencies]
|
||||
embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt", "defmt-trace"] }
|
||||
embassy-rp = { version = "0.1.0", path = "../../embassy-rp", features = ["defmt", "defmt-trace"] }
|
||||
rp2040-pac2 = { git = "https://github.com/Dirbaio/rp2040-pac", rev="254f4677937801155ca3cb17c7bb9d38eb62683e" }
|
||||
atomic-polyfill = { version = "0.1.1" }
|
||||
|
||||
defmt = "0.2.0"
|
||||
defmt-rtt = "0.2.0"
|
||||
|
||||
cortex-m = { version = "0.7.1", features = ["inline-asm"] }
|
||||
cortex-m-rt = "0.6.13"
|
||||
embedded-hal = { version = "0.2.4" }
|
||||
panic-probe = { version = "0.2.0", features = ["print-defmt"] }
|
||||
futures = { version = "0.3.8", default-features = false, features = ["async-await", "cfg-target-has-atomic", "unstable"] }
|
31
examples/rp/build.rs
Normal file
31
examples/rp/build.rs
Normal file
@ -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");
|
||||
}
|
5
examples/rp/memory.x
Normal file
5
examples/rp/memory.x
Normal file
@ -0,0 +1,5 @@
|
||||
MEMORY {
|
||||
BOOT2 : ORIGIN = 0x10000000, LENGTH = 0x100
|
||||
FLASH : ORIGIN = 0x10000100, LENGTH = 2048K - 0x100
|
||||
RAM : ORIGIN = 0x20000000, LENGTH = 256K
|
||||
}
|
31
examples/rp/src/bin/blinky.rs
Normal file
31
examples/rp/src/bin/blinky.rs
Normal file
@ -0,0 +1,31 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(asm)]
|
||||
#![feature(min_type_alias_impl_trait)]
|
||||
#![feature(impl_trait_in_bindings)]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
#[path = "../example_common.rs"]
|
||||
mod example_common;
|
||||
|
||||
use defmt::*;
|
||||
use embassy::executor::Spawner;
|
||||
use embassy_rp::{gpio, Peripherals};
|
||||
use embedded_hal::digital::v2::OutputPin;
|
||||
use gpio::{Level, Output};
|
||||
|
||||
#[embassy::main]
|
||||
async fn main(_spawner: Spawner, p: Peripherals) {
|
||||
let mut led = Output::new(p.PIN_25, Level::Low);
|
||||
|
||||
loop {
|
||||
info!("led on!");
|
||||
led.set_high().unwrap();
|
||||
cortex_m::asm::delay(1_000_000);
|
||||
|
||||
info!("led off!");
|
||||
led.set_low().unwrap();
|
||||
cortex_m::asm::delay(1_000_000);
|
||||
}
|
||||
}
|
29
examples/rp/src/bin/button.rs
Normal file
29
examples/rp/src/bin/button.rs
Normal file
@ -0,0 +1,29 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(asm)]
|
||||
#![feature(min_type_alias_impl_trait)]
|
||||
#![feature(impl_trait_in_bindings)]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
#[path = "../example_common.rs"]
|
||||
mod example_common;
|
||||
|
||||
use embassy::executor::Spawner;
|
||||
use embassy_rp::gpio::{Input, Level, Output, Pull};
|
||||
use embassy_rp::Peripherals;
|
||||
use embedded_hal::digital::v2::{InputPin, OutputPin};
|
||||
|
||||
#[embassy::main]
|
||||
async fn main(_spawner: Spawner, p: Peripherals) {
|
||||
let button = Input::new(p.PIN_28, Pull::Up);
|
||||
let mut led = Output::new(p.PIN_25, Level::Low);
|
||||
|
||||
loop {
|
||||
if button.is_high().unwrap() {
|
||||
led.set_high().unwrap();
|
||||
} else {
|
||||
led.set_low().unwrap();
|
||||
}
|
||||
}
|
||||
}
|
25
examples/rp/src/bin/uart.rs
Normal file
25
examples/rp/src/bin/uart.rs
Normal file
@ -0,0 +1,25 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(asm)]
|
||||
#![feature(min_type_alias_impl_trait)]
|
||||
#![feature(impl_trait_in_bindings)]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
#[path = "../example_common.rs"]
|
||||
mod example_common;
|
||||
|
||||
use embassy::executor::Spawner;
|
||||
use embassy_rp::{uart, Peripherals};
|
||||
|
||||
#[embassy::main]
|
||||
async fn main(_spawner: Spawner, p: Peripherals) {
|
||||
let config = uart::Config::default();
|
||||
let mut uart = uart::Uart::new(p.UART0, p.PIN_0, p.PIN_1, p.PIN_2, p.PIN_3, config);
|
||||
uart.send("Hello World!\r\n".as_bytes());
|
||||
|
||||
loop {
|
||||
uart.send("hello there!\r\n".as_bytes());
|
||||
cortex_m::asm::delay(1_000_000);
|
||||
}
|
||||
}
|
12
examples/rp/src/example_common.rs
Normal file
12
examples/rp/src/example_common.rs
Normal file
@ -0,0 +1,12 @@
|
||||
use core::sync::atomic::{AtomicUsize, Ordering};
|
||||
use defmt_rtt as _;
|
||||
use panic_probe as _;
|
||||
|
||||
defmt::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
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user