Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src/riot-rs-boards: add rpi-pico-w support #53

Merged
merged 6 commits into from
Jan 25, 2024
Merged
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
33 changes: 33 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ embassy-rp = { version = "0.1", default-features = false }
embassy-sync = { version = "0.5", default-features = false }
embassy-time = { version = "0.3", default-features = false }
embassy-usb = { version = "0.1", default-features = false }
embassy-net-driver-channel = { version = "0.2.0", default-features = false }

linkme = { version = "0.3.21", features = ["used_linker"] }

Expand Down Expand Up @@ -86,8 +87,11 @@ nrf52832-pac = { git = "https://github.com/kaspar030/nrf-pacs", branch = "riot-r
embassy-executor = { git = "https://github.com/kaspar030/embassy", branch = "for-riot-rs-230124" }
embassy-executor-macros = { git = "https://github.com/kaspar030/embassy", branch = "for-riot-rs-230124"}
embassy-net = { git = "https://github.com/kaspar030/embassy", branch = "for-riot-rs-230124" }
embassy-net-driver-channel = { git = "https://github.com/kaspar030/embassy", branch = "for-riot-rs-230124" }
embassy-nrf = { git = "https://github.com/kaspar030/embassy", branch = "for-riot-rs-230124" }
embassy-rp = { git = "https://github.com/kaspar030/embassy", branch = "for-riot-rs-230124" }
embassy-time = { git = "https://github.com/kaspar030/embassy", branch = "for-riot-rs-230124" }
embassy-sync = { git = "https://github.com/kaspar030/embassy", branch = "for-riot-rs-230124" }
embassy-usb = { git = "https://github.com/kaspar030/embassy", branch = "for-riot-rs-230124" }
cyw43 = { git = "https://github.com/kaspar030/embassy", branch = "for-riot-rs-230124" }
cyw43-pio = { git = "https://github.com/kaspar030/embassy", branch = "for-riot-rs-230124" }
2 changes: 1 addition & 1 deletion examples/embassy-http-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition.workspace = true
publish = false

[dependencies]
riot-rs = { path = "../../src/riot-rs", features = [ "time", "usb_ethernet"] }
riot-rs = { path = "../../src/riot-rs", features = [ "time" ] }
riot-rs-boards = { path = "../../src/riot-rs-boards" }
embassy-executor = { workspace = true, default-features = false }
embassy-nrf = { workspace = true }
Expand Down
1 change: 1 addition & 0 deletions examples/embassy-http-server/laze.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ apps:
context: nrf52840dk
selects:
- ?release
- network
4 changes: 2 additions & 2 deletions examples/embassy-http-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use riot_rs as _;

use riot_rs::embassy::{
arch::OptionalPeripherals, Application, ApplicationInitError, Drivers, InitializationArgs,
UsbEthernetStack,
NetworkStack,
};
use riot_rs::rt::debug::println;

Expand Down Expand Up @@ -63,7 +63,7 @@ const WEB_TASK_POOL_SIZE: usize = 2;
#[embassy_executor::task(pool_size = WEB_TASK_POOL_SIZE)]
async fn web_task(
id: usize,
stack: &'static UsbEthernetStack,
stack: &'static NetworkStack,
app: &'static picoserve::Router<AppRouter, AppState>,
config: &'static picoserve::Config<Duration>,
state: AppState,
Expand Down
2 changes: 1 addition & 1 deletion examples/embassy-net-tcp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition.workspace = true
publish = false

[dependencies]
riot-rs = { path = "../../src/riot-rs", features = [ "time", "usb_ethernet"] }
riot-rs = { path = "../../src/riot-rs", features = [ "time" ] }
riot-rs-boards = { path = "../../src/riot-rs-boards" }
embassy-executor = { workspace = true, default-features = false }
embassy-time = { workspace = true, default-features = false }
Expand Down
1 change: 1 addition & 0 deletions examples/embassy-net-tcp/laze.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ apps:
- name: embassy-net-tcp
selects:
- ?release
- network
2 changes: 1 addition & 1 deletion examples/embassy-net-udp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition.workspace = true
publish = false

[dependencies]
riot-rs = { path = "../../src/riot-rs", features = [ "time", "usb_ethernet"] }
riot-rs = { path = "../../src/riot-rs", features = [ "time" ] }
riot-rs-boards = { path = "../../src/riot-rs-boards" }
embassy-executor = { workspace = true, default-features = false }
embassy-time = { workspace = true, default-features = false }
Expand Down
1 change: 1 addition & 0 deletions examples/embassy-net-udp/laze.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ apps:
- name: embassy-net-udp
selects:
- ?release
- network
35 changes: 35 additions & 0 deletions laze-project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,36 @@ modules:
global:
CARGO_RUNNER: "'probe-rs run --chip ${PROBE_RS_CHIP}'"

- name: network
selects:
- network_device

- name: wifi_cyw43
context:
- rpi-pico-w
provides_unique:
- network_device
env:
global:
FEATURES:
- riot-rs/wifi_cyw43

- name: usb_ethernet
provides_unique:
- network_device
selects:
- usb_device_port
env:
global:
FEATURES:
- riot-rs/usb_ethernet

- name: usb_device_port
context:
- nrf52840dk
- rpi-pico
- rpi-pico-w

builders:
# host builder (for housekeeping tasks)
- name: host
Expand Down Expand Up @@ -532,6 +562,11 @@ builders:
env:
BOARD: rpi-pico

- name: rpi-pico-w
parent: rpi-pico
env:
BOARD: rpi-pico-w

apps:
# define a dummy host application so the host tasks work
- name: host
Expand Down
3 changes: 3 additions & 0 deletions src/riot-rs-boards/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ microbit = { optional=true, path="microbit" }
microbit-v2 = { optional=true, path="microbit-v2" }
dwm1001 = { optional=true, path="dwm1001" }
rpi-pico = { optional=true, path="rpi-pico" }

[features]
rpi-pico-w = [ "rpi-pico/rpi-pico-w" ]
3 changes: 3 additions & 0 deletions src/riot-rs-boards/rpi-pico/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ edition = "2021"
[dependencies]
riot-rs-rt.workspace = true
rp2040 = { path = "../../riot-rs-chips/rp2040" }

[features]
rpi-pico-w = []
3 changes: 3 additions & 0 deletions src/riot-rs-boards/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ cfg_if! {
pub use lm3s6965evb as board;
} else if #[cfg(feature = "rpi-pico")] {
pub use rpi_pico as board;
} else if #[cfg(feature = "rpi-pico-w")] {
// sharing rpi-pico
pub use rpi_pico as board;
} else {
compile_error!("no board feature selected");
}
Expand Down
8 changes: 8 additions & 0 deletions src/riot-rs-embassy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,20 @@ critical-section.workspace = true
embassy-sync = { workspace = true }
riot-rs-core = { path = "../riot-rs-core", optional = true }
riot-rs-rt = { path = "../riot-rs-rt" }
riot-rs-utils = { path = "../riot-rs-utils" }

# time
embassy-time = { workspace = true, optional = true }

embassy-usb = { workspace = true, optional = true }
embassy-net = { workspace = true, optional = true, features = [ "dhcpv4", "medium-ethernet" ] }
embassy-net-driver-channel = { workspace = true, optional = true }
heapless = "0.8.0"

# rpi-pico-w cyw43
cyw43 = { version = "0.1.0", features = ["firmware-logs"], optional = true }
cyw43-pio = { version = "0.1.0", features = ["overclock"], optional = true }

[target.'cfg(context = "cortex-m")'.dependencies]
embassy-executor = { workspace = true, features = [
"arch-cortex-m",
Expand Down Expand Up @@ -58,6 +64,8 @@ usb = [ "dep:embassy-usb" ]
net = [ "dep:embassy-net" ]
usb_ethernet = [ "usb", "net" ]

wifi_cyw43 = [ "dep:cyw43", "dep:cyw43-pio", "dep:embassy-net-driver-channel", "net" ]

threading = ["dep:riot-rs-core"]
override_network_config = []
override_usb_config = []
Binary file added src/riot-rs-embassy/firmware/cyw43/43439A0.bin
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
Permissive Binary License

Version 1.0, July 2019

Redistribution. Redistribution and use in binary form, without
modification, are permitted provided that the following conditions are
met:

1) Redistributions must reproduce the above copyright notice and the
following disclaimer in the documentation and/or other materials
provided with the distribution.

2) Unless to the extent explicitly permitted by law, no reverse
engineering, decompilation, or disassembly of this software is
permitted.

3) Redistribution as part of a software development kit must include the
accompanying file named �DEPENDENCIES� and any dependencies listed in
that file.

4) Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

Limited patent license. The copyright holders (and contributors) grant a
worldwide, non-exclusive, no-charge, royalty-free patent license to
make, have made, use, offer to sell, sell, import, and otherwise
transfer this software, where such license applies only to those patent
claims licensable by the copyright holders (and contributors) that are
necessarily infringed by this software. This patent license shall not
apply to any combinations that include this software. No hardware is
licensed hereunder.

If you institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the software
itself infringes your patent(s), then your rights granted under this
license shall terminate as of the date such litigation is filed.

DISCLAIMER. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS." ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9 changes: 9 additions & 0 deletions src/riot-rs-embassy/firmware/cyw43/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# WiFi firmware

Firmware obtained from https://github.com/Infineon/wifi-host-driver/tree/master/WiFi_Host_Driver/resources/firmware/COMPONENT_43439

Licensed under the [Infineon Permissive Binary License](./LICENSE-permissive-binary-license-1.0.txt)

## Changelog

* 2023-07-28: synced with `ad3bad0` - Update 43439 fw from 7.95.55 ot 7.95.62
10 changes: 9 additions & 1 deletion src/riot-rs-embassy/src/arch/rp2040.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pub use embassy_rp::interrupt;
pub use embassy_rp::interrupt::SWI_IRQ_1 as SWI;
pub use embassy_rp::{init, OptionalPeripherals, Peripherals};
pub use embassy_rp::{config::Config, peripherals, OptionalPeripherals, Peripherals};

#[cfg(feature = "usb")]
use embassy_rp::{bind_interrupts, peripherals::USB, usb::InterruptHandler};
Expand All @@ -25,3 +25,11 @@ pub mod usb {
Driver::new(usb, super::Irqs)
}
}

pub fn init(config: Config) -> Peripherals {
// SWI & DMA priority need to match. DMA is hard-coded to P3 by upstream.
use embassy_rp::interrupt::{InterruptExt, Priority};
SWI.set_priority(Priority::P3);

embassy_rp::init(config)
}
67 changes: 67 additions & 0 deletions src/riot-rs-embassy/src/cyw43.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
pub use cyw43::NetDriver;

use cyw43::{Control, Runner};
use cyw43_pio::PioSpi;
use embassy_rp::bind_interrupts;
use embassy_rp::gpio::{Level, Output};
use embassy_rp::pio::{InterruptHandler, Pio};

use crate::{arch::peripherals, arch::OptionalPeripherals, define_peripherals, make_static};

// board specifics start
define_peripherals!(Cyw43Periphs {
pwr: PIN_23,
cs: PIN_25,
pio: PIO0 = CYW43_PIO,
dma: DMA_CH0 = CYW43_DMA_CH,
dio: PIN_24,
clk: PIN_29,
});

bind_interrupts!(struct Irqs {
PIO0_IRQ_0 => InterruptHandler<CYW43_PIO>;
});

type CywSpi = PioSpi<'static, CYW43_PIO, 0, CYW43_DMA_CH>;
// board specifics end

#[embassy_executor::task]
async fn wifi_cyw43_task(runner: Runner<'static, Output<'static>, CywSpi>) -> ! {
runner.run().await
}

pub(crate) async fn device<'a, 'b: 'a>(
p: &'a mut OptionalPeripherals,
spawner: &crate::Spawner,
) -> (embassy_net_driver_channel::Device<'b, 1514>, Control<'b>) {
let p = Cyw43Periphs::take_from(p).unwrap();

let fw = include_bytes!("../firmware/cyw43/43439A0.bin");
let clm = include_bytes!("../firmware/cyw43/43439A0_clm.bin");

// To make flashing faster for development, you may want to flash the firmwares independently
// at hardcoded addresses, instead of baking them into the program with `include_bytes!`:
// probe-rs download 43439A0.bin --format bin --chip RP2040 --base-address 0x10100000
// probe-rs download 43439A0_clm.bin --format bin --chip RP2040 --base-address 0x10140000
//let fw = unsafe { core::slice::from_raw_parts(0x10100000 as *const u8, 230321) };
//let clm = unsafe { core::slice::from_raw_parts(0x10140000 as *const u8, 4752) };

let pwr = Output::new(p.pwr, Level::Low);
let cs = Output::new(p.cs, Level::High);
let mut pio = Pio::new(p.pio, Irqs);
let spi = PioSpi::new(&mut pio.common, pio.sm0, pio.irq0, cs, p.dio, p.clk, p.dma);

let state = make_static!(cyw43::State::new());
let (net_device, mut control, runner) = cyw43::new(state, pwr, spi, fw).await;

// this needs to be spawned here (before using `control`)
spawner.spawn(wifi_cyw43_task(runner)).unwrap();

control.init(clm).await;

// control
// .set_power_management(cyw43::PowerManagementMode::PowerSave)
// .await;

(net_device, control)
}
Loading
Loading