Skip to main content
Gabriel T
Senior
March 5, 2021
Solved

STM32H7 DMA2 wont trigger interrupt

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 ?

This topic has been closed for replies.
Gabriel T
Gabriel TBest answer
Senior
March 8, 2021

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

19 replies

Gabriel T
Gabriel TAuthor
Senior
March 8, 2021

@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

waclawek.jan
Super User
March 8, 2021

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
Gabriel TAuthor
Senior
March 8, 2021

@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
Gabriel TAuthorBest answer
Senior
March 8, 2021

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

Grundyoso
Associate
May 13, 2021

@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

Gabriel T
Gabriel TAuthor
Senior
May 14, 2021

@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) ;