AnsweredAssumed Answered

DMA Interrupt is not pre-empting USB interrupt

Question asked by woolston.jared on Aug 13, 2014
Latest reply on Aug 13, 2014 by woolston.jared
I am having some trouble getting the expected behavior out of my interrupts for DMA and USB.

Using the STCubeMX HAL libraries, I have configured the interrupts as follows:

/**
 * @brief System NVIC priority group
 */
#define GLOBAL_IRQ_PRI_GROUP                NVIC_PRIORITYGROUP_2
 
/**
 * @brief Interrupt Priority Settings
 */
#define SYSTICK_PREEMPT_PRI                 0
#define SYSTICK_SUB_PRI                     0
 
#define HOST_READY_IRQ_PREEMPT_PRI          1
#define HOST_READY_IRQ_SUB_PRI              0
 
#define DEVICE_READY_IRQ_PREEMPT_PRI        1
#define DEVICE_READY_IRQ_SUB_PRI            0
 
#define HOST_SPI_ACTIVE_IRQ_PREEMPT_PRI     1
#define HOST_SPI_ACTIVE_IRQ_SUB_PRI         0
 
#define SPI_DMA_CHANNEL_IRQ_PREEMPT_PRI     2
#define SPI_DMA_CHANNEL_IRQ_SUB_PRI         0
 
#define SPI_IRQ_PREEMPT_PRI                 2
#define SPI_IRQ_SUB_PRI                     0
 
#define USB_IRQ_PREEMPT_PRI                 4
#define USB_IRQ_SUB_PRI                     0
 
/* USB Peripheral interrupt init*/
/* Sets the priority grouping field */
HAL_NVIC_SetPriorityGrouping(GLOBAL_IRQ_PRI_GROUP);
HAL_NVIC_SetPriority(OTG_HS_EP1_IN_IRQn, USB_IRQ_PREEMPT_PRI, USB_IRQ_SUB_PRI);
HAL_NVIC_EnableIRQ(OTG_HS_EP1_IN_IRQn);
/* Sets the priority grouping field */
HAL_NVIC_SetPriorityGrouping(GLOBAL_IRQ_PRI_GROUP);
HAL_NVIC_SetPriority(OTG_HS_IRQn, USB_IRQ_PREEMPT_PRI, USB_IRQ_SUB_PRI);
HAL_NVIC_EnableIRQ(OTG_HS_IRQn);
/* Sets the priority grouping field */
HAL_NVIC_SetPriorityGrouping(GLOBAL_IRQ_PRI_GROUP);
HAL_NVIC_SetPriority(OTG_HS_EP1_OUT_IRQn, USB_IRQ_PREEMPT_PRI, USB_IRQ_SUB_PRI);
HAL_NVIC_EnableIRQ(OTG_HS_EP1_OUT_IRQn);
 
/* SPI DMA interrupt init */
/* Sets the priority grouping field */
HAL_NVIC_SetPriorityGrouping(GLOBAL_IRQ_PRI_GROUP);
HAL_NVIC_SetPriority(SPI_DMA_RX_IRQn, SPI_DMA_CHANNEL_IRQ_PREEMPT_PRI, SPI_DMA_CHANNEL_IRQ_SUB_PRI);
HAL_NVIC_EnableIRQ(SPI_DMA_RX_IRQn);
/* Sets the priority grouping field */
HAL_NVIC_SetPriorityGrouping(GLOBAL_IRQ_PRI_GROUP);
HAL_NVIC_SetPriority(SPI_DMA_TX_IRQn, SPI_DMA_CHANNEL_IRQ_PREEMPT_PRI, SPI_DMA_CHANNEL_IRQ_SUB_PRI);
HAL_NVIC_EnableIRQ(SPI_DMA_TX_IRQn);

While in the USB interrupt routine, I perform a series of SPI transfers via DMA requests. Unfortunately, I get stuck waiting for my first transfer to complete. I have confirmed that the transfer did in fact occur (the receiving side picked up the correct data) and if I check the interrupt pending bit for the DMA stream in question I see that it was clear before starting the transfer, and set after the reception by the other side. 

My understanding was that the configuration I have above should have the DMA interrupt a higher pre-emption priority than the USB interrupt and that it should begin execution even while I am in the USB interrupt. Am I wrong in this understanding or is there some subtle configuration I have messed up?

Outcomes