Attepted to switch to the embassy framework
This commit is contained in:
1 parent
a3d5a63a7f
commit
11a8fa7c6d
5 files changed
+57
-53
No files matched your search
+11
-5
@@ -6,17 +6,23 @@ name = "test-cargo"
|
||||
version = "0.1.0"
|
||||
|
||||
[dependencies]
|
||||
rp-pico = "0.9.0"
|
||||
cortex-m = "0.7.7"
|
||||
cortex-m-rt = "0.7.3"
|
||||
cortex-m-semihosting = "0.5.0"
|
||||
panic-halt = "0.2.0"
|
||||
rp2040-boot2 = "0.3.0"
|
||||
rp2040-hal = { version = "0.10.2", features = ["rt"] }
|
||||
embedded-time = "0.12.1"
|
||||
defmt = "0.3.8"
|
||||
defmt-rtt = "0.4.1"
|
||||
embedded-hal = "1.0.0"
|
||||
embedded-hal-async = "1.0.0"
|
||||
embedded-io = "0.6.1"
|
||||
embedded-io-async = "0.6.1"
|
||||
embedded-storage = "0.3.1"
|
||||
embassy-rp = { version = "0.2.0", features = [ "defmt", "time-driver", "unstable-pac", "critical-section-impl" ] }
|
||||
embassy-time = { version = "0.3.0", features = [ "defmt", "defmt-timestamp-uptime" ] }
|
||||
embassy-executor = { version = "0.5.0", features = [ "task-arena-size-1024", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers", "executor-interrupt" ] }
|
||||
cyw43 = { version = "=0.1.0", features = [ "defmt", "firmware-logs" ] }
|
||||
cyw43-pio = "0.2.0"
|
||||
static_cell = "2.1.0"
|
||||
portable-atomic = { version = "1.7.0", features = ["critical-section"] }
|
||||
|
||||
[[bin]]
|
||||
name = "test-cargo"
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
+46
-48
@@ -1,62 +1,60 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use cortex_m_rt::entry;
|
||||
use cortex_m::delay::Delay;
|
||||
use embedded_hal::digital::OutputPin;
|
||||
use panic_halt as _; // you can put a breakpoint on `rust_begin_unwind` to catch panics
|
||||
use rp2040_hal as hal;
|
||||
|
||||
use hal::{
|
||||
clocks::{init_clocks_and_plls, Clock},
|
||||
pac,
|
||||
watchdog::Watchdog,
|
||||
Sio,
|
||||
use cyw43_pio::PioSpi;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_time::{Duration, Timer};
|
||||
use embassy_rp::{
|
||||
bind_interrupts, gpio::{Level, Output}, pio::{InterruptHandler, Pio}, peripherals::{DMA_CH0, PIO0}
|
||||
};
|
||||
use defmt::{info, unwrap};
|
||||
use defmt_rtt as _;
|
||||
use panic_halt as _;
|
||||
use static_cell::StaticCell;
|
||||
|
||||
// Initialize BOOT2 sector
|
||||
#[link_section = ".boot2"]
|
||||
#[used]
|
||||
pub static BOOT2: [u8; 256] = rp2040_boot2::BOOT_LOADER_W25Q080;
|
||||
macro_rules! singleton {
|
||||
($val:expr) => {{
|
||||
type T = impl Sized;
|
||||
static STATIC_CELL: StaticCell<T> = StaticCell::new();
|
||||
STATIC_CELL.init_with(move || $val)
|
||||
}};
|
||||
}
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
let mut pac = pac::Peripherals::take().unwrap();
|
||||
let core = pac::CorePeripherals::take().unwrap();
|
||||
let mut watchdog = Watchdog::new(pac.WATCHDOG);
|
||||
let sio = Sio::new(pac.SIO);
|
||||
bind_interrupts!(struct Irqs {
|
||||
PIO0_IRQ_0 => InterruptHandler<PIO0>;
|
||||
});
|
||||
|
||||
let external_xtal_freq_hz = 12_000_000u32;
|
||||
let clocks = init_clocks_and_plls(
|
||||
external_xtal_freq_hz,
|
||||
pac.XOSC,
|
||||
pac.CLOCKS,
|
||||
pac.PLL_SYS,
|
||||
pac.PLL_USB,
|
||||
&mut pac.RESETS,
|
||||
&mut watchdog,
|
||||
)
|
||||
.ok()
|
||||
.unwrap();
|
||||
#[embassy_executor::task]
|
||||
async fn cyw43_task(runner: cyw43::Runner<'static, Output<'static>, PioSpi<'static, PIO0, 0, DMA_CH0>>) -> ! {
|
||||
runner.run().await
|
||||
}
|
||||
|
||||
let mut delay = Delay::new(core.SYST, clocks.system_clock.freq().raw());
|
||||
#[embassy_executor::main]
|
||||
async fn main(spawner: Spawner) {
|
||||
let p = embassy_rp::init(Default::default());
|
||||
let fw = include_bytes!("../firmware/43439A0.bin");
|
||||
let clm = include_bytes!("../firmware/43439A0_clm.bin");
|
||||
|
||||
let pins = hal::gpio::Pins::new(
|
||||
pac.IO_BANK0,
|
||||
pac.PADS_BANK0,
|
||||
sio.gpio_bank0,
|
||||
&mut pac.RESETS,
|
||||
);
|
||||
let power = Output::new(p.PIN_23, Level::Low);
|
||||
let cs = Output::new(p.PIN_25, Level::High);
|
||||
let mut pio = Pio::new(p.PIO0, Irqs);
|
||||
let spi = PioSpi::new(&mut pio.common, pio.sm0, pio.irq0, cs, p.PIN_24, p.PIN_29, p.DMA_CH0);
|
||||
|
||||
let mut led_pin = pins.gpio25.into_push_pull_output();
|
||||
let mut ext_pin = pins.gpio20.into_push_pull_output();
|
||||
let state = singleton!(cyw43::State::new());
|
||||
static THING: StaticCell<cyw43::State> = StaticCell::new();
|
||||
let state = THING.init_with(cyw43::State::new());
|
||||
let (_net_device, mut control, runner) = cyw43::new(state, power, spi, fw).await;
|
||||
unwrap!(spawner.spawn(cyw43_task(runner)));
|
||||
|
||||
control.init(clm).await;
|
||||
control.set_power_management(cyw43::PowerManagementMode::PowerSave).await;
|
||||
|
||||
loop {
|
||||
led_pin.set_high().unwrap();
|
||||
ext_pin.set_high().unwrap();
|
||||
delay.delay_ms(500);
|
||||
led_pin.set_low().unwrap();
|
||||
ext_pin.set_low().unwrap();
|
||||
delay.delay_ms(500);
|
||||
// Main loop
|
||||
info!("Blink!");
|
||||
control.gpio_set(0, true).await;
|
||||
Timer::after(Duration::from_millis(500)).await;
|
||||
control.gpio_set(0, false).await;
|
||||
Timer::after(Duration::from_millis(500)).await;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user