Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ std = ["embedded-io-async/std"]
[dev-dependencies]
tokio = { version = "1.36.0", features = ["macros", "rt"] }

[workspace]
members = [".", "examples/rp2040"]

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]
11 changes: 11 additions & 0 deletions examples/rp2040/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
runner = "probe-rs run --chip RP2040"

[build]
target = "thumbv6m-none-eabi" # Cortex-M0 and Cortex-M0+

[env]
DEFMT_LOG = "trace"

[profile.release]
debug = 2
53 changes: 53 additions & 0 deletions examples/rp2040/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
[package]
name = "rp2040"
version = "0.1.0"
edition = "2021"

[dependencies]
cortex-m = { version = "0.7.6", features = ["inline-asm"] }
cortex-m-rt = "0.7.0"
cyw43 = { version = "0.1.0", git = "https://github.com/embassy-rs/embassy", features = [
"defmt",
"firmware-logs",
] }
cyw43-pio = { version = "0.1.0", git = "https://github.com/embassy-rs/embassy", features = [
"defmt",
"overclock",
] }
defmt = "0.3"
defmt-rtt = "0.4"
embassy-embedded-hal = { version = "0.1.0", git = "https://github.com/embassy-rs/embassy", features = [
"defmt",
] }
embassy-executor = { version = "0.5.0", git = "https://github.com/embassy-rs/embassy", features = [
"task-arena-size-32768",
"arch-cortex-m",
"executor-thread",
"executor-interrupt",
"defmt",
"integrated-timers",
] }
embassy-rp = { version = "0.1.0", git = "https://github.com/embassy-rs/embassy", features = [
"defmt",
"unstable-pac",
"time-driver",
"critical-section-impl",
] }
embassy-sync = "0.5.0"
embassy-time = { version = "0.3.0", git = "https://github.com/embassy-rs/embassy", features = [
"defmt",
"defmt-timestamp-uptime",
] }
embedded-hal-async = "1.0.0"
fixed = "1.23.1"
fixed-macro = "1.2"
panic-probe = { version = "0.3", features = ["print-defmt"] }
pio = "0.2.1"
pio-proc = "0.2"
portable-atomic = { version = "1.5", features = ["critical-section"] }
static_cell = "2"
han = { path = "../..", features = [
"defmt-03",
"embedded-io-async",
], default-features = false }
embedded-io-async = { version = "0.6.1", features = ["defmt-03"] }
36 changes: 36 additions & 0 deletions examples/rp2040/build.rs
Original file line number Diff line number Diff line change
@@ -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");
}
Empty file.
Empty file.
17 changes: 17 additions & 0 deletions examples/rp2040/memory.x
Original file line number Diff line number Diff line change
@@ -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 */
}
27 changes: 27 additions & 0 deletions examples/rp2040/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//! This example shows how to use UART (Universal asynchronous receiver-transmitter) in the RP2040 chip.
//!
//! No specific hardware is specified in this example. Only output on pin 0 is tested.
//! The Raspberry Pi Debug Probe (https://www.raspberrypi.com/products/debug-probe/) could be used
//! with its UART port.

#![no_std]
#![no_main]

use embassy_executor::Spawner;
use embassy_rp::uart;
use {defmt_rtt as _, panic_probe as _};

#[embassy_executor::main]
async fn main(_spawner: Spawner) {
let p = embassy_rp::init(Default::default());
let mut config = uart::Config::default();
config.invert_rx = true;
config.baudrate = 115_200;
let mut uart = uart::UartRx::new_blocking(p.UART1, p.PIN_5, config);

loop {
defmt::info!("read");
let mut buf = [0; 1];
let n = uart.blocking_read(&mut buf).unwrap();
}
}