Skip to content

Commit 239e790

Browse files
ForsakenHarmonykorken89
authored andcommitted
feat: add spi rx dma (and migrate to embedded-dma)
1 parent 158315f commit 239e790

File tree

8 files changed

+547
-177
lines changed

8 files changed

+547
-177
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ edition = "2018"
2424
cortex-m = "0.6.3"
2525
nb = "0.1.1"
2626
stm32l4 = "0.13.0"
27+
embedded-dma = "0.1"
2728

2829
[dependencies.rand_core]
2930
version = "0.6.2"

examples/rtic_frame_serial_dma.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
use hal::{
1414
dma::{self, DMAFrame, FrameReader, FrameSender},
15+
pac::USART2,
1516
prelude::*,
1617
rcc::{ClockSecuritySystem, CrystalBypass, MsiFreq},
1718
serial::{self, Config, Serial},
@@ -23,6 +24,8 @@ use heapless::{
2324
use panic_halt as _;
2425
use rtic::app;
2526
use stm32l4xx_hal as hal;
27+
use stm32l4xx_hal::dma::{RxDma, TxDma};
28+
use stm32l4xx_hal::serial::{Rx, Tx};
2629

2730
// The pool gives out `Box<DMAFrame>`s that can hold 8 bytes
2831
pool!(
@@ -34,8 +37,8 @@ pool!(
3437
const APP: () = {
3538
struct Resources {
3639
rx: serial::Rx<hal::stm32::USART2>,
37-
frame_reader: FrameReader<Box<SerialDMAPool>, dma::dma1::C6, 8>,
38-
frame_sender: FrameSender<Box<SerialDMAPool>, dma::dma1::C7, 8>,
40+
frame_reader: FrameReader<Box<SerialDMAPool>, RxDma<Rx<USART2>, dma::dma1::C6>, 8>,
41+
frame_sender: FrameSender<Box<SerialDMAPool>, TxDma<Tx<USART2>, dma::dma1::C7>, 8>,
3942
}
4043

4144
#[init]
@@ -88,13 +91,13 @@ const APP: () = {
8891
let fr = if let Some(dma_buf) = SerialDMAPool::alloc() {
8992
// Set up the first reader frame
9093
let dma_buf = dma_buf.init(DMAFrame::new());
91-
serial_rx.frame_read(dma_ch6, dma_buf)
94+
serial_rx.with_dma(dma_ch6).frame_read(dma_buf)
9295
} else {
9396
unreachable!()
9497
};
9598

9699
// Serial frame sender (DMA based)
97-
let fs: FrameSender<Box<SerialDMAPool>, _, 8> = serial_tx.frame_sender(dma_ch7);
100+
let fs: FrameSender<Box<SerialDMAPool>, _, 8> = serial_tx.with_dma(dma_ch7).frame_sender();
98101

99102
init::LateResources {
100103
rx: serial_rx,

examples/serial_dma.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ extern crate stm32l4xx_hal as hal;
1818
// #[macro_use(block)]
1919
// extern crate nb;
2020

21-
use crate::hal::dma::Half;
21+
use crate::hal::dma::{CircReadDma, Half};
2222
use crate::hal::prelude::*;
2323
use crate::hal::serial::{Config, Serial};
2424
use crate::rt::ExceptionFrame;
@@ -68,7 +68,7 @@ fn main() -> ! {
6868

6969
let buf = singleton!(: [[u8; 8]; 2] = [[0; 8]; 2]).unwrap();
7070

71-
let mut circ_buffer = rx.circ_read(channels.5, buf);
71+
let mut circ_buffer = rx.with_dma(channels.5).circ_read(buf);
7272

7373
for _ in 0..2 {
7474
while circ_buffer.readable_half().unwrap() != Half::First {}

examples/serial_dma_partial_peek.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ extern crate stm32l4xx_hal as hal;
2020

2121
use crate::cortex_m::asm;
2222
use crate::hal::delay::Delay;
23+
use crate::hal::dma::CircReadDma;
2324
use crate::hal::prelude::*;
2425
use crate::hal::serial::{Config, Serial};
2526
use crate::rt::ExceptionFrame;
@@ -71,7 +72,7 @@ fn main() -> ! {
7172

7273
let buf = singleton!(: [[u8; 8]; 2] = [[0; 8]; 2]).unwrap();
7374

74-
let mut circ_buffer = rx.circ_read(channels.5, buf);
75+
let mut circ_buffer = rx.with_dma(channels.5).circ_read(buf);
7576

7677
// wait for 3 seconds, enter data on serial
7778
timer.delay_ms(1000_u32);

examples/serial_dma_us2.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ extern crate stm32l4xx_hal as hal;
1818
// #[macro_use(block)]
1919
// extern crate nb;
2020

21-
use crate::hal::dma::Half;
21+
use crate::hal::dma::{CircReadDma, Half};
2222
use crate::hal::prelude::*;
2323
use crate::hal::serial::{Config, Serial};
2424
use crate::rt::ExceptionFrame;
@@ -67,7 +67,7 @@ fn main() -> ! {
6767

6868
let buf = singleton!(: [[u8; 8]; 2] = [[0; 8]; 2]).unwrap();
6969

70-
let mut circ_buffer = rx.circ_read(channels.6, buf);
70+
let mut circ_buffer = rx.with_dma(channels.6).circ_read(buf);
7171

7272
for _ in 0..2 {
7373
while circ_buffer.readable_half().unwrap() != Half::First {}

0 commit comments

Comments
 (0)