Skip to content

Commit 66a5a33

Browse files
authored
Merge pull request #3243 from HellbenderInc/rp2350
Initial rp235x support
2 parents fdc34b6 + 13cb431 commit 66a5a33

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+7516
-102
lines changed

.github/ci/test.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ cargo test --manifest-path ./embassy-boot/Cargo.toml --features ed25519-salty
2121

2222
cargo test --manifest-path ./embassy-nrf/Cargo.toml --no-default-features --features nrf52840,time-driver-rtc1,gpiote
2323

24-
cargo test --manifest-path ./embassy-rp/Cargo.toml --no-default-features --features time-driver
24+
cargo test --manifest-path ./embassy-rp/Cargo.toml --no-default-features --features time-driver,rp2040,_test
25+
cargo test --manifest-path ./embassy-rp/Cargo.toml --no-default-features --features time-driver,rp235xa,_test
2526

2627
cargo test --manifest-path ./embassy-stm32/Cargo.toml --no-default-features --features stm32f429vg,exti,time-driver-any,exti
2728
cargo test --manifest-path ./embassy-stm32/Cargo.toml --no-default-features --features stm32f732ze,exti,time-driver-any,exti

ci.sh

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,12 @@ cargo batch \
8282
--- build --release --manifest-path embassy-nrf/Cargo.toml --target thumbv6m-none-eabi --features nrf51,defmt,time,time-driver-rtc1 \
8383
--- build --release --manifest-path embassy-nrf/Cargo.toml --target thumbv6m-none-eabi --features nrf51,defmt,time \
8484
--- build --release --manifest-path embassy-nrf/Cargo.toml --target thumbv6m-none-eabi --features nrf51,time \
85-
--- build --release --manifest-path embassy-rp/Cargo.toml --target thumbv6m-none-eabi --features time-driver,defmt \
86-
--- build --release --manifest-path embassy-rp/Cargo.toml --target thumbv6m-none-eabi --features time-driver,log \
87-
--- build --release --manifest-path embassy-rp/Cargo.toml --target thumbv6m-none-eabi --features time-driver,intrinsics \
88-
--- build --release --manifest-path embassy-rp/Cargo.toml --target thumbv6m-none-eabi --features time-driver,qspi-as-gpio \
85+
--- build --release --manifest-path embassy-rp/Cargo.toml --target thumbv6m-none-eabi --features time-driver,defmt,rp2040 \
86+
--- build --release --manifest-path embassy-rp/Cargo.toml --target thumbv6m-none-eabi --features time-driver,log,rp2040 \
87+
--- build --release --manifest-path embassy-rp/Cargo.toml --target thumbv6m-none-eabi --features time-driver,intrinsics,rp2040 \
88+
--- build --release --manifest-path embassy-rp/Cargo.toml --target thumbv6m-none-eabi --features time-driver,qspi-as-gpio,rp2040 \
89+
--- build --release --manifest-path embassy-rp/Cargo.toml --target thumbv8m.main-none-eabihf --features time-driver,defmt,rp235xa \
90+
--- build --release --manifest-path embassy-rp/Cargo.toml --target thumbv8m.main-none-eabihf --features time-driver,log,rp235xa \
8991
--- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features stm32l552ze,defmt,exti,time-driver-any,time \
9092
--- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features stm32l552ze,defmt,time-driver-any,time \
9193
--- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features stm32l552ze,defmt,exti,time \
@@ -175,12 +177,12 @@ cargo batch \
175177
--- build --release --manifest-path cyw43/Cargo.toml --target thumbv6m-none-eabi --features 'defmt,firmware-logs' \
176178
--- build --release --manifest-path cyw43/Cargo.toml --target thumbv6m-none-eabi --features 'log,firmware-logs,bluetooth' \
177179
--- build --release --manifest-path cyw43/Cargo.toml --target thumbv6m-none-eabi --features 'defmt,firmware-logs,bluetooth' \
178-
--- build --release --manifest-path cyw43-pio/Cargo.toml --target thumbv6m-none-eabi --features '' \
179-
--- build --release --manifest-path cyw43-pio/Cargo.toml --target thumbv6m-none-eabi --features 'overclock' \
180+
--- build --release --manifest-path cyw43-pio/Cargo.toml --target thumbv6m-none-eabi --features 'embassy-rp/rp2040' \
181+
--- build --release --manifest-path cyw43-pio/Cargo.toml --target thumbv6m-none-eabi --features 'embassy-rp/rp2040,overclock' \
180182
--- build --release --manifest-path embassy-boot-nrf/Cargo.toml --target thumbv7em-none-eabi --features embassy-nrf/nrf52840 \
181183
--- build --release --manifest-path embassy-boot-nrf/Cargo.toml --target thumbv8m.main-none-eabihf --features embassy-nrf/nrf9160-ns \
182184
--- build --release --manifest-path embassy-boot-nrf/Cargo.toml --target thumbv8m.main-none-eabihf --features embassy-nrf/nrf9120-ns \
183-
--- build --release --manifest-path embassy-boot-rp/Cargo.toml --target thumbv6m-none-eabi \
185+
--- build --release --manifest-path embassy-boot-rp/Cargo.toml --target thumbv6m-none-eabi --features embassy-rp/rp2040 \
184186
--- build --release --manifest-path embassy-boot-stm32/Cargo.toml --target thumbv7em-none-eabi --features embassy-stm32/stm32l496zg \
185187
--- build --release --manifest-path docs/examples/basic/Cargo.toml --target thumbv7em-none-eabi \
186188
--- build --release --manifest-path docs/examples/layer-by-layer/blinky-pac/Cargo.toml --target thumbv7em-none-eabi \
@@ -195,6 +197,7 @@ cargo batch \
195197
--- build --release --manifest-path examples/nrf9151/ns/Cargo.toml --target thumbv8m.main-none-eabihf --out-dir out/examples/nrf9151/ns \
196198
--- build --release --manifest-path examples/nrf51/Cargo.toml --target thumbv6m-none-eabi --out-dir out/examples/nrf51 \
197199
--- build --release --manifest-path examples/rp/Cargo.toml --target thumbv6m-none-eabi --out-dir out/examples/rp \
200+
--- build --release --manifest-path examples/rp23/Cargo.toml --target thumbv8m.main-none-eabihf --out-dir out/examples/rp23 \
198201
--- build --release --manifest-path examples/stm32f0/Cargo.toml --target thumbv6m-none-eabi --out-dir out/examples/stm32f0 \
199202
--- build --release --manifest-path examples/stm32f1/Cargo.toml --target thumbv7m-none-eabi --out-dir out/examples/stm32f1 \
200203
--- build --release --manifest-path examples/stm32f2/Cargo.toml --target thumbv7m-none-eabi --out-dir out/examples/stm32f2 \

embassy-rp/Cargo.toml

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ src_base = "https://github.com/embassy-rs/embassy/blob/embassy-rp-v$VERSION/emba
1414
src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-rp/src/"
1515
features = ["defmt", "unstable-pac", "time-driver"]
1616
flavors = [
17-
{ name = "rp2040", target = "thumbv6m-none-eabi" },
17+
{ name = "rp2040", target = "thumbv6m-none-eabi", features = ["rp2040"] },
18+
{ name = "rp235xa", target = "thumbv8m.main-none-eabi", features = ["rp235xa"] },
19+
{ name = "rp235xb", target = "thumbv8m.main-none-eabi", features = ["rp235xb"] },
1820
]
1921

2022
[package.metadata.docs.rs]
@@ -88,6 +90,23 @@ boot2-w25x10cl = []
8890
## ```
8991
boot2-none = []
9092

93+
## Configure the hal for use with the rp2040
94+
rp2040 = ["rp-pac/rp2040"]
95+
_rp235x = ["rp-pac/rp235x"]
96+
## Configure the hal for use with the rp235xA
97+
rp235xa = ["_rp235x"]
98+
## Configure the hal for use with the rp235xB
99+
rp235xb = ["_rp235x"]
100+
101+
# hack around cortex-m peripherals being wrong when running tests.
102+
_test = []
103+
104+
## Add a binary-info header block containing picotool-compatible metadata.
105+
##
106+
## Takes up a little flash space, but picotool can then report the name of your
107+
## program and other details.
108+
binary-info = [ "rt" ]
109+
91110
[dependencies]
92111
embassy-sync = { version = "0.6.0", path = "../embassy-sync" }
93112
embassy-time-driver = { version = "0.1", path = "../embassy-time-driver", optional = true }
@@ -112,7 +131,7 @@ embedded-storage-async = { version = "0.4.1" }
112131
rand_core = "0.6.4"
113132
fixed = "1.23.1"
114133

115-
rp-pac = { version = "6" }
134+
rp-pac = { git = "https://github.com/embassy-rs/rp-pac.git", rev = "a7f42d25517f7124ad3b4ed492dec8b0f50a0e6c", feature = ["rt"] }
116135

117136
embedded-hal-02 = { package = "embedded-hal", version = "0.2.6", features = ["unproven"] }
118137
embedded-hal-1 = { package = "embedded-hal", version = "1.0" }
@@ -123,6 +142,7 @@ pio-proc = {version= "0.2" }
123142
pio = {version= "0.2.1" }
124143
rp2040-boot2 = "0.3"
125144
document-features = "0.2.7"
145+
sha2-const-stable = "0.1"
126146

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

embassy-rp/build.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@ use std::io::Write;
44
use std::path::PathBuf;
55

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

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

15-
println!("cargo:rerun-if-changed=build.rs");
16-
println!("cargo:rerun-if-changed=link-rp.x.in");
16+
println!("cargo:rerun-if-changed=build.rs");
17+
println!("cargo:rerun-if-changed=link-rp.x.in");
18+
}
1719
}

embassy-rp/link-rp.x.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ SECTIONS {
55
{
66
KEEP(*(.boot2));
77
} > BOOT2
8-
}
8+
}

embassy-rp/src/adc.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use embassy_sync::waitqueue::AtomicWaker;
1111
use crate::gpio::{self, AnyPin, Pull, SealedPin as GpioPin};
1212
use crate::interrupt::typelevel::Binding;
1313
use crate::interrupt::InterruptExt;
14+
use crate::pac::dma::vals::TreqSel;
1415
use crate::peripherals::{ADC, ADC_TEMP_SENSOR};
1516
use crate::{dma, interrupt, pac, peripherals, Peripheral, RegExt};
1617

@@ -34,6 +35,8 @@ impl<'p> Channel<'p> {
3435
pub fn new_pin(pin: impl Peripheral<P = impl AdcPin + 'p> + 'p, pull: Pull) -> Self {
3536
into_ref!(pin);
3637
pin.pad_ctrl().modify(|w| {
38+
#[cfg(feature = "_rp235x")]
39+
w.set_iso(false);
3740
// manual says:
3841
//
3942
// > When using an ADC input shared with a GPIO pin, the pin’s
@@ -229,7 +232,10 @@ impl<'d> Adc<'d, Async> {
229232
div: u16,
230233
dma: impl Peripheral<P = impl dma::Channel>,
231234
) -> Result<(), Error> {
235+
#[cfg(feature = "rp2040")]
232236
let mut rrobin = 0_u8;
237+
#[cfg(feature = "_rp235x")]
238+
let mut rrobin = 0_u16;
233239
for c in channels {
234240
rrobin |= 1 << c;
235241
}
@@ -278,7 +284,7 @@ impl<'d> Adc<'d, Async> {
278284
}
279285
let auto_reset = ResetDmaConfig;
280286

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

432+
#[cfg(any(feature = "rp235xa", feature = "rp2040"))]
426433
impl_pin!(PIN_26, 0);
434+
#[cfg(any(feature = "rp235xa", feature = "rp2040"))]
427435
impl_pin!(PIN_27, 1);
436+
#[cfg(any(feature = "rp235xa", feature = "rp2040"))]
428437
impl_pin!(PIN_28, 2);
438+
#[cfg(any(feature = "rp235xa", feature = "rp2040"))]
429439
impl_pin!(PIN_29, 3);
430440

441+
#[cfg(feature = "rp235xb")]
442+
impl_pin!(PIN_40, 0);
443+
#[cfg(feature = "rp235xb")]
444+
impl_pin!(PIN_41, 1);
445+
#[cfg(feature = "rp235xb")]
446+
impl_pin!(PIN_42, 2);
447+
#[cfg(feature = "rp235xb")]
448+
impl_pin!(PIN_43, 3);
449+
#[cfg(feature = "rp235xb")]
450+
impl_pin!(PIN_44, 4);
451+
#[cfg(feature = "rp235xb")]
452+
impl_pin!(PIN_45, 5);
453+
#[cfg(feature = "rp235xb")]
454+
impl_pin!(PIN_46, 6);
455+
#[cfg(feature = "rp235xb")]
456+
impl_pin!(PIN_47, 7);
457+
431458
impl SealedAdcChannel for peripherals::ADC_TEMP_SENSOR {}
432459
impl AdcChannel for peripherals::ADC_TEMP_SENSOR {}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//! Constants for binary info
2+
3+
/// All Raspberry Pi specified IDs have this tag.
4+
///
5+
/// You can create your own for custom fields.
6+
pub const TAG_RASPBERRY_PI: u16 = super::make_tag(b"RP");
7+
8+
/// Used to note the program name - use with StringEntry
9+
pub const ID_RP_PROGRAM_NAME: u32 = 0x02031c86;
10+
/// Used to note the program version - use with StringEntry
11+
pub const ID_RP_PROGRAM_VERSION_STRING: u32 = 0x11a9bc3a;
12+
/// Used to note the program build date - use with StringEntry
13+
pub const ID_RP_PROGRAM_BUILD_DATE_STRING: u32 = 0x9da22254;
14+
/// Used to note the size of the binary - use with IntegerEntry
15+
pub const ID_RP_BINARY_END: u32 = 0x68f465de;
16+
/// Used to note a URL for the program - use with StringEntry
17+
pub const ID_RP_PROGRAM_URL: u32 = 0x1856239a;
18+
/// Used to note a description of the program - use with StringEntry
19+
pub const ID_RP_PROGRAM_DESCRIPTION: u32 = 0xb6a07c19;
20+
/// Used to note some feature of the program - use with StringEntry
21+
pub const ID_RP_PROGRAM_FEATURE: u32 = 0xa1f4b453;
22+
/// Used to note some whether this was a Debug or Release build - use with StringEntry
23+
pub const ID_RP_PROGRAM_BUILD_ATTRIBUTE: u32 = 0x4275f0d3;
24+
/// Used to note the Pico SDK version used - use with StringEntry
25+
pub const ID_RP_SDK_VERSION: u32 = 0x5360b3ab;
26+
/// Used to note which board this program targets - use with StringEntry
27+
pub const ID_RP_PICO_BOARD: u32 = 0xb63cffbb;
28+
/// Used to note which `boot2` image this program uses - use with StringEntry
29+
pub const ID_RP_BOOT2_NAME: u32 = 0x7f8882e1;
30+
31+
// End of file

0 commit comments

Comments
 (0)