2023-06-22 21:11:53 +02:00
|
|
|
#![no_std]
|
|
|
|
#![no_main]
|
|
|
|
#![feature(type_alias_impl_trait)]
|
2023-08-18 16:11:18 +02:00
|
|
|
teleprobe_meta::target!(b"nrf52840-dk");
|
|
|
|
teleprobe_meta::timeout!(120);
|
2023-06-22 21:11:53 +02:00
|
|
|
|
2023-09-28 03:46:33 +02:00
|
|
|
use defmt::{info, unwrap};
|
2023-06-22 21:11:53 +02:00
|
|
|
use embassy_executor::Spawner;
|
2023-09-28 03:46:33 +02:00
|
|
|
use embassy_net::{Config, Stack, StackResources};
|
2023-06-22 21:11:53 +02:00
|
|
|
use embassy_nrf::gpio::{AnyPin, Input, Level, Output, OutputDrive, Pin, Pull};
|
|
|
|
use embassy_nrf::rng::Rng;
|
|
|
|
use embassy_nrf::spim::{self, Spim};
|
|
|
|
use embassy_nrf::{bind_interrupts, peripherals};
|
2023-09-28 03:46:33 +02:00
|
|
|
use embassy_time::Delay;
|
2023-08-16 00:40:56 +02:00
|
|
|
use embedded_hal_bus::spi::ExclusiveDevice;
|
2023-06-22 21:11:53 +02:00
|
|
|
use static_cell::make_static;
|
|
|
|
use {defmt_rtt as _, embassy_net_esp_hosted as hosted, panic_probe as _};
|
|
|
|
|
|
|
|
bind_interrupts!(struct Irqs {
|
|
|
|
SPIM3 => spim::InterruptHandler<peripherals::SPI3>;
|
|
|
|
RNG => embassy_nrf::rng::InterruptHandler<peripherals::RNG>;
|
|
|
|
});
|
|
|
|
|
2023-09-28 03:46:33 +02:00
|
|
|
// Test-only wifi network, no internet access!
|
|
|
|
const WIFI_NETWORK: &str = "EmbassyTest";
|
|
|
|
const WIFI_PASSWORD: &str = "V8YxhKt5CdIAJFud";
|
|
|
|
|
2023-06-22 21:11:53 +02:00
|
|
|
#[embassy_executor::task]
|
|
|
|
async fn wifi_task(
|
|
|
|
runner: hosted::Runner<
|
|
|
|
'static,
|
2023-07-04 19:53:06 +02:00
|
|
|
ExclusiveDevice<Spim<'static, peripherals::SPI3>, Output<'static, peripherals::P0_31>, Delay>,
|
2023-06-22 21:11:53 +02:00
|
|
|
Input<'static, AnyPin>,
|
|
|
|
Output<'static, peripherals::P1_05>,
|
|
|
|
>,
|
|
|
|
) -> ! {
|
|
|
|
runner.run().await
|
|
|
|
}
|
|
|
|
|
|
|
|
type MyDriver = hosted::NetDriver<'static>;
|
|
|
|
|
|
|
|
#[embassy_executor::task]
|
|
|
|
async fn net_task(stack: &'static Stack<MyDriver>) -> ! {
|
|
|
|
stack.run().await
|
|
|
|
}
|
|
|
|
|
|
|
|
#[embassy_executor::main]
|
|
|
|
async fn main(spawner: Spawner) {
|
|
|
|
info!("Hello World!");
|
|
|
|
|
|
|
|
let p = embassy_nrf::init(Default::default());
|
|
|
|
|
|
|
|
let miso = p.P0_28;
|
|
|
|
let sck = p.P0_29;
|
|
|
|
let mosi = p.P0_30;
|
|
|
|
let cs = Output::new(p.P0_31, Level::High, OutputDrive::HighDrive);
|
|
|
|
let handshake = Input::new(p.P1_01.degrade(), Pull::Up);
|
|
|
|
let ready = Input::new(p.P1_04.degrade(), Pull::None);
|
|
|
|
let reset = Output::new(p.P1_05, Level::Low, OutputDrive::Standard);
|
|
|
|
|
|
|
|
let mut config = spim::Config::default();
|
|
|
|
config.frequency = spim::Frequency::M32;
|
|
|
|
config.mode = spim::MODE_2; // !!!
|
|
|
|
let spi = spim::Spim::new(p.SPI3, Irqs, sck, miso, mosi, config);
|
2023-07-04 19:53:06 +02:00
|
|
|
let spi = ExclusiveDevice::new(spi, cs, Delay);
|
2023-06-22 21:11:53 +02:00
|
|
|
|
|
|
|
let (device, mut control, runner) = embassy_net_esp_hosted::new(
|
|
|
|
make_static!(embassy_net_esp_hosted::State::new()),
|
|
|
|
spi,
|
|
|
|
handshake,
|
|
|
|
ready,
|
|
|
|
reset,
|
|
|
|
)
|
|
|
|
.await;
|
|
|
|
|
|
|
|
unwrap!(spawner.spawn(wifi_task(runner)));
|
|
|
|
|
2023-08-17 00:11:15 +02:00
|
|
|
unwrap!(control.init().await);
|
|
|
|
unwrap!(control.connect(WIFI_NETWORK, WIFI_PASSWORD).await);
|
2023-06-22 21:11:53 +02:00
|
|
|
|
|
|
|
// Generate random seed
|
|
|
|
let mut rng = Rng::new(p.RNG, Irqs);
|
|
|
|
let mut seed = [0; 8];
|
|
|
|
rng.blocking_fill_bytes(&mut seed);
|
|
|
|
let seed = u64::from_le_bytes(seed);
|
|
|
|
|
|
|
|
// Init network stack
|
|
|
|
let stack = &*make_static!(Stack::new(
|
|
|
|
device,
|
|
|
|
Config::dhcpv4(Default::default()),
|
|
|
|
make_static!(StackResources::<2>::new()),
|
|
|
|
seed
|
|
|
|
));
|
|
|
|
|
|
|
|
unwrap!(spawner.spawn(net_task(stack)));
|
|
|
|
|
2023-09-28 03:46:33 +02:00
|
|
|
perf_client::run(
|
|
|
|
stack,
|
|
|
|
perf_client::Expected {
|
|
|
|
down_kbps: 50,
|
|
|
|
up_kbps: 50,
|
|
|
|
updown_kbps: 50,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
.await;
|
2023-06-22 21:11:53 +02:00
|
|
|
|
|
|
|
info!("Test OK");
|
|
|
|
cortex_m::asm::bkpt();
|
|
|
|
}
|