rp: add initial version
This commit is contained in:
30
embassy-rp-examples/.cargo/config
Normal file
30
embassy-rp-examples/.cargo/config
Normal file
@ -0,0 +1,30 @@
|
||||
[unstable]
|
||||
build-std = ["core"]
|
||||
build-std-features = ["panic_immediate_abort"]
|
||||
|
||||
[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=-Tdefmt.x",
|
||||
|
||||
# if you run into problems with LLD switch to the GNU linker by commenting out
|
||||
# this line
|
||||
# "-C", "linker=arm-none-eabi-ld",
|
||||
|
||||
# if you need to link to pre-compiled C libraries provided by a C toolchain
|
||||
# use GCC as the linker by commenting out both lines above and then
|
||||
# uncommenting the three lines below
|
||||
# "-C", "linker=arm-none-eabi-gcc",
|
||||
# "-C", "link-arg=-Wl,-Tlink.x",
|
||||
# "-C", "link-arg=-nostartfiles",
|
||||
|
||||
# Code-size optimizations.
|
||||
"-Z", "trap-unreachable=no",
|
||||
]
|
||||
|
||||
[build]
|
||||
target = "thumbv6m-none-eabi" # Cortex-M0 and Cortex-M0+
|
33
embassy-rp-examples/Cargo.toml
Normal file
33
embassy-rp-examples/Cargo.toml
Normal file
@ -0,0 +1,33 @@
|
||||
[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-boot2 = { git = "https://github.com/rp-rs/rp2040-boot2-rs", branch="main" }
|
||||
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 = "0.1.0"
|
||||
futures = { version = "0.3.8", default-features = false, features = ["async-await", "cfg-target-has-atomic", "unstable"] }
|
31
embassy-rp-examples/build.rs
Normal file
31
embassy-rp-examples/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");
|
||||
}
|
13
embassy-rp-examples/memory.x
Normal file
13
embassy-rp-examples/memory.x
Normal file
@ -0,0 +1,13 @@
|
||||
MEMORY {
|
||||
BOOT2 : ORIGIN = 0x10000000, LENGTH = 0x100
|
||||
FLASH : ORIGIN = 0x10000100, LENGTH = 2048K - 0x100
|
||||
RAM : ORIGIN = 0x20000000, LENGTH = 256K
|
||||
}
|
||||
|
||||
SECTIONS {
|
||||
/* ### Boot loader */
|
||||
.boot2 ORIGIN(BOOT2) :
|
||||
{
|
||||
KEEP(*(.boot2));
|
||||
} > BOOT2
|
||||
} INSERT BEFORE .text;
|
72
embassy-rp-examples/src/main.rs
Normal file
72
embassy-rp-examples/src/main.rs
Normal file
@ -0,0 +1,72 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(asm)]
|
||||
#![feature(min_type_alias_impl_trait)]
|
||||
#![feature(impl_trait_in_bindings)]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use core::sync::atomic::{AtomicUsize, Ordering};
|
||||
use defmt::{panic, *};
|
||||
use defmt_rtt as _;
|
||||
use embassy::executor::Spawner;
|
||||
use embassy::interrupt::InterruptExt;
|
||||
use embassy_rp::{dma, gpio, interrupt, uart, Peripherals};
|
||||
use embedded_hal::digital::v2::OutputPin;
|
||||
use panic_probe as _;
|
||||
use rp2040_pac2 as pac;
|
||||
|
||||
#[link_section = ".boot2"]
|
||||
#[used]
|
||||
pub static BOOT2: [u8; 256] = rp2040_boot2::BOOT_LOADER;
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
#[embassy::main]
|
||||
async fn main(spanwer: Spawner) {
|
||||
let p = unwrap!(Peripherals::take());
|
||||
|
||||
let mut 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());
|
||||
|
||||
let mut led = gpio::Output::new(p.PIN_25, gpio::Level::Low);
|
||||
|
||||
let irq = interrupt::take!(DMA_IRQ_0);
|
||||
unsafe {
|
||||
//pac::DMA.inte0().write(|w| w.set_inte0(1 << 0));
|
||||
}
|
||||
irq.set_handler(dma_irq);
|
||||
irq.unpend();
|
||||
irq.enable();
|
||||
|
||||
let from: [u32; 4] = [1, 2, 3, 4];
|
||||
let mut to: [u32; 4] = [9, 8, 7, 6];
|
||||
info!("before dma: from = {:?}, to = {:?}", from, to);
|
||||
cortex_m::asm::delay(4_000_000);
|
||||
dma::Dma::copy(p.DMA_CH0, &from, &mut to);
|
||||
cortex_m::asm::delay(4_000_000);
|
||||
info!("after dma: from = {:?}, to = {:?}", from, to);
|
||||
|
||||
loop {
|
||||
info!("led on!");
|
||||
uart.send("ON!\r".as_bytes());
|
||||
led.set_high().unwrap();
|
||||
cortex_m::asm::delay(1_000_000);
|
||||
|
||||
info!("led off!");
|
||||
uart.send("Off!\r".as_bytes());
|
||||
led.set_low().unwrap();
|
||||
cortex_m::asm::delay(4_000_000);
|
||||
}
|
||||
}
|
||||
|
||||
unsafe fn dma_irq(ctx: *mut ()) {
|
||||
info!("DMA IRQ!");
|
||||
}
|
Reference in New Issue
Block a user