Skip to content

Commit 79bb4fd

Browse files
committed
Bind DMA channel for SPI and I2C
1 parent a684e1d commit 79bb4fd

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

examples/f103c8/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ fn uart_interrupt_init<U: UartPeriphExt + 'static>(
167167
) -> UartPollTask<impl embedded_io::Write + 'static, impl embedded_io::Read + 'static> {
168168
let (rx, mut rx_it) = rx.into_interrupt(64, SysTickTimeout::new(100));
169169
let (tx, mut tx_it) =
170-
tx.into_interrupt(64, SysTickTimeout::new(0), SysTickTimeout::new(20_000));
170+
tx.into_interrupt(32, SysTickTimeout::new(0), SysTickTimeout::new(32 * 200));
171171
interrupt_callback.set(mcu, move || {
172172
rx_it.handler();
173173
tx_it.handler();
@@ -189,7 +189,7 @@ fn uart_dma_init<'r, U: UartPeriphExt + 'static>(
189189
dma_tx,
190190
32,
191191
SysTickTimeout::new(0),
192-
SysTickTimeout::new(20_000),
192+
SysTickTimeout::new(32 * 200),
193193
);
194194
interrupt_callback.set(mcu, move || {
195195
tx_it.interrupt_reload();

scripts/generate_dma_table.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ def match_filter(filter: str, name: str) -> bool:
2020
}
2121

2222

23-
TEMPLATE = """
24-
impl DmaBind{func}<pac::{peri}> for {dma}::{ch} {{}}"""
23+
TEMPLATE = """impl DmaBind{func}<pac::{peri}> for {dma}::{ch} {{}}
24+
"""
2525

2626

2727
def write_item(dma: str, ch: str, func: str, w: Write) -> None:
@@ -32,6 +32,7 @@ def write_item(dma: str, ch: str, func: str, w: Write) -> None:
3232

3333

3434
def write_table(d: dict, filter: str, w: Write) -> None:
35+
w.write("\n")
3536
for dma, ch_table in sorted(d.items()):
3637
for ch, func_list in sorted(ch_table.items()):
3738
for func in sorted(func_list):
@@ -78,6 +79,8 @@ def csv_to_code(csv_file: str, show: bool = False) -> None:
7879
)
7980

8081
write_table(d, "UART", w)
82+
write_table(d, "SPI", w)
83+
write_table(d, "I2C", w)
8184

8285
w.close()
8386
subprocess.run(["rustfmt", target_file])

src/dma.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! # Direct Memory Access
22
3-
use crate::{Steal, common::wrap_trait::*, pac, rcc::Rcc};
3+
use crate::{common::wrap_trait::*, pac, rcc::Rcc, Steal};
44

55
pub use crate::common::dma::*;
66
pub type DmaPriority = pac::dma1::ch::cr::PL;
@@ -227,3 +227,15 @@ impl DmaBindRx<pac::USART2> for dma1::C6 {}
227227
impl DmaBindTx<pac::USART2> for dma1::C7 {}
228228
impl DmaBindRx<pac::UART4> for dma2::C3 {}
229229
impl DmaBindTx<pac::UART4> for dma2::C5 {}
230+
231+
impl DmaBindRx<pac::SPI1> for dma1::C2 {}
232+
impl DmaBindTx<pac::SPI1> for dma1::C3 {}
233+
impl DmaBindRx<pac::SPI2> for dma1::C4 {}
234+
impl DmaBindTx<pac::SPI2> for dma1::C5 {}
235+
impl DmaBindRx<pac::SPI3> for dma2::C1 {}
236+
impl DmaBindTx<pac::SPI3> for dma2::C2 {}
237+
238+
impl DmaBindTx<pac::I2C2> for dma1::C4 {}
239+
impl DmaBindRx<pac::I2C2> for dma1::C5 {}
240+
impl DmaBindTx<pac::I2C1> for dma1::C6 {}
241+
impl DmaBindRx<pac::I2C1> for dma1::C7 {}

0 commit comments

Comments
 (0)