summaryrefslogtreecommitdiff
path: root/examples/stm32l4/src/bin/spi_dma.rs
blob: 4b74c7d7d74b9c331180f312f549bfbf5ba2835d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#![no_std]
#![no_main]
#![feature(type_alias_impl_trait)]

#[path = "../example_common.rs"]
mod example_common;

use embassy::executor::Spawner;
use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
use embassy_stm32::spi::{Config, Spi};
use embassy_stm32::time::Hertz;
use embassy_stm32::Peripherals;
use embassy_traits::spi::FullDuplex;
use embedded_hal::digital::v2::{InputPin, OutputPin};
use example_common::*;

#[embassy::main]
async fn main(_spawner: Spawner, p: Peripherals) {
    info!("Hello World!");

    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(),
    );

    // These are the pins for the Inventek eS-Wifi SPI Wifi Adapter.

    let _boot = Output::new(p.PB12, Level::Low, Speed::VeryHigh);
    let _wake = Output::new(p.PB13, Level::Low, Speed::VeryHigh);
    let mut reset = Output::new(p.PE8, Level::Low, Speed::VeryHigh);
    let mut cs = Output::new(p.PE0, Level::High, Speed::VeryHigh);
    let ready = Input::new(p.PE1, Pull::Up);

    cortex_m::asm::delay(100_000);
    unwrap!(reset.set_high());
    cortex_m::asm::delay(100_000);

    while unwrap!(ready.is_low()) {
        info!("waiting for ready");
    }

    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);
}