cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H7 DMA2 wont trigger interrupt

Gabriel T
Senior

Using STM32H743ZI

I am using SPI1 in 2 lines Rx only mode with DMA2 Stream 2 as in ST example

I use Rx DMA with a buffer located in D2 RAM. Using debugger I found that the first reception works well, data gets written into my buffer. But my DMA doesn't fire any interrupt, so the next transfers do not work.

Here is my init code :

hdma_spi1_rx.Instance = DMA2_Stream2;
 
hdma_spi1_rx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
hdma_spi1_rx.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL;
hdma_spi1_rx.Init.MemBurst = DMA_MBURST_INC4;
hdma_spi1_rx.Init.PeriphBurst = DMA_PBURST_INC4;
hdma_spi1_rx.Init.Request = DMA_REQUEST_SPI1_RX;
hdma_spi1_rx.Init.Direction = DMA_PERIPH_TO_MEMORY;
hdma_spi1_rx.Init.PeriphInc = DMA_PINC_DISABLE;
hdma_spi1_rx.Init.MemInc = DMA_MINC_ENABLE;
hdma_spi1_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
hdma_spi1_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
hdma_spi1_rx.Init.Mode = DMA_NORMAL;
hdma_spi1_rx.Init.Priority = DMA_PRIORITY_HIGH;
 
if (HAL_DMA_Init(&hdma_spi1_rx) != HAL_OK)
{
  Error_Handler();
}
 
__HAL_LINKDMA(hspi,hdmarx,hdma_spi1_rx);
 
/* SPI1 interrupt Init */
__HAL_SPI_ENABLE_IT(hspi, SPI_IT_RXNE) ;
/* USER CODE BEGIN SPI1_MspInit 1 */
HAL_NVIC_SetPriority(DMA2_Stream2_IRQn, 1, 0);
HAL_NVIC_EnableIRQ(DMA2_Stream2_IRQn);
HAL_NVIC_SetPriority(SPI1_IRQn, 1, 0);
HAL_NVIC_EnableIRQ(SPI1_IRQn);

Any idea why my DMA2 peripheral wont trigger interrupt ?

19 REPLIES 19
Gabriel T
Senior

Yes, DMA2 Stream 2 configuration register gets set in HAL_SPI_Receive_DMA function

Here is register :

0693W000008wHMgQAM.png

Okay, so if

  • interrupts are locally enabled in DMA stream
  • interrupt flags in DMA are set
  • interrupt is enabled and pending in NVIC (you haven't reported about the "pending" part here)
  • ISR is in proper position of vector table and VTOR is checked
  • breakpoint inserted in the proper function (as checked in disasm view)
  • program won't stop on the breakpoint

then either breakpoints don't work (this can be circumvented by toggling a pin and observing in the ISR), or, which IMO may be more probable, processor runs with interrupts globally disabled or at a priority level which is higher than the ISR in questions' priority. I am lazy to look up how to check easily either of these, both involve looking at SCB registers.

JW

Gabriel T
Senior

@Community member​ 

Thank you for the help,

NVIC Pending register after first Rx : The bit 35 is 1 (SP1) and the bit 58 is 1 (DMA2 Stream 2), but my breakpoints in both Handler aren't triggered (I will try GPIO debug)

0693W000008wHVOQA2.pngFor priority, I registered my interrupts at level 0 or 1 (highest) because in my application SPI1 Rx is the most critical process

Maybe interrupts are globally disabled.

This is in PRIMASK, which is a processor internal register, I don't know if and how your debugger can display it.

Also, you may be inside an interrupt of the same or higher priority. Check IPSR (again, a processor internal register).

You can also have a look at the SCB_ICSR register, that should contain the currently executed interrupt number (or 0 if no interrupt), too.

JW

Gabriel T
Senior

@Community member​ 

Here is my EXTI callback that starts a SPI Rx, I added two variable to get PRIMASK and IPSR

void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
	ADS1x9x_csn_0_en();
	uint32_t res = __get_PRIMASK();
	uint32_t res2 = __get_IPSR();
	HAL_SPI_Receive_DMA(&hspi1, ads_buf2, READBACK_LENGTH);
}

I read this :

PRIMASK = 0

IPSR = 0x17

SCB->ICSR = 0x400817 But I know I am in EXTI interrupt

The EXTI triggers at 4kHz and I am supposed to SPI1 Rx each trigger

EDIT : When I remove my breakpoint in EXTI callback I get into HAL_DMA_IRQHandler

Gabriel T
Senior

My interrupts are working now, I added some flag clearing bare metal programming and removed breakpoints and it works now thanks !

@Gabriel Tétar​ which ST example did you start with?? I'm doing something similar and running into an issue of subsequent DMA transfers not generating SCLK

> I am using SPI1 in 2 lines Rx only mode with DMA2 Stream 2 as in ST example

@Grundyoso​  Hi, I didn't use any example, just HAL library documentation in the comment on top of "stm32h7xx_hal_spi.c" (very helpful) and also the reference manual (for such thing as MDMA + DMA combination). Also your question is strange because in Rx only it's your SPI peripheral that generates DMA transfer (not DMA transfer triggers SPI). But if you are indeed in Rx case, make sure you call this when you start a transfer :

HAL_MDMA_Start_IT();
HAL_SPI_Receive_DMA();

Make sure you have the callbacks activated in NVIC, I don't register the SPI1 callback but I enable RXNE event, I only register DMA and MDMA in NVIC.

HAL_NVIC_EnableIRQ(DMA2_Stream2_IRQn);
HAL_NVIC_EnableIRQ(MDMA_IRQn);
__HAL_SPI_ENABLE_IT(hspi, SPI_IT_RXNE) ;

> I added some flag clearing bare metal programming

It would be useful (to me since I am seeing a similar issue) if you were to post exactly what you did?

I am porting SPI code I have on STM32F2xx/4xx using the standard peripheral library to the LL library on STM32F7xx (as it regrettably has no SPF) and it is not interrupting on TC.

Start a new thread stating your problem in detail.

Here are some general "interrupt does not fire" troubleshooting hints.

JW