SPIv2 + DMA.
This commit is contained in:
@ -17,6 +17,7 @@ use embassy_stm32::time::Hertz;
|
||||
use embedded_hal::blocking::spi::Transfer;
|
||||
use embedded_hal::digital::v2::OutputPin;
|
||||
use example_common::*;
|
||||
use embassy_stm32::dma::NoDma;
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
@ -41,6 +42,8 @@ fn main() -> ! {
|
||||
p.PC10,
|
||||
p.PC12,
|
||||
p.PC11,
|
||||
NoDma,
|
||||
NoDma,
|
||||
Hertz(1_000_000),
|
||||
Config::default(),
|
||||
);
|
||||
|
103
examples/stm32l4/src/bin/spi_dma.rs
Normal file
103
examples/stm32l4/src/bin/spi_dma.rs
Normal file
@ -0,0 +1,103 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(trait_alias)]
|
||||
#![feature(min_type_alias_impl_trait)]
|
||||
#![feature(impl_trait_in_bindings)]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
#[path = "../example_common.rs"]
|
||||
mod example_common;
|
||||
|
||||
use cortex_m_rt::entry;
|
||||
use embassy::executor::Executor;
|
||||
use embassy::time::Clock;
|
||||
use embassy::util::Forever;
|
||||
use embassy_stm32::pac;
|
||||
use example_common::*;
|
||||
use embassy_stm32::spi::{Spi, Config};
|
||||
use embassy_traits::spi::FullDuplex;
|
||||
use embassy_stm32::time::Hertz;
|
||||
use embassy_stm32::gpio::{Output, Level, Speed};
|
||||
use embedded_hal::digital::v2::OutputPin;
|
||||
|
||||
#[embassy::task]
|
||||
async fn main_task() {
|
||||
let p = embassy_stm32::init(Default::default());
|
||||
|
||||
let mut spi = Spi::new(
|
||||
p.SPI3,
|
||||
p.PC10,
|
||||
p.PC12,
|
||||
p.PC11,
|
||||
p.DMA1_CH0,
|
||||
p.DMA1_CH1,
|
||||
Hertz(1_000_000),
|
||||
Config::default(),
|
||||
);
|
||||
|
||||
let mut cs = Output::new(p.PE0, Level::High, Speed::VeryHigh);
|
||||
|
||||
loop {
|
||||
let write = [0x0A; 10];
|
||||
let mut read = [0; 10];
|
||||
unwrap!(cs.set_low());
|
||||
spi.read_write(&mut read, &write).await.ok();
|
||||
unwrap!(cs.set_high());
|
||||
info!("xfer {=[u8]:x}", read);
|
||||
}
|
||||
}
|
||||
|
||||
struct ZeroClock;
|
||||
|
||||
impl Clock for ZeroClock {
|
||||
fn now(&self) -> u64 {
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
static EXECUTOR: Forever<Executor> = Forever::new();
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
info!("Hello World!");
|
||||
|
||||
unsafe {
|
||||
pac::DBGMCU.cr().modify(|w| {
|
||||
w.set_dbg_sleep(true);
|
||||
w.set_dbg_standby(true);
|
||||
w.set_dbg_stop(true);
|
||||
});
|
||||
|
||||
//pac::RCC.apbenr().modify(|w| {
|
||||
//w.set_spi3en(true);
|
||||
// });
|
||||
|
||||
pac::RCC.apb2enr().modify(|w| {
|
||||
w.set_syscfgen(true);
|
||||
});
|
||||
|
||||
pac::RCC.ahb1enr().modify(|w| {
|
||||
w.set_dmamux1en(true);
|
||||
w.set_dma1en(true);
|
||||
w.set_dma2en(true);
|
||||
});
|
||||
|
||||
pac::RCC.ahb2enr().modify(|w| {
|
||||
w.set_gpioaen(true);
|
||||
w.set_gpioben(true);
|
||||
w.set_gpiocen(true);
|
||||
w.set_gpioden(true);
|
||||
w.set_gpioeen(true);
|
||||
w.set_gpiofen(true);
|
||||
});
|
||||
}
|
||||
|
||||
unsafe { embassy::time::set_clock(&ZeroClock) };
|
||||
|
||||
let executor = EXECUTOR.put(Executor::new());
|
||||
|
||||
executor.run(|spawner| {
|
||||
unwrap!(spawner.spawn(main_task()));
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user