Merge branch 'main' of https://github.com/embassy-rs/embassy into hrtim
This commit is contained in:
@ -7,7 +7,7 @@ license = "MIT OR Apache-2.0"
|
||||
[dependencies]
|
||||
embassy-sync = { version = "0.2.0", path = "../../../../embassy-sync" }
|
||||
embassy-executor = { version = "0.2.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "nightly", "integrated-timers", "arch-cortex-m", "executor-thread"] }
|
||||
embassy-time = { version = "0.1.0", path = "../../../../embassy-time", features = ["nightly"] }
|
||||
embassy-time = { version = "0.1.2", path = "../../../../embassy-time", features = ["nightly"] }
|
||||
embassy-nrf = { version = "0.1.0", path = "../../../../embassy-nrf", features = ["time-driver-rtc1", "gpiote", "nightly"] }
|
||||
embassy-boot = { version = "0.1.0", path = "../../../../embassy-boot/boot", features = ["nightly"] }
|
||||
embassy-boot-nrf = { version = "0.1.0", path = "../../../../embassy-boot/nrf", features = ["nightly"] }
|
||||
|
@ -7,7 +7,7 @@ license = "MIT OR Apache-2.0"
|
||||
[dependencies]
|
||||
embassy-sync = { version = "0.2.0", path = "../../../../embassy-sync" }
|
||||
embassy-executor = { version = "0.2.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "nightly", "integrated-timers", "arch-cortex-m", "executor-thread"] }
|
||||
embassy-time = { version = "0.1.0", path = "../../../../embassy-time", features = ["nightly"] }
|
||||
embassy-time = { version = "0.1.2", path = "../../../../embassy-time", features = ["nightly"] }
|
||||
embassy-rp = { version = "0.1.0", path = "../../../../embassy-rp", features = ["time-driver", "unstable-traits", "nightly"] }
|
||||
embassy-boot-rp = { version = "0.1.0", path = "../../../../embassy-boot/rp", features = ["nightly"] }
|
||||
embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" }
|
||||
|
@ -7,7 +7,7 @@ license = "MIT OR Apache-2.0"
|
||||
[dependencies]
|
||||
embassy-sync = { version = "0.2.0", path = "../../../../embassy-sync", features = ["defmt"] }
|
||||
embassy-executor = { version = "0.2.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "nightly", "integrated-timers"] }
|
||||
embassy-time = { version = "0.1.0", path = "../../../../embassy-time", features = ["nightly", "tick-hz-32_768"] }
|
||||
embassy-time = { version = "0.1.2", path = "../../../../embassy-time", features = ["nightly", "tick-hz-32_768"] }
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32f303re", "time-driver-any", "exti"] }
|
||||
embassy-boot-stm32 = { version = "0.1.0", path = "../../../../embassy-boot/stm32", features = ["nightly"] }
|
||||
embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" }
|
||||
|
@ -7,7 +7,7 @@ license = "MIT OR Apache-2.0"
|
||||
[dependencies]
|
||||
embassy-sync = { version = "0.2.0", path = "../../../../embassy-sync", features = ["defmt"] }
|
||||
embassy-executor = { version = "0.2.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "nightly", "integrated-timers"] }
|
||||
embassy-time = { version = "0.1.0", path = "../../../../embassy-time", features = ["nightly", "tick-hz-32_768"] }
|
||||
embassy-time = { version = "0.1.2", path = "../../../../embassy-time", features = ["nightly", "tick-hz-32_768"] }
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32f767zi", "time-driver-any", "exti"] }
|
||||
embassy-boot-stm32 = { version = "0.1.0", path = "../../../../embassy-boot/stm32", features = ["nightly"] }
|
||||
embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" }
|
||||
|
@ -7,7 +7,7 @@ license = "MIT OR Apache-2.0"
|
||||
[dependencies]
|
||||
embassy-sync = { version = "0.2.0", path = "../../../../embassy-sync" }
|
||||
embassy-executor = { version = "0.2.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "nightly", "integrated-timers"] }
|
||||
embassy-time = { version = "0.1.0", path = "../../../../embassy-time", features = ["nightly", "tick-hz-32_768"] }
|
||||
embassy-time = { version = "0.1.2", path = "../../../../embassy-time", features = ["nightly", "tick-hz-32_768"] }
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32h743zi", "time-driver-any", "exti"] }
|
||||
embassy-boot-stm32 = { version = "0.1.0", path = "../../../../embassy-boot/stm32", features = ["nightly"] }
|
||||
embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" }
|
||||
|
@ -7,7 +7,7 @@ license = "MIT OR Apache-2.0"
|
||||
[dependencies]
|
||||
embassy-sync = { version = "0.2.0", path = "../../../../embassy-sync", features = ["defmt"] }
|
||||
embassy-executor = { version = "0.2.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "nightly", "integrated-timers"] }
|
||||
embassy-time = { version = "0.1.0", path = "../../../../embassy-time", features = ["nightly", "tick-hz-32_768"] }
|
||||
embassy-time = { version = "0.1.2", path = "../../../../embassy-time", features = ["nightly", "tick-hz-32_768"] }
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32l072cz", "time-driver-any", "exti", "memory-x"] }
|
||||
embassy-boot-stm32 = { version = "0.1.0", path = "../../../../embassy-boot/stm32", features = ["nightly"] }
|
||||
embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" }
|
||||
|
@ -7,7 +7,7 @@ license = "MIT OR Apache-2.0"
|
||||
[dependencies]
|
||||
embassy-sync = { version = "0.2.0", path = "../../../../embassy-sync", features = ["defmt"] }
|
||||
embassy-executor = { version = "0.2.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "nightly", "integrated-timers"] }
|
||||
embassy-time = { version = "0.1.0", path = "../../../../embassy-time", features = ["nightly", "tick-hz-32_768"] }
|
||||
embassy-time = { version = "0.1.2", path = "../../../../embassy-time", features = ["nightly", "tick-hz-32_768"] }
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32l151cb-a", "time-driver-any", "exti"] }
|
||||
embassy-boot-stm32 = { version = "0.1.0", path = "../../../../embassy-boot/stm32", features = ["nightly"] }
|
||||
embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" }
|
||||
|
@ -7,7 +7,7 @@ license = "MIT OR Apache-2.0"
|
||||
[dependencies]
|
||||
embassy-sync = { version = "0.2.0", path = "../../../../embassy-sync", features = ["defmt"] }
|
||||
embassy-executor = { version = "0.2.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "nightly", "integrated-timers"] }
|
||||
embassy-time = { version = "0.1.0", path = "../../../../embassy-time", features = ["nightly", "tick-hz-32_768"] }
|
||||
embassy-time = { version = "0.1.2", path = "../../../../embassy-time", features = ["nightly", "tick-hz-32_768"] }
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32l475vg", "time-driver-any", "exti"] }
|
||||
embassy-boot-stm32 = { version = "0.1.0", path = "../../../../embassy-boot/stm32", features = ["nightly"] }
|
||||
embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" }
|
||||
|
@ -7,7 +7,7 @@ license = "MIT OR Apache-2.0"
|
||||
[dependencies]
|
||||
embassy-sync = { version = "0.2.0", path = "../../../../embassy-sync", features = ["defmt"] }
|
||||
embassy-executor = { version = "0.2.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "nightly", "integrated-timers"] }
|
||||
embassy-time = { version = "0.1.0", path = "../../../../embassy-time", features = ["nightly", "tick-hz-32_768"] }
|
||||
embassy-time = { version = "0.1.2", path = "../../../../embassy-time", features = ["nightly", "tick-hz-32_768"] }
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32wl55jc-cm4", "time-driver-any", "exti"] }
|
||||
embassy-boot-stm32 = { version = "0.1.0", path = "../../../../embassy-boot/stm32", features = ["nightly"] }
|
||||
embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" }
|
||||
|
@ -18,7 +18,7 @@ log = [
|
||||
[dependencies]
|
||||
embassy-sync = { version = "0.2.0", path = "../../embassy-sync" }
|
||||
embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "rtos-trace", "rtos-trace-interrupt", "integrated-timers"] }
|
||||
embassy-time = { version = "0.1.0", path = "../../embassy-time" }
|
||||
embassy-time = { version = "0.1.2", path = "../../embassy-time" }
|
||||
embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["nrf52840", "time-driver-rtc1", "gpiote", "unstable-pac"] }
|
||||
|
||||
cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] }
|
||||
|
@ -9,7 +9,7 @@ rtic = { version = "2", features = ["thumbv7-backend"] }
|
||||
|
||||
embassy-futures = { version = "0.1.0", path = "../../embassy-futures" }
|
||||
embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
|
||||
embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["nightly", "unstable-traits", "defmt", "defmt-timestamp-uptime", "generic-queue"] }
|
||||
embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["nightly", "unstable-traits", "defmt", "defmt-timestamp-uptime", "generic-queue"] }
|
||||
embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["nightly", "unstable-traits", "defmt", "nrf52840", "time-driver-rtc1", "gpiote", "unstable-pac", "time"] }
|
||||
|
||||
defmt = "0.3"
|
||||
|
@ -29,7 +29,7 @@ nightly = [
|
||||
embassy-futures = { version = "0.1.0", path = "../../embassy-futures" }
|
||||
embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
|
||||
embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] }
|
||||
embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] }
|
||||
embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] }
|
||||
embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["defmt", "nrf52840", "time-driver-rtc1", "gpiote", "unstable-pac", "time"] }
|
||||
embassy-net = { version = "0.1.0", path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet"], optional = true }
|
||||
embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt", "msos-descriptor",], optional = true }
|
||||
@ -43,6 +43,7 @@ embassy-net-esp-hosted = { version = "0.1.0", path = "../../embassy-net-esp-host
|
||||
defmt = "0.3"
|
||||
defmt-rtt = "0.4"
|
||||
|
||||
fixed = "1.10.0"
|
||||
static_cell = "1.1"
|
||||
cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] }
|
||||
cortex-m-rt = "0.7.0"
|
||||
@ -52,4 +53,9 @@ rand = { version = "0.8.4", default-features = false }
|
||||
embedded-storage = "0.3.0"
|
||||
usbd-hid = "0.6.0"
|
||||
serde = { version = "1.0.136", default-features = false }
|
||||
embedded-hal-async = { version = "0.2.0-alpha.1", optional = true }
|
||||
embedded-hal-async = { version = "0.2.0-alpha.2", optional = true }
|
||||
num-integer = { version = "0.1.45", default-features = false }
|
||||
microfft = "0.5.0"
|
||||
|
||||
[patch.crates-io]
|
||||
lora-phy = { git = "https://github.com/embassy-rs/lora-phy", rev = "ad289428fd44b02788e2fa2116445cc8f640a265" }
|
||||
|
@ -7,6 +7,8 @@ use embassy_executor::Spawner;
|
||||
use embassy_nrf::pdm::{self, Config, Pdm};
|
||||
use embassy_nrf::{bind_interrupts, peripherals};
|
||||
use embassy_time::{Duration, Timer};
|
||||
use fixed::types::I7F1;
|
||||
use num_integer::Roots;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
bind_interrupts!(struct Irqs {
|
||||
@ -20,18 +22,36 @@ async fn main(_p: Spawner) {
|
||||
let mut pdm = Pdm::new(p.PDM, Irqs, p.P0_01, p.P0_00, config);
|
||||
|
||||
loop {
|
||||
pdm.start().await;
|
||||
for gain in [I7F1::from_num(-20), I7F1::from_num(0), I7F1::from_num(20)] {
|
||||
pdm.set_gain(gain, gain);
|
||||
info!("Gain = {} dB", defmt::Debug2Format(&gain));
|
||||
pdm.start().await;
|
||||
|
||||
// wait some time till the microphon settled
|
||||
Timer::after(Duration::from_millis(1000)).await;
|
||||
// wait some time till the microphon settled
|
||||
Timer::after(Duration::from_millis(1000)).await;
|
||||
|
||||
const SAMPLES: usize = 2048;
|
||||
let mut buf = [0i16; SAMPLES];
|
||||
pdm.sample(&mut buf).await.unwrap();
|
||||
const SAMPLES: usize = 2048;
|
||||
let mut buf = [0i16; SAMPLES];
|
||||
pdm.sample(&mut buf).await.unwrap();
|
||||
|
||||
info!("samples: {:?}", &buf);
|
||||
let mean = (buf.iter().map(|v| i32::from(*v)).sum::<i32>() / buf.len() as i32) as i16;
|
||||
info!(
|
||||
"{} samples, min {=i16}, max {=i16}, mean {=i16}, AC RMS {=i16}",
|
||||
buf.len(),
|
||||
buf.iter().min().unwrap(),
|
||||
buf.iter().max().unwrap(),
|
||||
mean,
|
||||
(buf.iter()
|
||||
.map(|v| i32::from(*v - mean).pow(2))
|
||||
.fold(0i32, |a, b| a.saturating_add(b))
|
||||
/ buf.len() as i32)
|
||||
.sqrt() as i16,
|
||||
);
|
||||
|
||||
pdm.stop().await;
|
||||
Timer::after(Duration::from_millis(100)).await;
|
||||
info!("samples: {:?}", &buf);
|
||||
|
||||
pdm.stop().await;
|
||||
Timer::after(Duration::from_millis(100)).await;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
81
examples/nrf52840/src/bin/pdm_continuous.rs
Normal file
81
examples/nrf52840/src/bin/pdm_continuous.rs
Normal file
@ -0,0 +1,81 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use core::cmp::Ordering;
|
||||
|
||||
use defmt::info;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_nrf::pdm::{self, Config, Frequency, OperationMode, Pdm, Ratio, SamplerState};
|
||||
use embassy_nrf::{bind_interrupts, peripherals};
|
||||
use fixed::types::I7F1;
|
||||
use microfft::real::rfft_1024;
|
||||
use num_integer::Roots;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
// Demonstrates both continuous sampling and scanning multiple channels driven by a PPI linked timer
|
||||
|
||||
bind_interrupts!(struct Irqs {
|
||||
PDM => pdm::InterruptHandler<peripherals::PDM>;
|
||||
});
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_p: Spawner) {
|
||||
let mut p = embassy_nrf::init(Default::default());
|
||||
let mut config = Config::default();
|
||||
// Pins are correct for the onboard microphone on the Feather nRF52840 Sense.
|
||||
config.frequency = Frequency::_1280K; // 16 kHz sample rate
|
||||
config.ratio = Ratio::RATIO80;
|
||||
config.operation_mode = OperationMode::Mono;
|
||||
config.gain_left = I7F1::from_bits(5); // 2.5 dB
|
||||
let mut pdm = Pdm::new(p.PDM, Irqs, &mut p.P0_00, &mut p.P0_01, config);
|
||||
|
||||
let mut bufs = [[0; 1024]; 2];
|
||||
|
||||
pdm.run_task_sampler(&mut bufs, move |buf| {
|
||||
// NOTE: It is important that the time spent within this callback
|
||||
// does not exceed the time taken to acquire the 1500 samples we
|
||||
// have in this example, which would be 10us + 2us per
|
||||
// sample * 1500 = 18ms. You need to measure the time taken here
|
||||
// and set the sample buffer size accordingly. Exceeding this
|
||||
// time can lead to the peripheral re-writing the other buffer.
|
||||
let mean = (buf.iter().map(|v| i32::from(*v)).sum::<i32>() / buf.len() as i32) as i16;
|
||||
let (peak_freq_index, peak_mag) = fft_peak_freq(&buf);
|
||||
let peak_freq = peak_freq_index * 16000 / buf.len();
|
||||
info!(
|
||||
"{} samples, min {=i16}, max {=i16}, mean {=i16}, AC RMS {=i16}, peak {} @ {} Hz",
|
||||
buf.len(),
|
||||
buf.iter().min().unwrap(),
|
||||
buf.iter().max().unwrap(),
|
||||
mean,
|
||||
(buf.iter()
|
||||
.map(|v| i32::from(*v - mean).pow(2))
|
||||
.fold(0i32, |a, b| a.saturating_add(b))
|
||||
/ buf.len() as i32)
|
||||
.sqrt() as i16,
|
||||
peak_mag,
|
||||
peak_freq,
|
||||
);
|
||||
SamplerState::Sampled
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
fn fft_peak_freq(input: &[i16; 1024]) -> (usize, u32) {
|
||||
let mut f = [0f32; 1024];
|
||||
for i in 0..input.len() {
|
||||
f[i] = (input[i] as f32) / 32768.0;
|
||||
}
|
||||
// N.B. rfft_1024 does the FFT in-place so result is actually also a reference to f.
|
||||
let result = rfft_1024(&mut f);
|
||||
result[0].im = 0.0;
|
||||
|
||||
result
|
||||
.iter()
|
||||
.map(|c| c.norm_sqr())
|
||||
.enumerate()
|
||||
.max_by(|(_, a), (_, b)| a.partial_cmp(b).unwrap_or(Ordering::Equal))
|
||||
.map(|(i, v)| (i, ((v * 32768.0) as u32).sqrt()))
|
||||
.unwrap()
|
||||
}
|
@ -10,11 +10,15 @@ 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};
|
||||
use embassy_time::Delay;
|
||||
use embedded_hal_async::spi::ExclusiveDevice;
|
||||
use embedded_io::asynch::Write;
|
||||
use static_cell::make_static;
|
||||
use {defmt_rtt as _, embassy_net_esp_hosted as hosted, panic_probe as _};
|
||||
|
||||
const WIFI_NETWORK: &str = "EmbassyTest";
|
||||
const WIFI_PASSWORD: &str = "V8YxhKt5CdIAJFud";
|
||||
|
||||
bind_interrupts!(struct Irqs {
|
||||
SPIM3 => spim::InterruptHandler<peripherals::SPI3>;
|
||||
RNG => embassy_nrf::rng::InterruptHandler<peripherals::RNG>;
|
||||
@ -24,7 +28,7 @@ bind_interrupts!(struct Irqs {
|
||||
async fn wifi_task(
|
||||
runner: hosted::Runner<
|
||||
'static,
|
||||
ExclusiveDevice<Spim<'static, peripherals::SPI3>, Output<'static, peripherals::P0_31>>,
|
||||
ExclusiveDevice<Spim<'static, peripherals::SPI3>, Output<'static, peripherals::P0_31>, Delay>,
|
||||
Input<'static, AnyPin>,
|
||||
Output<'static, peripherals::P1_05>,
|
||||
>,
|
||||
@ -55,7 +59,7 @@ async fn main(spawner: Spawner) {
|
||||
config.frequency = spim::Frequency::M32;
|
||||
config.mode = spim::MODE_2; // !!!
|
||||
let spi = spim::Spim::new(p.SPI3, Irqs, sck, miso, mosi, config);
|
||||
let spi = ExclusiveDevice::new(spi, cs);
|
||||
let spi = ExclusiveDevice::new(spi, cs, Delay);
|
||||
|
||||
let (device, mut control, runner) = embassy_net_esp_hosted::new(
|
||||
make_static!(embassy_net_esp_hosted::State::new()),
|
||||
@ -69,7 +73,7 @@ async fn main(spawner: Spawner) {
|
||||
unwrap!(spawner.spawn(wifi_task(runner)));
|
||||
|
||||
control.init().await;
|
||||
control.join(env!("WIFI_NETWORK"), env!("WIFI_PASSWORD")).await;
|
||||
control.join(WIFI_NETWORK, WIFI_PASSWORD).await;
|
||||
|
||||
let config = embassy_net::Config::dhcpv4(Default::default());
|
||||
// let config = embassy_net::Config::ipv4_static(embassy_net::StaticConfigV4 {
|
||||
|
@ -14,7 +14,7 @@ embassy-executor = { version = "0.2.0", path = "../../embassy-executor", feature
|
||||
"defmt",
|
||||
"integrated-timers",
|
||||
] }
|
||||
embassy-time = { version = "0.1.0", path = "../../embassy-time", features = [
|
||||
embassy-time = { version = "0.1.2", path = "../../embassy-time", features = [
|
||||
"defmt",
|
||||
"defmt-timestamp-uptime",
|
||||
] }
|
||||
|
@ -9,7 +9,7 @@ license = "MIT OR Apache-2.0"
|
||||
embassy-embedded-hal = { version = "0.1.0", path = "../../embassy-embedded-hal", features = ["defmt"] }
|
||||
embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
|
||||
embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] }
|
||||
embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["nightly", "unstable-traits", "defmt", "defmt-timestamp-uptime"] }
|
||||
embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["nightly", "unstable-traits", "defmt", "defmt-timestamp-uptime"] }
|
||||
embassy-rp = { version = "0.1.0", path = "../../embassy-rp", features = ["defmt", "unstable-traits", "nightly", "unstable-pac", "time-driver", "critical-section-impl"] }
|
||||
embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] }
|
||||
embassy-net = { version = "0.1.0", path = "../../embassy-net", features = ["defmt", "nightly", "tcp", "udp", "dhcpv4", "medium-ethernet"] }
|
||||
@ -40,9 +40,10 @@ display-interface = "0.4.1"
|
||||
byte-slice-cast = { version = "1.2.0", default-features = false }
|
||||
smart-leds = "0.3.0"
|
||||
heapless = "0.7.15"
|
||||
usbd-hid = "0.6.1"
|
||||
|
||||
embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.10" }
|
||||
embedded-hal-async = "0.2.0-alpha.1"
|
||||
embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.11" }
|
||||
embedded-hal-async = "0.2.0-alpha.2"
|
||||
embedded-io = { version = "0.4.0", features = ["async", "defmt"] }
|
||||
embedded-storage = { version = "0.3" }
|
||||
static_cell = { version = "1.1", features = ["nightly"]}
|
||||
@ -53,3 +54,6 @@ rand = { version = "0.8.5", default-features = false }
|
||||
|
||||
[profile.release]
|
||||
debug = true
|
||||
|
||||
[patch.crates-io]
|
||||
lora-phy = { git = "https://github.com/embassy-rs/lora-phy", rev = "ad289428fd44b02788e2fa2116445cc8f640a265" }
|
||||
|
@ -1,11 +1,15 @@
|
||||
//! This example test the ADC (Analog to Digital Conversion) of the RS2040 pin 26, 27 and 28.
|
||||
//! It also reads the temperature sensor in the chip.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_rp::adc::{Adc, Config, InterruptHandler};
|
||||
use embassy_rp::adc::{Adc, Config, InterruptHandler, Pin};
|
||||
use embassy_rp::bind_interrupts;
|
||||
use embassy_rp::gpio::Pull;
|
||||
use embassy_time::{Duration, Timer};
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
@ -18,18 +22,18 @@ async fn main(_spawner: Spawner) {
|
||||
let p = embassy_rp::init(Default::default());
|
||||
let mut adc = Adc::new(p.ADC, Irqs, Config::default());
|
||||
|
||||
let mut p26 = p.PIN_26;
|
||||
let mut p27 = p.PIN_27;
|
||||
let mut p28 = p.PIN_28;
|
||||
let mut p26 = Pin::new(p.PIN_26, Pull::None);
|
||||
let mut p27 = Pin::new(p.PIN_27, Pull::None);
|
||||
let mut p28 = Pin::new(p.PIN_28, Pull::None);
|
||||
|
||||
loop {
|
||||
let level = adc.read(&mut p26).await;
|
||||
let level = adc.read(&mut p26).await.unwrap();
|
||||
info!("Pin 26 ADC: {}", level);
|
||||
let level = adc.read(&mut p27).await;
|
||||
let level = adc.read(&mut p27).await.unwrap();
|
||||
info!("Pin 27 ADC: {}", level);
|
||||
let level = adc.read(&mut p28).await;
|
||||
let level = adc.read(&mut p28).await.unwrap();
|
||||
info!("Pin 28 ADC: {}", level);
|
||||
let temp = adc.read_temperature().await;
|
||||
let temp = adc.read_temperature().await.unwrap();
|
||||
info!("Temp: {} degrees", convert_to_celsius(temp));
|
||||
Timer::after(Duration::from_secs(1)).await;
|
||||
}
|
||||
@ -37,5 +41,8 @@ async fn main(_spawner: Spawner) {
|
||||
|
||||
fn convert_to_celsius(raw_temp: u16) -> f32 {
|
||||
// According to chapter 4.9.5. Temperature Sensor in RP2040 datasheet
|
||||
27.0 - (raw_temp as f32 * 3.3 / 4096.0 - 0.706) / 0.001721 as f32
|
||||
let temp = 27.0 - (raw_temp as f32 * 3.3 / 4096.0 - 0.706) / 0.001721;
|
||||
let sign = if temp < 0.0 { -1.0 } else { 1.0 };
|
||||
let rounded_temp_x10: i16 = ((temp * 10.0) + 0.5 * sign) as i16;
|
||||
(rounded_temp_x10 as f32) / 10.0
|
||||
}
|
||||
|
@ -1,3 +1,7 @@
|
||||
//! This example test the RP Pico on board LED.
|
||||
//!
|
||||
//! It does not work with the RP Pico W board. See wifi_blinky.rs.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
@ -1,3 +1,7 @@
|
||||
//! This example uses the RP Pico on board LED to test input pin 28. This is not the button on the board.
|
||||
//!
|
||||
//! It does not work with the RP Pico W board. Use wifi_blinky.rs and add input pin.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
@ -15,7 +15,7 @@ use embassy_rp::clocks::RoscRng;
|
||||
use embassy_rp::gpio::{Input, Level, Output, Pull};
|
||||
use embassy_rp::peripherals::{PIN_17, PIN_20, PIN_21, SPI0};
|
||||
use embassy_rp::spi::{Async, Config as SpiConfig, Spi};
|
||||
use embassy_time::Duration;
|
||||
use embassy_time::{Delay, Duration};
|
||||
use embedded_hal_async::spi::ExclusiveDevice;
|
||||
use embedded_io::asynch::Write;
|
||||
use rand::RngCore;
|
||||
@ -26,7 +26,7 @@ use {defmt_rtt as _, panic_probe as _};
|
||||
async fn ethernet_task(
|
||||
runner: Runner<
|
||||
'static,
|
||||
ExclusiveDevice<Spi<'static, SPI0, Async>, Output<'static, PIN_17>>,
|
||||
ExclusiveDevice<Spi<'static, SPI0, Async>, Output<'static, PIN_17>, Delay>,
|
||||
Input<'static, PIN_21>,
|
||||
Output<'static, PIN_20>,
|
||||
>,
|
||||
@ -54,8 +54,14 @@ async fn main(spawner: Spawner) {
|
||||
|
||||
let mac_addr = [0x02, 0x00, 0x00, 0x00, 0x00, 0x00];
|
||||
let state = make_static!(State::<8, 8>::new());
|
||||
let (device, runner) =
|
||||
embassy_net_w5500::new(mac_addr, state, ExclusiveDevice::new(spi, cs), w5500_int, w5500_reset).await;
|
||||
let (device, runner) = embassy_net_w5500::new(
|
||||
mac_addr,
|
||||
state,
|
||||
ExclusiveDevice::new(spi, cs, Delay),
|
||||
w5500_int,
|
||||
w5500_reset,
|
||||
)
|
||||
.await;
|
||||
unwrap!(spawner.spawn(ethernet_task(runner)));
|
||||
|
||||
// Generate random seed
|
||||
|
@ -17,7 +17,7 @@ use embassy_rp::clocks::RoscRng;
|
||||
use embassy_rp::gpio::{Input, Level, Output, Pull};
|
||||
use embassy_rp::peripherals::{PIN_17, PIN_20, PIN_21, SPI0};
|
||||
use embassy_rp::spi::{Async, Config as SpiConfig, Spi};
|
||||
use embassy_time::{Duration, Timer};
|
||||
use embassy_time::{Delay, Duration, Timer};
|
||||
use embedded_hal_async::spi::ExclusiveDevice;
|
||||
use embedded_io::asynch::Write;
|
||||
use rand::RngCore;
|
||||
@ -28,7 +28,7 @@ use {defmt_rtt as _, panic_probe as _};
|
||||
async fn ethernet_task(
|
||||
runner: Runner<
|
||||
'static,
|
||||
ExclusiveDevice<Spi<'static, SPI0, Async>, Output<'static, PIN_17>>,
|
||||
ExclusiveDevice<Spi<'static, SPI0, Async>, Output<'static, PIN_17>, Delay>,
|
||||
Input<'static, PIN_21>,
|
||||
Output<'static, PIN_20>,
|
||||
>,
|
||||
@ -57,8 +57,14 @@ async fn main(spawner: Spawner) {
|
||||
|
||||
let mac_addr = [0x02, 0x00, 0x00, 0x00, 0x00, 0x00];
|
||||
let state = make_static!(State::<8, 8>::new());
|
||||
let (device, runner) =
|
||||
embassy_net_w5500::new(mac_addr, state, ExclusiveDevice::new(spi, cs), w5500_int, w5500_reset).await;
|
||||
let (device, runner) = embassy_net_w5500::new(
|
||||
mac_addr,
|
||||
state,
|
||||
ExclusiveDevice::new(spi, cs, Delay),
|
||||
w5500_int,
|
||||
w5500_reset,
|
||||
)
|
||||
.await;
|
||||
unwrap!(spawner.spawn(ethernet_task(runner)));
|
||||
|
||||
// Generate random seed
|
||||
|
@ -16,7 +16,7 @@ use embassy_rp::clocks::RoscRng;
|
||||
use embassy_rp::gpio::{Input, Level, Output, Pull};
|
||||
use embassy_rp::peripherals::{PIN_17, PIN_20, PIN_21, SPI0};
|
||||
use embassy_rp::spi::{Async, Config as SpiConfig, Spi};
|
||||
use embassy_time::Duration;
|
||||
use embassy_time::{Delay, Duration};
|
||||
use embedded_hal_async::spi::ExclusiveDevice;
|
||||
use embedded_io::asynch::Write;
|
||||
use rand::RngCore;
|
||||
@ -26,7 +26,7 @@ use {defmt_rtt as _, panic_probe as _};
|
||||
async fn ethernet_task(
|
||||
runner: Runner<
|
||||
'static,
|
||||
ExclusiveDevice<Spi<'static, SPI0, Async>, Output<'static, PIN_17>>,
|
||||
ExclusiveDevice<Spi<'static, SPI0, Async>, Output<'static, PIN_17>, Delay>,
|
||||
Input<'static, PIN_21>,
|
||||
Output<'static, PIN_20>,
|
||||
>,
|
||||
@ -55,8 +55,14 @@ async fn main(spawner: Spawner) {
|
||||
|
||||
let mac_addr = [0x02, 0x00, 0x00, 0x00, 0x00, 0x00];
|
||||
let state = make_static!(State::<8, 8>::new());
|
||||
let (device, runner) =
|
||||
embassy_net_w5500::new(mac_addr, state, ExclusiveDevice::new(spi, cs), w5500_int, w5500_reset).await;
|
||||
let (device, runner) = embassy_net_w5500::new(
|
||||
mac_addr,
|
||||
state,
|
||||
ExclusiveDevice::new(spi, cs, Delay),
|
||||
w5500_int,
|
||||
w5500_reset,
|
||||
)
|
||||
.await;
|
||||
unwrap!(spawner.spawn(ethernet_task(runner)));
|
||||
|
||||
// Generate random seed
|
||||
|
@ -16,6 +16,7 @@ use embassy_rp::clocks::RoscRng;
|
||||
use embassy_rp::gpio::{Input, Level, Output, Pull};
|
||||
use embassy_rp::peripherals::{PIN_17, PIN_20, PIN_21, SPI0};
|
||||
use embassy_rp::spi::{Async, Config as SpiConfig, Spi};
|
||||
use embassy_time::Delay;
|
||||
use embedded_hal_async::spi::ExclusiveDevice;
|
||||
use rand::RngCore;
|
||||
use static_cell::make_static;
|
||||
@ -24,7 +25,7 @@ use {defmt_rtt as _, panic_probe as _};
|
||||
async fn ethernet_task(
|
||||
runner: Runner<
|
||||
'static,
|
||||
ExclusiveDevice<Spi<'static, SPI0, Async>, Output<'static, PIN_17>>,
|
||||
ExclusiveDevice<Spi<'static, SPI0, Async>, Output<'static, PIN_17>, Delay>,
|
||||
Input<'static, PIN_21>,
|
||||
Output<'static, PIN_20>,
|
||||
>,
|
||||
@ -52,8 +53,14 @@ async fn main(spawner: Spawner) {
|
||||
|
||||
let mac_addr = [0x02, 0x00, 0x00, 0x00, 0x00, 0x00];
|
||||
let state = make_static!(State::<8, 8>::new());
|
||||
let (device, runner) =
|
||||
embassy_net_w5500::new(mac_addr, state, ExclusiveDevice::new(spi, cs), w5500_int, w5500_reset).await;
|
||||
let (device, runner) = embassy_net_w5500::new(
|
||||
mac_addr,
|
||||
state,
|
||||
ExclusiveDevice::new(spi, cs, Delay),
|
||||
w5500_int,
|
||||
w5500_reset,
|
||||
)
|
||||
.await;
|
||||
unwrap!(spawner.spawn(ethernet_task(runner)));
|
||||
|
||||
// Generate random seed
|
||||
|
@ -1,3 +1,5 @@
|
||||
//! This example test the flash connected to the RP2040 chip.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
@ -1,3 +1,7 @@
|
||||
//! This example shows how async gpio can be used with a RP2040.
|
||||
//!
|
||||
//! The LED on the RP Pico W board is connected differently. See wifi_blinky.rs.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
@ -9,8 +13,6 @@ use embassy_time::{Duration, Timer};
|
||||
use gpio::{Input, Level, Output, Pull};
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
/// This example shows how async gpio can be used with a RP2040.
|
||||
///
|
||||
/// It requires an external signal to be manually triggered on PIN 16. For
|
||||
/// example, this could be accomplished using an external power source with a
|
||||
/// button so that it is possible to toggle the signal from low to high.
|
||||
|
@ -1,3 +1,7 @@
|
||||
//! This example shows how GPOUT (General purpose clock outputs) can toggle a output pin.
|
||||
//!
|
||||
//! The LED on the RP Pico W board is connected differently. Add a LED and resistor to another pin.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
@ -1,3 +1,8 @@
|
||||
//! This example shows how to communicate asynchronous using i2c with external chips.
|
||||
//!
|
||||
//! Example written for the [`MCP23017 16-Bit I2C I/O Expander with Serial Interface`] chip.
|
||||
//! (https://www.microchip.com/en-us/product/mcp23017)
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
@ -1,3 +1,8 @@
|
||||
//! This example shows how to communicate using i2c with external chips.
|
||||
//!
|
||||
//! Example written for the [`MCP23017 16-Bit I2C I/O Expander with Serial Interface`] chip.
|
||||
//! (https://www.microchip.com/en-us/product/mcp23017)
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
@ -1,5 +1,6 @@
|
||||
//! This example runs on the Raspberry Pi Pico with a Waveshare board containing a Semtech Sx1262 radio.
|
||||
//! It demonstrates LoRaWAN join functionality.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![macro_use]
|
||||
|
@ -1,5 +1,6 @@
|
||||
//! This example runs on the Raspberry Pi Pico with a Waveshare board containing a Semtech Sx1262 radio.
|
||||
//! It demonstrates LORA P2P receive functionality in conjunction with the lora_p2p_send example.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![macro_use]
|
||||
|
@ -1,5 +1,6 @@
|
||||
//! This example runs on the Raspberry Pi Pico with a Waveshare board containing a Semtech Sx1262 radio.
|
||||
//! It demonstrates LORA P2P send functionality.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![macro_use]
|
||||
|
@ -1,5 +1,6 @@
|
||||
//! This example runs on the Raspberry Pi Pico with a Waveshare board containing a Semtech Sx1262 radio.
|
||||
//! It demonstrates LORA P2P send functionality using the second core, with data provided by the first core.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![macro_use]
|
||||
|
@ -1,3 +1,7 @@
|
||||
//! This example shows how to send messages between the two cores in the RP2040 chip.
|
||||
//!
|
||||
//! The LED on the RP Pico W board is connected differently. See wifi_blinky.rs.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
@ -1,15 +1,22 @@
|
||||
//! This example shows powerful PIO module in the RP2040 chip.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
use defmt::info;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_rp::bind_interrupts;
|
||||
use embassy_rp::peripherals::PIO0;
|
||||
use embassy_rp::pio::{Common, Config, Irq, Pio, PioPin, ShiftDirection, StateMachine};
|
||||
use embassy_rp::pio::{Common, Config, InterruptHandler, Irq, Pio, PioPin, ShiftDirection, StateMachine};
|
||||
use embassy_rp::relocate::RelocatedProgram;
|
||||
use fixed::traits::ToFixed;
|
||||
use fixed_macro::types::U56F8;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
bind_interrupts!(struct Irqs {
|
||||
PIO0_IRQ_0 => InterruptHandler<PIO0>;
|
||||
});
|
||||
|
||||
fn setup_pio_task_sm0<'a>(pio: &mut Common<'a, PIO0>, sm: &mut StateMachine<'a, PIO0, 0>, pin: impl PioPin) {
|
||||
// Setup sm0
|
||||
|
||||
@ -49,7 +56,14 @@ fn setup_pio_task_sm1<'a>(pio: &mut Common<'a, PIO0>, sm: &mut StateMachine<'a,
|
||||
// Setupm sm1
|
||||
|
||||
// Read 0b10101 repeatedly until ISR is full
|
||||
let prg = pio_proc::pio_asm!(".origin 8", "set x, 0x15", ".wrap_target", "in x, 5 [31]", ".wrap",);
|
||||
let prg = pio_proc::pio_asm!(
|
||||
//
|
||||
".origin 8",
|
||||
"set x, 0x15",
|
||||
".wrap_target",
|
||||
"in x, 5 [31]",
|
||||
".wrap",
|
||||
);
|
||||
|
||||
let relocated = RelocatedProgram::new(&prg.program);
|
||||
let mut cfg = Config::default();
|
||||
@ -110,7 +124,7 @@ async fn main(spawner: Spawner) {
|
||||
mut sm1,
|
||||
mut sm2,
|
||||
..
|
||||
} = Pio::new(pio);
|
||||
} = Pio::new(pio, Irqs);
|
||||
|
||||
setup_pio_task_sm0(&mut common, &mut sm0, p.PIN_0);
|
||||
setup_pio_task_sm1(&mut common, &mut sm1);
|
||||
|
@ -1,16 +1,23 @@
|
||||
//! This example shows powerful PIO module in the RP2040 chip.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
use defmt::info;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_futures::join::join;
|
||||
use embassy_rp::pio::{Config, Pio, ShiftConfig, ShiftDirection};
|
||||
use embassy_rp::peripherals::PIO0;
|
||||
use embassy_rp::pio::{Config, InterruptHandler, Pio, ShiftConfig, ShiftDirection};
|
||||
use embassy_rp::relocate::RelocatedProgram;
|
||||
use embassy_rp::Peripheral;
|
||||
use embassy_rp::{bind_interrupts, Peripheral};
|
||||
use fixed::traits::ToFixed;
|
||||
use fixed_macro::types::U56F8;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
bind_interrupts!(struct Irqs {
|
||||
PIO0_IRQ_0 => InterruptHandler<PIO0>;
|
||||
});
|
||||
|
||||
fn swap_nibbles(v: u32) -> u32 {
|
||||
let v = (v & 0x0f0f_0f0f) << 4 | (v & 0xf0f0_f0f0) >> 4;
|
||||
let v = (v & 0x00ff_00ff) << 8 | (v & 0xff00_ff00) >> 8;
|
||||
@ -25,7 +32,7 @@ async fn main(_spawner: Spawner) {
|
||||
mut common,
|
||||
sm0: mut sm,
|
||||
..
|
||||
} = Pio::new(pio);
|
||||
} = Pio::new(pio, Irqs);
|
||||
|
||||
let prg = pio_proc::pio_asm!(
|
||||
".origin 0",
|
||||
|
@ -1,3 +1,6 @@
|
||||
//! This example shows powerful PIO module in the RP2040 chip to communicate with a HD44780 display.
|
||||
//! See (https://www.sparkfun.com/datasheets/LCD/HD44780.pdf)
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
@ -7,13 +10,19 @@ use core::fmt::Write;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_rp::dma::{AnyChannel, Channel};
|
||||
use embassy_rp::peripherals::PIO0;
|
||||
use embassy_rp::pio::{Config, Direction, FifoJoin, Pio, PioPin, ShiftConfig, ShiftDirection, StateMachine};
|
||||
use embassy_rp::pio::{
|
||||
Config, Direction, FifoJoin, InterruptHandler, Pio, PioPin, ShiftConfig, ShiftDirection, StateMachine,
|
||||
};
|
||||
use embassy_rp::pwm::{self, Pwm};
|
||||
use embassy_rp::relocate::RelocatedProgram;
|
||||
use embassy_rp::{into_ref, Peripheral, PeripheralRef};
|
||||
use embassy_rp::{bind_interrupts, into_ref, Peripheral, PeripheralRef};
|
||||
use embassy_time::{Duration, Instant, Timer};
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
bind_interrupts!(pub struct Irqs {
|
||||
PIO0_IRQ_0 => InterruptHandler<PIO0>;
|
||||
});
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) {
|
||||
// this test assumes a 2x16 HD44780 display attached as follow:
|
||||
@ -37,7 +46,7 @@ async fn main(_spawner: Spawner) {
|
||||
});
|
||||
|
||||
let mut hd = HD44780::new(
|
||||
p.PIO0, p.DMA_CH3, p.PIN_0, p.PIN_1, p.PIN_2, p.PIN_3, p.PIN_4, p.PIN_5, p.PIN_6,
|
||||
p.PIO0, Irqs, p.DMA_CH3, p.PIN_0, p.PIN_1, p.PIN_2, p.PIN_3, p.PIN_4, p.PIN_5, p.PIN_6,
|
||||
)
|
||||
.await;
|
||||
|
||||
@ -72,6 +81,7 @@ pub struct HD44780<'l> {
|
||||
impl<'l> HD44780<'l> {
|
||||
pub async fn new(
|
||||
pio: impl Peripheral<P = PIO0> + 'l,
|
||||
irq: Irqs,
|
||||
dma: impl Peripheral<P = impl Channel> + 'l,
|
||||
rs: impl PioPin,
|
||||
rw: impl PioPin,
|
||||
@ -88,7 +98,7 @@ impl<'l> HD44780<'l> {
|
||||
mut irq0,
|
||||
mut sm0,
|
||||
..
|
||||
} = Pio::new(pio);
|
||||
} = Pio::new(pio, irq);
|
||||
|
||||
// takes command words (<wait:24> <command:4> <0:4>)
|
||||
let prg = pio_proc::pio_asm!(
|
||||
|
@ -1,3 +1,6 @@
|
||||
//! This example shows powerful PIO module in the RP2040 chip to communicate with WS2812 LED modules.
|
||||
//! See (https://www.sparkfun.com/categories/tags/ws2812)
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
@ -5,15 +8,22 @@
|
||||
use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_rp::dma::{AnyChannel, Channel};
|
||||
use embassy_rp::pio::{Common, Config, FifoJoin, Instance, Pio, PioPin, ShiftConfig, ShiftDirection, StateMachine};
|
||||
use embassy_rp::peripherals::PIO0;
|
||||
use embassy_rp::pio::{
|
||||
Common, Config, FifoJoin, Instance, InterruptHandler, Pio, PioPin, ShiftConfig, ShiftDirection, StateMachine,
|
||||
};
|
||||
use embassy_rp::relocate::RelocatedProgram;
|
||||
use embassy_rp::{clocks, into_ref, Peripheral, PeripheralRef};
|
||||
use embassy_rp::{bind_interrupts, clocks, into_ref, Peripheral, PeripheralRef};
|
||||
use embassy_time::{Duration, Timer};
|
||||
use fixed::types::U24F8;
|
||||
use fixed_macro::fixed;
|
||||
use smart_leds::RGB8;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
bind_interrupts!(struct Irqs {
|
||||
PIO0_IRQ_0 => InterruptHandler<PIO0>;
|
||||
});
|
||||
|
||||
pub struct Ws2812<'d, P: Instance, const S: usize, const N: usize> {
|
||||
dma: PeripheralRef<'d, AnyChannel>,
|
||||
sm: StateMachine<'d, P, S>,
|
||||
@ -123,7 +133,7 @@ async fn main(_spawner: Spawner) {
|
||||
info!("Start");
|
||||
let p = embassy_rp::init(Default::default());
|
||||
|
||||
let Pio { mut common, sm0, .. } = Pio::new(p.PIO0);
|
||||
let Pio { mut common, sm0, .. } = Pio::new(p.PIO0, Irqs);
|
||||
|
||||
// This is the number of leds in the string. Helpfully, the sparkfun thing plus and adafruit
|
||||
// feather boards for the 2040 both have one built in.
|
||||
|
@ -1,3 +1,7 @@
|
||||
//! This example shows how to use PWM (Pulse Width Modulation) in the RP2040 chip.
|
||||
//!
|
||||
//! The LED on the RP Pico W board is connected differently. Add a LED and resistor to another pin.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
46
examples/rp/src/bin/rtc.rs
Normal file
46
examples/rp/src/bin/rtc.rs
Normal file
@ -0,0 +1,46 @@
|
||||
//! This example shows how to use RTC (Real Time Clock) in the RP2040 chip.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_rp::rtc::{DateTime, DayOfWeek, Rtc};
|
||||
use embassy_time::{Duration, Timer};
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) {
|
||||
let p = embassy_rp::init(Default::default());
|
||||
info!("Wait for 20s");
|
||||
|
||||
let mut rtc = Rtc::new(p.RTC);
|
||||
|
||||
if !rtc.is_running() {
|
||||
info!("Start RTC");
|
||||
let now = DateTime {
|
||||
year: 2000,
|
||||
month: 1,
|
||||
day: 1,
|
||||
day_of_week: DayOfWeek::Saturday,
|
||||
hour: 0,
|
||||
minute: 0,
|
||||
second: 0,
|
||||
};
|
||||
rtc.set_datetime(now).unwrap();
|
||||
}
|
||||
|
||||
Timer::after(Duration::from_millis(20000)).await;
|
||||
|
||||
if let Ok(dt) = rtc.now() {
|
||||
info!(
|
||||
"Now: {}-{:02}-{:02} {}:{:02}:{:02}",
|
||||
dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second,
|
||||
);
|
||||
}
|
||||
|
||||
info!("Reboot.");
|
||||
Timer::after(Duration::from_millis(200)).await;
|
||||
cortex_m::peripheral::SCB::sys_reset();
|
||||
}
|
@ -1,3 +1,7 @@
|
||||
//! This example shows how to use SPI (Serial Peripheral Interface) in the RP2040 chip.
|
||||
//!
|
||||
//! Example for resistive touch sensor in Waveshare Pico-ResTouch
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
@ -1,3 +1,6 @@
|
||||
//! This example shows how to use SPI (Serial Peripheral Interface) in the RP2040 chip.
|
||||
//! No specific hardware is specified in this example. If you connect pin 11 and 12 you should get the same data back.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
@ -1,3 +1,8 @@
|
||||
//! This example shows how to use SPI (Serial Peripheral Interface) in the RP2040 chip.
|
||||
//!
|
||||
//! Example written for a display using the ST7789 chip. Possibly the Waveshare Pico-ResTouch
|
||||
//! (https://www.waveshare.com/wiki/Pico-ResTouch-LCD-2.8)
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
@ -175,7 +180,7 @@ mod touch {
|
||||
mod my_display_interface {
|
||||
use display_interface::{DataFormat, DisplayError, WriteOnlyDataCommand};
|
||||
use embedded_hal_1::digital::OutputPin;
|
||||
use embedded_hal_1::spi::SpiDeviceWrite;
|
||||
use embedded_hal_1::spi::SpiDevice;
|
||||
|
||||
/// SPI display interface.
|
||||
///
|
||||
@ -187,7 +192,7 @@ mod my_display_interface {
|
||||
|
||||
impl<SPI, DC> SPIDeviceInterface<SPI, DC>
|
||||
where
|
||||
SPI: SpiDeviceWrite,
|
||||
SPI: SpiDevice,
|
||||
DC: OutputPin,
|
||||
{
|
||||
/// Create new SPI interface for communciation with a display driver
|
||||
@ -198,7 +203,7 @@ mod my_display_interface {
|
||||
|
||||
impl<SPI, DC> WriteOnlyDataCommand for SPIDeviceInterface<SPI, DC>
|
||||
where
|
||||
SPI: SpiDeviceWrite,
|
||||
SPI: SpiDevice,
|
||||
DC: OutputPin,
|
||||
{
|
||||
fn send_commands(&mut self, cmds: DataFormat<'_>) -> Result<(), DisplayError> {
|
||||
@ -218,7 +223,7 @@ mod my_display_interface {
|
||||
}
|
||||
}
|
||||
|
||||
fn send_u8<T: SpiDeviceWrite>(spi: &mut T, words: DataFormat<'_>) -> Result<(), T::Error> {
|
||||
fn send_u8<T: SpiDevice>(spi: &mut T, words: DataFormat<'_>) -> Result<(), T::Error> {
|
||||
match words {
|
||||
DataFormat::U8(slice) => spi.write(slice),
|
||||
DataFormat::U16(slice) => {
|
||||
|
@ -1,3 +1,9 @@
|
||||
//! This example shows how to use UART (Universal asynchronous receiver-transmitter) in the RP2040 chip.
|
||||
//!
|
||||
//! No specific hardware is specified in this example. Only output on pin 0 is tested.
|
||||
//! The Raspberry Pi Debug Probe (https://www.raspberrypi.com/products/debug-probe/) could be used
|
||||
//! with its UART port.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
@ -1,3 +1,9 @@
|
||||
//! This example shows how to use UART (Universal asynchronous receiver-transmitter) in the RP2040 chip.
|
||||
//!
|
||||
//! No specific hardware is specified in this example. If you connect pin 0 and 1 you should get the same data back.
|
||||
//! The Raspberry Pi Debug Probe (https://www.raspberrypi.com/products/debug-probe/) could be used
|
||||
//! with its UART port.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
@ -1,5 +1,9 @@
|
||||
//! test TX-only and RX-only UARTs. You need to connect GPIO0 to GPIO5 for
|
||||
//! This example shows how to use UART (Universal asynchronous receiver-transmitter) in the RP2040 chip.
|
||||
//!
|
||||
//! Test TX-only and RX-only on two different UARTs. You need to connect GPIO0 to GPIO5 for
|
||||
//! this to work
|
||||
//! The Raspberry Pi Debug Probe (https://www.raspberrypi.com/products/debug-probe/) could be used
|
||||
//! with its UART port.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
@ -1,3 +1,7 @@
|
||||
//! This example shows how to use USB (Universal Serial Bus) in the RP2040 chip.
|
||||
//!
|
||||
//! This is a CDC-NCM class implementation, aka Ethernet over USB.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
188
examples/rp/src/bin/usb_hid_keyboard.rs
Normal file
188
examples/rp/src/bin/usb_hid_keyboard.rs
Normal file
@ -0,0 +1,188 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use core::sync::atomic::{AtomicBool, Ordering};
|
||||
|
||||
use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_futures::join::join;
|
||||
use embassy_rp::bind_interrupts;
|
||||
use embassy_rp::gpio::{Input, Pull};
|
||||
use embassy_rp::peripherals::USB;
|
||||
use embassy_rp::usb::{Driver, InterruptHandler};
|
||||
use embassy_usb::class::hid::{HidReaderWriter, ReportId, RequestHandler, State};
|
||||
use embassy_usb::control::OutResponse;
|
||||
use embassy_usb::{Builder, Config, Handler};
|
||||
use usbd_hid::descriptor::{KeyboardReport, SerializedDescriptor};
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
bind_interrupts!(struct Irqs {
|
||||
USBCTRL_IRQ => InterruptHandler<USB>;
|
||||
});
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) {
|
||||
let p = embassy_rp::init(Default::default());
|
||||
// Create the driver, from the HAL.
|
||||
let driver = Driver::new(p.USB, Irqs);
|
||||
|
||||
// Create embassy-usb Config
|
||||
let mut config = Config::new(0xc0de, 0xcafe);
|
||||
config.manufacturer = Some("Embassy");
|
||||
config.product = Some("HID keyboard example");
|
||||
config.serial_number = Some("12345678");
|
||||
config.max_power = 100;
|
||||
config.max_packet_size_0 = 64;
|
||||
|
||||
// Create embassy-usb DeviceBuilder using the driver and config.
|
||||
// It needs some buffers for building the descriptors.
|
||||
let mut device_descriptor = [0; 256];
|
||||
let mut config_descriptor = [0; 256];
|
||||
let mut bos_descriptor = [0; 256];
|
||||
// You can also add a Microsoft OS descriptor.
|
||||
// let mut msos_descriptor = [0; 256];
|
||||
let mut control_buf = [0; 64];
|
||||
let request_handler = MyRequestHandler {};
|
||||
let mut device_handler = MyDeviceHandler::new();
|
||||
|
||||
let mut state = State::new();
|
||||
|
||||
let mut builder = Builder::new(
|
||||
driver,
|
||||
config,
|
||||
&mut device_descriptor,
|
||||
&mut config_descriptor,
|
||||
&mut bos_descriptor,
|
||||
// &mut msos_descriptor,
|
||||
&mut control_buf,
|
||||
);
|
||||
|
||||
builder.handler(&mut device_handler);
|
||||
|
||||
// Create classes on the builder.
|
||||
let config = embassy_usb::class::hid::Config {
|
||||
report_descriptor: KeyboardReport::desc(),
|
||||
request_handler: Some(&request_handler),
|
||||
poll_ms: 60,
|
||||
max_packet_size: 64,
|
||||
};
|
||||
let hid = HidReaderWriter::<_, 1, 8>::new(&mut builder, &mut state, config);
|
||||
|
||||
// Build the builder.
|
||||
let mut usb = builder.build();
|
||||
|
||||
// Run the USB device.
|
||||
let usb_fut = usb.run();
|
||||
|
||||
// Set up the signal pin that will be used to trigger the keyboard.
|
||||
let mut signal_pin = Input::new(p.PIN_16, Pull::None);
|
||||
|
||||
let (reader, mut writer) = hid.split();
|
||||
|
||||
// Do stuff with the class!
|
||||
let in_fut = async {
|
||||
loop {
|
||||
info!("Waiting for HIGH on pin 16");
|
||||
signal_pin.wait_for_high().await;
|
||||
info!("HIGH DETECTED");
|
||||
// Create a report with the A key pressed. (no shift modifier)
|
||||
let report = KeyboardReport {
|
||||
keycodes: [4, 0, 0, 0, 0, 0],
|
||||
leds: 0,
|
||||
modifier: 0,
|
||||
reserved: 0,
|
||||
};
|
||||
// Send the report.
|
||||
match writer.write_serialize(&report).await {
|
||||
Ok(()) => {}
|
||||
Err(e) => warn!("Failed to send report: {:?}", e),
|
||||
};
|
||||
signal_pin.wait_for_low().await;
|
||||
info!("LOW DETECTED");
|
||||
let report = KeyboardReport {
|
||||
keycodes: [0, 0, 0, 0, 0, 0],
|
||||
leds: 0,
|
||||
modifier: 0,
|
||||
reserved: 0,
|
||||
};
|
||||
match writer.write_serialize(&report).await {
|
||||
Ok(()) => {}
|
||||
Err(e) => warn!("Failed to send report: {:?}", e),
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
let out_fut = async {
|
||||
reader.run(false, &request_handler).await;
|
||||
};
|
||||
|
||||
// Run everything concurrently.
|
||||
// If we had made everything `'static` above instead, we could do this using separate tasks instead.
|
||||
join(usb_fut, join(in_fut, out_fut)).await;
|
||||
}
|
||||
|
||||
struct MyRequestHandler {}
|
||||
|
||||
impl RequestHandler for MyRequestHandler {
|
||||
fn get_report(&self, id: ReportId, _buf: &mut [u8]) -> Option<usize> {
|
||||
info!("Get report for {:?}", id);
|
||||
None
|
||||
}
|
||||
|
||||
fn set_report(&self, id: ReportId, data: &[u8]) -> OutResponse {
|
||||
info!("Set report for {:?}: {=[u8]}", id, data);
|
||||
OutResponse::Accepted
|
||||
}
|
||||
|
||||
fn set_idle_ms(&self, id: Option<ReportId>, dur: u32) {
|
||||
info!("Set idle rate for {:?} to {:?}", id, dur);
|
||||
}
|
||||
|
||||
fn get_idle_ms(&self, id: Option<ReportId>) -> Option<u32> {
|
||||
info!("Get idle rate for {:?}", id);
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
struct MyDeviceHandler {
|
||||
configured: AtomicBool,
|
||||
}
|
||||
|
||||
impl MyDeviceHandler {
|
||||
fn new() -> Self {
|
||||
MyDeviceHandler {
|
||||
configured: AtomicBool::new(false),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Handler for MyDeviceHandler {
|
||||
fn enabled(&mut self, enabled: bool) {
|
||||
self.configured.store(false, Ordering::Relaxed);
|
||||
if enabled {
|
||||
info!("Device enabled");
|
||||
} else {
|
||||
info!("Device disabled");
|
||||
}
|
||||
}
|
||||
|
||||
fn reset(&mut self) {
|
||||
self.configured.store(false, Ordering::Relaxed);
|
||||
info!("Bus reset, the Vbus current limit is 100mA");
|
||||
}
|
||||
|
||||
fn addressed(&mut self, addr: u8) {
|
||||
self.configured.store(false, Ordering::Relaxed);
|
||||
info!("USB address set to: {}", addr);
|
||||
}
|
||||
|
||||
fn configured(&mut self, configured: bool) {
|
||||
self.configured.store(configured, Ordering::Relaxed);
|
||||
if configured {
|
||||
info!("Device configured, it may now draw up to the configured current limit from Vbus.")
|
||||
} else {
|
||||
info!("Device is no longer configured, the Vbus current limit is 100mA.");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,3 +1,7 @@
|
||||
//! This example shows how to use USB (Universal Serial Bus) in the RP2040 chip.
|
||||
//!
|
||||
//! This creates the possibility to send log::info/warn/error/debug! to USB serial port.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
@ -1,3 +1,7 @@
|
||||
//! This example shows how to use USB (Universal Serial Bus) in the RP2040 chip.
|
||||
//!
|
||||
//! This creates a USB serial port that echos.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
@ -1,3 +1,7 @@
|
||||
//! This example shows how to use Watchdog in the RP2040 chip.
|
||||
//!
|
||||
//! It does not work with the RP Pico W board. See wifi_blinky.rs or connect external LED and resistor.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
@ -1,3 +1,6 @@
|
||||
//! This example uses the RP Pico W board Wifi chip (cyw43).
|
||||
//! Creates an Access point Wifi network and creates a TCP endpoint on port 1234.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
@ -11,14 +14,19 @@ use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_net::tcp::TcpSocket;
|
||||
use embassy_net::{Config, Stack, StackResources};
|
||||
use embassy_rp::bind_interrupts;
|
||||
use embassy_rp::gpio::{Level, Output};
|
||||
use embassy_rp::peripherals::{DMA_CH0, PIN_23, PIN_25, PIO0};
|
||||
use embassy_rp::pio::Pio;
|
||||
use embassy_rp::pio::{InterruptHandler, Pio};
|
||||
use embassy_time::Duration;
|
||||
use embedded_io::asynch::Write;
|
||||
use static_cell::make_static;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
bind_interrupts!(struct Irqs {
|
||||
PIO0_IRQ_0 => InterruptHandler<PIO0>;
|
||||
});
|
||||
|
||||
#[embassy_executor::task]
|
||||
async fn wifi_task(
|
||||
runner: cyw43::Runner<'static, Output<'static, PIN_23>, PioSpi<'static, PIN_25, PIO0, 0, DMA_CH0>>,
|
||||
@ -49,7 +57,7 @@ async fn main(spawner: Spawner) {
|
||||
|
||||
let pwr = Output::new(p.PIN_23, Level::Low);
|
||||
let cs = Output::new(p.PIN_25, Level::High);
|
||||
let mut pio = Pio::new(p.PIO0);
|
||||
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 state = make_static!(cyw43::State::new());
|
||||
|
@ -1,3 +1,7 @@
|
||||
//! This example test the RP Pico W on board LED.
|
||||
//!
|
||||
//! It does not work with the RP Pico board. See blinky.rs.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
@ -5,13 +9,18 @@
|
||||
use cyw43_pio::PioSpi;
|
||||
use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_rp::bind_interrupts;
|
||||
use embassy_rp::gpio::{Level, Output};
|
||||
use embassy_rp::peripherals::{DMA_CH0, PIN_23, PIN_25, PIO0};
|
||||
use embassy_rp::pio::Pio;
|
||||
use embassy_rp::pio::{InterruptHandler, Pio};
|
||||
use embassy_time::{Duration, Timer};
|
||||
use static_cell::make_static;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
bind_interrupts!(struct Irqs {
|
||||
PIO0_IRQ_0 => InterruptHandler<PIO0>;
|
||||
});
|
||||
|
||||
#[embassy_executor::task]
|
||||
async fn wifi_task(
|
||||
runner: cyw43::Runner<'static, Output<'static, PIN_23>, PioSpi<'static, PIN_25, PIO0, 0, DMA_CH0>>,
|
||||
@ -34,7 +43,7 @@ async fn main(spawner: Spawner) {
|
||||
|
||||
let pwr = Output::new(p.PIN_23, Level::Low);
|
||||
let cs = Output::new(p.PIN_25, Level::High);
|
||||
let mut pio = Pio::new(p.PIO0);
|
||||
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 state = make_static!(cyw43::State::new());
|
||||
|
@ -1,3 +1,6 @@
|
||||
//! This example uses the RP Pico W board Wifi chip (cyw43).
|
||||
//! Scans Wifi for ssid names.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
@ -10,12 +13,17 @@ use cyw43_pio::PioSpi;
|
||||
use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_net::Stack;
|
||||
use embassy_rp::bind_interrupts;
|
||||
use embassy_rp::gpio::{Level, Output};
|
||||
use embassy_rp::peripherals::{DMA_CH0, PIN_23, PIN_25, PIO0};
|
||||
use embassy_rp::pio::Pio;
|
||||
use embassy_rp::pio::{InterruptHandler, Pio};
|
||||
use static_cell::make_static;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
bind_interrupts!(struct Irqs {
|
||||
PIO0_IRQ_0 => InterruptHandler<PIO0>;
|
||||
});
|
||||
|
||||
#[embassy_executor::task]
|
||||
async fn wifi_task(
|
||||
runner: cyw43::Runner<'static, Output<'static, PIN_23>, PioSpi<'static, PIN_25, PIO0, 0, DMA_CH0>>,
|
||||
@ -46,7 +54,7 @@ async fn main(spawner: Spawner) {
|
||||
|
||||
let pwr = Output::new(p.PIN_23, Level::Low);
|
||||
let cs = Output::new(p.PIN_25, Level::High);
|
||||
let mut pio = Pio::new(p.PIO0);
|
||||
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 state = make_static!(cyw43::State::new());
|
||||
|
@ -1,3 +1,6 @@
|
||||
//! This example uses the RP Pico W board Wifi chip (cyw43).
|
||||
//! Connects to specified Wifi network and creates a TCP endpoint on port 1234.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
@ -11,14 +14,22 @@ use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_net::tcp::TcpSocket;
|
||||
use embassy_net::{Config, Stack, StackResources};
|
||||
use embassy_rp::bind_interrupts;
|
||||
use embassy_rp::gpio::{Level, Output};
|
||||
use embassy_rp::peripherals::{DMA_CH0, PIN_23, PIN_25, PIO0};
|
||||
use embassy_rp::pio::Pio;
|
||||
use embassy_rp::pio::{InterruptHandler, Pio};
|
||||
use embassy_time::Duration;
|
||||
use embedded_io::asynch::Write;
|
||||
use static_cell::make_static;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
bind_interrupts!(struct Irqs {
|
||||
PIO0_IRQ_0 => InterruptHandler<PIO0>;
|
||||
});
|
||||
|
||||
const WIFI_NETWORK: &str = "EmbassyTest";
|
||||
const WIFI_PASSWORD: &str = "V8YxhKt5CdIAJFud";
|
||||
|
||||
#[embassy_executor::task]
|
||||
async fn wifi_task(
|
||||
runner: cyw43::Runner<'static, Output<'static, PIN_23>, PioSpi<'static, PIN_25, PIO0, 0, DMA_CH0>>,
|
||||
@ -49,7 +60,7 @@ async fn main(spawner: Spawner) {
|
||||
|
||||
let pwr = Output::new(p.PIN_23, Level::Low);
|
||||
let cs = Output::new(p.PIN_25, Level::High);
|
||||
let mut pio = Pio::new(p.PIO0);
|
||||
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 state = make_static!(cyw43::State::new());
|
||||
@ -82,8 +93,8 @@ async fn main(spawner: Spawner) {
|
||||
unwrap!(spawner.spawn(net_task(stack)));
|
||||
|
||||
loop {
|
||||
//control.join_open(env!("WIFI_NETWORK")).await;
|
||||
match control.join_wpa2(env!("WIFI_NETWORK"), env!("WIFI_PASSWORD")).await {
|
||||
//control.join_open(WIFI_NETWORK).await;
|
||||
match control.join_wpa2(WIFI_NETWORK, WIFI_PASSWORD).await {
|
||||
Ok(_) => break,
|
||||
Err(err) => {
|
||||
info!("join failed with status={}", err.status);
|
||||
|
@ -7,7 +7,7 @@ license = "MIT OR Apache-2.0"
|
||||
[dependencies]
|
||||
embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["log"] }
|
||||
embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["arch-std", "executor-thread", "log", "nightly", "integrated-timers"] }
|
||||
embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["log", "std", "nightly"] }
|
||||
embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["log", "std", "nightly"] }
|
||||
embassy-net = { version = "0.1.0", path = "../../embassy-net", features=[ "std", "nightly", "log", "medium-ethernet", "tcp", "udp", "dns", "dhcpv4", "unstable-traits", "proto-ipv6"] }
|
||||
embassy-net-driver = { version = "0.1.0", path = "../../embassy-net-driver" }
|
||||
embedded-io = { version = "0.4.0", features = ["async", "std", "futures"] }
|
||||
|
@ -7,7 +7,7 @@ license = "MIT OR Apache-2.0"
|
||||
[dependencies]
|
||||
embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
|
||||
embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
|
||||
embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
|
||||
embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "time-driver-any", "stm32c031c6", "memory-x", "unstable-pac", "exti"] }
|
||||
|
||||
defmt = "0.3"
|
||||
|
@ -14,6 +14,6 @@ defmt-rtt = "0.4"
|
||||
panic-probe = "0.3"
|
||||
embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
|
||||
embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] }
|
||||
embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
|
||||
embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "memory-x", "stm32f091rc", "time-driver-any", "exti", "unstable-pac"] }
|
||||
static_cell = { version = "1.1", features = ["nightly"]}
|
||||
|
@ -7,7 +7,7 @@ license = "MIT OR Apache-2.0"
|
||||
[dependencies]
|
||||
embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
|
||||
embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
|
||||
embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
|
||||
embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f103c8", "unstable-pac", "memory-x", "time-driver-any", "unstable-traits" ] }
|
||||
embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] }
|
||||
embassy-futures = { version = "0.1.0", path = "../../embassy-futures" }
|
||||
|
@ -7,7 +7,7 @@ license = "MIT OR Apache-2.0"
|
||||
[dependencies]
|
||||
embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
|
||||
embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
|
||||
embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
|
||||
embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f207zg", "unstable-pac", "memory-x", "time-driver-any", "exti"] }
|
||||
|
||||
defmt = "0.3"
|
||||
|
@ -7,7 +7,7 @@ license = "MIT OR Apache-2.0"
|
||||
[dependencies]
|
||||
embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
|
||||
embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] }
|
||||
embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
|
||||
embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f303ze", "unstable-pac", "memory-x", "time-driver-any", "exti"] }
|
||||
embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] }
|
||||
embassy-futures = { version = "0.1.0", path = "../../embassy-futures" }
|
||||
|
@ -7,7 +7,7 @@ license = "MIT OR Apache-2.0"
|
||||
[dependencies]
|
||||
embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
|
||||
embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers", "arch-cortex-m", "executor-thread", "executor-interrupt"] }
|
||||
embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "tick-hz-32_768"] }
|
||||
embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "tick-hz-32_768"] }
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "unstable-traits", "defmt", "stm32f429zi", "unstable-pac", "memory-x", "time-driver-any", "exti", "embedded-sdmmc", "chrono"] }
|
||||
embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] }
|
||||
embassy-net = { version = "0.1.0", path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet", "nightly"] }
|
||||
|
@ -2,8 +2,8 @@
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use cortex_m_rt::entry;
|
||||
use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_stm32::bind_interrupts;
|
||||
use embassy_stm32::can::bxcan::filter::Mask32;
|
||||
use embassy_stm32::can::bxcan::{Fifo, Frame, StandardId};
|
||||
@ -19,8 +19,8 @@ bind_interrupts!(struct Irqs {
|
||||
CAN1_TX => TxInterruptHandler<CAN1>;
|
||||
});
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) {
|
||||
info!("Hello World!");
|
||||
|
||||
let mut p = embassy_stm32::init(Default::default());
|
||||
@ -34,9 +34,12 @@ fn main() -> ! {
|
||||
|
||||
let mut can = Can::new(p.CAN1, p.PA11, p.PA12, Irqs);
|
||||
|
||||
can.modify_filters().enable_bank(0, Fifo::Fifo0, Mask32::accept_all());
|
||||
can.as_mut()
|
||||
.modify_filters()
|
||||
.enable_bank(0, Fifo::Fifo0, Mask32::accept_all());
|
||||
|
||||
can.modify_config()
|
||||
can.as_mut()
|
||||
.modify_config()
|
||||
.set_bit_timing(0x001c0003) // http://www.bittiming.can-wiki.info/
|
||||
.set_loopback(true) // Receive own frames
|
||||
.set_silent(true)
|
||||
@ -45,9 +48,8 @@ fn main() -> ! {
|
||||
let mut i: u8 = 0;
|
||||
loop {
|
||||
let tx_frame = Frame::new_data(unwrap!(StandardId::new(i as _)), [i]);
|
||||
unwrap!(nb::block!(can.transmit(&tx_frame)));
|
||||
while !can.is_transmitter_idle() {}
|
||||
let rx_frame = unwrap!(nb::block!(can.receive()));
|
||||
can.write(&tx_frame).await;
|
||||
let (_, rx_frame) = can.read().await.unwrap();
|
||||
info!("loopback frame {=u8}", unwrap!(rx_frame.data())[0]);
|
||||
i += 1;
|
||||
}
|
||||
|
111
examples/stm32f4/src/bin/eth.rs
Normal file
111
examples/stm32f4/src/bin/eth.rs
Normal file
@ -0,0 +1,111 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_net::tcp::TcpSocket;
|
||||
use embassy_net::{Ipv4Address, Stack, StackResources};
|
||||
use embassy_stm32::eth::generic_smi::GenericSMI;
|
||||
use embassy_stm32::eth::{Ethernet, PacketQueue};
|
||||
use embassy_stm32::peripherals::ETH;
|
||||
use embassy_stm32::rng::Rng;
|
||||
use embassy_stm32::time::mhz;
|
||||
use embassy_stm32::{bind_interrupts, eth, Config};
|
||||
use embassy_time::{Duration, Timer};
|
||||
use embedded_io::asynch::Write;
|
||||
use static_cell::make_static;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
bind_interrupts!(struct Irqs {
|
||||
ETH => eth::InterruptHandler;
|
||||
});
|
||||
|
||||
type Device = Ethernet<'static, ETH, GenericSMI>;
|
||||
|
||||
#[embassy_executor::task]
|
||||
async fn net_task(stack: &'static Stack<Device>) -> ! {
|
||||
stack.run().await
|
||||
}
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(spawner: Spawner) -> ! {
|
||||
let mut config = Config::default();
|
||||
config.rcc.sys_ck = Some(mhz(200));
|
||||
let p = embassy_stm32::init(config);
|
||||
|
||||
info!("Hello World!");
|
||||
|
||||
// Generate random seed.
|
||||
let mut rng = Rng::new(p.RNG);
|
||||
let mut seed = [0; 8];
|
||||
let _ = rng.async_fill_bytes(&mut seed).await;
|
||||
let seed = u64::from_le_bytes(seed);
|
||||
|
||||
let mac_addr = [0x00, 0x00, 0xDE, 0xAD, 0xBE, 0xEF];
|
||||
|
||||
let device = Ethernet::new(
|
||||
make_static!(PacketQueue::<16, 16>::new()),
|
||||
p.ETH,
|
||||
Irqs,
|
||||
p.PA1,
|
||||
p.PA2,
|
||||
p.PC1,
|
||||
p.PA7,
|
||||
p.PC4,
|
||||
p.PC5,
|
||||
p.PG13,
|
||||
p.PB13,
|
||||
p.PG11,
|
||||
GenericSMI::new(),
|
||||
mac_addr,
|
||||
0,
|
||||
);
|
||||
|
||||
let config = embassy_net::Config::dhcpv4(Default::default());
|
||||
//let config = embassy_net::Config::ipv4_static(embassy_net::StaticConfigV4 {
|
||||
// address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24),
|
||||
// dns_servers: Vec::new(),
|
||||
// gateway: Some(Ipv4Address::new(10, 42, 0, 1)),
|
||||
//});
|
||||
|
||||
// Init network stack
|
||||
let stack = &*make_static!(Stack::new(
|
||||
device,
|
||||
config,
|
||||
make_static!(StackResources::<2>::new()),
|
||||
seed
|
||||
));
|
||||
|
||||
// Launch network task
|
||||
unwrap!(spawner.spawn(net_task(&stack)));
|
||||
|
||||
info!("Network task initialized");
|
||||
|
||||
// Then we can use it!
|
||||
let mut rx_buffer = [0; 4096];
|
||||
let mut tx_buffer = [0; 4096];
|
||||
|
||||
loop {
|
||||
let mut socket = TcpSocket::new(&stack, &mut rx_buffer, &mut tx_buffer);
|
||||
|
||||
socket.set_timeout(Some(embassy_time::Duration::from_secs(10)));
|
||||
|
||||
let remote_endpoint = (Ipv4Address::new(10, 42, 0, 1), 8000);
|
||||
info!("connecting...");
|
||||
let r = socket.connect(remote_endpoint).await;
|
||||
if let Err(e) = r {
|
||||
info!("connect error: {:?}", e);
|
||||
continue;
|
||||
}
|
||||
info!("connected!");
|
||||
let buf = [0; 1024];
|
||||
loop {
|
||||
let r = socket.write_all(&buf).await;
|
||||
if let Err(e) = r {
|
||||
info!("write error: {:?}", e);
|
||||
continue;
|
||||
}
|
||||
Timer::after(Duration::from_secs(1)).await;
|
||||
}
|
||||
}
|
||||
}
|
@ -7,7 +7,7 @@ license = "MIT OR Apache-2.0"
|
||||
[dependencies]
|
||||
embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
|
||||
embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
|
||||
embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
|
||||
embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f767zi", "unstable-pac", "time-driver-any", "exti"] }
|
||||
embassy-net = { path = "../../embassy-net", features = ["defmt", "nightly", "tcp", "dhcpv4", "medium-ethernet"] }
|
||||
embedded-io = { version = "0.4.0", features = ["async"] }
|
||||
|
66
examples/stm32f7/src/bin/can.rs
Normal file
66
examples/stm32f7/src/bin/can.rs
Normal file
@ -0,0 +1,66 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_stm32::bind_interrupts;
|
||||
use embassy_stm32::can::bxcan::filter::Mask32;
|
||||
use embassy_stm32::can::bxcan::{Fifo, Frame, StandardId};
|
||||
use embassy_stm32::can::{
|
||||
Can, CanTx, Rx0InterruptHandler, Rx1InterruptHandler, SceInterruptHandler, TxInterruptHandler,
|
||||
};
|
||||
use embassy_stm32::gpio::{Input, Pull};
|
||||
use embassy_stm32::peripherals::CAN3;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
bind_interrupts!(struct Irqs {
|
||||
CAN3_RX0 => Rx0InterruptHandler<CAN3>;
|
||||
CAN3_RX1 => Rx1InterruptHandler<CAN3>;
|
||||
CAN3_SCE => SceInterruptHandler<CAN3>;
|
||||
CAN3_TX => TxInterruptHandler<CAN3>;
|
||||
});
|
||||
|
||||
#[embassy_executor::task]
|
||||
pub async fn send_can_message(tx: &'static mut CanTx<'static, 'static, CAN3>) {
|
||||
loop {
|
||||
let frame = Frame::new_data(unwrap!(StandardId::new(0 as _)), [0]);
|
||||
tx.write(&frame).await;
|
||||
embassy_time::Timer::after(embassy_time::Duration::from_secs(1)).await;
|
||||
}
|
||||
}
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(spawner: Spawner) {
|
||||
info!("Hello World!");
|
||||
|
||||
let mut p = embassy_stm32::init(Default::default());
|
||||
|
||||
// The next two lines are a workaround for testing without transceiver.
|
||||
// To synchronise to the bus the RX input needs to see a high level.
|
||||
// Use `mem::forget()` to release the borrow on the pin but keep the
|
||||
// pull-up resistor enabled.
|
||||
let rx_pin = Input::new(&mut p.PA15, Pull::Up);
|
||||
core::mem::forget(rx_pin);
|
||||
|
||||
let can: &'static mut Can<'static, CAN3> = static_cell::make_static!(Can::new(p.CAN3, p.PA8, p.PA15, Irqs));
|
||||
can.as_mut()
|
||||
.modify_filters()
|
||||
.enable_bank(0, Fifo::Fifo0, Mask32::accept_all());
|
||||
|
||||
can.as_mut()
|
||||
.modify_config()
|
||||
.set_bit_timing(0x001c0001) // http://www.bittiming.can-wiki.info/
|
||||
.set_loopback(true)
|
||||
.enable();
|
||||
|
||||
let (tx, mut rx) = can.split();
|
||||
|
||||
let tx: &'static mut CanTx<'static, 'static, CAN3> = static_cell::make_static!(tx);
|
||||
spawner.spawn(send_can_message(tx)).unwrap();
|
||||
|
||||
loop {
|
||||
let frame = rx.read().await.unwrap();
|
||||
println!("Received: {:?}", frame);
|
||||
}
|
||||
}
|
@ -57,7 +57,7 @@ async fn main(spawner: Spawner) -> ! {
|
||||
p.PG13,
|
||||
p.PB13,
|
||||
p.PG11,
|
||||
GenericSMI,
|
||||
GenericSMI::new(),
|
||||
mac_addr,
|
||||
0,
|
||||
);
|
||||
|
@ -7,7 +7,7 @@ license = "MIT OR Apache-2.0"
|
||||
[dependencies]
|
||||
embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
|
||||
embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
|
||||
embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
|
||||
embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "time-driver-any", "stm32g071rb", "memory-x", "unstable-pac", "exti"] }
|
||||
|
||||
defmt = "0.3"
|
||||
|
@ -7,7 +7,7 @@ license = "MIT OR Apache-2.0"
|
||||
[dependencies]
|
||||
embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
|
||||
embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
|
||||
embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
|
||||
embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "time-driver-any", "stm32g491re", "memory-x", "unstable-pac", "exti"] }
|
||||
embassy-hal-common = {version = "0.1.0", path = "../../embassy-hal-common" }
|
||||
embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] }
|
||||
|
@ -7,7 +7,7 @@ license = "MIT OR Apache-2.0"
|
||||
[dependencies]
|
||||
embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
|
||||
embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
|
||||
embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "tick-hz-32_768"] }
|
||||
embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "tick-hz-32_768"] }
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32h563zi", "time-driver-any", "exti", "unstable-pac", "unstable-traits"] }
|
||||
embassy-net = { path = "../../embassy-net", features = ["defmt", "nightly", "tcp", "dhcpv4", "medium-ethernet", "unstable-traits", "proto-ipv6"] }
|
||||
embedded-io = { version = "0.4.0", features = ["async"] }
|
||||
@ -19,8 +19,8 @@ defmt-rtt = "0.4"
|
||||
cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] }
|
||||
cortex-m-rt = "0.7.0"
|
||||
embedded-hal = "0.2.6"
|
||||
embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.10" }
|
||||
embedded-hal-async = { version = "=0.2.0-alpha.1" }
|
||||
embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.11" }
|
||||
embedded-hal-async = { version = "=0.2.0-alpha.2" }
|
||||
embedded-nal-async = "0.4.0"
|
||||
panic-probe = { version = "0.3", features = ["print-defmt"] }
|
||||
futures = { version = "0.3.17", default-features = false, features = ["async-await"] }
|
||||
|
@ -76,7 +76,7 @@ async fn main(spawner: Spawner) -> ! {
|
||||
p.PG13,
|
||||
p.PB15,
|
||||
p.PG11,
|
||||
GenericSMI,
|
||||
GenericSMI::new(),
|
||||
mac_addr,
|
||||
0,
|
||||
);
|
||||
|
@ -7,7 +7,7 @@ license = "MIT OR Apache-2.0"
|
||||
[dependencies]
|
||||
embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
|
||||
embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
|
||||
embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "tick-hz-32_768"] }
|
||||
embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "tick-hz-32_768"] }
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32h743bi", "time-driver-any", "exti", "unstable-pac", "unstable-traits"] }
|
||||
embassy-net = { path = "../../embassy-net", features = ["defmt", "nightly", "tcp", "dhcpv4", "medium-ethernet", "unstable-traits", "proto-ipv6"] }
|
||||
embedded-io = { version = "0.4.0", features = ["async"] }
|
||||
@ -19,8 +19,8 @@ defmt-rtt = "0.4"
|
||||
cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] }
|
||||
cortex-m-rt = "0.7.0"
|
||||
embedded-hal = "0.2.6"
|
||||
embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.10" }
|
||||
embedded-hal-async = { version = "=0.2.0-alpha.1" }
|
||||
embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.11" }
|
||||
embedded-hal-async = { version = "=0.2.0-alpha.2" }
|
||||
embedded-nal-async = "0.4.0"
|
||||
panic-probe = { version = "0.3", features = ["print-defmt"] }
|
||||
futures = { version = "0.3.17", default-features = false, features = ["async-await"] }
|
||||
|
@ -58,7 +58,7 @@ async fn main(spawner: Spawner) -> ! {
|
||||
p.PG13,
|
||||
p.PB13,
|
||||
p.PG11,
|
||||
GenericSMI,
|
||||
GenericSMI::new(),
|
||||
mac_addr,
|
||||
0,
|
||||
);
|
||||
|
@ -59,7 +59,7 @@ async fn main(spawner: Spawner) -> ! {
|
||||
p.PG13,
|
||||
p.PB13,
|
||||
p.PG11,
|
||||
GenericSMI,
|
||||
GenericSMI::new(),
|
||||
mac_addr,
|
||||
0,
|
||||
);
|
||||
|
@ -12,7 +12,7 @@ nightly = ["embassy-stm32/nightly", "embassy-time/nightly", "embassy-time/unstab
|
||||
[dependencies]
|
||||
embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
|
||||
embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
|
||||
embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
|
||||
embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32l072cz", "time-driver-any", "exti", "unstable-traits", "memory-x"] }
|
||||
embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["time", "defmt"], optional = true }
|
||||
lora-phy = { version = "1", optional = true }
|
||||
@ -32,3 +32,6 @@ futures = { version = "0.3.17", default-features = false, features = ["async-awa
|
||||
heapless = { version = "0.7.5", default-features = false }
|
||||
embedded-hal = "0.2.6"
|
||||
static_cell = "1.1"
|
||||
|
||||
[patch.crates-io]
|
||||
lora-phy = { git = "https://github.com/embassy-rs/lora-phy", rev = "ad289428fd44b02788e2fa2116445cc8f640a265" }
|
||||
|
@ -7,7 +7,7 @@ license = "MIT OR Apache-2.0"
|
||||
[dependencies]
|
||||
embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
|
||||
embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
|
||||
embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
|
||||
embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32l151cb-a", "time-driver-any", "memory-x"] }
|
||||
|
||||
defmt = "0.3"
|
||||
|
@ -7,9 +7,9 @@ license = "MIT OR Apache-2.0"
|
||||
[dependencies]
|
||||
embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
|
||||
embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
|
||||
embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
|
||||
embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
|
||||
embassy-embedded-hal = { version = "0.1.0", path = "../../embassy-embedded-hal" }
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "unstable-pac", "stm32l4s5vi", "time-driver-any", "exti", "unstable-traits"] }
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "unstable-pac", "stm32l4s5vi", "time-driver-any", "exti", "unstable-traits", "chrono"] }
|
||||
embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] }
|
||||
|
||||
defmt = "0.3"
|
||||
@ -18,10 +18,11 @@ defmt-rtt = "0.4"
|
||||
cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }
|
||||
cortex-m-rt = "0.7.0"
|
||||
embedded-hal = "0.2.6"
|
||||
embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.10" }
|
||||
embedded-hal-async = { version = "=0.2.0-alpha.1" }
|
||||
embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.11" }
|
||||
embedded-hal-async = { version = "=0.2.0-alpha.2" }
|
||||
panic-probe = { version = "0.3", features = ["print-defmt"] }
|
||||
futures = { version = "0.3.17", default-features = false, features = ["async-await"] }
|
||||
heapless = { version = "0.7.5", default-features = false }
|
||||
chrono = { version = "^0.4", default-features = false }
|
||||
|
||||
micromath = "2.0.0"
|
||||
|
49
examples/stm32l4/src/bin/rtc.rs
Normal file
49
examples/stm32l4/src/bin/rtc.rs
Normal file
@ -0,0 +1,49 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use chrono::{NaiveDate, NaiveDateTime};
|
||||
use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_stm32::rcc::{self, ClockSrc, PLLClkDiv, PLLMul, PLLSource, PLLSrcDiv};
|
||||
use embassy_stm32::rtc::{Rtc, RtcConfig};
|
||||
use embassy_stm32::time::Hertz;
|
||||
use embassy_stm32::Config;
|
||||
use embassy_time::{Duration, Timer};
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) {
|
||||
let p = {
|
||||
let mut config = Config::default();
|
||||
config.rcc.mux = ClockSrc::PLL(
|
||||
PLLSource::HSE(Hertz::mhz(8)),
|
||||
PLLClkDiv::Div2,
|
||||
PLLSrcDiv::Div1,
|
||||
PLLMul::Mul20,
|
||||
None,
|
||||
);
|
||||
config.rcc.rtc_mux = rcc::RtcClockSource::LSE32;
|
||||
embassy_stm32::init(config)
|
||||
};
|
||||
info!("Hello World!");
|
||||
|
||||
let now = NaiveDate::from_ymd_opt(2020, 5, 15)
|
||||
.unwrap()
|
||||
.and_hms_opt(10, 30, 15)
|
||||
.unwrap();
|
||||
|
||||
let mut rtc = Rtc::new(
|
||||
p.RTC,
|
||||
RtcConfig::default().clock_config(embassy_stm32::rtc::RtcClockSource::LSE),
|
||||
);
|
||||
info!("Got RTC! {:?}", now.timestamp());
|
||||
|
||||
rtc.set_datetime(now.into()).expect("datetime not set");
|
||||
|
||||
// In reality the delay would be much longer
|
||||
Timer::after(Duration::from_millis(20000)).await;
|
||||
|
||||
let then: NaiveDateTime = rtc.now().unwrap().into();
|
||||
info!("Got RTC! {:?}", then.timestamp());
|
||||
}
|
@ -7,7 +7,7 @@ license = "MIT OR Apache-2.0"
|
||||
[dependencies]
|
||||
embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
|
||||
embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
|
||||
embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
|
||||
embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "unstable-pac", "stm32l552ze", "time-driver-any", "exti", "unstable-traits", "memory-x"] }
|
||||
embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] }
|
||||
embassy-net = { version = "0.1.0", path = "../../embassy-net", features = ["defmt", "nightly", "tcp", "dhcpv4", "medium-ethernet"] }
|
||||
|
@ -7,7 +7,7 @@ license = "MIT OR Apache-2.0"
|
||||
[dependencies]
|
||||
embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
|
||||
embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
|
||||
embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
|
||||
embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "unstable-pac", "stm32u585ai", "time-driver-any", "memory-x" ] }
|
||||
embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] }
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
|
||||
# replace STM32WB55CCUx with your chip as listed in `probe-rs chip list`
|
||||
# runner = "probe-rs run --chip STM32WB55RGVx --speed 1000 --connect-under-reset"
|
||||
# runner = "probe-run --chip STM32WB55RGVx --speed 1000 --connect-under-reset"
|
||||
runner = "teleprobe local run --chip STM32WB55RG --elf"
|
||||
|
||||
[build]
|
||||
|
@ -7,9 +7,10 @@ license = "MIT OR Apache-2.0"
|
||||
[dependencies]
|
||||
embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
|
||||
embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
|
||||
embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
|
||||
embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32wb55rg", "time-driver-any", "memory-x", "exti"] }
|
||||
embassy-stm32-wpan = { version = "0.1.0", path = "../../embassy-stm32-wpan", features = ["defmt", "stm32wb55rg"] }
|
||||
embassy-net = { version = "0.1.0", path = "../../embassy-net", features = ["defmt", "udp", "medium-ieee802154", "nightly"], optional=true }
|
||||
|
||||
defmt = "0.3"
|
||||
defmt-rtt = "0.4"
|
||||
@ -20,11 +21,11 @@ embedded-hal = "0.2.6"
|
||||
panic-probe = { version = "0.3", features = ["print-defmt"] }
|
||||
futures = { version = "0.3.17", default-features = false, features = ["async-await"] }
|
||||
heapless = { version = "0.7.5", default-features = false }
|
||||
|
||||
static_cell = { version = "1.1", features = ["nightly"]}
|
||||
|
||||
[features]
|
||||
default = ["ble"]
|
||||
mac = ["embassy-stm32-wpan/mac"]
|
||||
default = ["ble", "mac"]
|
||||
mac = ["embassy-stm32-wpan/mac", "dep:embassy-net"]
|
||||
ble = ["embassy-stm32-wpan/ble"]
|
||||
|
||||
[[bin]]
|
||||
@ -35,9 +36,18 @@ required-features = ["ble"]
|
||||
name = "tl_mbox_mac"
|
||||
required-features = ["mac"]
|
||||
|
||||
[[bin]]
|
||||
name = "mac_ffd"
|
||||
required-features = ["mac"]
|
||||
|
||||
[[bin]]
|
||||
name = "mac_ffd_net"
|
||||
required-features = ["mac"]
|
||||
|
||||
[[bin]]
|
||||
name = "eddystone_beacon"
|
||||
required-features = ["ble"]
|
||||
|
||||
[patch.crates-io]
|
||||
stm32wb-hci = { git = "https://github.com/OueslatiGhaith/stm32wb-hci", rev = "9f663be"}
|
||||
[[bin]]
|
||||
name = "gatt_server"
|
||||
required-features = ["ble"]
|
@ -63,7 +63,7 @@ async fn main(_spawner: Spawner) {
|
||||
let sys_event = mbox.sys_subsystem.read().await;
|
||||
info!("sys event: {}", sys_event.payload());
|
||||
|
||||
mbox.sys_subsystem.shci_c2_ble_init(Default::default()).await;
|
||||
let _ = mbox.sys_subsystem.shci_c2_ble_init(Default::default()).await;
|
||||
|
||||
info!("resetting BLE...");
|
||||
mbox.ble_subsystem.reset().await;
|
||||
|
397
examples/stm32wb/src/bin/gatt_server.rs
Normal file
397
examples/stm32wb/src/bin/gatt_server.rs
Normal file
@ -0,0 +1,397 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use core::time::Duration;
|
||||
|
||||
use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_stm32::bind_interrupts;
|
||||
use embassy_stm32::ipcc::{Config, ReceiveInterruptHandler, TransmitInterruptHandler};
|
||||
use embassy_stm32_wpan::hci::event::command::{CommandComplete, ReturnParameters};
|
||||
use embassy_stm32_wpan::hci::host::uart::{Packet, UartHci};
|
||||
use embassy_stm32_wpan::hci::host::{AdvertisingFilterPolicy, EncryptionKey, HostHci, OwnAddressType};
|
||||
use embassy_stm32_wpan::hci::types::AdvertisingType;
|
||||
use embassy_stm32_wpan::hci::vendor::stm32wb::command::gap::{
|
||||
AddressType, AuthenticationRequirements, DiscoverableParameters, GapCommands, IoCapability, LocalName, Pin, Role,
|
||||
SecureConnectionSupport,
|
||||
};
|
||||
use embassy_stm32_wpan::hci::vendor::stm32wb::command::gatt::{
|
||||
AddCharacteristicParameters, AddServiceParameters, CharacteristicEvent, CharacteristicPermission,
|
||||
CharacteristicProperty, EncryptionKeySize, GattCommands, ServiceType, UpdateCharacteristicValueParameters, Uuid,
|
||||
WriteResponseParameters,
|
||||
};
|
||||
use embassy_stm32_wpan::hci::vendor::stm32wb::command::hal::{ConfigData, HalCommands, PowerLevel};
|
||||
use embassy_stm32_wpan::hci::vendor::stm32wb::event::{self, AttributeHandle, Stm32Wb5xEvent};
|
||||
use embassy_stm32_wpan::hci::{BdAddr, Event};
|
||||
use embassy_stm32_wpan::lhci::LhciC1DeviceInformationCcrp;
|
||||
use embassy_stm32_wpan::sub::ble::Ble;
|
||||
use embassy_stm32_wpan::TlMbox;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
bind_interrupts!(struct Irqs{
|
||||
IPCC_C1_RX => ReceiveInterruptHandler;
|
||||
IPCC_C1_TX => TransmitInterruptHandler;
|
||||
});
|
||||
|
||||
const BLE_GAP_DEVICE_NAME_LENGTH: u8 = 7;
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) {
|
||||
/*
|
||||
How to make this work:
|
||||
|
||||
- Obtain a NUCLEO-STM32WB55 from your preferred supplier.
|
||||
- Download and Install STM32CubeProgrammer.
|
||||
- Download stm32wb5x_FUS_fw.bin, stm32wb5x_BLE_Stack_full_fw.bin, and Release_Notes.html from
|
||||
gh:STMicroelectronics/STM32CubeWB@2234d97/Projects/STM32WB_Copro_Wireless_Binaries/STM32WB5x
|
||||
- Open STM32CubeProgrammer
|
||||
- On the right-hand pane, click "firmware upgrade" to upgrade the st-link firmware.
|
||||
- Once complete, click connect to connect to the device.
|
||||
- On the left hand pane, click the RSS signal icon to open "Firmware Upgrade Services".
|
||||
- In the Release_Notes.html, find the memory address that corresponds to your device for the stm32wb5x_FUS_fw.bin file
|
||||
- Select that file, the memory address, "verify download", and then "Firmware Upgrade".
|
||||
- Once complete, in the Release_Notes.html, find the memory address that corresponds to your device for the
|
||||
stm32wb5x_BLE_Stack_full_fw.bin file. It should not be the same memory address.
|
||||
- Select that file, the memory address, "verify download", and then "Firmware Upgrade".
|
||||
- Select "Start Wireless Stack".
|
||||
- Disconnect from the device.
|
||||
- In the examples folder for stm32wb, modify the memory.x file to match your target device.
|
||||
- Run this example.
|
||||
|
||||
Note: extended stack versions are not supported at this time. Do not attempt to install a stack with "extended" in the name.
|
||||
*/
|
||||
|
||||
let p = embassy_stm32::init(Default::default());
|
||||
info!("Hello World!");
|
||||
|
||||
let config = Config::default();
|
||||
let mut mbox = TlMbox::init(p.IPCC, Irqs, config);
|
||||
|
||||
let sys_event = mbox.sys_subsystem.read().await;
|
||||
info!("sys event: {}", sys_event.payload());
|
||||
|
||||
let _ = mbox.sys_subsystem.shci_c2_ble_init(Default::default()).await;
|
||||
|
||||
info!("resetting BLE...");
|
||||
mbox.ble_subsystem.reset().await;
|
||||
let response = mbox.ble_subsystem.read().await;
|
||||
defmt::debug!("{}", response);
|
||||
|
||||
info!("config public address...");
|
||||
mbox.ble_subsystem
|
||||
.write_config_data(&ConfigData::public_address(get_bd_addr()).build())
|
||||
.await;
|
||||
let response = mbox.ble_subsystem.read().await;
|
||||
defmt::debug!("{}", response);
|
||||
|
||||
info!("config random address...");
|
||||
mbox.ble_subsystem
|
||||
.write_config_data(&ConfigData::random_address(get_random_addr()).build())
|
||||
.await;
|
||||
let response = mbox.ble_subsystem.read().await;
|
||||
defmt::debug!("{}", response);
|
||||
|
||||
info!("config identity root...");
|
||||
mbox.ble_subsystem
|
||||
.write_config_data(&ConfigData::identity_root(&get_irk()).build())
|
||||
.await;
|
||||
let response = mbox.ble_subsystem.read().await;
|
||||
defmt::debug!("{}", response);
|
||||
|
||||
info!("config encryption root...");
|
||||
mbox.ble_subsystem
|
||||
.write_config_data(&ConfigData::encryption_root(&get_erk()).build())
|
||||
.await;
|
||||
let response = mbox.ble_subsystem.read().await;
|
||||
defmt::debug!("{}", response);
|
||||
|
||||
info!("config tx power level...");
|
||||
mbox.ble_subsystem.set_tx_power_level(PowerLevel::ZerodBm).await;
|
||||
let response = mbox.ble_subsystem.read().await;
|
||||
defmt::debug!("{}", response);
|
||||
|
||||
info!("GATT init...");
|
||||
mbox.ble_subsystem.init_gatt().await;
|
||||
let response = mbox.ble_subsystem.read().await;
|
||||
defmt::debug!("{}", response);
|
||||
|
||||
info!("GAP init...");
|
||||
mbox.ble_subsystem
|
||||
.init_gap(Role::PERIPHERAL, false, BLE_GAP_DEVICE_NAME_LENGTH)
|
||||
.await;
|
||||
let response = mbox.ble_subsystem.read().await;
|
||||
defmt::debug!("{}", response);
|
||||
|
||||
info!("set IO capabilities...");
|
||||
mbox.ble_subsystem.set_io_capability(IoCapability::DisplayConfirm).await;
|
||||
let response = mbox.ble_subsystem.read().await;
|
||||
defmt::debug!("{}", response);
|
||||
|
||||
info!("set authentication requirements...");
|
||||
mbox.ble_subsystem
|
||||
.set_authentication_requirement(&AuthenticationRequirements {
|
||||
bonding_required: false,
|
||||
keypress_notification_support: false,
|
||||
mitm_protection_required: false,
|
||||
encryption_key_size_range: (8, 16),
|
||||
fixed_pin: Pin::Requested,
|
||||
identity_address_type: AddressType::Public,
|
||||
secure_connection_support: SecureConnectionSupport::Optional,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
let response = mbox.ble_subsystem.read().await;
|
||||
defmt::debug!("{}", response);
|
||||
|
||||
info!("set scan response data...");
|
||||
mbox.ble_subsystem.le_set_scan_response_data(b"TXTX").await.unwrap();
|
||||
let response = mbox.ble_subsystem.read().await;
|
||||
defmt::debug!("{}", response);
|
||||
|
||||
info!("set scan response data...");
|
||||
mbox.ble_subsystem.le_set_scan_response_data(b"TXTX").await.unwrap();
|
||||
let response = mbox.ble_subsystem.read().await;
|
||||
defmt::debug!("{}", response);
|
||||
|
||||
defmt::info!("initializing services and characteristics...");
|
||||
let mut ble_context = init_gatt_services(&mut mbox.ble_subsystem).await.unwrap();
|
||||
defmt::info!("{}", ble_context);
|
||||
|
||||
let discovery_params = DiscoverableParameters {
|
||||
advertising_type: AdvertisingType::ConnectableUndirected,
|
||||
advertising_interval: Some((Duration::from_millis(100), Duration::from_millis(100))),
|
||||
address_type: OwnAddressType::Public,
|
||||
filter_policy: AdvertisingFilterPolicy::AllowConnectionAndScan,
|
||||
local_name: Some(LocalName::Complete(b"TXTX")),
|
||||
advertising_data: &[],
|
||||
conn_interval: (None, None),
|
||||
};
|
||||
|
||||
info!("set discoverable...");
|
||||
mbox.ble_subsystem.set_discoverable(&discovery_params).await.unwrap();
|
||||
let response = mbox.ble_subsystem.read().await;
|
||||
defmt::debug!("{}", response);
|
||||
|
||||
loop {
|
||||
let response = mbox.ble_subsystem.read().await;
|
||||
defmt::debug!("{}", response);
|
||||
|
||||
if let Ok(Packet::Event(event)) = response {
|
||||
match event {
|
||||
Event::LeConnectionComplete(_) => {
|
||||
defmt::info!("connected");
|
||||
}
|
||||
Event::DisconnectionComplete(_) => {
|
||||
defmt::info!("disconnected");
|
||||
ble_context.is_subscribed = false;
|
||||
mbox.ble_subsystem.set_discoverable(&discovery_params).await.unwrap();
|
||||
}
|
||||
Event::Vendor(vendor_event) => match vendor_event {
|
||||
Stm32Wb5xEvent::AttReadPermitRequest(read_req) => {
|
||||
defmt::info!("read request received {}, allowing", read_req);
|
||||
mbox.ble_subsystem.allow_read(read_req.conn_handle).await
|
||||
}
|
||||
Stm32Wb5xEvent::AttWritePermitRequest(write_req) => {
|
||||
defmt::info!("write request received {}, allowing", write_req);
|
||||
mbox.ble_subsystem
|
||||
.write_response(&WriteResponseParameters {
|
||||
conn_handle: write_req.conn_handle,
|
||||
attribute_handle: write_req.attribute_handle,
|
||||
status: Ok(()),
|
||||
value: write_req.value(),
|
||||
})
|
||||
.await
|
||||
.unwrap()
|
||||
}
|
||||
Stm32Wb5xEvent::GattAttributeModified(attribute) => {
|
||||
defmt::info!("{}", ble_context);
|
||||
if attribute.attr_handle.0 == ble_context.chars.notify.0 + 2 {
|
||||
if attribute.data()[0] == 0x01 {
|
||||
defmt::info!("subscribed");
|
||||
ble_context.is_subscribed = true;
|
||||
} else {
|
||||
defmt::info!("unsubscribed");
|
||||
ble_context.is_subscribed = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn get_bd_addr() -> BdAddr {
|
||||
let mut bytes = [0u8; 6];
|
||||
|
||||
let lhci_info = LhciC1DeviceInformationCcrp::new();
|
||||
bytes[0] = (lhci_info.uid64 & 0xff) as u8;
|
||||
bytes[1] = ((lhci_info.uid64 >> 8) & 0xff) as u8;
|
||||
bytes[2] = ((lhci_info.uid64 >> 16) & 0xff) as u8;
|
||||
bytes[3] = lhci_info.device_type_id;
|
||||
bytes[4] = (lhci_info.st_company_id & 0xff) as u8;
|
||||
bytes[5] = (lhci_info.st_company_id >> 8 & 0xff) as u8;
|
||||
|
||||
BdAddr(bytes)
|
||||
}
|
||||
|
||||
fn get_random_addr() -> BdAddr {
|
||||
let mut bytes = [0u8; 6];
|
||||
|
||||
let lhci_info = LhciC1DeviceInformationCcrp::new();
|
||||
bytes[0] = (lhci_info.uid64 & 0xff) as u8;
|
||||
bytes[1] = ((lhci_info.uid64 >> 8) & 0xff) as u8;
|
||||
bytes[2] = ((lhci_info.uid64 >> 16) & 0xff) as u8;
|
||||
bytes[3] = 0;
|
||||
bytes[4] = 0x6E;
|
||||
bytes[5] = 0xED;
|
||||
|
||||
BdAddr(bytes)
|
||||
}
|
||||
|
||||
const BLE_CFG_IRK: [u8; 16] = [
|
||||
0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
|
||||
];
|
||||
const BLE_CFG_ERK: [u8; 16] = [
|
||||
0xfe, 0xdc, 0xba, 0x09, 0x87, 0x65, 0x43, 0x21, 0xfe, 0xdc, 0xba, 0x09, 0x87, 0x65, 0x43, 0x21,
|
||||
];
|
||||
|
||||
fn get_irk() -> EncryptionKey {
|
||||
EncryptionKey(BLE_CFG_IRK)
|
||||
}
|
||||
|
||||
fn get_erk() -> EncryptionKey {
|
||||
EncryptionKey(BLE_CFG_ERK)
|
||||
}
|
||||
|
||||
#[derive(defmt::Format)]
|
||||
pub struct BleContext {
|
||||
pub service_handle: AttributeHandle,
|
||||
pub chars: CharHandles,
|
||||
pub is_subscribed: bool,
|
||||
}
|
||||
|
||||
#[derive(defmt::Format)]
|
||||
pub struct CharHandles {
|
||||
pub read: AttributeHandle,
|
||||
pub write: AttributeHandle,
|
||||
pub notify: AttributeHandle,
|
||||
}
|
||||
|
||||
pub async fn init_gatt_services(ble_subsystem: &mut Ble) -> Result<BleContext, ()> {
|
||||
let service_handle = gatt_add_service(ble_subsystem, Uuid::Uuid16(0x500)).await?;
|
||||
|
||||
let read = gatt_add_char(
|
||||
ble_subsystem,
|
||||
service_handle,
|
||||
Uuid::Uuid16(0x501),
|
||||
CharacteristicProperty::READ,
|
||||
Some(b"Hello from embassy!"),
|
||||
)
|
||||
.await?;
|
||||
|
||||
let write = gatt_add_char(
|
||||
ble_subsystem,
|
||||
service_handle,
|
||||
Uuid::Uuid16(0x502),
|
||||
CharacteristicProperty::WRITE_WITHOUT_RESPONSE | CharacteristicProperty::WRITE | CharacteristicProperty::READ,
|
||||
None,
|
||||
)
|
||||
.await?;
|
||||
|
||||
let notify = gatt_add_char(
|
||||
ble_subsystem,
|
||||
service_handle,
|
||||
Uuid::Uuid16(0x503),
|
||||
CharacteristicProperty::NOTIFY | CharacteristicProperty::READ,
|
||||
None,
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(BleContext {
|
||||
service_handle,
|
||||
is_subscribed: false,
|
||||
chars: CharHandles { read, write, notify },
|
||||
})
|
||||
}
|
||||
|
||||
async fn gatt_add_service(ble_subsystem: &mut Ble, uuid: Uuid) -> Result<AttributeHandle, ()> {
|
||||
ble_subsystem
|
||||
.add_service(&AddServiceParameters {
|
||||
uuid,
|
||||
service_type: ServiceType::Primary,
|
||||
max_attribute_records: 8,
|
||||
})
|
||||
.await;
|
||||
let response = ble_subsystem.read().await;
|
||||
defmt::debug!("{}", response);
|
||||
|
||||
if let Ok(Packet::Event(Event::CommandComplete(CommandComplete {
|
||||
return_params:
|
||||
ReturnParameters::Vendor(event::command::ReturnParameters::GattAddService(event::command::GattService {
|
||||
service_handle,
|
||||
..
|
||||
})),
|
||||
..
|
||||
}))) = response
|
||||
{
|
||||
Ok(service_handle)
|
||||
} else {
|
||||
Err(())
|
||||
}
|
||||
}
|
||||
|
||||
async fn gatt_add_char(
|
||||
ble_subsystem: &mut Ble,
|
||||
service_handle: AttributeHandle,
|
||||
characteristic_uuid: Uuid,
|
||||
characteristic_properties: CharacteristicProperty,
|
||||
default_value: Option<&[u8]>,
|
||||
) -> Result<AttributeHandle, ()> {
|
||||
ble_subsystem
|
||||
.add_characteristic(&AddCharacteristicParameters {
|
||||
service_handle,
|
||||
characteristic_uuid,
|
||||
characteristic_properties,
|
||||
characteristic_value_len: 32,
|
||||
security_permissions: CharacteristicPermission::empty(),
|
||||
gatt_event_mask: CharacteristicEvent::all(),
|
||||
encryption_key_size: EncryptionKeySize::with_value(7).unwrap(),
|
||||
is_variable: true,
|
||||
})
|
||||
.await;
|
||||
let response = ble_subsystem.read().await;
|
||||
defmt::debug!("{}", response);
|
||||
|
||||
if let Ok(Packet::Event(Event::CommandComplete(CommandComplete {
|
||||
return_params:
|
||||
ReturnParameters::Vendor(event::command::ReturnParameters::GattAddCharacteristic(
|
||||
event::command::GattCharacteristic {
|
||||
characteristic_handle, ..
|
||||
},
|
||||
)),
|
||||
..
|
||||
}))) = response
|
||||
{
|
||||
if let Some(value) = default_value {
|
||||
ble_subsystem
|
||||
.update_characteristic_value(&UpdateCharacteristicValueParameters {
|
||||
service_handle,
|
||||
characteristic_handle,
|
||||
offset: 0,
|
||||
value,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let response = ble_subsystem.read().await;
|
||||
defmt::debug!("{}", response);
|
||||
}
|
||||
Ok(characteristic_handle)
|
||||
} else {
|
||||
Err(())
|
||||
}
|
||||
}
|
185
examples/stm32wb/src/bin/mac_ffd.rs
Normal file
185
examples/stm32wb/src/bin/mac_ffd.rs
Normal file
@ -0,0 +1,185 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_stm32::bind_interrupts;
|
||||
use embassy_stm32::ipcc::{Config, ReceiveInterruptHandler, TransmitInterruptHandler};
|
||||
use embassy_stm32_wpan::mac::commands::{AssociateResponse, ResetRequest, SetRequest, StartRequest};
|
||||
use embassy_stm32_wpan::mac::event::MacEvent;
|
||||
use embassy_stm32_wpan::mac::typedefs::{MacChannel, MacStatus, PanId, PibId, SecurityLevel};
|
||||
use embassy_stm32_wpan::sub::mm;
|
||||
use embassy_stm32_wpan::TlMbox;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
bind_interrupts!(struct Irqs{
|
||||
IPCC_C1_RX => ReceiveInterruptHandler;
|
||||
IPCC_C1_TX => TransmitInterruptHandler;
|
||||
});
|
||||
|
||||
#[embassy_executor::task]
|
||||
async fn run_mm_queue(memory_manager: mm::MemoryManager) {
|
||||
memory_manager.run_queue().await;
|
||||
}
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(spawner: Spawner) {
|
||||
/*
|
||||
How to make this work:
|
||||
|
||||
- Obtain a NUCLEO-STM32WB55 from your preferred supplier.
|
||||
- Download and Install STM32CubeProgrammer.
|
||||
- Download stm32wb5x_FUS_fw.bin, stm32wb5x_BLE_Stack_full_fw.bin, and Release_Notes.html from
|
||||
gh:STMicroelectronics/STM32CubeWB@2234d97/Projects/STM32WB_Copro_Wireless_Binaries/STM32WB5x
|
||||
- Open STM32CubeProgrammer
|
||||
- On the right-hand pane, click "firmware upgrade" to upgrade the st-link firmware.
|
||||
- Once complete, click connect to connect to the device.
|
||||
- On the left hand pane, click the RSS signal icon to open "Firmware Upgrade Services".
|
||||
- In the Release_Notes.html, find the memory address that corresponds to your device for the stm32wb5x_FUS_fw.bin file
|
||||
- Select that file, the memory address, "verify download", and then "Firmware Upgrade".
|
||||
- Once complete, in the Release_Notes.html, find the memory address that corresponds to your device for the
|
||||
stm32wb5x_BLE_Stack_full_fw.bin file. It should not be the same memory address.
|
||||
- Select that file, the memory address, "verify download", and then "Firmware Upgrade".
|
||||
- Select "Start Wireless Stack".
|
||||
- Disconnect from the device.
|
||||
- In the examples folder for stm32wb, modify the memory.x file to match your target device.
|
||||
- Run this example.
|
||||
|
||||
Note: extended stack versions are not supported at this time. Do not attempt to install a stack with "extended" in the name.
|
||||
*/
|
||||
|
||||
let p = embassy_stm32::init(Default::default());
|
||||
info!("Hello World!");
|
||||
|
||||
let config = Config::default();
|
||||
let mbox = TlMbox::init(p.IPCC, Irqs, config);
|
||||
|
||||
spawner.spawn(run_mm_queue(mbox.mm_subsystem)).unwrap();
|
||||
|
||||
let sys_event = mbox.sys_subsystem.read().await;
|
||||
info!("sys event: {}", sys_event.payload());
|
||||
|
||||
core::mem::drop(sys_event);
|
||||
|
||||
let result = mbox.sys_subsystem.shci_c2_mac_802_15_4_init().await;
|
||||
info!("initialized mac: {}", result);
|
||||
|
||||
info!("resetting");
|
||||
mbox.mac_subsystem
|
||||
.send_command(&ResetRequest {
|
||||
set_default_pib: true,
|
||||
..Default::default()
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
defmt::info!("{:#x}", mbox.mac_subsystem.read().await.unwrap());
|
||||
|
||||
info!("setting extended address");
|
||||
let extended_address: u64 = 0xACDE480000000001;
|
||||
mbox.mac_subsystem
|
||||
.send_command(&SetRequest {
|
||||
pib_attribute_ptr: &extended_address as *const _ as *const u8,
|
||||
pib_attribute: PibId::ExtendedAddress,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
defmt::info!("{:#x}", mbox.mac_subsystem.read().await.unwrap());
|
||||
|
||||
info!("setting short address");
|
||||
let short_address: u16 = 0x1122;
|
||||
mbox.mac_subsystem
|
||||
.send_command(&SetRequest {
|
||||
pib_attribute_ptr: &short_address as *const _ as *const u8,
|
||||
pib_attribute: PibId::ShortAddress,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
defmt::info!("{:#x}", mbox.mac_subsystem.read().await.unwrap());
|
||||
|
||||
info!("setting association permit");
|
||||
let association_permit: bool = true;
|
||||
mbox.mac_subsystem
|
||||
.send_command(&SetRequest {
|
||||
pib_attribute_ptr: &association_permit as *const _ as *const u8,
|
||||
pib_attribute: PibId::AssociationPermit,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
defmt::info!("{:#x}", mbox.mac_subsystem.read().await.unwrap());
|
||||
|
||||
info!("setting TX power");
|
||||
let transmit_power: i8 = 2;
|
||||
mbox.mac_subsystem
|
||||
.send_command(&SetRequest {
|
||||
pib_attribute_ptr: &transmit_power as *const _ as *const u8,
|
||||
pib_attribute: PibId::TransmitPower,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
defmt::info!("{:#x}", mbox.mac_subsystem.read().await.unwrap());
|
||||
|
||||
info!("starting FFD device");
|
||||
mbox.mac_subsystem
|
||||
.send_command(&StartRequest {
|
||||
pan_id: PanId([0x1A, 0xAA]),
|
||||
channel_number: MacChannel::Channel16,
|
||||
beacon_order: 0x0F,
|
||||
superframe_order: 0x0F,
|
||||
pan_coordinator: true,
|
||||
battery_life_extension: false,
|
||||
..Default::default()
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
defmt::info!("{:#x}", mbox.mac_subsystem.read().await.unwrap());
|
||||
|
||||
info!("setting RX on when idle");
|
||||
let rx_on_while_idle: bool = true;
|
||||
mbox.mac_subsystem
|
||||
.send_command(&SetRequest {
|
||||
pib_attribute_ptr: &rx_on_while_idle as *const _ as *const u8,
|
||||
pib_attribute: PibId::RxOnWhenIdle,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
defmt::info!("{:#x}", mbox.mac_subsystem.read().await.unwrap());
|
||||
|
||||
loop {
|
||||
let evt = mbox.mac_subsystem.read().await;
|
||||
if let Ok(evt) = evt {
|
||||
defmt::info!("parsed mac event");
|
||||
defmt::info!("{:#x}", evt);
|
||||
|
||||
match evt {
|
||||
MacEvent::MlmeAssociateInd(association) => mbox
|
||||
.mac_subsystem
|
||||
.send_command(&AssociateResponse {
|
||||
device_address: association.device_address,
|
||||
assoc_short_address: [0x33, 0x44],
|
||||
status: MacStatus::Success,
|
||||
security_level: SecurityLevel::Unsecure,
|
||||
..Default::default()
|
||||
})
|
||||
.await
|
||||
.unwrap(),
|
||||
MacEvent::McpsDataInd(data_ind) => {
|
||||
let payload = data_ind.payload();
|
||||
let ref_payload = b"Hello from embassy!";
|
||||
info!("{}", payload);
|
||||
|
||||
if payload == ref_payload {
|
||||
info!("success");
|
||||
} else {
|
||||
info!("ref payload: {}", ref_payload);
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
defmt::info!("other mac event");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
defmt::info!("failed to parse mac event");
|
||||
}
|
||||
}
|
||||
}
|
170
examples/stm32wb/src/bin/mac_ffd_net.rs
Normal file
170
examples/stm32wb/src/bin/mac_ffd_net.rs
Normal file
@ -0,0 +1,170 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_stm32::bind_interrupts;
|
||||
use embassy_stm32::ipcc::{Config, ReceiveInterruptHandler, TransmitInterruptHandler};
|
||||
use embassy_stm32_wpan::mac::commands::{ResetRequest, SetRequest, StartRequest};
|
||||
use embassy_stm32_wpan::mac::typedefs::{MacChannel, PanId, PibId};
|
||||
use embassy_stm32_wpan::mac::{self, Runner};
|
||||
use embassy_stm32_wpan::sub::mm;
|
||||
use embassy_stm32_wpan::TlMbox;
|
||||
use static_cell::make_static;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
bind_interrupts!(struct Irqs{
|
||||
IPCC_C1_RX => ReceiveInterruptHandler;
|
||||
IPCC_C1_TX => TransmitInterruptHandler;
|
||||
});
|
||||
|
||||
#[embassy_executor::task]
|
||||
async fn run_mm_queue(memory_manager: mm::MemoryManager) {
|
||||
memory_manager.run_queue().await;
|
||||
}
|
||||
|
||||
#[embassy_executor::task]
|
||||
async fn run_mac(runner: &'static Runner<'static>) {
|
||||
runner.run().await;
|
||||
}
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(spawner: Spawner) {
|
||||
/*
|
||||
How to make this work:
|
||||
|
||||
- Obtain a NUCLEO-STM32WB55 from your preferred supplier.
|
||||
- Download and Install STM32CubeProgrammer.
|
||||
- Download stm32wb5x_FUS_fw.bin, stm32wb5x_BLE_Stack_full_fw.bin, and Release_Notes.html from
|
||||
gh:STMicroelectronics/STM32CubeWB@2234d97/Projects/STM32WB_Copro_Wireless_Binaries/STM32WB5x
|
||||
- Open STM32CubeProgrammer
|
||||
- On the right-hand pane, click "firmware upgrade" to upgrade the st-link firmware.
|
||||
- Once complete, click connect to connect to the device.
|
||||
- On the left hand pane, click the RSS signal icon to open "Firmware Upgrade Services".
|
||||
- In the Release_Notes.html, find the memory address that corresponds to your device for the stm32wb5x_FUS_fw.bin file
|
||||
- Select that file, the memory address, "verify download", and then "Firmware Upgrade".
|
||||
- Once complete, in the Release_Notes.html, find the memory address that corresponds to your device for the
|
||||
stm32wb5x_BLE_Stack_full_fw.bin file. It should not be the same memory address.
|
||||
- Select that file, the memory address, "verify download", and then "Firmware Upgrade".
|
||||
- Select "Start Wireless Stack".
|
||||
- Disconnect from the device.
|
||||
- In the examples folder for stm32wb, modify the memory.x file to match your target device.
|
||||
- Run this example.
|
||||
|
||||
Note: extended stack versions are not supported at this time. Do not attempt to install a stack with "extended" in the name.
|
||||
*/
|
||||
|
||||
let p = embassy_stm32::init(Default::default());
|
||||
info!("Hello World!");
|
||||
|
||||
let config = Config::default();
|
||||
let mbox = TlMbox::init(p.IPCC, Irqs, config);
|
||||
|
||||
spawner.spawn(run_mm_queue(mbox.mm_subsystem)).unwrap();
|
||||
|
||||
let sys_event = mbox.sys_subsystem.read().await;
|
||||
info!("sys event: {}", sys_event.payload());
|
||||
|
||||
core::mem::drop(sys_event);
|
||||
|
||||
let result = mbox.sys_subsystem.shci_c2_mac_802_15_4_init().await;
|
||||
info!("initialized mac: {}", result);
|
||||
|
||||
info!("resetting");
|
||||
mbox.mac_subsystem
|
||||
.send_command(&ResetRequest {
|
||||
set_default_pib: true,
|
||||
..Default::default()
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
defmt::info!("{:#x}", mbox.mac_subsystem.read().await.unwrap());
|
||||
|
||||
info!("setting extended address");
|
||||
let extended_address: u64 = 0xACDE480000000001;
|
||||
mbox.mac_subsystem
|
||||
.send_command(&SetRequest {
|
||||
pib_attribute_ptr: &extended_address as *const _ as *const u8,
|
||||
pib_attribute: PibId::ExtendedAddress,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
defmt::info!("{:#x}", mbox.mac_subsystem.read().await.unwrap());
|
||||
|
||||
info!("setting short address");
|
||||
let short_address: u16 = 0x1122;
|
||||
mbox.mac_subsystem
|
||||
.send_command(&SetRequest {
|
||||
pib_attribute_ptr: &short_address as *const _ as *const u8,
|
||||
pib_attribute: PibId::ShortAddress,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
defmt::info!("{:#x}", mbox.mac_subsystem.read().await.unwrap());
|
||||
|
||||
info!("setting association permit");
|
||||
let association_permit: bool = true;
|
||||
mbox.mac_subsystem
|
||||
.send_command(&SetRequest {
|
||||
pib_attribute_ptr: &association_permit as *const _ as *const u8,
|
||||
pib_attribute: PibId::AssociationPermit,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
defmt::info!("{:#x}", mbox.mac_subsystem.read().await.unwrap());
|
||||
|
||||
info!("setting TX power");
|
||||
let transmit_power: i8 = 2;
|
||||
mbox.mac_subsystem
|
||||
.send_command(&SetRequest {
|
||||
pib_attribute_ptr: &transmit_power as *const _ as *const u8,
|
||||
pib_attribute: PibId::TransmitPower,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
defmt::info!("{:#x}", mbox.mac_subsystem.read().await.unwrap());
|
||||
|
||||
info!("starting FFD device");
|
||||
mbox.mac_subsystem
|
||||
.send_command(&StartRequest {
|
||||
pan_id: PanId([0x1A, 0xAA]),
|
||||
channel_number: MacChannel::Channel16,
|
||||
beacon_order: 0x0F,
|
||||
superframe_order: 0x0F,
|
||||
pan_coordinator: true,
|
||||
battery_life_extension: false,
|
||||
..Default::default()
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
defmt::info!("{:#x}", mbox.mac_subsystem.read().await.unwrap());
|
||||
|
||||
info!("setting RX on when idle");
|
||||
let rx_on_while_idle: bool = true;
|
||||
mbox.mac_subsystem
|
||||
.send_command(&SetRequest {
|
||||
pib_attribute_ptr: &rx_on_while_idle as *const _ as *const u8,
|
||||
pib_attribute: PibId::RxOnWhenIdle,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
defmt::info!("{:#x}", mbox.mac_subsystem.read().await.unwrap());
|
||||
|
||||
let tx_queue = [
|
||||
make_static!([0u8; 127]),
|
||||
make_static!([0u8; 127]),
|
||||
make_static!([0u8; 127]),
|
||||
make_static!([0u8; 127]),
|
||||
make_static!([0u8; 127]),
|
||||
];
|
||||
|
||||
let runner = make_static!(Runner::new(mbox.mac_subsystem, tx_queue));
|
||||
|
||||
spawner.spawn(run_mac(runner)).unwrap();
|
||||
|
||||
let (driver, control) = mac::new(runner).await;
|
||||
|
||||
let _ = driver;
|
||||
let _ = control;
|
||||
}
|
182
examples/stm32wb/src/bin/mac_rfd.rs
Normal file
182
examples/stm32wb/src/bin/mac_rfd.rs
Normal file
@ -0,0 +1,182 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_stm32::bind_interrupts;
|
||||
use embassy_stm32::ipcc::{Config, ReceiveInterruptHandler, TransmitInterruptHandler};
|
||||
use embassy_stm32_wpan::mac::commands::{AssociateRequest, DataRequest, GetRequest, ResetRequest, SetRequest};
|
||||
use embassy_stm32_wpan::mac::event::MacEvent;
|
||||
use embassy_stm32_wpan::mac::typedefs::{
|
||||
AddressMode, Capabilities, KeyIdMode, MacAddress, MacChannel, PanId, PibId, SecurityLevel,
|
||||
};
|
||||
use embassy_stm32_wpan::sub::mm;
|
||||
use embassy_stm32_wpan::TlMbox;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
bind_interrupts!(struct Irqs{
|
||||
IPCC_C1_RX => ReceiveInterruptHandler;
|
||||
IPCC_C1_TX => TransmitInterruptHandler;
|
||||
});
|
||||
|
||||
#[embassy_executor::task]
|
||||
async fn run_mm_queue(memory_manager: mm::MemoryManager) {
|
||||
memory_manager.run_queue().await;
|
||||
}
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(spawner: Spawner) {
|
||||
/*
|
||||
How to make this work:
|
||||
|
||||
- Obtain a NUCLEO-STM32WB55 from your preferred supplier.
|
||||
- Download and Install STM32CubeProgrammer.
|
||||
- Download stm32wb5x_FUS_fw.bin, stm32wb5x_BLE_Stack_full_fw.bin, and Release_Notes.html from
|
||||
gh:STMicroelectronics/STM32CubeWB@2234d97/Projects/STM32WB_Copro_Wireless_Binaries/STM32WB5x
|
||||
- Open STM32CubeProgrammer
|
||||
- On the right-hand pane, click "firmware upgrade" to upgrade the st-link firmware.
|
||||
- Once complete, click connect to connect to the device.
|
||||
- On the left hand pane, click the RSS signal icon to open "Firmware Upgrade Services".
|
||||
- In the Release_Notes.html, find the memory address that corresponds to your device for the stm32wb5x_FUS_fw.bin file
|
||||
- Select that file, the memory address, "verify download", and then "Firmware Upgrade".
|
||||
- Once complete, in the Release_Notes.html, find the memory address that corresponds to your device for the
|
||||
stm32wb5x_BLE_Stack_full_fw.bin file. It should not be the same memory address.
|
||||
- Select that file, the memory address, "verify download", and then "Firmware Upgrade".
|
||||
- Select "Start Wireless Stack".
|
||||
- Disconnect from the device.
|
||||
- In the examples folder for stm32wb, modify the memory.x file to match your target device.
|
||||
- Run this example.
|
||||
|
||||
Note: extended stack versions are not supported at this time. Do not attempt to install a stack with "extended" in the name.
|
||||
*/
|
||||
|
||||
let p = embassy_stm32::init(Default::default());
|
||||
info!("Hello World!");
|
||||
|
||||
let config = Config::default();
|
||||
let mbox = TlMbox::init(p.IPCC, Irqs, config);
|
||||
|
||||
spawner.spawn(run_mm_queue(mbox.mm_subsystem)).unwrap();
|
||||
|
||||
let sys_event = mbox.sys_subsystem.read().await;
|
||||
info!("sys event: {}", sys_event.payload());
|
||||
|
||||
core::mem::drop(sys_event);
|
||||
|
||||
let result = mbox.sys_subsystem.shci_c2_mac_802_15_4_init().await;
|
||||
info!("initialized mac: {}", result);
|
||||
|
||||
info!("resetting");
|
||||
mbox.mac_subsystem
|
||||
.send_command(&ResetRequest {
|
||||
set_default_pib: true,
|
||||
..Default::default()
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
defmt::info!("{:#x}", mbox.mac_subsystem.read().await.unwrap());
|
||||
|
||||
info!("setting extended address");
|
||||
let extended_address: u64 = 0xACDE480000000002;
|
||||
mbox.mac_subsystem
|
||||
.send_command(&SetRequest {
|
||||
pib_attribute_ptr: &extended_address as *const _ as *const u8,
|
||||
pib_attribute: PibId::ExtendedAddress,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
defmt::info!("{:#x}", mbox.mac_subsystem.read().await.unwrap());
|
||||
|
||||
info!("getting extended address");
|
||||
mbox.mac_subsystem
|
||||
.send_command(&GetRequest {
|
||||
pib_attribute: PibId::ExtendedAddress,
|
||||
..Default::default()
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
{
|
||||
let evt = mbox.mac_subsystem.read().await.unwrap();
|
||||
info!("{:#x}", evt);
|
||||
|
||||
if let MacEvent::MlmeGetCnf(evt) = evt {
|
||||
if evt.pib_attribute_value_len == 8 {
|
||||
let value = unsafe { core::ptr::read_unaligned(evt.pib_attribute_value_ptr as *const u64) };
|
||||
|
||||
info!("value {:#x}", value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
info!("assocation request");
|
||||
let a = AssociateRequest {
|
||||
channel_number: MacChannel::Channel16,
|
||||
channel_page: 0,
|
||||
coord_addr_mode: AddressMode::Short,
|
||||
coord_address: MacAddress { short: [34, 17] },
|
||||
capability_information: Capabilities::ALLOCATE_ADDRESS,
|
||||
coord_pan_id: PanId([0x1A, 0xAA]),
|
||||
security_level: SecurityLevel::Unsecure,
|
||||
key_id_mode: KeyIdMode::Implicite,
|
||||
key_source: [0; 8],
|
||||
key_index: 152,
|
||||
};
|
||||
info!("{}", a);
|
||||
mbox.mac_subsystem.send_command(&a).await.unwrap();
|
||||
let short_addr = {
|
||||
let evt = mbox.mac_subsystem.read().await.unwrap();
|
||||
info!("{:#x}", evt);
|
||||
|
||||
if let MacEvent::MlmeAssociateCnf(conf) = evt {
|
||||
conf.assoc_short_address
|
||||
} else {
|
||||
defmt::panic!()
|
||||
}
|
||||
};
|
||||
|
||||
info!("setting short address");
|
||||
mbox.mac_subsystem
|
||||
.send_command(&SetRequest {
|
||||
pib_attribute_ptr: &short_addr as *const _ as *const u8,
|
||||
pib_attribute: PibId::ShortAddress,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
{
|
||||
let evt = mbox.mac_subsystem.read().await.unwrap();
|
||||
info!("{:#x}", evt);
|
||||
}
|
||||
|
||||
info!("sending data");
|
||||
let data = b"Hello from embassy!";
|
||||
mbox.mac_subsystem
|
||||
.send_command(
|
||||
DataRequest {
|
||||
src_addr_mode: AddressMode::Short,
|
||||
dst_addr_mode: AddressMode::Short,
|
||||
dst_pan_id: PanId([0x1A, 0xAA]),
|
||||
dst_address: MacAddress::BROADCAST,
|
||||
msdu_handle: 0x02,
|
||||
ack_tx: 0x00,
|
||||
gts_tx: false,
|
||||
security_level: SecurityLevel::Unsecure,
|
||||
..Default::default()
|
||||
}
|
||||
.set_buffer(data),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
{
|
||||
let evt = mbox.mac_subsystem.read().await.unwrap();
|
||||
info!("{:#x}", evt);
|
||||
}
|
||||
|
||||
loop {
|
||||
match mbox.mac_subsystem.read().await {
|
||||
Ok(evt) => info!("{:#x}", evt),
|
||||
_ => continue,
|
||||
};
|
||||
}
|
||||
}
|
@ -49,7 +49,7 @@ async fn main(_spawner: Spawner) {
|
||||
let sys_event = mbox.sys_subsystem.read().await;
|
||||
info!("sys event: {}", sys_event.payload());
|
||||
|
||||
mbox.sys_subsystem.shci_c2_ble_init(Default::default()).await;
|
||||
let _ = mbox.sys_subsystem.shci_c2_ble_init(Default::default()).await;
|
||||
|
||||
info!("starting ble...");
|
||||
mbox.ble_subsystem.tl_write(0x0c, &[]).await;
|
||||
|
@ -6,6 +6,7 @@ use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_stm32::bind_interrupts;
|
||||
use embassy_stm32::ipcc::{Config, ReceiveInterruptHandler, TransmitInterruptHandler};
|
||||
use embassy_stm32_wpan::sub::mm;
|
||||
use embassy_stm32_wpan::TlMbox;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
@ -14,8 +15,13 @@ bind_interrupts!(struct Irqs{
|
||||
IPCC_C1_TX => TransmitInterruptHandler;
|
||||
});
|
||||
|
||||
#[embassy_executor::task]
|
||||
async fn run_mm_queue(memory_manager: mm::MemoryManager) {
|
||||
memory_manager.run_queue().await;
|
||||
}
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) {
|
||||
async fn main(spawner: Spawner) {
|
||||
/*
|
||||
How to make this work:
|
||||
|
||||
@ -46,9 +52,13 @@ async fn main(_spawner: Spawner) {
|
||||
let config = Config::default();
|
||||
let mbox = TlMbox::init(p.IPCC, Irqs, config);
|
||||
|
||||
spawner.spawn(run_mm_queue(mbox.mm_subsystem)).unwrap();
|
||||
|
||||
let sys_event = mbox.sys_subsystem.read().await;
|
||||
info!("sys event: {}", sys_event.payload());
|
||||
|
||||
core::mem::drop(sys_event);
|
||||
|
||||
let result = mbox.sys_subsystem.shci_c2_mac_802_15_4_init().await;
|
||||
info!("initialized mac: {}", result);
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
runner = "probe-rs run --chip STM32WLE5JCIx"
|
||||
|
||||
[build]
|
||||
target = "thumbv7em-none-eabihf"
|
||||
target = "thumbv7em-none-eabi"
|
||||
|
||||
[env]
|
||||
DEFMT_LOG = "trace"
|
||||
|
@ -7,9 +7,9 @@ license = "MIT OR Apache-2.0"
|
||||
[dependencies]
|
||||
embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
|
||||
embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
|
||||
embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["nightly", "unstable-traits", "defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "unstable-traits", "defmt", "stm32wl55jc-cm4", "time-driver-any", "memory-x", "unstable-pac", "exti"] }
|
||||
embassy-embedded-hal = {version = "0.1.0", path = "../../embassy-embedded-hal" }
|
||||
embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["nightly", "unstable-traits", "defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "unstable-traits", "defmt", "stm32wl55jc-cm4", "time-driver-any", "memory-x", "unstable-pac", "exti", "chrono"] }
|
||||
embassy-embedded-hal = { version = "0.1.0", path = "../../embassy-embedded-hal" }
|
||||
embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["stm32wl", "time", "defmt"] }
|
||||
lora-phy = { version = "1" }
|
||||
lorawan-device = { version = "0.10.0", default-features = false, features = ["async", "external-lora-phy"] }
|
||||
@ -25,3 +25,7 @@ embedded-storage = "0.3.0"
|
||||
panic-probe = { version = "0.3", features = ["print-defmt"] }
|
||||
futures = { version = "0.3.17", default-features = false, features = ["async-await"] }
|
||||
heapless = { version = "0.7.5", default-features = false }
|
||||
chrono = { version = "^0.4", default-features = false }
|
||||
|
||||
[patch.crates-io]
|
||||
lora-phy = { git = "https://github.com/embassy-rs/lora-phy", rev = "ad289428fd44b02788e2fa2116445cc8f640a265" }
|
||||
|
43
examples/stm32wl/src/bin/rtc.rs
Normal file
43
examples/stm32wl/src/bin/rtc.rs
Normal file
@ -0,0 +1,43 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use chrono::{NaiveDate, NaiveDateTime};
|
||||
use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_stm32::rcc::{self, ClockSrc};
|
||||
use embassy_stm32::rtc::{Rtc, RtcConfig};
|
||||
use embassy_stm32::Config;
|
||||
use embassy_time::{Duration, Timer};
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) {
|
||||
let p = {
|
||||
let mut config = Config::default();
|
||||
config.rcc.mux = ClockSrc::HSE32;
|
||||
config.rcc.rtc_mux = rcc::RtcClockSource::LSE32;
|
||||
config.rcc.enable_rtc_apb = true;
|
||||
embassy_stm32::init(config)
|
||||
};
|
||||
info!("Hello World!");
|
||||
|
||||
let now = NaiveDate::from_ymd_opt(2020, 5, 15)
|
||||
.unwrap()
|
||||
.and_hms_opt(10, 30, 15)
|
||||
.unwrap();
|
||||
|
||||
let mut rtc = Rtc::new(
|
||||
p.RTC,
|
||||
RtcConfig::default().clock_config(embassy_stm32::rtc::RtcClockSource::LSE),
|
||||
);
|
||||
info!("Got RTC! {:?}", now.timestamp());
|
||||
|
||||
rtc.set_datetime(now.into()).expect("datetime not set");
|
||||
|
||||
// In reality the delay would be much longer
|
||||
Timer::after(Duration::from_millis(20000)).await;
|
||||
|
||||
let then: NaiveDateTime = rtc.now().unwrap().into();
|
||||
info!("Got RTC! {:?}", then.timestamp());
|
||||
}
|
@ -10,7 +10,7 @@ crate-type = ["cdylib"]
|
||||
[dependencies]
|
||||
embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["log"] }
|
||||
embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["arch-wasm", "executor-thread", "log", "nightly", "integrated-timers"] }
|
||||
embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["log", "wasm", "nightly"] }
|
||||
embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["log", "wasm", "nightly"] }
|
||||
|
||||
wasm-logger = "0.2.0"
|
||||
wasm-bindgen = "0.2"
|
||||
|
Reference in New Issue
Block a user