cancel
Showing results for 
Search instead for 
Did you mean: 

DMA Interrupt is not pre-empting USB interrupt

jwoolston
Associate II
Posted on August 13, 2014 at 02:22

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? #stm32 #dma #stmf4 #isr
2 REPLIES 2
Posted on August 13, 2014 at 04:02

I'll observe that you only need to call the Priority Grouping once, and that with 2-bits you can't represent a level of 4

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
jwoolston
Associate II
Posted on August 13, 2014 at 06:46

Thanks clive. I was uncertain on the multiple grouping call, but followed (perhaps mistakenly I'm beginning to realize) the example of the generated STCubeMX code which places it for every enabled interrupt. 

As for the priority of 4, a face palm is in order. I should have known better but got burnt out on my prior SPI issue.

Anyway, thanks again.