cancel
Showing results for 
Search instead for 
Did you mean: 

Using SPI with DMA

BTurc.2
Senior

Hi All, I'm using an STM32F1 with a 240x240 LCD screen that comunicates with the micro by SPI (with DMA). The screen uses the ST7789 driver (I supose it is not important). I'm working with RGB565 color format.

The problem that I have is, for example, when I'm using the ST7789_Fill_Color(YELLOW); the SPI uses the DMA and the LCD shoul be yellow but it's not. If yellow is 0b1111 1111 1110 0000 the DMA only sends to SPI the LSB (0b0000 0000 1110 0000) witch is a wrong color.
When I do the same without DMA it work's fine!

The DMA is configures this way:

BTurc2_0-1688298032648.png

I tried every configuration possible but nothing works. My question is why the DMA only graps the first byte of a color and what I have to change in order to send the real color.

Thanks in advance!!!

 

19 REPLIES 19

Hello, sorry I didn't see the message on time. Yes it is library fault and I have solved it. If you still need the library I can send it to you!

Hello @BTurc.2 !!!

No problem, I discovered this library has a problem by the worst way. But until now I don't know where is the problem.
So, would it be possible for you to send me this library corrected?

Thank you so much.
Best Regards,
CVSta

Hey @CVSta ,

Here you have! The .c file is where are the change. There was a problem with filling correctly the color buffer.

Hey @BTurc.2 !
I really appreciated your time and your work to send me your library.
I'm trying to use DMA in the same library, but not work too. I think there is a DMA problem too.
I'll continuos studying... So, thank you for the moment.

Best Reagards.

What microcontroller do you use? A have a project with an STM32F1 (bluepill). If you want I can share with you the project. Then you could see all the setting I'm using and try to replicate them.

I'm using the STM32G0B1RE microcontroller.
In your project with Bluepill, did you used DMA with this library from ST7789?
If is possible to you share, I really appreciate.

I share with you the project here because I don't know how github works. This project uses the bluepill, the 240x240 lcd screen and an RS485 soil sensor. I also use an UART-TTL converter for serial comunication with the PC. It is a project only for testing.

Things to keep in mind:

1- I only use the main to initialize the peripherals and 2 functions: the App_Init() and the App_Task() witch are like the setup() and loop() for arduino. Those functions are located in Core/App.

2- The libraries I used for LCD and the RS485 comunication are located in Drivers/BSP.

Here you have the project. I hope you find it useful.

 

 

Hello @BTurc.2 !
Thank you for this project and your time to answer me.
I'll study a little bit here and if I have some doubts I'll ask you after.
For this moment, I'm really gratefull.

Best Regards,
CVSta.

Hi @BTurc.2 

I have very similar setup with ST7789 240x240 display but MCU is STM32F746ZG (NUCLEO board). I use the same display library and the same SPI1+DMA setup. Problem always happens after DMA transfer request here:

 

static void ST7789_WriteData(uint8_t *buff, size_t buff_size) {
    ...
    HAL_SPI_Transmit_DMA(&ST7789_SPI_PORT, buff, chunk_size);
    while (ST7789_SPI_PORT.hdmatx->State != HAL_DMA_STATE_READY) {}
    ...}

 

To fill the screen, 115200 bytes (240 * 240 * 2) must be transferred to display via SPI. Default buffer size is 2400 bytes and chunk size is the same as buffer (2400 bytes). ST7789_Fill_Color() calls ST7789_WriteData() 48 times and stuck. After 48 DMA transactions (48 * 2400 = 115200) there is no more HAL_DMA_STATE_READY signal, DMA becomes always BUSY and code stuck in the infinite while loop.

Even if I make buffer size 115200 bytes and chunk size 57600 bytes, HAL_SPI_Transmit_DMA() makes only 2 transactions by 57600 bytes and becomes always BUSY again.

Did you have such problem?

UPDATE:

Problem was in the code attempting to transfer the memory outside buffer boundaries.
With DMA full frame transfer of 240x240x2 = 115200 bytes takes 64 ms.
Updates uploaded to GitHub

 

No, I didn't have the same problem. Does it now works properly?