Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 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
10 changes: 6 additions & 4 deletions ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,12 @@ cargo batch \
--- build --release --manifest-path embassy-nrf/Cargo.toml --target thumbv6m-none-eabi --features nrf51,defmt,time,time-driver-rtc1 \
--- build --release --manifest-path embassy-nrf/Cargo.toml --target thumbv6m-none-eabi --features nrf51,defmt,time \
--- build --release --manifest-path embassy-nrf/Cargo.toml --target thumbv6m-none-eabi --features nrf51,time \
--- build --release --manifest-path embassy-rp/Cargo.toml --target thumbv6m-none-eabi --features time-driver,defmt \
--- build --release --manifest-path embassy-rp/Cargo.toml --target thumbv6m-none-eabi --features time-driver,log \
--- build --release --manifest-path embassy-rp/Cargo.toml --target thumbv6m-none-eabi --features time-driver,intrinsics \
--- build --release --manifest-path embassy-rp/Cargo.toml --target thumbv6m-none-eabi --features time-driver,qspi-as-gpio \
--- build --release --manifest-path embassy-rp/Cargo.toml --target thumbv6m-none-eabi --features time-driver,defmt,rp2040 \
--- build --release --manifest-path embassy-rp/Cargo.toml --target thumbv6m-none-eabi --features time-driver,log,rp2040 \
--- build --release --manifest-path embassy-rp/Cargo.toml --target thumbv6m-none-eabi --features time-driver,intrinsics,rp2040 \
--- build --release --manifest-path embassy-rp/Cargo.toml --target thumbv6m-none-eabi --features time-driver,qspi-as-gpio,rp2040 \
--- build --release --manifest-path embassy-rp/Cargo.toml --target thumbv8m.main-none-eabihf --features time-driver,defmt,rp235xa \
--- build --release --manifest-path embassy-rp/Cargo.toml --target thumbv8m.main-none-eabihf --features time-driver,log,rp235xa \
--- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features stm32l552ze,defmt,exti,time-driver-any,time \
--- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features stm32l552ze,defmt,time-driver-any,time \
--- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features stm32l552ze,defmt,exti,time \
Expand Down
18 changes: 17 additions & 1 deletion embassy-rp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-rp/sr
features = ["defmt", "unstable-pac", "time-driver"]
flavors = [
{ name = "rp2040", target = "thumbv6m-none-eabi" },
{ name = "rp235x", target = "thumbv8m.main-none-eabi" },
]

[package.metadata.docs.rs]
Expand Down Expand Up @@ -88,6 +89,17 @@ boot2-w25x10cl = []
## ```
boot2-none = []

rp2040 = ["rp-pac/rp2040"]
rp235x = ["rp-pac/rp235x"]
rp235xa = ["rp235x"]
rp235xb = ["rp235x"]

# Add a binary-info header block containing picotool-compatible metadata.
#
# Takes up a little flash space, but picotool can then report the name of your
# program and other details.
binary-info = [ "rt" ]

[dependencies]
embassy-sync = { version = "0.6.0", path = "../embassy-sync" }
embassy-time-driver = { version = "0.1", path = "../embassy-time-driver", optional = true }
Expand All @@ -112,7 +124,7 @@ embedded-storage-async = { version = "0.4.1" }
rand_core = "0.6.4"
fixed = "1.23.1"

rp-pac = { version = "6" }
rp-pac = { version = "6.0.0", feature = ["rt"] }

embedded-hal-02 = { package = "embedded-hal", version = "0.2.6", features = ["unproven"] }
embedded-hal-1 = { package = "embedded-hal", version = "1.0" }
Expand All @@ -123,7 +135,11 @@ pio-proc = {version= "0.2" }
pio = {version= "0.2.1" }
rp2040-boot2 = "0.3"
document-features = "0.2.7"
sha2-const-stable = "0.1"

[dev-dependencies]
embassy-executor = { version = "0.6.0", path = "../embassy-executor", features = ["arch-std", "executor-thread"] }
static_cell = { version = "2" }

[patch.crates-io]
rp-pac = { git = "https://github.com/embassy-rs/rp-pac.git" }
18 changes: 10 additions & 8 deletions embassy-rp/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ use std::io::Write;
use std::path::PathBuf;

fn main() {
// Put the linker script somewhere the linker can find it
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
let link_x = include_bytes!("link-rp.x.in");
let mut f = File::create(out.join("link-rp.x")).unwrap();
f.write_all(link_x).unwrap();
if env::var("CARGO_FEATURE_RP2040").is_ok() {
// Put the linker script somewhere the linker can find it
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
let link_x = include_bytes!("link-rp.x.in");
let mut f = File::create(out.join("link-rp.x")).unwrap();
f.write_all(link_x).unwrap();

println!("cargo:rustc-link-search={}", out.display());
println!("cargo:rustc-link-search={}", out.display());

println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=link-rp.x.in");
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=link-rp.x.in");
}
}
2 changes: 1 addition & 1 deletion embassy-rp/link-rp.x.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ SECTIONS {
{
KEEP(*(.boot2));
} > BOOT2
}
}
29 changes: 28 additions & 1 deletion embassy-rp/src/adc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use embassy_sync::waitqueue::AtomicWaker;
use crate::gpio::{self, AnyPin, Pull, SealedPin as GpioPin};
use crate::interrupt::typelevel::Binding;
use crate::interrupt::InterruptExt;
use crate::pac::dma::vals::TreqSel;
use crate::peripherals::{ADC, ADC_TEMP_SENSOR};
use crate::{dma, interrupt, pac, peripherals, Peripheral, RegExt};

Expand All @@ -34,6 +35,8 @@ impl<'p> Channel<'p> {
pub fn new_pin(pin: impl Peripheral<P = impl AdcPin + 'p> + 'p, pull: Pull) -> Self {
into_ref!(pin);
pin.pad_ctrl().modify(|w| {
#[cfg(feature = "rp235x")]
w.set_iso(false);
// manual says:
//
// > When using an ADC input shared with a GPIO pin, the pin’s
Expand Down Expand Up @@ -229,7 +232,10 @@ impl<'d> Adc<'d, Async> {
div: u16,
dma: impl Peripheral<P = impl dma::Channel>,
) -> Result<(), Error> {
#[cfg(feature = "rp2040")]
let mut rrobin = 0_u8;
#[cfg(feature = "rp235x")]
let mut rrobin = 0_u16;
for c in channels {
rrobin |= 1 << c;
}
Expand Down Expand Up @@ -278,7 +284,7 @@ impl<'d> Adc<'d, Async> {
}
let auto_reset = ResetDmaConfig;

let dma = unsafe { dma::read(dma, r.fifo().as_ptr() as *const W, buf as *mut [W], 36) };
let dma = unsafe { dma::read(dma, r.fifo().as_ptr() as *const W, buf as *mut [W], TreqSel::ADC) };
// start conversions and wait for dma to finish. we can't report errors early
// because there's no interrupt to signal them, and inspecting every element
// of the fifo is too costly to do here.
Expand Down Expand Up @@ -423,10 +429,31 @@ macro_rules! impl_pin {
};
}

#[cfg(any(feature = "rp235xa", feature = "rp2040"))]
impl_pin!(PIN_26, 0);
#[cfg(any(feature = "rp235xa", feature = "rp2040"))]
impl_pin!(PIN_27, 1);
#[cfg(any(feature = "rp235xa", feature = "rp2040"))]
impl_pin!(PIN_28, 2);
#[cfg(any(feature = "rp235xa", feature = "rp2040"))]
impl_pin!(PIN_29, 3);

#[cfg(feature = "rp235xb")]
impl_pin!(PIN_40, 0);
#[cfg(feature = "rp235xb")]
impl_pin!(PIN_41, 1);
#[cfg(feature = "rp235xb")]
impl_pin!(PIN_42, 2);
#[cfg(feature = "rp235xb")]
impl_pin!(PIN_43, 3);
#[cfg(feature = "rp235xb")]
impl_pin!(PIN_44, 4);
#[cfg(feature = "rp235xb")]
impl_pin!(PIN_45, 5);
#[cfg(feature = "rp235xb")]
impl_pin!(PIN_46, 6);
#[cfg(feature = "rp235xb")]
impl_pin!(PIN_47, 7);

impl SealedAdcChannel for peripherals::ADC_TEMP_SENSOR {}
impl AdcChannel for peripherals::ADC_TEMP_SENSOR {}
31 changes: 31 additions & 0 deletions embassy-rp/src/binary_info/consts.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//! Constants for binary info

/// All Raspberry Pi specified IDs have this tag.
///
/// You can create your own for custom fields.
pub const TAG_RASPBERRY_PI: u16 = super::make_tag(b"RP");

/// Used to note the program name - use with StringEntry
pub const ID_RP_PROGRAM_NAME: u32 = 0x02031c86;
/// Used to note the program version - use with StringEntry
pub const ID_RP_PROGRAM_VERSION_STRING: u32 = 0x11a9bc3a;
/// Used to note the program build date - use with StringEntry
pub const ID_RP_PROGRAM_BUILD_DATE_STRING: u32 = 0x9da22254;
/// Used to note the size of the binary - use with IntegerEntry
pub const ID_RP_BINARY_END: u32 = 0x68f465de;
/// Used to note a URL for the program - use with StringEntry
pub const ID_RP_PROGRAM_URL: u32 = 0x1856239a;
/// Used to note a description of the program - use with StringEntry
pub const ID_RP_PROGRAM_DESCRIPTION: u32 = 0xb6a07c19;
/// Used to note some feature of the program - use with StringEntry
pub const ID_RP_PROGRAM_FEATURE: u32 = 0xa1f4b453;
/// Used to note some whether this was a Debug or Release build - use with StringEntry
pub const ID_RP_PROGRAM_BUILD_ATTRIBUTE: u32 = 0x4275f0d3;
/// Used to note the Pico SDK version used - use with StringEntry
pub const ID_RP_SDK_VERSION: u32 = 0x5360b3ab;
/// Used to note which board this program targets - use with StringEntry
pub const ID_RP_PICO_BOARD: u32 = 0xb63cffbb;
/// Used to note which `boot2` image this program uses - use with StringEntry
pub const ID_RP_BOOT2_NAME: u32 = 0x7f8882e1;

// End of file
168 changes: 168 additions & 0 deletions embassy-rp/src/binary_info/macros.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
//! Handy macros for making Binary Info entries

/// Generate a static item containing the given environment variable,
/// and return its [`EntryAddr`](super::EntryAddr).
#[macro_export]
macro_rules! binary_info_env {
($tag:expr, $id:expr, $env_var_name:expr) => {
$crate::binary_info_str!($tag, $id, {
let value = concat!(env!($env_var_name), "\0");
// # Safety
//
// We used `concat!` to null-terminate on the line above.
let value_cstr = unsafe { core::ffi::CStr::from_bytes_with_nul_unchecked(value.as_bytes()) };
value_cstr
})
};
}

/// Generate a static item containing the given string, and return its
/// [`EntryAddr`](super::EntryAddr).
///
/// You must pass a numeric tag, a numeric ID, and `&CStr` (which is always
/// null-terminated).
#[macro_export]
macro_rules! binary_info_str {
($tag:expr, $id:expr, $str:expr) => {{
static ENTRY: $crate::binary_info::StringEntry = $crate::binary_info::StringEntry::new($tag, $id, $str);
ENTRY.addr()
}};
}

/// Generate a static item containing the given string, and return its
/// [`EntryAddr`](super::EntryAddr).
///
/// You must pass a numeric tag, a numeric ID, and `&CStr` (which is always
/// null-terminated).
#[macro_export]
macro_rules! binary_info_int {
($tag:expr, $id:expr, $int:expr) => {{
static ENTRY: $crate::binary_info::IntegerEntry = $crate::binary_info::IntegerEntry::new($tag, $id, $int);
ENTRY.addr()
}};
}

/// Generate a static item containing the program name, and return its
/// [`EntryAddr`](super::EntryAddr).
#[macro_export]
macro_rules! binary_info_rp_program_name {
($name:expr) => {
$crate::binary_info_str!(
$crate::binary_info::consts::TAG_RASPBERRY_PI,
$crate::binary_info::consts::ID_RP_PROGRAM_NAME,
$name
)
};
}

/// Generate a static item containing the `CARGO_BIN_NAME` as the program name,
/// and return its [`EntryAddr`](super::EntryAddr).
#[macro_export]
macro_rules! binary_info_rp_cargo_bin_name {
() => {
$crate::binary_info_env!(
$crate::binary_info::consts::TAG_RASPBERRY_PI,
$crate::binary_info::consts::ID_RP_PROGRAM_NAME,
"CARGO_BIN_NAME"
)
};
}

/// Generate a static item containing the program version, and return its
/// [`EntryAddr`](super::EntryAddr).
#[macro_export]
macro_rules! binary_info_rp_program_version {
($version:expr) => {{
$crate::binary_info_str!(
$crate::binary_info::consts::TAG_RASPBERRY_PI,
$crate::binary_info::consts::ID_RP_PROGRAM_VERSION,
$version
)
}};
}

/// Generate a static item containing the `CARGO_PKG_VERSION` as the program
/// version, and return its [`EntryAddr`](super::EntryAddr).
#[macro_export]
macro_rules! binary_info_rp_cargo_version {
() => {
$crate::binary_info_env!(
$crate::binary_info::consts::TAG_RASPBERRY_PI,
$crate::binary_info::consts::ID_RP_PROGRAM_VERSION_STRING,
"CARGO_PKG_VERSION"
)
};
}

/// Generate a static item containing the program URL, and return its
/// [`EntryAddr`](super::EntryAddr).
#[macro_export]
macro_rules! binary_info_rp_program_url {
($url:expr) => {
$crate::binary_info_str!(
$crate::binary_info::consts::TAG_RASPBERRY_PI,
$crate::binary_info::consts::ID_RP_PROGRAM_URL,
$url
)
};
}

/// Generate a static item containing the `CARGO_PKG_HOMEPAGE` as the program URL,
/// and return its [`EntryAddr`](super::EntryAddr).
#[macro_export]
macro_rules! binary_info_rp_cargo_homepage_url {
() => {
$crate::binary_info_env!(
$crate::binary_info::consts::TAG_RASPBERRY_PI,
$crate::binary_info::consts::ID_RP_PROGRAM_URL,
"CARGO_PKG_HOMEPAGE"
)
};
}

/// Generate a static item containing the program description, and return its
/// [`EntryAddr`](super::EntryAddr).
#[macro_export]
macro_rules! binary_info_rp_program_description {
($description:expr) => {
$crate::binary_info_str!(
$crate::binary_info::consts::TAG_RASPBERRY_PI,
$crate::binary_info::consts::ID_RP_PROGRAM_DESCRIPTION,
$description
)
};
}

/// Generate a static item containing whether this is a debug or a release
/// build, and return its [`EntryAddr`](super::EntryAddr).
#[macro_export]
macro_rules! binary_info_rp_program_build_attribute {
() => {
$crate::binary_info_str!(
$crate::binary_info::consts::TAG_RASPBERRY_PI,
$crate::binary_info::consts::ID_RP_PROGRAM_BUILD_ATTRIBUTE,
{
if cfg!(debug_assertions) {
c"debug"
} else {
c"release"
}
}
)
};
}

/// Generate a static item containing the specific board this program runs on,
/// and return its [`EntryAddr`](super::EntryAddr).
#[macro_export]
macro_rules! binary_info_rp_pico_board {
($board:expr) => {
$crate::binary_info_str!(
$crate::binary_info::consts::TAG_RASPBERRY_PI,
$crate::binary_info::consts::ID_RP_PICO_BOARD,
$board
)
};
}

// End of file
Loading