AnsweredAssumed Answered

[SOLVED] STM32H7 SPI does not seem to work with DMA

Question asked by Geo En on Mar 7, 2018
Latest reply on Apr 18, 2018 by Nawres GHARBI

EDIT: 14/03/2018
H S found that we need to use RAM_D1 and not DTCMRAM of the memory area. This is not made by default when we use STM32CubeMx to set SPI and DMA together.

Hello, 
I am working on a full duplex SPI communication through DMA using STM32H7. So, I have bought 2 NUCLEO-H743ZI, one to be the master, the other to be the slave. I have downloaded, built and flashed SPI_FullDuplex_ComDMA example via TrueStudio. As there is no "TrueStudio format" example, I have generated the project with STM32CubeMx and replace Inc and Src generated files with SPI_FullDuplex_ComDMA files. And tadada! ... It is not working correctly....... Only a few bytes are sent and Rxbuffer is never filled.


I have made connexion wires as short as possible and I have increased spi clock prescaler to get  "slow, nice and smooth" signals. Electronic not seems to be the problem.
I have modified the example to run it without DMA  by replacing :

HAL_SPI_TransmitReceive_DMA(&SpiHandle, (uint8_t*)aTxBuffer, (uint8_t *)aRxBuffer, BUFFERSIZE)

With :

HAL_SPI_TransmitReceive(&SpiHandle, (uint8_t*)aTxBuffer, (uint8_t *)aRxBuffer, BUFFERSIZE,5000)

And now it's working! But not with the DMA .... This test shows that SPI is set and works correctly. aRxBuffer is filled with the good values.

 

Back in my code, I am trying now to send data through DMA with master and read them with slave:

// Master
HAL_SPI_Transmit_DMA(&SpiHandle, (uint8_t*)aTxBuffer, BUFFERSIZE)
// Slave
HAL_SPI_TransmitReceive(&SpiHandle, (uint8_t*)aTxBuffer, (uint8_t *)aRxBuffer, BUFFERSIZE, 5000)

It's working! Master sends DATA through DMA and my aRxBuffer is correctly filled on slave.

 

However, I have never been able to read DATA on master or slave with one of these functions:

HAL_SPI_TransmitReceive_DMA(&SpiHandle, (uint8_t*)aTxBuffer, (uint8_t *)aRxBuffer, BUFFERSIZE)
HAL_SPI_Receive_DMA(&SpiHandle, (uint8_t *)aRxBuffer, BUFFERSIZE)


I have tried to set DMA and SPI with STM32CubeMx but the problem remains the same.
HAL_SPI_TransmitReceive_DMA always returns HAL_OK but code quickly falls into HAL_SPI_ErrorCallback. That only happens with DMA, never wih SPI only...

 

I do not think that I am doing something wrong as I have not modified the SPI_FullDuplex_ComDMA "example" Src and Inc files...

 

EDIT: 13/03/2018

I have tried HAL_SPI_TransmitReceive_DMA and HAL_SPI_Receive_DMA on a STM32F7 to be sure that there is no technological problem on Cortex-M7. All DMA functions are working perfectly with F7.

 

EDIT: 14/03/2018
H S 
has tested SPI_FullDuplex_ComDMA example with Keil and it seems to work. However, he can't make it work with same configuration files if he creates a new project. 

 

For me there is a problem with files generated by STM32CubeMX.

Does anyone have already made a full duplex spi communication with dma on a stm32h7 with a new STM32CubeMx project?

 

Thanks for your help! 

Outcomes