Skip to content

Commit 624c87e

Browse files
committed
Add BDMA2 support for RM0455 parts
This means there is at least some DMA support for these parts, even if the main DMAs aren't supported yet
1 parent 0575235 commit 624c87e

File tree

4 files changed

+69
-10
lines changed

4 files changed

+69
-10
lines changed

Cargo.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,6 @@ required-features = ["rm0433"]
183183
name = "dma"
184184
required-features = ["rm0433"]
185185

186-
[[example]]
187-
name = "i2c4_bdma"
188-
required-features = ["rm0433"]
189-
190186
[[example]]
191187
name = "spi_dma"
192188
required-features = ["rm0433"]

examples/i2c4_bdma.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,20 @@ fn main() -> ! {
7676
}
7777

7878
// Setup the DMA transfer on stream 0
79-
//
80-
// We need to specify the direction with a type annotation
79+
#[cfg(not(feature = "rm0455"))]
8180
let streams = StreamsTuple::new(
8281
dp.BDMA,
8382
ccdr.peripheral.BDMA.low_power(LowPowerMode::Autonomous),
8483
);
84+
#[cfg(feature = "rm0455")]
85+
let streams = StreamsTuple::new(
86+
dp.BDMA2,
87+
ccdr.peripheral.BDMA.low_power(LowPowerMode::Autonomous),
88+
);
8589

8690
let config = BdmaConfig::default().memory_increment(true);
8791

92+
// We need to specify the direction with a type annotation
8893
let mut transfer: Transfer<_, _, PeripheralToMemory, _> = Transfer::init(
8994
streams.0,
9095
i2c,

src/dma/bdma.rs

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
//! BDMA
2+
//!
3+
//! For RM0455 parts, only BDMA2 is implemented
24
35
use super::{
46
config,
@@ -10,17 +12,30 @@ use core::marker::PhantomData;
1012

1113
use crate::{
1214
i2c::I2c,
13-
pac::{self, BDMA, DMAMUX2},
15+
pac,
1416
rcc::{rec, rec::ResetEnable},
1517
//serial::{Rx, Tx},
18+
spi,
1619
};
1720

21+
#[cfg(not(feature = "rm0455"))]
22+
use crate::pac::{BDMA, DMAMUX2};
23+
24+
#[cfg(feature = "rm0455")]
25+
use crate::pac::{BDMA2, DMAMUX2};
26+
1827
use core::ops::Deref;
1928

29+
#[cfg(not(feature = "rm0455"))]
2030
impl Sealed for BDMA {}
31+
#[cfg(feature = "rm0455")]
32+
impl Sealed for BDMA2 {}
2133

2234
/// Type aliases for register blocks
35+
#[cfg(not(feature = "rm0455"))]
2336
pub type BDMARegisterBlock = pac::bdma::RegisterBlock;
37+
#[cfg(feature = "rm0455")]
38+
pub type BDMARegisterBlock = pac::bdma2::RegisterBlock;
2439
pub type DMAMUXRegisterBlock = pac::dmamux2::RegisterBlock;
2540

2641
/// Trait that represents an instance of a BDMA peripheral
@@ -36,6 +51,7 @@ pub trait Instance: Deref<Target = BDMARegisterBlock> + Sealed {
3651
const DMA_MUX_STREAM_OFFSET: usize;
3752
}
3853

54+
#[cfg(not(feature = "rm0455"))]
3955
impl Instance for BDMA {
4056
type Rec = rec::Bdma;
4157

@@ -52,6 +68,23 @@ impl Instance for BDMA {
5268
const DMA_MUX_STREAM_OFFSET: usize = 0;
5369
}
5470

71+
#[cfg(feature = "rm0455")]
72+
impl Instance for BDMA2 {
73+
type Rec = rec::Bdma;
74+
75+
#[inline(always)]
76+
fn ptr() -> *const BDMARegisterBlock {
77+
BDMA2::ptr()
78+
}
79+
80+
#[inline(always)]
81+
fn mux_ptr() -> *const DMAMUXRegisterBlock {
82+
DMAMUX2::ptr()
83+
}
84+
85+
const DMA_MUX_STREAM_OFFSET: usize = 0;
86+
}
87+
5588
/// BDMA interrupts
5689
#[derive(Debug, Clone, Copy)]
5790
pub struct BdmaInterrupts {
@@ -562,20 +595,46 @@ bdma_stream!(
562595
);
563596

564597
/// Type alias for the DMA Request Multiplexer
598+
///
599+
/// TODO: Needs fixing upstream for RM0455
600+
#[cfg(not(feature = "rm0455"))]
565601
pub type DMAReq = pac::dmamux2::ccr::DMAREQ_ID_A;
566602

567603
type P2M = PeripheralToMemory;
568604
type M2P = MemoryToPeripheral;
569605

606+
#[cfg(not(feature = "rm0455"))]
570607
peripheral_target_address!(
571608
(pac::LPUART1, rdr, u8, P2M, DMAReq::LPUART1_RX_DMA),
572609
(pac::LPUART1, tdr, u8, M2P, DMAReq::LPUART1_TX_DMA),
573-
(pac::SPI6, rxdr, u8, P2M, DMAReq::SPI6_RX_DMA),
574-
(pac::SPI6, txdr, u8, M2P, DMAReq::SPI6_TX_DMA),
610+
(
611+
SPI: pac::SPI6,
612+
rxdr,
613+
txdr,
614+
[u8, u16],
615+
DMAReq::SPI6_RX_DMA,
616+
DMAReq::SPI6_TX_DMA
617+
),
575618
(pac::I2C4, rxdr, u8, P2M, DMAReq::I2C4_RX_DMA),
576619
(pac::I2C4, txdr, u8, M2P, DMAReq::I2C4_TX_DMA),
577620
(INNER: I2c<pac::I2C4>, rxdr, u8, P2M, DMAReq::I2C4_RX_DMA),
578621
(INNER: I2c<pac::I2C4>, txdr, u8, M2P, DMAReq::I2C4_TX_DMA),
622+
);
623+
624+
#[cfg(not(feature = "rm0455"))]
625+
peripheral_target_address!(
579626
(pac::SAI4, cha.dr, u32, M2P, DMAReq::SAI4_A_DMA),
580627
(pac::SAI4, chb.dr, u32, P2M, DMAReq::SAI4_B_DMA),
581628
);
629+
630+
// TODO: Remove when fixed upstream
631+
#[cfg(feature = "rm0455")]
632+
peripheral_target_address!(
633+
(pac::LPUART1, rdr, u8, P2M, 9),
634+
(pac::LPUART1, tdr, u8, M2P, 10),
635+
(SPI: pac::SPI6, rxdr, txdr, [u8, u16], 11, 12),
636+
(pac::I2C4, rxdr, u8, P2M, 13),
637+
(pac::I2C4, txdr, u8, M2P, 14),
638+
(INNER: I2c<pac::I2C4>, rxdr, u8, P2M, 13),
639+
(INNER: I2c<pac::I2C4>, txdr, u8, M2P, 14),
640+
);

src/dma/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ mod macros;
3232
#[cfg(not(feature = "rm0455"))] // Remove when fixed upstream
3333
pub mod dma; // DMA1 and DMA2
3434

35-
#[cfg(not(feature = "rm0455"))] // Remove when fixed upstream
3635
pub mod bdma;
3736

3837
pub mod traits;

0 commit comments

Comments
 (0)