cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103RB SPI TX DMA transfer complete check ?

Posted on July 21, 2016 at 11:07

Hello everyone

with an STM32F103RB and an ILI9341 TFT i am accelerating my Firmware with DMA functionality. With DMA, I get a huge boost in Performance but I am missing some Infos how to use DMA correctly. With MEM2MEM DMA and the HAL Drivers i can start an MEM2MEM DMA and poll the end of the DMA Transfer like this:

HAL_DMA_Start( ... );

HAL_DMA_PollForTransfer( ... );

Using SPI TX DMA works also ( with great Performance boost, up to 6 times faster Screen refresh):

HAL_SPI_Transmit_DMA( ... );

But I do not know how to determine if the SPI TX DMA transfer is finished. The STM32F103RB can prepare new data to send faster than the DMA Transfer takes time, so I have to wait for the next SPI DMA Transfer. Now, im am using a delay to ensure that the SPI DMA Transfer has finished but this is not reliable, because it depends on the calculating time of the CPU and the amount of transferred data. UM1850 offers no function like for MEM2MEM DMA to determine the end of an SPI TX DMA Transfer. AN4931 brought some Infos, but no solution. Register NDTR should be checked, but DMA1->... gives no auto complete for this Register (I am using Keil5+ CubeMX 4.14). Also enabling the IRQ for SPI DMA in CubeMX and adding a control variable into the IRQ Routine ''void DMA1_Channel5_IRQHandler(void)'' which i can check did not work. The IRQ Handler is started, i checked it with printf on SWO. How do I check the end of an SPI TX DMA Transfer in the CubeMX way ?

Thanks for your suggestions,

Markus.

2 REPLIES 2
Walid FTITI_O
Senior II
Posted on July 21, 2016 at 17:13

Hi,

I suggest to take a look to the ''SPI_FullDuplex_ComDMA'' example in

http://www.st.com/content/st_com/en/products/embedded-software/mcus-embedded-software/stm32-embedded-software/stm32cube-embedded-software/stm32cubef1.html

at this path: STM32Cube_FW_F1_V1.4.0\Projects\STM32F103RB-Nucleo\Examples\SPI\SPI_FullDuplex_ComDMA

Compare the code and implimentation there in the different user file ( main.c , STM32f1_it.c and msp.c) with your own code.

-Hannibal-
Posted on July 22, 2016 at 08:54

After dissecting the ''SPI_FullDuplex_ComDMA'' Project, the answer ist to implement ''void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef *hspi)'' in my main to overwrite the weak implemention in ''stm32f1xx_hal.c'' ? There I can toggle a variable to detect the end of an Transmission like in the example ''wTransferState''. Am I correct ?

Best regards,

Markus.