stm32: move lora to bind_interrupts
This commit is contained in:
parent
316be179af
commit
b6ba1ea53a
6 changed files with 71 additions and 56 deletions
2
ci.sh
2
ci.sh
|
@ -112,6 +112,7 @@ cargo batch \
|
|||
--- build --release --manifest-path examples/stm32l5/Cargo.toml --target thumbv8m.main-none-eabihf --out-dir out/examples/stm32l5 \
|
||||
--- build --release --manifest-path examples/stm32u5/Cargo.toml --target thumbv8m.main-none-eabihf --out-dir out/examples/stm32u5 \
|
||||
--- build --release --manifest-path examples/stm32wb/Cargo.toml --target thumbv7em-none-eabihf --out-dir out/examples/stm32wb \
|
||||
--- build --release --manifest-path examples/stm32wl/Cargo.toml --target thumbv7em-none-eabihf --out-dir out/examples/stm32wl \
|
||||
--- build --release --manifest-path examples/boot/application/nrf/Cargo.toml --target thumbv7em-none-eabi --features embassy-nrf/nrf52840 --out-dir out/examples/boot/nrf --bin b \
|
||||
--- build --release --manifest-path examples/boot/application/nrf/Cargo.toml --target thumbv8m.main-none-eabihf --features embassy-nrf/nrf9160-ns --out-dir out/examples/boot/nrf --bin b \
|
||||
--- build --release --manifest-path examples/boot/application/rp/Cargo.toml --target thumbv6m-none-eabi --out-dir out/examples/boot/rp --bin b \
|
||||
|
@ -142,7 +143,6 @@ cargo batch \
|
|||
$BUILD_EXTRA
|
||||
|
||||
|
||||
# --- build --release --manifest-path examples/stm32wl/Cargo.toml --target thumbv7em-none-eabihf --out-dir out/examples/stm32wl \
|
||||
|
||||
function run_elf {
|
||||
echo Running target=$1 elf=$2
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
#[cfg(feature = "stm32wl")]
|
||||
use embassy_stm32::interrupt;
|
||||
#[cfg(feature = "stm32wl")]
|
||||
use embassy_stm32::interrupt::*;
|
||||
#[cfg(feature = "stm32wl")]
|
||||
use embassy_stm32::{pac, PeripheralRef};
|
||||
use embassy_stm32::pac;
|
||||
#[cfg(feature = "stm32wl")]
|
||||
use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
|
||||
#[cfg(feature = "stm32wl")]
|
||||
|
@ -13,47 +15,51 @@ use lora_phy::mod_params::RadioError::*;
|
|||
use lora_phy::mod_params::{BoardType, RadioError};
|
||||
use lora_phy::mod_traits::InterfaceVariant;
|
||||
|
||||
/// Interrupt handler.
|
||||
#[cfg(feature = "stm32wl")]
|
||||
static IRQ_SIGNAL: Signal<CriticalSectionRawMutex, ()> = Signal::new();
|
||||
pub struct InterruptHandler {}
|
||||
|
||||
#[cfg(feature = "stm32wl")]
|
||||
/// Base for the InterfaceVariant implementation for an stm32wl/sx1262 combination
|
||||
pub struct Stm32wlInterfaceVariant<'a, CTRL> {
|
||||
board_type: BoardType,
|
||||
irq: PeripheralRef<'a, SUBGHZ_RADIO>,
|
||||
rf_switch_rx: Option<CTRL>,
|
||||
rf_switch_tx: Option<CTRL>,
|
||||
}
|
||||
|
||||
#[cfg(feature = "stm32wl")]
|
||||
impl<'a, CTRL> Stm32wlInterfaceVariant<'a, CTRL>
|
||||
where
|
||||
CTRL: OutputPin,
|
||||
{
|
||||
/// Create an InterfaceVariant instance for an stm32wl/sx1262 combination
|
||||
pub fn new(
|
||||
irq: PeripheralRef<'a, SUBGHZ_RADIO>,
|
||||
rf_switch_rx: Option<CTRL>,
|
||||
rf_switch_tx: Option<CTRL>,
|
||||
) -> Result<Self, RadioError> {
|
||||
irq.disable();
|
||||
irq.set_handler(Self::on_interrupt);
|
||||
Ok(Self {
|
||||
board_type: BoardType::Stm32wlSx1262, // updated when associated with a specific LoRa board
|
||||
irq,
|
||||
rf_switch_rx,
|
||||
rf_switch_tx,
|
||||
})
|
||||
}
|
||||
|
||||
fn on_interrupt(_: *mut ()) {
|
||||
impl interrupt::Handler<interrupt::SUBGHZ_RADIO> for InterruptHandler {
|
||||
unsafe fn on_interrupt() {
|
||||
unsafe { SUBGHZ_RADIO::steal() }.disable();
|
||||
IRQ_SIGNAL.signal(());
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "stm32wl")]
|
||||
impl<CTRL> InterfaceVariant for Stm32wlInterfaceVariant<'_, CTRL>
|
||||
static IRQ_SIGNAL: Signal<CriticalSectionRawMutex, ()> = Signal::new();
|
||||
|
||||
#[cfg(feature = "stm32wl")]
|
||||
/// Base for the InterfaceVariant implementation for an stm32wl/sx1262 combination
|
||||
pub struct Stm32wlInterfaceVariant<CTRL> {
|
||||
board_type: BoardType,
|
||||
rf_switch_rx: Option<CTRL>,
|
||||
rf_switch_tx: Option<CTRL>,
|
||||
}
|
||||
|
||||
#[cfg(feature = "stm32wl")]
|
||||
impl<'a, CTRL> Stm32wlInterfaceVariant<CTRL>
|
||||
where
|
||||
CTRL: OutputPin,
|
||||
{
|
||||
/// Create an InterfaceVariant instance for an stm32wl/sx1262 combination
|
||||
pub fn new(
|
||||
_irq: impl interrupt::Binding<interrupt::SUBGHZ_RADIO, InterruptHandler>,
|
||||
rf_switch_rx: Option<CTRL>,
|
||||
rf_switch_tx: Option<CTRL>,
|
||||
) -> Result<Self, RadioError> {
|
||||
unsafe { interrupt::SUBGHZ_RADIO::steal() }.disable();
|
||||
Ok(Self {
|
||||
board_type: BoardType::Stm32wlSx1262, // updated when associated with a specific LoRa board
|
||||
rf_switch_rx,
|
||||
rf_switch_tx,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "stm32wl")]
|
||||
impl<CTRL> InterfaceVariant for Stm32wlInterfaceVariant<CTRL>
|
||||
where
|
||||
CTRL: OutputPin,
|
||||
{
|
||||
|
@ -89,7 +95,7 @@ where
|
|||
}
|
||||
|
||||
async fn await_irq(&mut self) -> Result<(), RadioError> {
|
||||
self.irq.enable();
|
||||
unsafe { interrupt::SUBGHZ_RADIO::steal() }.enable();
|
||||
IRQ_SIGNAL.wait().await;
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -7,12 +7,12 @@
|
|||
|
||||
use defmt::info;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_lora::iv::Stm32wlInterfaceVariant;
|
||||
use embassy_lora::iv::{InterruptHandler, Stm32wlInterfaceVariant};
|
||||
use embassy_lora::LoraTimer;
|
||||
use embassy_stm32::gpio::{Level, Output, Pin, Speed};
|
||||
use embassy_stm32::rng::Rng;
|
||||
use embassy_stm32::spi::Spi;
|
||||
use embassy_stm32::{interrupt, into_ref, pac, Peripheral};
|
||||
use embassy_stm32::{bind_interrupts, pac};
|
||||
use embassy_time::Delay;
|
||||
use lora_phy::mod_params::*;
|
||||
use lora_phy::sx1261_2::SX1261_2;
|
||||
|
@ -24,6 +24,10 @@ use {defmt_rtt as _, panic_probe as _};
|
|||
|
||||
const LORAWAN_REGION: region::Region = region::Region::EU868; // warning: set this appropriately for the region
|
||||
|
||||
bind_interrupts!(struct Irqs{
|
||||
SUBGHZ_RADIO => InterruptHandler;
|
||||
});
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) {
|
||||
let mut config = embassy_stm32::Config::default();
|
||||
|
@ -35,13 +39,11 @@ async fn main(_spawner: Spawner) {
|
|||
|
||||
let spi = Spi::new_subghz(p.SUBGHZSPI, p.DMA1_CH1, p.DMA1_CH2);
|
||||
|
||||
let irq = interrupt::take!(SUBGHZ_RADIO);
|
||||
into_ref!(irq);
|
||||
// Set CTRL1 and CTRL3 for high-power transmission, while CTRL2 acts as an RF switch between tx and rx
|
||||
let _ctrl1 = Output::new(p.PC4.degrade(), Level::Low, Speed::High);
|
||||
let ctrl2 = Output::new(p.PC5.degrade(), Level::High, Speed::High);
|
||||
let _ctrl3 = Output::new(p.PC3.degrade(), Level::High, Speed::High);
|
||||
let iv = Stm32wlInterfaceVariant::new(irq, None, Some(ctrl2)).unwrap();
|
||||
let iv = Stm32wlInterfaceVariant::new(Irqs, None, Some(ctrl2)).unwrap();
|
||||
|
||||
let mut delay = Delay;
|
||||
|
||||
|
|
|
@ -7,10 +7,10 @@
|
|||
|
||||
use defmt::info;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_lora::iv::Stm32wlInterfaceVariant;
|
||||
use embassy_lora::iv::{InterruptHandler, Stm32wlInterfaceVariant};
|
||||
use embassy_stm32::bind_interrupts;
|
||||
use embassy_stm32::gpio::{Level, Output, Pin, Speed};
|
||||
use embassy_stm32::spi::Spi;
|
||||
use embassy_stm32::{interrupt, into_ref, Peripheral};
|
||||
use embassy_time::{Delay, Duration, Timer};
|
||||
use lora_phy::mod_params::*;
|
||||
use lora_phy::sx1261_2::SX1261_2;
|
||||
|
@ -19,6 +19,10 @@ use {defmt_rtt as _, panic_probe as _};
|
|||
|
||||
const LORA_FREQUENCY_IN_HZ: u32 = 903_900_000; // warning: set this appropriately for the region
|
||||
|
||||
bind_interrupts!(struct Irqs{
|
||||
SUBGHZ_RADIO => InterruptHandler;
|
||||
});
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) {
|
||||
let mut config = embassy_stm32::Config::default();
|
||||
|
@ -27,13 +31,11 @@ async fn main(_spawner: Spawner) {
|
|||
|
||||
let spi = Spi::new_subghz(p.SUBGHZSPI, p.DMA1_CH1, p.DMA1_CH2);
|
||||
|
||||
let irq = interrupt::take!(SUBGHZ_RADIO);
|
||||
into_ref!(irq);
|
||||
// Set CTRL1 and CTRL3 for high-power transmission, while CTRL2 acts as an RF switch between tx and rx
|
||||
let _ctrl1 = Output::new(p.PC4.degrade(), Level::Low, Speed::High);
|
||||
let ctrl2 = Output::new(p.PC5.degrade(), Level::High, Speed::High);
|
||||
let _ctrl3 = Output::new(p.PC3.degrade(), Level::High, Speed::High);
|
||||
let iv = Stm32wlInterfaceVariant::new(irq, None, Some(ctrl2)).unwrap();
|
||||
let iv = Stm32wlInterfaceVariant::new(Irqs, None, Some(ctrl2)).unwrap();
|
||||
|
||||
let mut delay = Delay;
|
||||
|
||||
|
|
|
@ -7,10 +7,10 @@
|
|||
|
||||
use defmt::info;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_lora::iv::Stm32wlInterfaceVariant;
|
||||
use embassy_lora::iv::{InterruptHandler, Stm32wlInterfaceVariant};
|
||||
use embassy_stm32::bind_interrupts;
|
||||
use embassy_stm32::gpio::{Level, Output, Pin, Speed};
|
||||
use embassy_stm32::spi::Spi;
|
||||
use embassy_stm32::{interrupt, into_ref, Peripheral};
|
||||
use embassy_time::Delay;
|
||||
use lora_phy::mod_params::*;
|
||||
use lora_phy::sx1261_2::SX1261_2;
|
||||
|
@ -19,6 +19,10 @@ use {defmt_rtt as _, panic_probe as _};
|
|||
|
||||
const LORA_FREQUENCY_IN_HZ: u32 = 903_900_000; // warning: set this appropriately for the region
|
||||
|
||||
bind_interrupts!(struct Irqs{
|
||||
SUBGHZ_RADIO => InterruptHandler;
|
||||
});
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) {
|
||||
let mut config = embassy_stm32::Config::default();
|
||||
|
@ -27,13 +31,11 @@ async fn main(_spawner: Spawner) {
|
|||
|
||||
let spi = Spi::new_subghz(p.SUBGHZSPI, p.DMA1_CH1, p.DMA1_CH2);
|
||||
|
||||
let irq = interrupt::take!(SUBGHZ_RADIO);
|
||||
into_ref!(irq);
|
||||
// Set CTRL1 and CTRL3 for high-power transmission, while CTRL2 acts as an RF switch between tx and rx
|
||||
let _ctrl1 = Output::new(p.PC4.degrade(), Level::Low, Speed::High);
|
||||
let ctrl2 = Output::new(p.PC5.degrade(), Level::High, Speed::High);
|
||||
let _ctrl3 = Output::new(p.PC3.degrade(), Level::High, Speed::High);
|
||||
let iv = Stm32wlInterfaceVariant::new(irq, None, Some(ctrl2)).unwrap();
|
||||
let iv = Stm32wlInterfaceVariant::new(Irqs, None, Some(ctrl2)).unwrap();
|
||||
|
||||
let mut delay = Delay;
|
||||
|
||||
|
|
|
@ -4,10 +4,15 @@
|
|||
|
||||
use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_stm32::interrupt;
|
||||
use embassy_stm32::usart::{Config, Uart};
|
||||
use embassy_stm32::usart::{Config, InterruptHandler, Uart};
|
||||
use embassy_stm32::{bind_interrupts, peripherals};
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
bind_interrupts!(struct Irqs{
|
||||
USART1 => InterruptHandler<peripherals::USART1>;
|
||||
LPUART1 => InterruptHandler<peripherals::LPUART1>;
|
||||
});
|
||||
|
||||
/*
|
||||
Pass Incoming data from LPUART1 to USART1
|
||||
Example is written for the LoRa-E5 mini v1.0,
|
||||
|
@ -28,12 +33,10 @@ async fn main(_spawner: Spawner) {
|
|||
config2.baudrate = 9600;
|
||||
|
||||
//RX/TX connected to USB/UART Bridge on LoRa-E5 mini v1.0
|
||||
let irq = interrupt::take!(USART1);
|
||||
let mut usart1 = Uart::new(p.USART1, p.PB7, p.PB6, irq, p.DMA1_CH3, p.DMA1_CH4, config1);
|
||||
let mut usart1 = Uart::new(p.USART1, p.PB7, p.PB6, Irqs, p.DMA1_CH3, p.DMA1_CH4, config1);
|
||||
|
||||
//RX1/TX1 (LPUART) on LoRa-E5 mini v1.0
|
||||
let irq = interrupt::take!(LPUART1);
|
||||
let mut usart2 = Uart::new(p.LPUART1, p.PC0, p.PC1, irq, p.DMA1_CH5, p.DMA1_CH6, config2);
|
||||
let mut usart2 = Uart::new(p.LPUART1, p.PC0, p.PC1, Irqs, p.DMA1_CH5, p.DMA1_CH6, config2);
|
||||
|
||||
unwrap!(usart1.write(b"Hello Embassy World!\r\n").await);
|
||||
unwrap!(usart2.write(b"Hello Embassy World!\r\n").await);
|
||||
|
|
Loading…
Reference in a new issue