cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4: SPI output using DMA with LL driver

PMath.4
Senior III

Hi

I'm trying to get SPI output working using DMA with the LL drivers. I'm using CubeMX to set up the DMA and SPI and it works perfectly when I use HAL_SPI_Transmit_DMA to initiate the output. However, this is a very slow routine and I want to be able to initiate re-transmission as fast as possible. My code is attached below but I don't see any output. I'm clearly missing a bit of the jigsaw but can't find any examples to guide me.

Once I've got basic transmission working then I can pare back the routines in the loop to find the minimum needed to re-transmit.

The LED on PD8 is toggling so I know the loop is running

Help would be appreciated

while (1)
  {
		HAL_Delay(500);
		HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_8);
	    // Disable DMA to load new length to be transmitted
		  LL_DMA_DisableIT_TC(DMA2,
		                     LL_DMA_STREAM_3);
		  LL_DMA_SetDataLength(DMA2,
		                       LL_DMA_STREAM_3,
		                       sizeof(dmabuff));
		  LL_DMA_ConfigAddresses(DMA2,
		                         LL_DMA_STREAM_3,
		                         (uint32_t)dmabuff,
		                         LL_SPI_DMA_GetRegAddr(SPI1),
		                         LL_DMA_DIRECTION_MEMORY_TO_PERIPH);
		  LL_SPI_EnableDMAReq_TX(SPI1);
		  LL_SPI_EnableIT_TXE(SPI1);
		  LL_DMA_EnableIT_TC(DMA2,
		                     LL_DMA_STREAM_3);
		  LL_DMA_EnableStream(DMA2,
		                       LL_DMA_STREAM_3);
		  HAL_Delay(500);
//		HAL_SPI_Transmit_DMA(&hspi1, dmabuff, sizeof(dmabuff)); // This works perfectly
    /* USER CODE END WHILE */
 
    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}

2 REPLIES 2

Read out and check/post content of DMA, SPI and relevant GPIO registers.

JW

TDK
Guru

One relatively quick way to solve this is to compare register settings just prior to starting the transfer between your version and HAL to determine what you've done differently.

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