cancel
Showing results for 
Search instead for 
Did you mean: 

Using STM32CubeIDE project and MCU STM32H750. After calling HAL_DMA_Start() data is transferring, but the hdma_memtomem_dma2_stream1.State is still in HAL_DMA_STATE_BUSY. So calling the abort HAL_DMA_Abort() and transferring the next set of data

Suryaprakash
Associate II

// Following is the DMA Initialization.

DMA_HandleTypeDef  hdma_memtomem_dma2_stream1;

main(){

:

:

:

 /* Initialize all configured peripherals */

 MX_DMA_Init();

HAL_DMA_Start(&hdma_memtomem_dma2_stream1, (uint32_t)&g_aui16SourceVal[0], (uint32_t)&g_auc16DestVal[0], 16);

if (HAL_DMA_STATE_READY != hdma_memtomem_dma2_stream1.State){

HAL_DMA_Abort(&hdma_memtomem_dma2_stream1);

}

:

:

:

} /* End of main */

static void MX_DMA_Init(void)

{

 /* DMA controller clock enable */

 __HAL_RCC_DMA1_CLK_ENABLE();

 __HAL_RCC_DMA2_CLK_ENABLE();

/* Configure DMA request hdma_memtomem_dma2_stream1 on DMA2_Stream1 */

 hdma_memtomem_dma2_stream1.Instance = DMA2_Stream1;

 hdma_memtomem_dma2_stream1.Init.Request = DMA_REQUEST_MEM2MEM;

 hdma_memtomem_dma2_stream1.Init.Direction = DMA_MEMORY_TO_MEMORY;

 hdma_memtomem_dma2_stream1.Init.PeriphInc = DMA_PINC_ENABLE;

 hdma_memtomem_dma2_stream1.Init.MemInc = DMA_MINC_DISABLE;

 hdma_memtomem_dma2_stream1.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;

 hdma_memtomem_dma2_stream1.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD;

 hdma_memtomem_dma2_stream1.Init.Mode = DMA_NORMAL;

 hdma_memtomem_dma2_stream1.Init.Priority = DMA_PRIORITY_LOW;

 hdma_memtomem_dma2_stream1.Init.FIFOMode = DMA_FIFOMODE_ENABLE;

 hdma_memtomem_dma2_stream1.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_1QUARTERFULL;

 hdma_memtomem_dma2_stream1.Init.MemBurst = DMA_MBURST_SINGLE;

 hdma_memtomem_dma2_stream1.Init.PeriphBurst = DMA_PBURST_SINGLE;

 if (HAL_DMA_Init(&hdma_memtomem_dma2_stream1) != HAL_OK)

 {

 Error_Handler( );

 }

:

:

}

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

The DMA processes in the background and lets your CPU do other things in the meantime. Of course it's still going to be busy immediately after you start it.

Follow the guidelines for usage as given in the source code:

     *** Polling mode IO operation ***
     =================================
    [..]
          (+) Use HAL_DMA_Start() to start DMA transfer after the configuration of Source 
              address and destination address and the Length of data to be transferred.
          (+) Use HAL_DMA_PollForTransfer() to poll for the end of current transfer, in this  
              case a fixed Timeout can be configured by User depending from his application.
          (+) Use HAL_DMA_Abort() function to abort the current transfer.
 
     *** Interrupt mode IO operation ***
     ===================================
    [..]
          (+) Configure the DMA interrupt priority using HAL_NVIC_SetPriority()
          (+) Enable the DMA IRQ handler using HAL_NVIC_EnableIRQ() 
          (+) Use HAL_DMA_Start_IT() to start DMA transfer after the configuration of  
              Source address and destination address and the Length of data to be transferred. In this 
              case the DMA interrupt is configured 
          (+) Use HAL_DMA_IRQHandler() called under DMA_IRQHandler() Interrupt subroutine
          (+) At the end of data transfer HAL_DMA_IRQHandler() function is executed and user can 
              add his own function by customization of function pointer XferCpltCallback and 
              XferErrorCallback (i.e a member of DMA handle structure).

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

2 REPLIES 2
Suryaprakash
Associate II

I would like to know the problem for hdma_memtomem_dma2_stream1.State not in HAL_DMA_STATE_READY  after the data transfer. Is there any thing I am missing in the mentioned code.

TDK
Guru

The DMA processes in the background and lets your CPU do other things in the meantime. Of course it's still going to be busy immediately after you start it.

Follow the guidelines for usage as given in the source code:

     *** Polling mode IO operation ***
     =================================
    [..]
          (+) Use HAL_DMA_Start() to start DMA transfer after the configuration of Source 
              address and destination address and the Length of data to be transferred.
          (+) Use HAL_DMA_PollForTransfer() to poll for the end of current transfer, in this  
              case a fixed Timeout can be configured by User depending from his application.
          (+) Use HAL_DMA_Abort() function to abort the current transfer.
 
     *** Interrupt mode IO operation ***
     ===================================
    [..]
          (+) Configure the DMA interrupt priority using HAL_NVIC_SetPriority()
          (+) Enable the DMA IRQ handler using HAL_NVIC_EnableIRQ() 
          (+) Use HAL_DMA_Start_IT() to start DMA transfer after the configuration of  
              Source address and destination address and the Length of data to be transferred. In this 
              case the DMA interrupt is configured 
          (+) Use HAL_DMA_IRQHandler() called under DMA_IRQHandler() Interrupt subroutine
          (+) At the end of data transfer HAL_DMA_IRQHandler() function is executed and user can 
              add his own function by customization of function pointer XferCpltCallback and 
              XferErrorCallback (i.e a member of DMA handle structure).

If you feel a post has answered your question, please click "Accept as Solution".