Using STM32's Hardware SPI(with simple DMA support) to drive a ST7789 based LCD display.
"st7789.h"
in where you want to use this driver. "st7789.h"
according to your own display panel ST7789_Init();
. ST7789_Test()
to exam this driver. This code has been tested on 240x240 & 170x320 LCD screens.
DMA is only useful when huge block write is performed, e.g: Fill full screen or draw a bitmap.
Most MCUs don't have a large enough RAM, so a framebuffer is "cut" into pieces, e.g: a 240x5 pixel buffer for a 240x240 screen.
If you are using Dupont Line(or jumper wire), please notice that your CLK frequency should not exceed 40MHz (may vary, depends on the length of your wire), otherwise data transfer will collapse!
For higher speed applications, it's recommended to use PCB rather than jumper wires.
In STM32CubeMX/CubeIDE, config the SPI params as follow:
I've had a simple test, connect the screen and mcu via 20cm dupont line, and it works normally on 21.25MB/s. And if I connect a logic analyzer to the clk and data lines(15cm probe), 21.25MB/s doesn't work anymore, I have to lower its datarate to 10.625MB/s. Using PCB to connect the display, it works up to 40MB/s and still looks nice.
If you like, you could customize it's resolution to drive different displays you prefer.
For example, a 240x320 display is perfectly suited for st7789.
Just set all X_SHIFT and Y_SHIFT to 0, and set resolution to 240|320.
For more details, please refer to ST7789's datasheet.
With DMA enabled, cpu won't participate in the data transfer process. So filling a large size of data block is much faster.e.g. fill, drawImage. (You can see no interval between each data write)
Without DMA enabled, the filling process could be a suffer. As you can see, before each data byte write, an interval is inserted, so the total datarate would degrade.
Especially in some functions where need a little math, the cpu needs to calculate data before a write operation, so the effective datarate would be much lower.(e.g. drawLine)