Merge pull request #1948 from embassy-rs/stm32-test-cleanup
tests/stm32: centralize pin configuration.
This commit is contained in:
commit
481d2998ef
@ -102,6 +102,7 @@ mod chip;
|
|||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! bind_interrupts {
|
macro_rules! bind_interrupts {
|
||||||
($vis:vis struct $name:ident { $($irq:ident => $($handler:ty),*;)* }) => {
|
($vis:vis struct $name:ident { $($irq:ident => $($handler:ty),*;)* }) => {
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
$vis struct $name;
|
$vis struct $name;
|
||||||
|
|
||||||
$(
|
$(
|
||||||
|
@ -90,7 +90,8 @@ embassy_hal_internal::interrupt_mod!(
|
|||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! bind_interrupts {
|
macro_rules! bind_interrupts {
|
||||||
($vis:vis struct $name:ident { $($irq:ident => $($handler:ty),*;)* }) => {
|
($vis:vis struct $name:ident { $($irq:ident => $($handler:ty),*;)* }) => {
|
||||||
$vis struct $name;
|
#[derive(Copy, Clone)]
|
||||||
|
$vis struct $name;
|
||||||
|
|
||||||
$(
|
$(
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
|
@ -88,6 +88,7 @@ pub use crate::_generated::interrupt;
|
|||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! bind_interrupts {
|
macro_rules! bind_interrupts {
|
||||||
($vis:vis struct $name:ident { $($irq:ident => $($handler:ty),*;)* }) => {
|
($vis:vis struct $name:ident { $($irq:ident => $($handler:ty),*;)* }) => {
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
$vis struct $name;
|
$vis struct $name;
|
||||||
|
|
||||||
$(
|
$(
|
||||||
|
@ -16,24 +16,8 @@ async fn main(_spawner: Spawner) {
|
|||||||
|
|
||||||
// Arduino pins D0 and D1
|
// Arduino pins D0 and D1
|
||||||
// They're connected together with a 1K resistor.
|
// They're connected together with a 1K resistor.
|
||||||
#[cfg(feature = "stm32f103c8")]
|
let mut a = peri!(p, UART_RX);
|
||||||
let (mut a, mut b) = (p.PA9, p.PA10);
|
let mut b = peri!(p, UART_TX);
|
||||||
#[cfg(feature = "stm32g491re")]
|
|
||||||
let (mut a, mut b) = (p.PC4, p.PC5);
|
|
||||||
#[cfg(feature = "stm32g071rb")]
|
|
||||||
let (mut a, mut b) = (p.PC4, p.PC5);
|
|
||||||
#[cfg(feature = "stm32f429zi")]
|
|
||||||
let (mut a, mut b) = (p.PG14, p.PG9);
|
|
||||||
#[cfg(feature = "stm32wb55rg")]
|
|
||||||
let (mut a, mut b) = (p.PA3, p.PA2);
|
|
||||||
#[cfg(feature = "stm32h755zi")]
|
|
||||||
let (mut a, mut b) = (p.PB6, p.PB7);
|
|
||||||
#[cfg(feature = "stm32u585ai")]
|
|
||||||
let (mut a, mut b) = (p.PD9, p.PD8);
|
|
||||||
#[cfg(feature = "stm32h563zi")]
|
|
||||||
let (mut a, mut b) = (p.PB6, p.PB7);
|
|
||||||
#[cfg(feature = "stm32c031c6")]
|
|
||||||
let (mut a, mut b) = (p.PB6, p.PB7);
|
|
||||||
|
|
||||||
// Test initial output
|
// Test initial output
|
||||||
{
|
{
|
||||||
|
@ -16,24 +16,10 @@ async fn main(_spawner: Spawner) {
|
|||||||
let p = embassy_stm32::init(config());
|
let p = embassy_stm32::init(config());
|
||||||
info!("Hello World!");
|
info!("Hello World!");
|
||||||
|
|
||||||
#[cfg(feature = "stm32f103c8")]
|
let spi = peri!(p, SPI);
|
||||||
let (spi, sck, mosi, miso) = (p.SPI1, p.PA5, p.PA7, p.PA6);
|
let sck = peri!(p, SPI_SCK);
|
||||||
#[cfg(feature = "stm32f429zi")]
|
let mosi = peri!(p, SPI_MOSI);
|
||||||
let (spi, sck, mosi, miso) = (p.SPI1, p.PA5, p.PA7, p.PA6);
|
let miso = peri!(p, SPI_MISO);
|
||||||
#[cfg(feature = "stm32h755zi")]
|
|
||||||
let (spi, sck, mosi, miso) = (p.SPI1, p.PA5, p.PB5, p.PA6);
|
|
||||||
#[cfg(feature = "stm32g491re")]
|
|
||||||
let (spi, sck, mosi, miso) = (p.SPI1, p.PA5, p.PA7, p.PA6);
|
|
||||||
#[cfg(feature = "stm32g071rb")]
|
|
||||||
let (spi, sck, mosi, miso) = (p.SPI1, p.PA5, p.PA7, p.PA6);
|
|
||||||
#[cfg(feature = "stm32wb55rg")]
|
|
||||||
let (spi, sck, mosi, miso) = (p.SPI1, p.PA5, p.PA7, p.PA6);
|
|
||||||
#[cfg(feature = "stm32u585ai")]
|
|
||||||
let (spi, sck, mosi, miso) = (p.SPI1, p.PE13, p.PE15, p.PE14);
|
|
||||||
#[cfg(feature = "stm32h563zi")]
|
|
||||||
let (spi, sck, mosi, miso) = (p.SPI4, p.PE12, p.PE14, p.PE13);
|
|
||||||
#[cfg(feature = "stm32c031c6")]
|
|
||||||
let (spi, sck, mosi, miso) = (p.SPI1, p.PA5, p.PA7, p.PA6);
|
|
||||||
|
|
||||||
let mut spi_config = spi::Config::default();
|
let mut spi_config = spi::Config::default();
|
||||||
spi_config.frequency = Hertz(1_000_000);
|
spi_config.frequency = Hertz(1_000_000);
|
||||||
|
@ -15,24 +15,12 @@ async fn main(_spawner: Spawner) {
|
|||||||
let p = embassy_stm32::init(config());
|
let p = embassy_stm32::init(config());
|
||||||
info!("Hello World!");
|
info!("Hello World!");
|
||||||
|
|
||||||
#[cfg(feature = "stm32f103c8")]
|
let spi = peri!(p, SPI);
|
||||||
let (spi, sck, mosi, miso, tx_dma, rx_dma) = (p.SPI1, p.PA5, p.PA7, p.PA6, p.DMA1_CH3, p.DMA1_CH2);
|
let sck = peri!(p, SPI_SCK);
|
||||||
#[cfg(feature = "stm32f429zi")]
|
let mosi = peri!(p, SPI_MOSI);
|
||||||
let (spi, sck, mosi, miso, tx_dma, rx_dma) = (p.SPI1, p.PA5, p.PA7, p.PA6, p.DMA2_CH3, p.DMA2_CH2);
|
let miso = peri!(p, SPI_MISO);
|
||||||
#[cfg(feature = "stm32h755zi")]
|
let tx_dma = peri!(p, SPI_TX_DMA);
|
||||||
let (spi, sck, mosi, miso, tx_dma, rx_dma) = (p.SPI1, p.PA5, p.PB5, p.PA6, p.DMA1_CH0, p.DMA1_CH1);
|
let rx_dma = peri!(p, SPI_RX_DMA);
|
||||||
#[cfg(feature = "stm32g491re")]
|
|
||||||
let (spi, sck, mosi, miso, tx_dma, rx_dma) = (p.SPI1, p.PA5, p.PA7, p.PA6, p.DMA1_CH1, p.DMA1_CH2);
|
|
||||||
#[cfg(feature = "stm32g071rb")]
|
|
||||||
let (spi, sck, mosi, miso, tx_dma, rx_dma) = (p.SPI1, p.PA5, p.PA7, p.PA6, p.DMA1_CH1, p.DMA1_CH2);
|
|
||||||
#[cfg(feature = "stm32wb55rg")]
|
|
||||||
let (spi, sck, mosi, miso, tx_dma, rx_dma) = (p.SPI1, p.PA5, p.PA7, p.PA6, p.DMA1_CH1, p.DMA1_CH2);
|
|
||||||
#[cfg(feature = "stm32u585ai")]
|
|
||||||
let (spi, sck, mosi, miso, tx_dma, rx_dma) = (p.SPI1, p.PE13, p.PE15, p.PE14, p.GPDMA1_CH0, p.GPDMA1_CH1);
|
|
||||||
#[cfg(feature = "stm32h563zi")]
|
|
||||||
let (spi, sck, mosi, miso, tx_dma, rx_dma) = (p.SPI4, p.PE12, p.PE14, p.PE13, p.GPDMA1_CH0, p.GPDMA1_CH1);
|
|
||||||
#[cfg(feature = "stm32c031c6")]
|
|
||||||
let (spi, sck, mosi, miso, tx_dma, rx_dma) = (p.SPI1, p.PA5, p.PA7, p.PA6, p.DMA1_CH1, p.DMA1_CH2);
|
|
||||||
|
|
||||||
let mut spi_config = spi::Config::default();
|
let mut spi_config = spi::Config::default();
|
||||||
spi_config.frequency = Hertz(1_000_000);
|
spi_config.frequency = Hertz(1_000_000);
|
||||||
|
@ -9,35 +9,8 @@ use defmt::assert_eq;
|
|||||||
use embassy_executor::Spawner;
|
use embassy_executor::Spawner;
|
||||||
use embassy_stm32::dma::NoDma;
|
use embassy_stm32::dma::NoDma;
|
||||||
use embassy_stm32::usart::{Config, Error, Uart};
|
use embassy_stm32::usart::{Config, Error, Uart};
|
||||||
use embassy_stm32::{bind_interrupts, peripherals, usart};
|
|
||||||
use embassy_time::{Duration, Instant};
|
use embassy_time::{Duration, Instant};
|
||||||
|
|
||||||
#[cfg(any(
|
|
||||||
feature = "stm32f103c8",
|
|
||||||
feature = "stm32g491re",
|
|
||||||
feature = "stm32g071rb",
|
|
||||||
feature = "stm32h755zi",
|
|
||||||
feature = "stm32c031c6",
|
|
||||||
))]
|
|
||||||
bind_interrupts!(struct Irqs {
|
|
||||||
USART1 => usart::InterruptHandler<peripherals::USART1>;
|
|
||||||
});
|
|
||||||
|
|
||||||
#[cfg(feature = "stm32u585ai")]
|
|
||||||
bind_interrupts!(struct Irqs {
|
|
||||||
USART3 => usart::InterruptHandler<peripherals::USART3>;
|
|
||||||
});
|
|
||||||
|
|
||||||
#[cfg(feature = "stm32f429zi")]
|
|
||||||
bind_interrupts!(struct Irqs {
|
|
||||||
USART6 => usart::InterruptHandler<peripherals::USART6>;
|
|
||||||
});
|
|
||||||
|
|
||||||
#[cfg(any(feature = "stm32wb55rg", feature = "stm32h563zi"))]
|
|
||||||
bind_interrupts!(struct Irqs {
|
|
||||||
LPUART1 => usart::InterruptHandler<peripherals::LPUART1>;
|
|
||||||
});
|
|
||||||
|
|
||||||
#[embassy_executor::main]
|
#[embassy_executor::main]
|
||||||
async fn main(_spawner: Spawner) {
|
async fn main(_spawner: Spawner) {
|
||||||
let p = embassy_stm32::init(config());
|
let p = embassy_stm32::init(config());
|
||||||
@ -45,28 +18,14 @@ async fn main(_spawner: Spawner) {
|
|||||||
|
|
||||||
// Arduino pins D0 and D1
|
// Arduino pins D0 and D1
|
||||||
// They're connected together with a 1K resistor.
|
// They're connected together with a 1K resistor.
|
||||||
#[cfg(feature = "stm32f103c8")]
|
let mut usart = peri!(p, UART);
|
||||||
let (mut tx, mut rx, mut usart) = (p.PA9, p.PA10, p.USART1);
|
let mut rx = peri!(p, UART_RX);
|
||||||
#[cfg(feature = "stm32g491re")]
|
let mut tx = peri!(p, UART_TX);
|
||||||
let (mut tx, mut rx, mut usart) = (p.PC4, p.PC5, p.USART1);
|
let irq = irqs!(UART);
|
||||||
#[cfg(feature = "stm32g071rb")]
|
|
||||||
let (mut tx, mut rx, mut usart) = (p.PC4, p.PC5, p.USART1);
|
|
||||||
#[cfg(feature = "stm32f429zi")]
|
|
||||||
let (mut tx, mut rx, mut usart) = (p.PG14, p.PG9, p.USART6);
|
|
||||||
#[cfg(feature = "stm32wb55rg")]
|
|
||||||
let (mut tx, mut rx, mut usart) = (p.PA2, p.PA3, p.LPUART1);
|
|
||||||
#[cfg(feature = "stm32h755zi")]
|
|
||||||
let (mut tx, mut rx, mut usart) = (p.PB6, p.PB7, p.USART1);
|
|
||||||
#[cfg(feature = "stm32u585ai")]
|
|
||||||
let (mut tx, mut rx, mut usart) = (p.PD8, p.PD9, p.USART3);
|
|
||||||
#[cfg(feature = "stm32h563zi")]
|
|
||||||
let (mut tx, mut rx, mut usart) = (p.PB6, p.PB7, p.LPUART1);
|
|
||||||
#[cfg(feature = "stm32c031c6")]
|
|
||||||
let (mut tx, mut rx, mut usart) = (p.PB6, p.PB7, p.USART1);
|
|
||||||
|
|
||||||
{
|
{
|
||||||
let config = Config::default();
|
let config = Config::default();
|
||||||
let mut usart = Uart::new(&mut usart, &mut rx, &mut tx, Irqs, NoDma, NoDma, config);
|
let mut usart = Uart::new(&mut usart, &mut rx, &mut tx, irq, NoDma, NoDma, config);
|
||||||
|
|
||||||
// We can't send too many bytes, they have to fit in the FIFO.
|
// We can't send too many bytes, they have to fit in the FIFO.
|
||||||
// This is because we aren't sending+receiving at the same time.
|
// This is because we aren't sending+receiving at the same time.
|
||||||
@ -82,7 +41,7 @@ async fn main(_spawner: Spawner) {
|
|||||||
// Test error handling with with an overflow error
|
// Test error handling with with an overflow error
|
||||||
{
|
{
|
||||||
let config = Config::default();
|
let config = Config::default();
|
||||||
let mut usart = Uart::new(&mut usart, &mut rx, &mut tx, Irqs, NoDma, NoDma, config);
|
let mut usart = Uart::new(&mut usart, &mut rx, &mut tx, irq, NoDma, NoDma, config);
|
||||||
|
|
||||||
// Send enough bytes to fill the RX FIFOs off all USART versions.
|
// Send enough bytes to fill the RX FIFOs off all USART versions.
|
||||||
let data = [0xC0, 0xDE, 0x12, 0x23, 0x34];
|
let data = [0xC0, 0xDE, 0x12, 0x23, 0x34];
|
||||||
@ -116,7 +75,7 @@ async fn main(_spawner: Spawner) {
|
|||||||
|
|
||||||
let mut config = Config::default();
|
let mut config = Config::default();
|
||||||
config.baudrate = baudrate;
|
config.baudrate = baudrate;
|
||||||
let mut usart = Uart::new(&mut usart, &mut rx, &mut tx, Irqs, NoDma, NoDma, config);
|
let mut usart = Uart::new(&mut usart, &mut rx, &mut tx, irq, NoDma, NoDma, config);
|
||||||
|
|
||||||
let n = (baudrate as usize / 100).max(64);
|
let n = (baudrate as usize / 100).max(64);
|
||||||
|
|
||||||
|
@ -9,33 +9,6 @@ use defmt::assert_eq;
|
|||||||
use embassy_executor::Spawner;
|
use embassy_executor::Spawner;
|
||||||
use embassy_futures::join::join;
|
use embassy_futures::join::join;
|
||||||
use embassy_stm32::usart::{Config, Uart};
|
use embassy_stm32::usart::{Config, Uart};
|
||||||
use embassy_stm32::{bind_interrupts, peripherals, usart};
|
|
||||||
|
|
||||||
#[cfg(any(
|
|
||||||
feature = "stm32f103c8",
|
|
||||||
feature = "stm32g491re",
|
|
||||||
feature = "stm32g071rb",
|
|
||||||
feature = "stm32h755zi",
|
|
||||||
feature = "stm32c031c6",
|
|
||||||
))]
|
|
||||||
bind_interrupts!(struct Irqs {
|
|
||||||
USART1 => usart::InterruptHandler<peripherals::USART1>;
|
|
||||||
});
|
|
||||||
|
|
||||||
#[cfg(feature = "stm32u585ai")]
|
|
||||||
bind_interrupts!(struct Irqs {
|
|
||||||
USART3 => usart::InterruptHandler<peripherals::USART3>;
|
|
||||||
});
|
|
||||||
|
|
||||||
#[cfg(feature = "stm32f429zi")]
|
|
||||||
bind_interrupts!(struct Irqs {
|
|
||||||
USART6 => usart::InterruptHandler<peripherals::USART6>;
|
|
||||||
});
|
|
||||||
|
|
||||||
#[cfg(any(feature = "stm32wb55rg", feature = "stm32h563zi"))]
|
|
||||||
bind_interrupts!(struct Irqs {
|
|
||||||
LPUART1 => usart::InterruptHandler<peripherals::LPUART1>;
|
|
||||||
});
|
|
||||||
|
|
||||||
#[embassy_executor::main]
|
#[embassy_executor::main]
|
||||||
async fn main(_spawner: Spawner) {
|
async fn main(_spawner: Spawner) {
|
||||||
@ -44,24 +17,12 @@ async fn main(_spawner: Spawner) {
|
|||||||
|
|
||||||
// Arduino pins D0 and D1
|
// Arduino pins D0 and D1
|
||||||
// They're connected together with a 1K resistor.
|
// They're connected together with a 1K resistor.
|
||||||
#[cfg(feature = "stm32f103c8")]
|
let usart = peri!(p, UART);
|
||||||
let (tx, rx, usart, irq, tx_dma, rx_dma) = (p.PA9, p.PA10, p.USART1, Irqs, p.DMA1_CH4, p.DMA1_CH5);
|
let rx = peri!(p, UART_RX);
|
||||||
#[cfg(feature = "stm32g491re")]
|
let tx = peri!(p, UART_TX);
|
||||||
let (tx, rx, usart, irq, tx_dma, rx_dma) = (p.PC4, p.PC5, p.USART1, Irqs, p.DMA1_CH1, p.DMA1_CH2);
|
let rx_dma = peri!(p, UART_RX_DMA);
|
||||||
#[cfg(feature = "stm32g071rb")]
|
let tx_dma = peri!(p, UART_TX_DMA);
|
||||||
let (tx, rx, usart, irq, tx_dma, rx_dma) = (p.PC4, p.PC5, p.USART1, Irqs, p.DMA1_CH1, p.DMA1_CH2);
|
let irq = irqs!(UART);
|
||||||
#[cfg(feature = "stm32f429zi")]
|
|
||||||
let (tx, rx, usart, irq, tx_dma, rx_dma) = (p.PG14, p.PG9, p.USART6, Irqs, p.DMA2_CH6, p.DMA2_CH1);
|
|
||||||
#[cfg(feature = "stm32wb55rg")]
|
|
||||||
let (tx, rx, usart, irq, tx_dma, rx_dma) = (p.PA2, p.PA3, p.LPUART1, Irqs, p.DMA1_CH1, p.DMA1_CH2);
|
|
||||||
#[cfg(feature = "stm32h755zi")]
|
|
||||||
let (tx, rx, usart, irq, tx_dma, rx_dma) = (p.PB6, p.PB7, p.USART1, Irqs, p.DMA1_CH0, p.DMA1_CH1);
|
|
||||||
#[cfg(feature = "stm32u585ai")]
|
|
||||||
let (tx, rx, usart, irq, tx_dma, rx_dma) = (p.PD8, p.PD9, p.USART3, Irqs, p.GPDMA1_CH0, p.GPDMA1_CH1);
|
|
||||||
#[cfg(feature = "stm32h563zi")]
|
|
||||||
let (tx, rx, usart, irq, tx_dma, rx_dma) = (p.PB6, p.PB7, p.LPUART1, Irqs, p.GPDMA1_CH0, p.GPDMA1_CH1);
|
|
||||||
#[cfg(feature = "stm32c031c6")]
|
|
||||||
let (tx, rx, usart, irq, tx_dma, rx_dma) = (p.PB6, p.PB7, p.USART1, Irqs, p.DMA1_CH1, p.DMA1_CH2);
|
|
||||||
|
|
||||||
let config = Config::default();
|
let config = Config::default();
|
||||||
let usart = Uart::new(usart, rx, tx, irq, tx_dma, rx_dma, config);
|
let usart = Uart::new(usart, rx, tx, irq, tx_dma, rx_dma, config);
|
||||||
|
@ -10,87 +10,10 @@ use common::*;
|
|||||||
use defmt::{assert_eq, panic};
|
use defmt::{assert_eq, panic};
|
||||||
use embassy_executor::Spawner;
|
use embassy_executor::Spawner;
|
||||||
use embassy_stm32::usart::{Config, DataBits, Parity, RingBufferedUartRx, StopBits, Uart, UartTx};
|
use embassy_stm32::usart::{Config, DataBits, Parity, RingBufferedUartRx, StopBits, Uart, UartTx};
|
||||||
use embassy_stm32::{bind_interrupts, peripherals, usart};
|
|
||||||
use embassy_time::{Duration, Timer};
|
use embassy_time::{Duration, Timer};
|
||||||
use rand_chacha::ChaCha8Rng;
|
use rand_chacha::ChaCha8Rng;
|
||||||
use rand_core::{RngCore, SeedableRng};
|
use rand_core::{RngCore, SeedableRng};
|
||||||
|
|
||||||
#[cfg(any(
|
|
||||||
feature = "stm32f103c8",
|
|
||||||
feature = "stm32g491re",
|
|
||||||
feature = "stm32g071rb",
|
|
||||||
feature = "stm32h755zi",
|
|
||||||
feature = "stm32c031c6",
|
|
||||||
))]
|
|
||||||
bind_interrupts!(struct Irqs {
|
|
||||||
USART1 => usart::InterruptHandler<peripherals::USART1>;
|
|
||||||
});
|
|
||||||
|
|
||||||
#[cfg(feature = "stm32u585ai")]
|
|
||||||
bind_interrupts!(struct Irqs {
|
|
||||||
USART3 => usart::InterruptHandler<peripherals::USART3>;
|
|
||||||
});
|
|
||||||
|
|
||||||
#[cfg(feature = "stm32f429zi")]
|
|
||||||
bind_interrupts!(struct Irqs {
|
|
||||||
USART1 => usart::InterruptHandler<peripherals::USART1>;
|
|
||||||
USART6 => usart::InterruptHandler<peripherals::USART6>;
|
|
||||||
});
|
|
||||||
|
|
||||||
#[cfg(any(feature = "stm32wb55rg", feature = "stm32h563zi"))]
|
|
||||||
bind_interrupts!(struct Irqs {
|
|
||||||
LPUART1 => usart::InterruptHandler<peripherals::LPUART1>;
|
|
||||||
});
|
|
||||||
|
|
||||||
#[cfg(feature = "stm32f103c8")]
|
|
||||||
mod board {
|
|
||||||
pub type Uart = embassy_stm32::peripherals::USART1;
|
|
||||||
pub type TxDma = embassy_stm32::peripherals::DMA1_CH4;
|
|
||||||
pub type RxDma = embassy_stm32::peripherals::DMA1_CH5;
|
|
||||||
}
|
|
||||||
#[cfg(feature = "stm32g491re")]
|
|
||||||
mod board {
|
|
||||||
pub type Uart = embassy_stm32::peripherals::USART1;
|
|
||||||
pub type TxDma = embassy_stm32::peripherals::DMA1_CH1;
|
|
||||||
pub type RxDma = embassy_stm32::peripherals::DMA1_CH2;
|
|
||||||
}
|
|
||||||
#[cfg(feature = "stm32g071rb")]
|
|
||||||
mod board {
|
|
||||||
pub type Uart = embassy_stm32::peripherals::USART1;
|
|
||||||
pub type TxDma = embassy_stm32::peripherals::DMA1_CH1;
|
|
||||||
pub type RxDma = embassy_stm32::peripherals::DMA1_CH2;
|
|
||||||
}
|
|
||||||
#[cfg(feature = "stm32f429zi")]
|
|
||||||
mod board {
|
|
||||||
pub type Uart = embassy_stm32::peripherals::USART6;
|
|
||||||
pub type TxDma = embassy_stm32::peripherals::DMA2_CH6;
|
|
||||||
pub type RxDma = embassy_stm32::peripherals::DMA2_CH1;
|
|
||||||
}
|
|
||||||
#[cfg(feature = "stm32wb55rg")]
|
|
||||||
mod board {
|
|
||||||
pub type Uart = embassy_stm32::peripherals::LPUART1;
|
|
||||||
pub type TxDma = embassy_stm32::peripherals::DMA1_CH1;
|
|
||||||
pub type RxDma = embassy_stm32::peripherals::DMA1_CH2;
|
|
||||||
}
|
|
||||||
#[cfg(feature = "stm32h755zi")]
|
|
||||||
mod board {
|
|
||||||
pub type Uart = embassy_stm32::peripherals::USART1;
|
|
||||||
pub type TxDma = embassy_stm32::peripherals::DMA1_CH0;
|
|
||||||
pub type RxDma = embassy_stm32::peripherals::DMA1_CH1;
|
|
||||||
}
|
|
||||||
#[cfg(feature = "stm32u585ai")]
|
|
||||||
mod board {
|
|
||||||
pub type Uart = embassy_stm32::peripherals::USART3;
|
|
||||||
pub type TxDma = embassy_stm32::peripherals::GPDMA1_CH0;
|
|
||||||
pub type RxDma = embassy_stm32::peripherals::GPDMA1_CH1;
|
|
||||||
}
|
|
||||||
#[cfg(feature = "stm32c031c6")]
|
|
||||||
mod board {
|
|
||||||
pub type Uart = embassy_stm32::peripherals::USART1;
|
|
||||||
pub type TxDma = embassy_stm32::peripherals::DMA1_CH1;
|
|
||||||
pub type RxDma = embassy_stm32::peripherals::DMA1_CH2;
|
|
||||||
}
|
|
||||||
|
|
||||||
const DMA_BUF_SIZE: usize = 256;
|
const DMA_BUF_SIZE: usize = 256;
|
||||||
|
|
||||||
#[embassy_executor::main]
|
#[embassy_executor::main]
|
||||||
@ -100,22 +23,12 @@ async fn main(spawner: Spawner) {
|
|||||||
|
|
||||||
// Arduino pins D0 and D1
|
// Arduino pins D0 and D1
|
||||||
// They're connected together with a 1K resistor.
|
// They're connected together with a 1K resistor.
|
||||||
#[cfg(feature = "stm32f103c8")]
|
let usart = peri!(p, UART);
|
||||||
let (tx, rx, usart, tx_dma, rx_dma) = (p.PA9, p.PA10, p.USART1, p.DMA1_CH4, p.DMA1_CH5);
|
let rx = peri!(p, UART_RX);
|
||||||
#[cfg(feature = "stm32g491re")]
|
let tx = peri!(p, UART_TX);
|
||||||
let (tx, rx, usart, tx_dma, rx_dma) = (p.PC4, p.PC5, p.USART1, p.DMA1_CH1, p.DMA1_CH2);
|
let rx_dma = peri!(p, UART_RX_DMA);
|
||||||
#[cfg(feature = "stm32g071rb")]
|
let tx_dma = peri!(p, UART_TX_DMA);
|
||||||
let (tx, rx, usart, tx_dma, rx_dma) = (p.PC4, p.PC5, p.USART1, p.DMA1_CH1, p.DMA1_CH2);
|
let irq = irqs!(UART);
|
||||||
#[cfg(feature = "stm32f429zi")]
|
|
||||||
let (tx, rx, usart, tx_dma, rx_dma) = (p.PG14, p.PG9, p.USART6, p.DMA2_CH6, p.DMA2_CH1);
|
|
||||||
#[cfg(feature = "stm32wb55rg")]
|
|
||||||
let (tx, rx, usart, tx_dma, rx_dma) = (p.PA2, p.PA3, p.LPUART1, p.DMA1_CH1, p.DMA1_CH2);
|
|
||||||
#[cfg(feature = "stm32h755zi")]
|
|
||||||
let (tx, rx, usart, tx_dma, rx_dma) = (p.PB6, p.PB7, p.USART1, p.DMA1_CH0, p.DMA1_CH1);
|
|
||||||
#[cfg(feature = "stm32u585ai")]
|
|
||||||
let (tx, rx, usart, tx_dma, rx_dma) = (p.PD8, p.PD9, p.USART3, p.GPDMA1_CH0, p.GPDMA1_CH1);
|
|
||||||
#[cfg(feature = "stm32c031c6")]
|
|
||||||
let (tx, rx, usart, tx_dma, rx_dma) = (p.PB6, p.PB7, p.USART1, p.DMA1_CH1, p.DMA1_CH2);
|
|
||||||
|
|
||||||
// To run this test, use the saturating_serial test utility to saturate the serial port
|
// To run this test, use the saturating_serial test utility to saturate the serial port
|
||||||
|
|
||||||
@ -127,7 +40,7 @@ async fn main(spawner: Spawner) {
|
|||||||
config.stop_bits = StopBits::STOP1;
|
config.stop_bits = StopBits::STOP1;
|
||||||
config.parity = Parity::ParityNone;
|
config.parity = Parity::ParityNone;
|
||||||
|
|
||||||
let usart = Uart::new(usart, rx, tx, Irqs, tx_dma, rx_dma, config);
|
let usart = Uart::new(usart, rx, tx, irq, tx_dma, rx_dma, config);
|
||||||
let (tx, rx) = usart.split();
|
let (tx, rx) = usart.split();
|
||||||
static mut DMA_BUF: [u8; DMA_BUF_SIZE] = [0; DMA_BUF_SIZE];
|
static mut DMA_BUF: [u8; DMA_BUF_SIZE] = [0; DMA_BUF_SIZE];
|
||||||
let dma_buf = unsafe { DMA_BUF.as_mut() };
|
let dma_buf = unsafe { DMA_BUF.as_mut() };
|
||||||
@ -139,7 +52,7 @@ async fn main(spawner: Spawner) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[embassy_executor::task]
|
#[embassy_executor::task]
|
||||||
async fn transmit_task(mut tx: UartTx<'static, board::Uart, board::TxDma>) {
|
async fn transmit_task(mut tx: UartTx<'static, peris::UART, peris::UART_TX_DMA>) {
|
||||||
// workaround https://github.com/embassy-rs/embassy/issues/1426
|
// workaround https://github.com/embassy-rs/embassy/issues/1426
|
||||||
Timer::after(Duration::from_millis(100) as _).await;
|
Timer::after(Duration::from_millis(100) as _).await;
|
||||||
|
|
||||||
@ -162,7 +75,7 @@ async fn transmit_task(mut tx: UartTx<'static, board::Uart, board::TxDma>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[embassy_executor::task]
|
#[embassy_executor::task]
|
||||||
async fn receive_task(mut rx: RingBufferedUartRx<'static, board::Uart, board::RxDma>) {
|
async fn receive_task(mut rx: RingBufferedUartRx<'static, peris::UART, peris::UART_RX_DMA>) {
|
||||||
info!("Ready to receive...");
|
info!("Ready to receive...");
|
||||||
|
|
||||||
let mut rng = ChaCha8Rng::seed_from_u64(1337);
|
let mut rng = ChaCha8Rng::seed_from_u64(1337);
|
||||||
|
@ -25,6 +25,91 @@ teleprobe_meta::target!(b"nucleo-stm32h563zi");
|
|||||||
#[cfg(feature = "stm32c031c6")]
|
#[cfg(feature = "stm32c031c6")]
|
||||||
teleprobe_meta::target!(b"nucleo-stm32c031c6");
|
teleprobe_meta::target!(b"nucleo-stm32c031c6");
|
||||||
|
|
||||||
|
macro_rules! define_peris {
|
||||||
|
($($name:ident = $peri:ident,)* $(@irq $irq_name:ident = $irq_code:tt,)*) => {
|
||||||
|
#[allow(unused_macros)]
|
||||||
|
macro_rules! peri {
|
||||||
|
$(
|
||||||
|
($p:expr, $name) => {
|
||||||
|
$p.$peri
|
||||||
|
};
|
||||||
|
)*
|
||||||
|
}
|
||||||
|
#[allow(unused_macros)]
|
||||||
|
macro_rules! irqs {
|
||||||
|
$(
|
||||||
|
($irq_name) => {{
|
||||||
|
embassy_stm32::bind_interrupts!(struct Irqs $irq_code);
|
||||||
|
Irqs
|
||||||
|
}};
|
||||||
|
)*
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(unused)]
|
||||||
|
#[allow(non_camel_case_types)]
|
||||||
|
pub mod peris {
|
||||||
|
$(
|
||||||
|
pub type $name = embassy_stm32::peripherals::$peri;
|
||||||
|
)*
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "stm32f103c8")]
|
||||||
|
define_peris!(
|
||||||
|
UART = USART1, UART_TX = PA9, UART_RX = PA10, UART_TX_DMA = DMA1_CH4, UART_RX_DMA = DMA1_CH5,
|
||||||
|
SPI = SPI1, SPI_SCK = PA5, SPI_MOSI = PA7, SPI_MISO = PA6, SPI_TX_DMA = DMA1_CH3, SPI_RX_DMA = DMA1_CH2,
|
||||||
|
@irq UART = {USART1 => embassy_stm32::usart::InterruptHandler<embassy_stm32::peripherals::USART1>;},
|
||||||
|
);
|
||||||
|
#[cfg(feature = "stm32g491re")]
|
||||||
|
define_peris!(
|
||||||
|
UART = USART1, UART_TX = PC4, UART_RX = PC5, UART_TX_DMA = DMA1_CH1, UART_RX_DMA = DMA1_CH2,
|
||||||
|
SPI = SPI1, SPI_SCK = PA5, SPI_MOSI = PA7, SPI_MISO = PA6, SPI_TX_DMA = DMA1_CH1, SPI_RX_DMA = DMA1_CH2,
|
||||||
|
@irq UART = {USART1 => embassy_stm32::usart::InterruptHandler<embassy_stm32::peripherals::USART1>;},
|
||||||
|
);
|
||||||
|
#[cfg(feature = "stm32g071rb")]
|
||||||
|
define_peris!(
|
||||||
|
UART = USART1, UART_TX = PC4, UART_RX = PC5, UART_TX_DMA = DMA1_CH1, UART_RX_DMA = DMA1_CH2,
|
||||||
|
SPI = SPI1, SPI_SCK = PA5, SPI_MOSI = PA7, SPI_MISO = PA6, SPI_TX_DMA = DMA1_CH1, SPI_RX_DMA = DMA1_CH2,
|
||||||
|
@irq UART = {USART1 => embassy_stm32::usart::InterruptHandler<embassy_stm32::peripherals::USART1>;},
|
||||||
|
);
|
||||||
|
#[cfg(feature = "stm32f429zi")]
|
||||||
|
define_peris!(
|
||||||
|
UART = USART6, UART_TX = PG14, UART_RX = PG9, UART_TX_DMA = DMA2_CH6, UART_RX_DMA = DMA2_CH1,
|
||||||
|
SPI = SPI1, SPI_SCK = PA5, SPI_MOSI = PA7, SPI_MISO = PA6, SPI_TX_DMA = DMA2_CH3, SPI_RX_DMA = DMA2_CH2,
|
||||||
|
@irq UART = {USART6 => embassy_stm32::usart::InterruptHandler<embassy_stm32::peripherals::USART6>;},
|
||||||
|
);
|
||||||
|
#[cfg(feature = "stm32wb55rg")]
|
||||||
|
define_peris!(
|
||||||
|
UART = LPUART1, UART_TX = PA2, UART_RX = PA3, UART_TX_DMA = DMA1_CH1, UART_RX_DMA = DMA1_CH2,
|
||||||
|
SPI = SPI1, SPI_SCK = PA5, SPI_MOSI = PA7, SPI_MISO = PA6, SPI_TX_DMA = DMA1_CH1, SPI_RX_DMA = DMA1_CH2,
|
||||||
|
@irq UART = {LPUART1 => embassy_stm32::usart::InterruptHandler<embassy_stm32::peripherals::LPUART1>;},
|
||||||
|
);
|
||||||
|
#[cfg(feature = "stm32h755zi")]
|
||||||
|
define_peris!(
|
||||||
|
UART = USART1, UART_TX = PB6, UART_RX = PB7, UART_TX_DMA = DMA1_CH0, UART_RX_DMA = DMA1_CH1,
|
||||||
|
SPI = SPI1, SPI_SCK = PA5, SPI_MOSI = PB5, SPI_MISO = PA6, SPI_TX_DMA = DMA1_CH0, SPI_RX_DMA = DMA1_CH1,
|
||||||
|
@irq UART = {USART1 => embassy_stm32::usart::InterruptHandler<embassy_stm32::peripherals::USART1>;},
|
||||||
|
);
|
||||||
|
#[cfg(feature = "stm32u585ai")]
|
||||||
|
define_peris!(
|
||||||
|
UART = USART3, UART_TX = PD8, UART_RX = PD9, UART_TX_DMA = GPDMA1_CH0, UART_RX_DMA = GPDMA1_CH1,
|
||||||
|
SPI = SPI1, SPI_SCK = PE13, SPI_MOSI = PE15, SPI_MISO = PE14, SPI_TX_DMA = GPDMA1_CH0, SPI_RX_DMA = GPDMA1_CH1,
|
||||||
|
@irq UART = {USART3 => embassy_stm32::usart::InterruptHandler<embassy_stm32::peripherals::USART3>;},
|
||||||
|
);
|
||||||
|
#[cfg(feature = "stm32h563zi")]
|
||||||
|
define_peris!(
|
||||||
|
UART = LPUART1, UART_TX = PB6, UART_RX = PB7, UART_TX_DMA = GPDMA1_CH0, UART_RX_DMA = GPDMA1_CH1,
|
||||||
|
SPI = SPI4, SPI_SCK = PE12, SPI_MOSI = PE14, SPI_MISO = PE13, SPI_TX_DMA = GPDMA1_CH0, SPI_RX_DMA = GPDMA1_CH1,
|
||||||
|
@irq UART = {LPUART1 => embassy_stm32::usart::InterruptHandler<embassy_stm32::peripherals::LPUART1>;},
|
||||||
|
);
|
||||||
|
#[cfg(feature = "stm32c031c6")]
|
||||||
|
define_peris!(
|
||||||
|
UART = USART1, UART_TX = PB6, UART_RX = PB7, UART_TX_DMA = DMA1_CH1, UART_RX_DMA = DMA1_CH2,
|
||||||
|
SPI = SPI1, SPI_SCK = PA5, SPI_MOSI = PA7, SPI_MISO = PA6, SPI_TX_DMA = DMA1_CH1, SPI_RX_DMA = DMA1_CH2,
|
||||||
|
@irq UART = {USART1 => embassy_stm32::usart::InterruptHandler<embassy_stm32::peripherals::USART1>;},
|
||||||
|
);
|
||||||
|
|
||||||
pub fn config() -> Config {
|
pub fn config() -> Config {
|
||||||
#[allow(unused_mut)]
|
#[allow(unused_mut)]
|
||||||
let mut config = Config::default();
|
let mut config = Config::default();
|
||||||
|
Loading…
Reference in New Issue
Block a user