stm32f4xx-hal icon indicating copy to clipboard operation
stm32f4xx-hal copied to clipboard

No way to access DMA interrupt source

Open TomasVanRoose opened this issue 3 years ago • 1 comments

When configuring a DMA request, there are 5 different interrupts we can enable. However, inside the interrupt enum fo the crate, there is only one variant for each DMA-Stream combo. There seems to be no way to retrieve what caused the interrupt.

Example

fn dma_init() {
    let config = DmaConfig::default()
        .transfer_complete_interrupt(true)
        .half_transfer_interrupt(true)
        .transfer_error_interrupt(true)
        .fifo_error_interrupt(true)
        .direct_mode_error_interrupt(true);
    let transfer = ... // Initialize Transfer for DMA2, Stream  1

    // Hand off transfer ownership to interrupt
    cortex_m::interrupt::free(|cs| *DCMI_TRANSFER.borrow(&cs).borrow_mut() = Some(transfer));
 
    // Enable interrupt for the dma stream combo
    unsafe { NVIC::unmask(interrupt::DMA2_STREAM1) }
}

#[interrupt]
fn DMA2_STREAM1() {
    static mut TRANSFER: Option<DcmiTranfer> = None;
    
    // <- even though we have access to the `Transfer` struct,
    //    there is no API for retrieving which event triggered the interrupt
}

This looks like something similar to #42, where access to the Status register is needed, but for the DMA case.

TomasVanRoose avatar May 23 '21 10:05 TomasVanRoose

Currently, you can get both the transfer complete flag and half transfer complete flag through the Stream trait, we should probably add methods to get at least the transfer error flag and the direct mode error flag too.

thalesfragoso avatar May 28 '21 00:05 thalesfragoso