stm32: Add basic support for DMA priority settings

This commit is contained in:
Matous Hybl 2022-11-23 10:11:19 +01:00
parent cea29d7de3
commit 4cc0463123
4 changed files with 31 additions and 8 deletions

View File

@ -3,6 +3,7 @@
use core::sync::atomic::{fence, Ordering}; use core::sync::atomic::{fence, Ordering};
use core::task::Waker; use core::task::Waker;
use embassy_cortex_m::interrupt::Priority;
use embassy_sync::waitqueue::AtomicWaker; use embassy_sync::waitqueue::AtomicWaker;
use super::{TransferOptions, Word, WordSize}; use super::{TransferOptions, Word, WordSize};
@ -38,10 +39,12 @@ impl State {
static STATE: State = State::new(); static STATE: State = State::new();
/// safety: must be called only once /// safety: must be called only once
pub(crate) unsafe fn init() { pub(crate) unsafe fn init(irq_priority: Priority) {
foreach_interrupt! { foreach_interrupt! {
($peri:ident, bdma, $block:ident, $signal_name:ident, $irq:ident) => { ($peri:ident, bdma, $block:ident, $signal_name:ident, $irq:ident) => {
crate::interrupt::$irq::steal().enable(); let irq = crate::interrupt::$irq::steal();
irq.set_priority(irq_priority);
irq.enable();
}; };
} }
crate::_generated::init_bdma(); crate::_generated::init_bdma();

View File

@ -1,6 +1,7 @@
use core::sync::atomic::{fence, Ordering}; use core::sync::atomic::{fence, Ordering};
use core::task::Waker; use core::task::Waker;
use embassy_cortex_m::interrupt::Priority;
use embassy_sync::waitqueue::AtomicWaker; use embassy_sync::waitqueue::AtomicWaker;
use super::{Burst, FlowControl, Request, TransferOptions, Word, WordSize}; use super::{Burst, FlowControl, Request, TransferOptions, Word, WordSize};
@ -67,10 +68,12 @@ impl State {
static STATE: State = State::new(); static STATE: State = State::new();
/// safety: must be called only once /// safety: must be called only once
pub(crate) unsafe fn init() { pub(crate) unsafe fn init(irq_priority: Priority) {
foreach_interrupt! { foreach_interrupt! {
($peri:ident, dma, $block:ident, $signal_name:ident, $irq:ident) => { ($peri:ident, dma, $block:ident, $signal_name:ident, $irq:ident) => {
interrupt::$irq::steal().enable(); let irq = interrupt::$irq::steal();
irq.set_priority(irq_priority);
irq.enable();
}; };
} }
crate::_generated::init_dma(); crate::_generated::init_dma();

View File

@ -12,6 +12,8 @@ use core::mem;
use core::pin::Pin; use core::pin::Pin;
use core::task::{Context, Poll, Waker}; use core::task::{Context, Poll, Waker};
#[cfg(any(dma, bdma))]
use embassy_cortex_m::interrupt::Priority;
use embassy_hal_common::{impl_peripheral, into_ref}; use embassy_hal_common::{impl_peripheral, into_ref};
#[cfg(dmamux)] #[cfg(dmamux)]
@ -294,11 +296,11 @@ pub struct NoDma;
impl_peripheral!(NoDma); impl_peripheral!(NoDma);
// safety: must be called only once at startup // safety: must be called only once at startup
pub(crate) unsafe fn init() { pub(crate) unsafe fn init(#[cfg(bdma)] bdma_priority: Priority, #[cfg(dma)] dma_priority: Priority) {
#[cfg(bdma)] #[cfg(bdma)]
bdma::init(); bdma::init(bdma_priority);
#[cfg(dma)] #[cfg(dma)]
dma::init(); dma::init(dma_priority);
#[cfg(dmamux)] #[cfg(dmamux)]
dmamux::init(); dmamux::init();
#[cfg(gpdma)] #[cfg(gpdma)]

View File

@ -79,6 +79,8 @@ pub(crate) mod _generated {
// Reexports // Reexports
pub use _generated::{peripherals, Peripherals}; pub use _generated::{peripherals, Peripherals};
pub use embassy_cortex_m::executor; pub use embassy_cortex_m::executor;
#[cfg(any(dma, bdma))]
use embassy_cortex_m::interrupt::Priority;
pub use embassy_cortex_m::interrupt::_export::interrupt; pub use embassy_cortex_m::interrupt::_export::interrupt;
pub use embassy_hal_common::{into_ref, Peripheral, PeripheralRef}; pub use embassy_hal_common::{into_ref, Peripheral, PeripheralRef};
#[cfg(feature = "unstable-pac")] #[cfg(feature = "unstable-pac")]
@ -91,6 +93,10 @@ pub struct Config {
pub rcc: rcc::Config, pub rcc: rcc::Config,
#[cfg(dbgmcu)] #[cfg(dbgmcu)]
pub enable_debug_during_sleep: bool, pub enable_debug_during_sleep: bool,
#[cfg(bdma)]
pub bdma_interrupt_priority: Priority,
#[cfg(dma)]
pub dma_interrupt_priority: Priority,
} }
impl Default for Config { impl Default for Config {
@ -99,6 +105,10 @@ impl Default for Config {
rcc: Default::default(), rcc: Default::default(),
#[cfg(dbgmcu)] #[cfg(dbgmcu)]
enable_debug_during_sleep: true, enable_debug_during_sleep: true,
#[cfg(bdma)]
bdma_interrupt_priority: Priority::P0,
#[cfg(dma)]
dma_interrupt_priority: Priority::P0,
} }
} }
} }
@ -137,7 +147,12 @@ pub fn init(config: Config) -> Peripherals {
} }
gpio::init(); gpio::init();
dma::init(); dma::init(
#[cfg(bdma)]
config.bdma_interrupt_priority,
#[cfg(dma)]
config.dma_interrupt_priority,
);
#[cfg(feature = "exti")] #[cfg(feature = "exti")]
exti::init(); exti::init();