Skip to content

Commit f93b505

Browse files
authored
Add stm32l4r9 support (#270)
* src/dma.rs: disable `cselr` for stm32l4+ The stm32l4+ devices do not have this register, but use a separate peripheral (DMAMUX) for routing between peripherals and DMA controllers. * src/rcc/enable.rs: fix some issues for stm32l4+ * src/i2c.rs: define stm32l4+ pins * src/spi.rs: add `unsafe` where required by stm32l4r9 PAC. To make this implementation also usable by stm32l4+ devices, some additional use of `unsafe` is necessary because of PAC differences. * src/timer.rs: disable creation of TIM4 for stm32l4+ because of PAC error. In the current release of the stm32l4 PAC, the `cnt` register of TIM3 and tim4 have an incorrect width. This was fixed in stm32-rs#669, once this is included in the next release, we will be able to start using TIM3 and TIM4. * Create module dmamux.rs as common interface for DMA request mapping. The new stm32l4+ devices use a separate peripheral (DMAMUX) for routing a DMA request line between peripherals and DMA controllers, whereas the "old" stm32l4 devices use the `CSELR` register for request mapping. This module tries to abstract this difference, and provides a common interface for all L4 devices. This commit also enable the DMAMUX clock when required. * Use new dmamux interface in adc.rs, serial.rs and spi.rs * src/lib.rs: enable most modules for stm32l4+ devices as well
1 parent c3b68e8 commit f93b505

File tree

9 files changed

+794
-59
lines changed

9 files changed

+794
-59
lines changed

src/adc.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use core::{
88

99
use crate::{
1010
dma::{dma1, Event as DMAEvent, RxDma, Transfer, TransferPayload, W},
11+
dmamux::{DmaInput, DmaMux},
1112
gpio::{self, Analog},
1213
hal::{
1314
adc::{Channel as EmbeddedHalChannel, OneShot},
@@ -526,7 +527,7 @@ where
526527
channel.set_memory_address(buffer.as_ptr() as u32, true);
527528
channel.set_transfer_length(N as u16);
528529

529-
channel.cselr().modify(|_, w| w.c1s().bits(0b0000));
530+
channel.set_request_line(DmaInput::Adc1).unwrap();
530531

531532
channel.ccr().modify(|_, w| unsafe {
532533
w.mem2mem()

src/dma.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,16 @@ macro_rules! dma {
644644
unsafe { &(*$DMAX::ptr()).$cmarX }
645645
}
646646

647+
#[cfg(not(any(
648+
// feature = "stm32l4p5",
649+
// feature = "stm32l4q5",
650+
// feature = "stm32l4r5",
651+
// feature = "stm32l4s5",
652+
// feature = "stm32l4r7",
653+
// feature = "stm32l4s7",
654+
feature = "stm32l4r9",
655+
feature = "stm32l4s9"
656+
)))]
647657
#[inline]
648658
pub(crate) fn cselr(&mut self) -> &dma1::CSELR {
649659
unsafe { &(*$DMAX::ptr()).cselr }
@@ -1072,6 +1082,18 @@ macro_rules! dma {
10721082
fn split(self, ahb: &mut AHB1) -> Channels {
10731083
<$DMAX>::enable(ahb);
10741084

1085+
#[cfg(any(
1086+
// feature = "stm32l4p5",
1087+
// feature = "stm32l4q5",
1088+
// feature = "stm32l4r5",
1089+
// feature = "stm32l4s5",
1090+
// feature = "stm32l4r7",
1091+
// feature = "stm32l4s7",
1092+
feature = "stm32l4r9",
1093+
feature = "stm32l4s9"
1094+
))]
1095+
ahb.enr().modify(|_, w| w.dmamux1en().set_bit());
1096+
10751097
// reset the DMA control registers (stops all on-going transfers)
10761098
$(
10771099
self.$ccrX.reset();

0 commit comments

Comments
 (0)