Skip to content

nopnop2002/Arduino-STM32-8bitTFT

Repository files navigation

Arduino-STM32-8bitTFT

8bit TFT Library for Arduino_Core_STM32(ST Core)

I ported from here.
https://github.com/prenticedavid/MCUFRIEND_kbv


Software requirement


Wirering for 8bit Parallel TFT

TFT STM32
LCD_RD -- PB0(*1)
LCD_WR -- PB1(*1)
LCD_RS -- PB5(*1)
LCD_CS -- PB6(*1)
LCD_RST -- PB7(*1)
LCD_D0 -- PA0(*2)
LCD_D1 -- PA1(*2)
LCD_D2 -- PA2(*2)
LCD_D3 -- PA3(*2)
LCD_D4 -- PA4(*2)
LCD_D5 -- PA5(*2)
LCD_D6 -- PA6(*2)
LCD_D7 -- PA7(*2)
5V -- 5V(*3)
3.3V -- 3.3V(*3)
GND -- GND

(*1)
You can change to other PB pin. To change the pin, change Arduino-STM32-8bitTFT.h.
Some boards assign PB3 and PB4 to the JTAG debug port by default.
Therefore, depending on the board, PB3 and PB4 may not be available as GPIO.
These GPIO are controlled using LL_GPIO_WriteOutputPort().

#define TFT_RD         LL_GPIO_PIN_0 // PB0
#define TFT_WR         LL_GPIO_PIN_1 // PB1
#define TFT_RS         LL_GPIO_PIN_5 // PB5
#define TFT_CS         LL_GPIO_PIN_6 // PB6
#define TFT_RST        LL_GPIO_PIN_7 // PB7

(*2)
Serial.print of NUCLEO and DISC1 gose to PA2.
Serial.print of STM32G series gose to PA2.
Serial.print of STM32H series gose to PA0.
If you are using these, you will need to do one of the following:

Change GPIO from D0 to D7

To change the port, change Arduino-STM32-8bitTFT.h.
D0 to D7 are controlled using CMSIS ODR Register.
This register can change multiple IOs at once, but only IOs on the same port.
Therefore, D0 to D7 must be the same port.
If PORT-A is used for D0-D7, all GPIOs on PORT-A cannot be used for other purposes.
Because CMSIS ODR Register manipulates all GPIOs of PORT-A.

You can use any of the following:

  • PORT-A LOW
    TFT Pin|D7 |D6 |D5 |D4 |D3 |D2 |D1 |D0 |
    STM32 Pin|PA7|PA6|PA5|PA4|PA3|PA2|PA1|PA0|
  • PORT-A HIGH
    TFT Pin|D7 |D6 |D5 |D4 |D3 |D2 |D1 |D0 |
    STM32 Pin|PA15|PA14|PA13|PA12|PA11|PA10|PA9|PA8|
  • PORT-C LOW
    TFT Pin|D7 |D6 |D5 |D4 |D3 |D2 |D1 |D0 |
    STM32 Pin|PC7|PC6|PC5|PC4|PC3|PC2|PC1|PC0|
  • PORT-C HIGH
    TFT Pin|D7 |D6 |D5 |D4 |D3 |D2 |D1 |D0 |
    STM32 Pin|PC15|PC14|PC13|PC12|PC11|PC10|PC9|PC8|
  • PORT-D LOW
    TFT Pin|D7 |D6 |D5 |D4 |D3 |D2 |D1 |D0 |
    STM32 Pin|PD7|PD6|PD5|PD4|PD3|PD2|PD1|PD0|
  • PORT-D HIGH
    TFT Pin|D7 |D6 |D5 |D4 |D3 |D2 |D1 |D0 |
    STM32 Pin|PD15|PD14|PD13|PD12|PD11|PD10|PD9|PD8|

Change default Serial instance pins

You can use another GPIO as a Serial object.
GPIO that can be used as a Serial object differs depending on the MCU.
You can know which GPIOs can be used in PeripheralPins.c of the MCU.
PeripheralPins.c is here.

  Serial.setTx(PB3);
  Serial.setRx(PB4);
  Serial.begin(115200);

(*3)
When a regulator(It's often AMS1117) is mounted on the back, it's operated 5V.
When a regulator is NOT mounted on the back, it's operated 3.3V.

Note:Keep the wire length as short as possible.


Tested TFT

  • ILI9325 2.4inch 240x320 TFT-Shield
  • ILI9341 2.4inch 240x320 TFT-Shield
  • ILI9342 2.4inch 240x320 TFT-Shield
  • SPFD5408 2.4inch 240x320 TFT-Shield
  • R61505 2.4inch 240x320 TFT-Shield
  • ST7783 2.4inch 240x320 TFT-Shield
  • LGDP4532 2.4inch 240x320 TFT-Shield
  • R61509V 3.6inch 240x400 TFT-Shield
  • ST7793 3.6inch 240x400 TFT-Shield
  • ILI9481 3.5inch 320x480 TFT-Shield
  • ILI9486 3.5inch 320x480 TFT-Shield
  • RM68140 3.95inch 320x480 TFT-Shield
  • ST7796 3.95inch 320x480 TFT-Shield

I found that these display cannot follow high-speed GPIO-ON and GPIO-OFF.

  • OPEN-SMART ILI9225 TFT-Shield
  • OPEN-SMART ILI9327 TFT-Shield
  • OPEN-SMART ILI9340 TFT-Shield
  • OPEN-SMART S6D1121 16Pin-Parallel
  • OPEN-SMART ST7775 16Pin-Parallel
  • OPEN-SMART ST7783 16Pin-Parallel
  • OPEN-SMART R61509V 16Pin-Parallel
  • OPEN-SMART ILI9488 16Pin-Parallel

TFT-SHIELD-2


Boards available

This library uses LL GPIO Generic Driver and CMSIS ODR Register.
Probably all boards have these available.
I tested with these.

  • STM32F0/F1/F3/F4 series
  • STM32G4 series
  • STM32H5 series
  • STM32L4 series

Setting your TFT's resolution

The default resolution of this library is 240x320.
If your TFT's resolution is 320x480,
you have to set your TFT's resolution using tft.setResoution.

ID = tft.readID();
tft.setResolution(320, 480); // Set your resolution
Serial.print("Device ID: 0x"); Serial.println(ID, HEX);
tft.begin(ID);
uint32_t width = tft.width();
Serial.print("Width: "); Serial.println(width); // You will see 320
uint32_t height = tft.height();
Serial.print("Height: "); Serial.println(height); // You will see 480

If your TFT's resolution is 240x400,
you have to set your TFT's resolution and TFT's offset.

ID = tft.readID();
tft.setResolution(240, 400); // Set your resolution
tft.setOffset(32); // Set your offset
Serial.print("Device ID: 0x"); Serial.println(ID, HEX);
tft.begin(ID);
uint32_t width = tft.width();
Serial.print("Width: "); Serial.println(width); // You will see 240
uint32_t height = tft.height();
Serial.print("Height: "); Serial.println(height); // You will see 400

  • STM32F103 + R61505 2.4 inch TFT

r61505

  • STM32F103 + SPFD5408 2.4 inch TFT

spfd5408

  • STM32F103 + ILI9325 2.4 inch TFT

ili9325

  • STM32F103 + ILI9341 2.4 inch TFT

ili9341

  • STM32F103 + ILI9342 2.4 inch TFT

ili9342

  • STM32F401 + ILI9341 2.4 inch TFT

STM32F401

  • STM32F407 + ILI9341 2.4 inch TFT

STM32F407

  • NUCLEO F446RE + ILI9341 2.4 inch TFT (Use PC0-PC7 for D0-D7)

8bitTFT

  • STM32G431 + ILI9341 2.4 inch TFT (Use Serial remapping)

STM32G431

  • STM32H750 + ILI9341 2.4 inch TFT (Use PC0-PC7 for D0-D7)

STM32H750


Benchmark using ILI9341(240x320)

Benchmark F072 F103 F303 F401 F411 F407 F446 G431 H750 L452 ATmega328
Screen fill 713964 737158 358057 247223 216304 141878 132427 140239 222478 259637 1379560
Text 73319 58985 37647 25814 22605 15097 14272 16275 14691 28825 344024
Lines 675985 556282 336332 235522 206064 137693 130958 134605 147000 250545 3390180
Horiz/Vert Lines 60070 61299 30165 20825 18221 11958 11173 11847 18372 21950 144664
Rectangles (outline) 39824 39994 20040 13835 12106 7953 7437 8178 11863 14875 104260
Rectangles (filled) 1482576 1530389 743518 513383 449170 294609 274991 291313 461782 539271 3267476
Circles (filled) 237519 215466 120380 83212 72840 48080 45358 58606 59632 97797 1211484
Circles (outline) 297537 245302 148705 103680 90733 60769 57622 59807 64510 110695 1475108
Triangles (outline) 149009 123427 74211 51938 45477 30354 28766 29767 32825 55313 1075596
Triangles (filled) 542331 528554 268777 185711 162496 106788 99944 112922 155465 202875 1721636
Rounded rects (outline) 117285 101407 58746 40758 35682 23791 22529 23750 27519 43702 506428
Rounded rects (filled) 1495318 1534484 750346 518107 453320 297450 277742 298242 132427 548296 3795228