cancel
Showing results for 
Search instead for 
Did you mean: 

Different data after the 1st transfer using SPI via DMA (using LL Libs)

TheRaprus
Associate III

Hi everybody.

I'm facing a strange behaviour on my application. I'm using a STM 23H562, and I'm usign LL library to drive a SPI display (classic iLi).

I take the example from c:\Users\[..]\NUCLEO-H533RE\Examples_LL\SPI\*
and the display do what I want... only sometime!

Due to the 65535 max transfer length, I need to split it into 3 session. I wait the end of the previous as indicate in the example, using:

while (!LL_DMA_IsActiveFlag_TC(GPDMA2, LL_DMA_CHANNEL_0)){}
LL_DMA_ClearFlag_TC(GPDMA2, LL_DMA_CHANNEL_0);

But the color of the filling change (= the data transmitted to the display) from one session to the others. The 1st is correct, the second "sometime", the 3rd rarely.

But if I put a small delay from one session to the following everything work fine. 

How I can fix it?
It seems I must wait for some other flag, but donnow wich!

Moreover, the command to the display is based on a 8 bit spi data, so I change to 16 and back to 8 when I use the DMA. But the session of manual sending command to SPI after DMA fail because the TXC flag is always 0, it never change!

while (!LL_SPI_IsActiveFlag_TXC(SPI2)){}

Thank in advance.

4 REPLIES 4
MOBEJ
ST Employee

Hello @TheRaprus , 

Could you please specify which LCD you are using with SPI? Are you using a TFT LCD display module?

Thank you
Br

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

I'm using a iLi9341 SPI display 320x240. It work only with SPI. With M4 DMA it work w/o problems.
SPI speed is 30MHz, but if I reduce there is no difference.

Because the total display memory is 320x240x2 byte = 153600B. I need 2 full DMA and one of ~22568B.

I tried to reduce the lengths to 60.000 and 20.000 but there is no differences.

What I presume is that the SPI shift reg isn't completely empty, so the 2nd or 3rd DMA Cycle had a dirty bit(s) in it, that "confuse" the display color command. 

Without DMA it work perfectly, changing the SPY from 8 to 16 bit, but I want the DMA, as in the M4 STM32!

The delay I mentioned above (between DMA calling) is 2 ms, 1 isn't enought. 

Bug still present.

I have test it again and the Delay isn't necessary, the problem is still here.

One question: Do I need to set the length both  in LL_DMA_SetBlkDataLength and LL_SPI_SetTransferSize?
(the H5 LL example do this).
Which "flag" do I need to test in status reg (GPDMA and SPI)?

Hi @MOBEJ 

After weeks of test I solve it!
Condensation: starting from DMA LL example as: 
c:\Users\...\STM32Cube\Repository\STM32Cube_FW_H5_V1.3.0\Projects\NUCLEO-H533RE\Examples_LL\SPI\SPI_OneBoard_HalfDuplex_DMA_Init\ 
I calle 3 time the DMA procedure to fill the display, due to the limit of 65534 byte for each call.

The example use the while (ubTransmissionComplete != 1){} to check the end of DMA transmission. But "sometime" the color used to fill the screen change form one session to another.

This because when the DMA finish the 16 bit inside the SPI isn't empty. So I add

while (!LL_SPI_IsActiveFlag_TXC(SPIx)) { n++; }

and it work!. The n after the while is = 25 (running @250MHz). I presume it is possible use the interrupt on SPI TC flag (transmit complete) instead the DMA but in my application I wait until it end, without ISR.

There is another critical point still on DMA, but I will create a new topic. Leave this to help other users...

BR.