cancel
Showing results for 
Search instead for 
Did you mean: 

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

Geo En
Associate III
Posted on March 07, 2018 at 13:01

EDIT: 14/03/2018

https://community.st.com/people/Schwaninger.Hannes

‌ 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_ComDMAfiles. And tadada! ... It is not working correctly....... Only a few bytes are sent and Rxbuffer is never filled.

0690X00000609ynQAA.png

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.

0690X00000609w9QAA.png

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

https://community.st.com/people/Schwaninger.Hannes

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!

#dma #spi #nucleo-h743zi #stm32h7 #hal
1 ACCEPTED SOLUTION

Accepted Solutions
H S
Associate III
Posted on March 14, 2018 at 18:03

I've just found the difference between the HAL Nucelo example projects and the CubeMX generated projects.The problem for the DMA transfer error is that we use the false RAM!!

I have changed the settings in MDK-ARM from

IRAM1 (default setting from CubeMX) to

IRAM2 (same is in the example projects) and now the SPI DMA transfer runs without error.

0690X0000060A89QAE.png

I've found out, that with this memory address

IRAM1 is the

DTCM-RAM and

IRAM2 is the

AXI SRAM D1.

 

enjolras.g

please check also in your project with TrueStudio and if it works, please share also the correct settings.

View solution in original post

29 REPLIES 29
T J
Lead
Posted on March 13, 2018 at 07:52

did you get it working ?  

you are ahead of most of us.

this will promote your question.

Geo En
Associate III
Posted on March 13, 2018 at 10:58

Thanks for your 'promoting support'!

I was looking at the worst case scenario: 'technological problem on cortex-m7'... So I have tried to receive SPI data with DMA on a STM32F7. And all DMA functions are working as expected. So it is definitely a problem in STM32H7 HAL library... I will try to find what is wrong in the library but It is extremely time-consuming... I would have preferred to have a way to report them a bug and let them correct it.
H S
Associate III
Posted on March 14, 2018 at 09:38

I've just started with the H743ZI Nucleo and have also troubles with SPI and DMA in my ''real Project''

(more about this later in a separate reply).

But the SPI_FullDuplex_ComDMA example from H7 HAL V1.2.0 works in my case with two Nucleo (Master/Slave).

I use Keil MDK-ARM and not TrueStudio.

0690X00000609ZpQAI.png
Geo En
Associate III
Posted on March 14, 2018 at 11:57

Can you confirm that Rx buffers on slave and on master are both filled with Tx buffer ?

Sometimes I can send the whole frame, but I never have anything in Rx buffer except 0.
David Littell
Senior III
Posted on March 14, 2018 at 13:44

Apologies if you've already verified this but is the data cache being handled correctly on the (DMA) receiving side?

H S
Associate III
Posted on March 14, 2018 at 13:24

Yes I can confirm this, the Rx Buffers are both full.

0690X00000609iNQAQ.png

You can check it also on the LED status of the Nucleos (the green and blue LED must be on).

Posted on March 14, 2018 at 14:26

Hey David, who do you mean?

If me, how can I check the data cache transfer, because I'm new with the Cortex M7...
H S
Associate III
Posted on March 14, 2018 at 15:34

As I wrote above, I have also a strange problem with the H743ZI Nucleo and SPI+DMA:

The SPI_FullDuplex_ComDMA example from the H7 HAL V1.2.0 works without problems with MDK-ARM and the Nucleo.

But

if I create a new MDK-ARM Projekt for the Nucleo with CubeMX 4.24 with the same configuration as in the SPI_FullDuplex_ComDMA example (SPI1 Master FullDuplex, DMA2, Stream2 Rx, Stream3 Tx, same Rx/TXBuffers, same SPI Send Function, ...) it will send only some byte and the transfer stop with the

hspi errorcode 0x10 (= HAL_SPI_ERROR_DMA = transfer error).

HAL_SPI_TransmitReceive_DMA(&hspi1, (uint8_t*)aTxBuffer, (uint8_t *)aRxBuffer, BUFFERSIZE);

0690X0000060A84QAE.png

Without DMA transfer (polling) the full SPI transfer works without problems again.

(a little bit similar to the behavior from Geo En if I look at the first post).

I have also create a new project for the F746ZG Nucleo with CubeMX and the same configuration.

The SPI DMA transfer works immediately without any problems.

Did anybody have an idea what could be wrong?

Or could anybody create a CubeMX project for the H743ZI Nucleo and check, if the SPI DMA transfer works?
Posted on March 14, 2018 at 14:51

In general, DMA receive buffers should be aligned and sized to cache-line boundaries and the cache invalidated before access.  Otherwise, DMA receive buffers should be located in a cache-inhibited address range.  ST's examples don't always rigorously follow either, leading the unwary on sometimes-wild chases.