From e92094986d1f7845539250ad2833069c49999ae9 Mon Sep 17 00:00:00 2001 From: Caleb Garrett <47389035+caleb-garrett@users.noreply.github.com> Date: Sun, 10 Mar 2024 16:53:37 -0400 Subject: [PATCH 1/3] Add DMA request priority as transfer option. --- embassy-stm32/src/dma/dma_bdma.rs | 63 ++++++++++++++++++++++++++++--- embassy-stm32/src/dma/mod.rs | 8 ++-- embassy-stm32/src/sdmmc/mod.rs | 1 + 3 files changed, 63 insertions(+), 9 deletions(-) diff --git a/embassy-stm32/src/dma/dma_bdma.rs b/embassy-stm32/src/dma/dma_bdma.rs index 08aba2795..5b3243de7 100644 --- a/embassy-stm32/src/dma/dma_bdma.rs +++ b/embassy-stm32/src/dma/dma_bdma.rs @@ -10,7 +10,7 @@ use super::ringbuffer::{DmaCtrl, OverrunError, ReadableDmaRingBuffer, WritableDm use super::word::{Word, WordSize}; use super::{AnyChannel, Channel, Dir, Request, STATE}; use crate::interrupt::typelevel::Interrupt; -use crate::interrupt::Priority; +use crate::interrupt; use crate::pac; pub(crate) struct ChannelInfo { @@ -45,6 +45,8 @@ pub struct TransferOptions { /// FIFO threshold for DMA FIFO mode. If none, direct mode is used. #[cfg(dma)] pub fifo_threshold: Option, + /// Request priority level + pub priority: Priority, /// Enable circular DMA /// /// Note: @@ -68,6 +70,7 @@ impl Default for TransferOptions { flow_ctrl: FlowControl::Dma, #[cfg(dma)] fifo_threshold: None, + priority: Priority::VeryHigh, circular: false, half_transfer_ir: false, complete_transfer_ir: true, @@ -170,6 +173,31 @@ mod dma_only { } } } + + /// DMA request priority + #[derive(Debug, Copy, Clone, PartialEq, Eq)] + #[cfg_attr(feature = "defmt", derive(defmt::Format))] + pub enum Priority { + /// Low Priority + Low, + /// Medium Priority + Medium, + /// High Priority + High, + /// Very High Priority + VeryHigh, + } + + impl From for vals::Pl { + fn from(value: Priority) -> Self { + match value { + Priority::Low => vals::Pl::LOW, + Priority::Medium => vals::Pl::MEDIUM, + Priority::High => vals::Pl::HIGH, + Priority::VeryHigh => vals::Pl::VERYHIGH, + } + } + } } #[cfg(bdma)] @@ -196,6 +224,31 @@ mod bdma_only { } } } + + /// DMA request priority + #[derive(Debug, Copy, Clone, PartialEq, Eq)] + #[cfg_attr(feature = "defmt", derive(defmt::Format))] + pub enum Priority { + /// Low Priority + Low, + /// Medium Priority + Medium, + /// High Priority + High, + /// Very High Priority + VeryHigh, + } + + impl From for vals::Pl { + fn from(value: Priority) -> Self { + match value { + Priority::Low => vals::Pl::LOW, + Priority::Medium => vals::Pl::MEDIUM, + Priority::High => vals::Pl::HIGH, + Priority::VeryHigh => vals::Pl::VERYHIGH, + } + } + } } pub(crate) struct ChannelState { @@ -213,8 +266,8 @@ impl ChannelState { /// safety: must be called only once pub(crate) unsafe fn init( cs: critical_section::CriticalSection, - #[cfg(dma)] dma_priority: Priority, - #[cfg(bdma)] bdma_priority: Priority, + #[cfg(dma)] dma_priority: interrupt::Priority, + #[cfg(bdma)] bdma_priority: interrupt::Priority, ) { foreach_interrupt! { ($peri:ident, dma, $block:ident, $signal_name:ident, $irq:ident) => { @@ -334,7 +387,7 @@ impl AnyChannel { w.set_dir(dir.into()); w.set_msize(data_size.into()); w.set_psize(data_size.into()); - w.set_pl(pac::dma::vals::Pl::VERYHIGH); + w.set_pl(options.priority.into()); w.set_minc(incr_mem); w.set_pinc(false); w.set_teie(true); @@ -374,7 +427,7 @@ impl AnyChannel { w.set_tcie(options.complete_transfer_ir); w.set_htie(options.half_transfer_ir); w.set_circ(options.circular); - w.set_pl(pac::bdma::vals::Pl::VERYHIGH); + w.set_pl(options.priority.into()); w.set_en(false); // don't start yet }); } diff --git a/embassy-stm32/src/dma/mod.rs b/embassy-stm32/src/dma/mod.rs index 960483f34..d5e88a20a 100644 --- a/embassy-stm32/src/dma/mod.rs +++ b/embassy-stm32/src/dma/mod.rs @@ -23,7 +23,7 @@ use core::mem; use embassy_hal_internal::{impl_peripheral, Peripheral}; -use crate::interrupt::Priority; +use crate::interrupt; #[derive(Debug, Copy, Clone, PartialEq, Eq)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] @@ -131,9 +131,9 @@ pub(crate) fn slice_ptr_parts_mut(slice: *mut [T]) -> (usize, usize) { // safety: must be called only once at startup pub(crate) unsafe fn init( cs: critical_section::CriticalSection, - #[cfg(bdma)] bdma_priority: Priority, - #[cfg(dma)] dma_priority: Priority, - #[cfg(gpdma)] gpdma_priority: Priority, + #[cfg(bdma)] bdma_priority: interrupt::Priority, + #[cfg(dma)] dma_priority: interrupt::Priority, + #[cfg(gpdma)] gpdma_priority: interrupt::Priority, ) { #[cfg(any(dma, bdma))] dma_bdma::init( diff --git a/embassy-stm32/src/sdmmc/mod.rs b/embassy-stm32/src/sdmmc/mod.rs index bf1d2ca9b..4d054aa7b 100644 --- a/embassy-stm32/src/sdmmc/mod.rs +++ b/embassy-stm32/src/sdmmc/mod.rs @@ -240,6 +240,7 @@ const DMA_TRANSFER_OPTIONS: crate::dma::TransferOptions = crate::dma::TransferOp mburst: crate::dma::Burst::Incr4, flow_ctrl: crate::dma::FlowControl::Peripheral, fifo_threshold: Some(crate::dma::FifoThreshold::Full), + priority: crate::dma::Priority::VeryHigh, circular: false, half_transfer_ir: false, complete_transfer_ir: true, From 50a7ada0bbc4ee8b93d1ec364a5fbf5e4e5eccf7 Mon Sep 17 00:00:00 2001 From: Caleb Garrett <47389035+caleb-garrett@users.noreply.github.com> Date: Sun, 10 Mar 2024 17:28:53 -0400 Subject: [PATCH 2/3] Fixed DMA CI build issues. --- embassy-stm32/src/dma/dma_bdma.rs | 91 +++++++++++++------------------ 1 file changed, 39 insertions(+), 52 deletions(-) diff --git a/embassy-stm32/src/dma/dma_bdma.rs b/embassy-stm32/src/dma/dma_bdma.rs index 5b3243de7..7b5b3cf58 100644 --- a/embassy-stm32/src/dma/dma_bdma.rs +++ b/embassy-stm32/src/dma/dma_bdma.rs @@ -10,8 +10,7 @@ use super::ringbuffer::{DmaCtrl, OverrunError, ReadableDmaRingBuffer, WritableDm use super::word::{Word, WordSize}; use super::{AnyChannel, Channel, Dir, Request, STATE}; use crate::interrupt::typelevel::Interrupt; -use crate::interrupt; -use crate::pac; +use crate::{interrupt, pac}; pub(crate) struct ChannelInfo { pub(crate) dma: DmaInfo, @@ -78,6 +77,44 @@ impl Default for TransferOptions { } } +/// DMA request priority +#[derive(Debug, Copy, Clone, PartialEq, Eq)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] +pub enum Priority { + /// Low Priority + Low, + /// Medium Priority + Medium, + /// High Priority + High, + /// Very High Priority + VeryHigh, +} + +#[cfg(dma)] +impl From for pac::dma::vals::Pl { + fn from(value: Priority) -> Self { + match value { + Priority::Low => pac::dma::vals::Pl::LOW, + Priority::Medium => pac::dma::vals::Pl::MEDIUM, + Priority::High => pac::dma::vals::Pl::HIGH, + Priority::VeryHigh => pac::dma::vals::Pl::VERYHIGH, + } + } +} + +#[cfg(bdma)] +impl From for pac::bdma::vals::Pl { + fn from(value: Priority) -> Self { + match value { + Priority::Low => pac::bdma::vals::Pl::LOW, + Priority::Medium => pac::bdma::vals::Pl::MEDIUM, + Priority::High => pac::bdma::vals::Pl::HIGH, + Priority::VeryHigh => pac::bdma::vals::Pl::VERYHIGH, + } + } +} + #[cfg(dma)] pub use dma_only::*; #[cfg(dma)] @@ -173,31 +210,6 @@ mod dma_only { } } } - - /// DMA request priority - #[derive(Debug, Copy, Clone, PartialEq, Eq)] - #[cfg_attr(feature = "defmt", derive(defmt::Format))] - pub enum Priority { - /// Low Priority - Low, - /// Medium Priority - Medium, - /// High Priority - High, - /// Very High Priority - VeryHigh, - } - - impl From for vals::Pl { - fn from(value: Priority) -> Self { - match value { - Priority::Low => vals::Pl::LOW, - Priority::Medium => vals::Pl::MEDIUM, - Priority::High => vals::Pl::HIGH, - Priority::VeryHigh => vals::Pl::VERYHIGH, - } - } - } } #[cfg(bdma)] @@ -224,31 +236,6 @@ mod bdma_only { } } } - - /// DMA request priority - #[derive(Debug, Copy, Clone, PartialEq, Eq)] - #[cfg_attr(feature = "defmt", derive(defmt::Format))] - pub enum Priority { - /// Low Priority - Low, - /// Medium Priority - Medium, - /// High Priority - High, - /// Very High Priority - VeryHigh, - } - - impl From for vals::Pl { - fn from(value: Priority) -> Self { - match value { - Priority::Low => vals::Pl::LOW, - Priority::Medium => vals::Pl::MEDIUM, - Priority::High => vals::Pl::HIGH, - Priority::VeryHigh => vals::Pl::VERYHIGH, - } - } - } } pub(crate) struct ChannelState { From 4a5b6e05fb806d70747e2abb2da7c90eeba0dc41 Mon Sep 17 00:00:00 2001 From: Caleb Garrett <47389035+caleb-garrett@users.noreply.github.com> Date: Sun, 10 Mar 2024 17:33:40 -0400 Subject: [PATCH 3/3] Correct more CI build issues. --- embassy-stm32/src/sdmmc/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/embassy-stm32/src/sdmmc/mod.rs b/embassy-stm32/src/sdmmc/mod.rs index 4d054aa7b..fa1f710d8 100644 --- a/embassy-stm32/src/sdmmc/mod.rs +++ b/embassy-stm32/src/sdmmc/mod.rs @@ -247,6 +247,7 @@ const DMA_TRANSFER_OPTIONS: crate::dma::TransferOptions = crate::dma::TransferOp }; #[cfg(all(sdmmc_v1, not(dma)))] const DMA_TRANSFER_OPTIONS: crate::dma::TransferOptions = crate::dma::TransferOptions { + priority: crate::dma::Priority::VeryHigh, circular: false, half_transfer_ir: false, complete_transfer_ir: true,