3.5" inch TFT LCD Display Module 480X320 driven with FSMC.

TFT LCD Display Module 480X320 driven with FSMC

I have recently bought a 3.5" inch TFT LCD Touch Screen Display Module 480X320 with a www.mcufriend.com label on the back side. The display was equipped with an 8bit parallel interface. First I decided to test it with the UniGraphic library using the BUS_8 protocol. The display was very slow but improved when I switched to the PAR_8 protocol. Because I heard about the possibility to use a Flexible Static Memory Controller (FSMC), built into some STM MCU's, to drive LCD's (read/write to LCD's memory rather than to an external SRAM) I thought it would be a fun to try it out.

https://os.mbed.com/media/uploads/hudakz/lcd_3.5_tft_480x320_mcufriend_front.png

Below is the brief story of what I did:

  • Selected FSMC in the Connectivity category and configured it as below: https://os.mbed.com/media/uploads/hudakz/arch_max_fsmc_conf.png
  • Let the STM32CubeIDE generate the code (files).
  • Created a new program for the Seeed Arch Max target in the Mbed Online Compiler by selecting a mbed os blinky template.
  • Replaced the main.cpp with the main.c content of the STM32CubeIDE project.
  • Copy & Pasted the other files with codes from the STM32CubeIDE project to the online compiler project.
  • Renamed and modified:
    "stm32f4xx_it.h" to "stm32f4xx_it_msp.h"
    "stm32f4xx_it.c" to "stm32f4xx_it_msp.c"
  • Added the UniGraphic library to the online compiler project.
  • Extended the UniGraphic library with a FSMC_8 protocol and replaced the TFT::set_orientation(int orient) function with the one used by mcufriend for arduino.
  • Modified the main.cpp as needed.
https://os.mbed.com/media/uploads/hudakz/stm32f407vet6_st-link03.pnghttps://os.mbed.com/media/uploads/hudakz/lcd_3.5_tft_480x320_mcufriend_back.png


Wiring

STM32F407VETFT LCD module
+3.3V3V3
GNDGND
PB_12LCD_RST
GNDLCD_CS
PD_13 (RS)LCD_RS
PD_5 (WR)LCD_WR
PD_4 (RD)LCD_RD
PD_14 (DB00)LCD_D0
PD_15 (DB01)LCD_D1
PD_0 (DB02)LCD_D2
PD_1 (DB03)LCD_D3
PE_7 (DB04)LCD_D4
PE_8 (DB05)LCD_D5
PE_9 (DB06)LCD_D6
PE_10 (DB07)LCD_D7



Results
Execution times
Used protocolBUS_8FSMC_8
Operation \ Timemsms
Clear2283.98038.454
Plot192.06611.365
8bit BMP63.80541.338
Large Font163.8727.895
Sparce pixels2072.265/1458.05174.107/52.168
16bit BMP2288.58959.904
Committer:
hudakz
Date:
Sun May 10 10:44:31 2020 +0000
Revision:
0:fa952828e34c
3.5" inch TFT LCD Display Module 480X320 driven with FSMC.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hudakz 0:fa952828e34c 1 /* mbed UniGraphic library - Device specific class
hudakz 0:fa952828e34c 2 * Copyright (c) 2015 Giuliano Dianda
hudakz 0:fa952828e34c 3 * Released under the MIT License: http://mbed.org/license/mit
hudakz 0:fa952828e34c 4 */
hudakz 0:fa952828e34c 5 #include "Protocols.h"
hudakz 0:fa952828e34c 6 #include "S6D04D1.h"
hudakz 0:fa952828e34c 7
hudakz 0:fa952828e34c 8 //////////////////////////////////////////////////////////////////////////////////
hudakz 0:fa952828e34c 9 // display settings ///////////////////////////////////////////////////////
hudakz 0:fa952828e34c 10 /////////////////////////////////////////////////////////////////////////
hudakz 0:fa952828e34c 11
hudakz 0:fa952828e34c 12 // put in constructor
hudakz 0:fa952828e34c 13 //#define LCDSIZE_X 240 // display X pixels, TFTs are usually portrait view
hudakz 0:fa952828e34c 14 //#define LCDSIZE_Y 400 // display Y pixels
hudakz 0:fa952828e34c 15
hudakz 0:fa952828e34c 16
hudakz 0:fa952828e34c 17
hudakz 0:fa952828e34c 18 S6D04D1::S6D04D1(proto_t displayproto, PortName port, PinName CS, PinName reset, PinName DC, PinName WR, PinName RD, const char *name , unsigned int LCDSIZE_X, unsigned int LCDSIZE_Y)
hudakz 0:fa952828e34c 19 : TFT(displayproto, port, CS, reset, DC, WR, RD, LCDSIZE_X, LCDSIZE_Y, name)
hudakz 0:fa952828e34c 20 {
hudakz 0:fa952828e34c 21 hw_reset();
hudakz 0:fa952828e34c 22 BusEnable(true);
hudakz 0:fa952828e34c 23 identify(); // will collect tftID, set mipistd flag
hudakz 0:fa952828e34c 24 init();
hudakz 0:fa952828e34c 25 auto_gram_read_format();// try to get read gram pixel format, could be 16bit or 18bit, RGB or BGR. Will set flags accordingly
hudakz 0:fa952828e34c 26 // scrollbugfix=1; // when scrolling 1 line, the last line disappears, set to 1 to fix it, for ili9481 is set automatically in identify()
hudakz 0:fa952828e34c 27 set_orientation(0);
hudakz 0:fa952828e34c 28 FastWindow(true); // most but not all controllers support this, even if datasheet tells they should. Give a try
hudakz 0:fa952828e34c 29 cls();
hudakz 0:fa952828e34c 30 locate(0,0);
hudakz 0:fa952828e34c 31 }
hudakz 0:fa952828e34c 32 S6D04D1::S6D04D1(proto_t displayproto, PinName* buspins, PinName CS, PinName reset, PinName DC, PinName WR, PinName RD, const char *name , unsigned int LCDSIZE_X, unsigned int LCDSIZE_Y)
hudakz 0:fa952828e34c 33 : TFT(displayproto, buspins, CS, reset, DC, WR, RD, LCDSIZE_X, LCDSIZE_Y, name)
hudakz 0:fa952828e34c 34 {
hudakz 0:fa952828e34c 35 hw_reset();
hudakz 0:fa952828e34c 36 BusEnable(true);
hudakz 0:fa952828e34c 37 identify(); // will collect tftID, set mipistd flag
hudakz 0:fa952828e34c 38 init();
hudakz 0:fa952828e34c 39 auto_gram_read_format();// try to get read gram pixel format, could be 16bit or 18bit, RGB or BGR. Will set flags accordingly
hudakz 0:fa952828e34c 40 // scrollbugfix=1; // when scrolling 1 line, the last line disappears, set to 1 to fix it, for ili9481 is set automatically in identify()
hudakz 0:fa952828e34c 41 set_orientation(0);
hudakz 0:fa952828e34c 42 FastWindow(true); // most but not all controllers support this, even if datasheet tells they should. Give a try
hudakz 0:fa952828e34c 43 cls();
hudakz 0:fa952828e34c 44 locate(0,0);
hudakz 0:fa952828e34c 45 }
hudakz 0:fa952828e34c 46 S6D04D1::S6D04D1(proto_t displayproto, int Hz, PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, PinName DC, const char *name , unsigned int LCDSIZE_X , unsigned int LCDSIZE_Y )
hudakz 0:fa952828e34c 47 : TFT(displayproto, Hz, mosi, miso, sclk, CS, reset, DC, LCDSIZE_X, LCDSIZE_Y, name)
hudakz 0:fa952828e34c 48 {
hudakz 0:fa952828e34c 49 hw_reset(); //TFT class forwards to Protocol class
hudakz 0:fa952828e34c 50 BusEnable(true); //TFT class forwards to Protocol class
hudakz 0:fa952828e34c 51 identify(); // will collect tftID and set mipistd flag
hudakz 0:fa952828e34c 52 init(); // per display custom init cmd sequence, implemented here
hudakz 0:fa952828e34c 53 auto_gram_read_format();// try to get read gram pixel format, could be 16bit or 18bit, RGB or BGR. Will set flags accordingly
hudakz 0:fa952828e34c 54 // scrollbugfix=1; // when scrolling 1 line, the last line disappears, set to 1 to fix it, for ili9481 is set automatically in identify()
hudakz 0:fa952828e34c 55 set_orientation(0); //TFT class does for MIPI standard and some ILIxxx
hudakz 0:fa952828e34c 56 FastWindow(true); // most but not all controllers support this, even if datasheet tells they should. Give a try
hudakz 0:fa952828e34c 57 cls();
hudakz 0:fa952828e34c 58 locate(0,0);
hudakz 0:fa952828e34c 59 }
hudakz 0:fa952828e34c 60 // reset and init the lcd controller
hudakz 0:fa952828e34c 61 void S6D04D1::init()
hudakz 0:fa952828e34c 62 {
hudakz 0:fa952828e34c 63 /**********************************************
hudakz 0:fa952828e34c 64 TFT1P CODE Initialization of Truly
hudakz 0:fa952828e34c 65
hudakz 0:fa952828e34c 66 ************************************************
hudakz 0:fa952828e34c 67 Panel:3.0 240400
hudakz 0:fa952828e34c 68 Driver IC:S6D04D1X21-BAF8
hudakz 0:fa952828e34c 69
hudakz 0:fa952828e34c 70 ************************************************/
hudakz 0:fa952828e34c 71 wr_cmd8(0xE0);
hudakz 0:fa952828e34c 72 wr_data8(0x01);
hudakz 0:fa952828e34c 73
hudakz 0:fa952828e34c 74 wr_cmd8(0x11);
hudakz 0:fa952828e34c 75 wait_ms(150);
hudakz 0:fa952828e34c 76
hudakz 0:fa952828e34c 77 wr_cmd8(0xF3);
hudakz 0:fa952828e34c 78 wr_data8(0x01);
hudakz 0:fa952828e34c 79 wr_data8(0x00);
hudakz 0:fa952828e34c 80 wr_data8(0x00);
hudakz 0:fa952828e34c 81 wr_data8(0x0C);//Do not set any higher VCI1 level than VCI -0.15V. 0C 0A
hudakz 0:fa952828e34c 82 wr_data8(0x03);//VGH和VGL 01 02VGH=6VCI1,VGL=-4VCI1.
hudakz 0:fa952828e34c 83 wr_data8(0x75);
hudakz 0:fa952828e34c 84 wr_data8(0x75);
hudakz 0:fa952828e34c 85 wr_data8(0x30);
hudakz 0:fa952828e34c 86
hudakz 0:fa952828e34c 87 wr_cmd8(0xF4);
hudakz 0:fa952828e34c 88 wr_data8(0x4C);
hudakz 0:fa952828e34c 89 wr_data8(0x4C);
hudakz 0:fa952828e34c 90 wr_data8(0x44);
hudakz 0:fa952828e34c 91 wr_data8(0x44);
hudakz 0:fa952828e34c 92 wr_data8(0x22);
hudakz 0:fa952828e34c 93
hudakz 0:fa952828e34c 94 wr_cmd8(0xF5);
hudakz 0:fa952828e34c 95 wr_data8(0x10);
hudakz 0:fa952828e34c 96 wr_data8(0x22);
hudakz 0:fa952828e34c 97 wr_data8(0x05);
hudakz 0:fa952828e34c 98 wr_data8(0xF0);
hudakz 0:fa952828e34c 99 wr_data8(0x70);
hudakz 0:fa952828e34c 100 wr_data8(0x1F);
hudakz 0:fa952828e34c 101 wait_ms(30);
hudakz 0:fa952828e34c 102
hudakz 0:fa952828e34c 103 wr_cmd8(0xF3);
hudakz 0:fa952828e34c 104 wr_data8(0x03);
hudakz 0:fa952828e34c 105 wait_ms(30);
hudakz 0:fa952828e34c 106 wr_cmd8(0xF3);
hudakz 0:fa952828e34c 107 wr_data8(0x07);
hudakz 0:fa952828e34c 108 wait_ms(30);
hudakz 0:fa952828e34c 109 wr_cmd8(0xF3);
hudakz 0:fa952828e34c 110 wr_data8(0x0F);
hudakz 0:fa952828e34c 111 wait_ms(30);
hudakz 0:fa952828e34c 112 wr_cmd8(0xF3);
hudakz 0:fa952828e34c 113 wr_data8(0x1F);
hudakz 0:fa952828e34c 114 wait_ms(30);
hudakz 0:fa952828e34c 115 wr_cmd8(0xF3);
hudakz 0:fa952828e34c 116 wr_data8(0x7F);
hudakz 0:fa952828e34c 117 wait_ms(30);
hudakz 0:fa952828e34c 118
hudakz 0:fa952828e34c 119
hudakz 0:fa952828e34c 120 wr_cmd8(0xF7);
hudakz 0:fa952828e34c 121 wr_data8(0x80);
hudakz 0:fa952828e34c 122 wr_data8(0x00);
hudakz 0:fa952828e34c 123 wr_data8(0x00);
hudakz 0:fa952828e34c 124 wr_data8(0x05);
hudakz 0:fa952828e34c 125 wr_data8(0x0D);
hudakz 0:fa952828e34c 126 wr_data8(0x1F);
hudakz 0:fa952828e34c 127 wr_data8(0x26);
hudakz 0:fa952828e34c 128 wr_data8(0x2D);
hudakz 0:fa952828e34c 129 wr_data8(0x14);
hudakz 0:fa952828e34c 130 wr_data8(0x15);
hudakz 0:fa952828e34c 131 wr_data8(0x26);
hudakz 0:fa952828e34c 132 wr_data8(0x20);
hudakz 0:fa952828e34c 133 wr_data8(0x01);
hudakz 0:fa952828e34c 134 wr_data8(0x22);
hudakz 0:fa952828e34c 135 wr_data8(0x22);
hudakz 0:fa952828e34c 136
hudakz 0:fa952828e34c 137 wr_cmd8(0xF8);
hudakz 0:fa952828e34c 138 wr_data8(0x80);
hudakz 0:fa952828e34c 139 wr_data8(0x00);
hudakz 0:fa952828e34c 140 wr_data8(0x00);
hudakz 0:fa952828e34c 141 wr_data8(0x00);
hudakz 0:fa952828e34c 142 wr_data8(0x07);
hudakz 0:fa952828e34c 143 wr_data8(0x1E);
hudakz 0:fa952828e34c 144 wr_data8(0x2A);
hudakz 0:fa952828e34c 145 wr_data8(0x32);
hudakz 0:fa952828e34c 146 wr_data8(0x10);
hudakz 0:fa952828e34c 147 wr_data8(0x16);
hudakz 0:fa952828e34c 148 wr_data8(0x36);
hudakz 0:fa952828e34c 149 wr_data8(0x3C);
hudakz 0:fa952828e34c 150 wr_data8(0x3B);
hudakz 0:fa952828e34c 151 wr_data8(0x22);
hudakz 0:fa952828e34c 152 wr_data8(0x22);
hudakz 0:fa952828e34c 153
hudakz 0:fa952828e34c 154 wr_cmd8(0xF9);
hudakz 0:fa952828e34c 155 wr_data8(0x80);
hudakz 0:fa952828e34c 156 wr_data8(0x00);
hudakz 0:fa952828e34c 157 wr_data8(0x00);
hudakz 0:fa952828e34c 158 wr_data8(0x05);
hudakz 0:fa952828e34c 159 wr_data8(0x0D);
hudakz 0:fa952828e34c 160 wr_data8(0x1F);
hudakz 0:fa952828e34c 161 wr_data8(0x26);
hudakz 0:fa952828e34c 162 wr_data8(0x2D);
hudakz 0:fa952828e34c 163 wr_data8(0x14);
hudakz 0:fa952828e34c 164 wr_data8(0x15);
hudakz 0:fa952828e34c 165 wr_data8(0x26);
hudakz 0:fa952828e34c 166 wr_data8(0x20);
hudakz 0:fa952828e34c 167 wr_data8(0x01);
hudakz 0:fa952828e34c 168 wr_data8(0x22);
hudakz 0:fa952828e34c 169 wr_data8(0x22);
hudakz 0:fa952828e34c 170
hudakz 0:fa952828e34c 171
hudakz 0:fa952828e34c 172 wr_cmd8(0xFA);
hudakz 0:fa952828e34c 173 wr_data8(0x80);
hudakz 0:fa952828e34c 174 wr_data8(0x00);
hudakz 0:fa952828e34c 175 wr_data8(0x00);
hudakz 0:fa952828e34c 176 wr_data8(0x00);
hudakz 0:fa952828e34c 177 wr_data8(0x07);
hudakz 0:fa952828e34c 178 wr_data8(0x1E);
hudakz 0:fa952828e34c 179 wr_data8(0x2A);
hudakz 0:fa952828e34c 180 wr_data8(0x32);
hudakz 0:fa952828e34c 181 wr_data8(0x10);
hudakz 0:fa952828e34c 182 wr_data8(0x16);
hudakz 0:fa952828e34c 183 wr_data8(0x36);
hudakz 0:fa952828e34c 184 wr_data8(0x3C);
hudakz 0:fa952828e34c 185 wr_data8(0x3B);
hudakz 0:fa952828e34c 186 wr_data8(0x22);
hudakz 0:fa952828e34c 187 wr_data8(0x22);
hudakz 0:fa952828e34c 188
hudakz 0:fa952828e34c 189
hudakz 0:fa952828e34c 190 wr_cmd8(0xFB);
hudakz 0:fa952828e34c 191 wr_data8(0x80);
hudakz 0:fa952828e34c 192 wr_data8(0x00);
hudakz 0:fa952828e34c 193 wr_data8(0x00);
hudakz 0:fa952828e34c 194 wr_data8(0x05);
hudakz 0:fa952828e34c 195 wr_data8(0x0D);
hudakz 0:fa952828e34c 196 wr_data8(0x1F);
hudakz 0:fa952828e34c 197 wr_data8(0x26);
hudakz 0:fa952828e34c 198 wr_data8(0x2D);
hudakz 0:fa952828e34c 199 wr_data8(0x14);
hudakz 0:fa952828e34c 200 wr_data8(0x15);
hudakz 0:fa952828e34c 201 wr_data8(0x26);
hudakz 0:fa952828e34c 202 wr_data8(0x20);
hudakz 0:fa952828e34c 203 wr_data8(0x01);
hudakz 0:fa952828e34c 204 wr_data8(0x22);
hudakz 0:fa952828e34c 205 wr_data8(0x22);
hudakz 0:fa952828e34c 206
hudakz 0:fa952828e34c 207 wr_cmd8(0xFC);
hudakz 0:fa952828e34c 208 wr_data8(0x80);
hudakz 0:fa952828e34c 209 wr_data8(0x00);
hudakz 0:fa952828e34c 210 wr_data8(0x00);
hudakz 0:fa952828e34c 211 wr_data8(0x00);
hudakz 0:fa952828e34c 212 wr_data8(0x07);
hudakz 0:fa952828e34c 213 wr_data8(0x1E);
hudakz 0:fa952828e34c 214 wr_data8(0x2A);
hudakz 0:fa952828e34c 215 wr_data8(0x32);
hudakz 0:fa952828e34c 216 wr_data8(0x10);
hudakz 0:fa952828e34c 217 wr_data8(0x16);
hudakz 0:fa952828e34c 218 wr_data8(0x36);
hudakz 0:fa952828e34c 219 wr_data8(0x3C);
hudakz 0:fa952828e34c 220 wr_data8(0x3B);
hudakz 0:fa952828e34c 221 wr_data8(0x22);
hudakz 0:fa952828e34c 222 wr_data8(0x22);
hudakz 0:fa952828e34c 223
hudakz 0:fa952828e34c 224 //wr_cmd8(0x35);
hudakz 0:fa952828e34c 225 wr_cmd8(0x34); // tearing effect line off
hudakz 0:fa952828e34c 226
hudakz 0:fa952828e34c 227 wr_cmd8(0x36);
hudakz 0:fa952828e34c 228 wr_data8(0x48);//08
hudakz 0:fa952828e34c 229
hudakz 0:fa952828e34c 230 wr_cmd8(0x3A);
hudakz 0:fa952828e34c 231 wr_data8(0x05);
hudakz 0:fa952828e34c 232
hudakz 0:fa952828e34c 233 wr_cmd8(0xF2);
hudakz 0:fa952828e34c 234 wr_data8(0x17);
hudakz 0:fa952828e34c 235 wr_data8(0x17);
hudakz 0:fa952828e34c 236 wr_data8(0x0F);
hudakz 0:fa952828e34c 237 wr_data8(0x08);
hudakz 0:fa952828e34c 238 wr_data8(0x08);
hudakz 0:fa952828e34c 239 wr_data8(0x00);
hudakz 0:fa952828e34c 240 wr_data8(0x00);
hudakz 0:fa952828e34c 241 wr_data8(0x00);
hudakz 0:fa952828e34c 242 wr_data8(0x00);
hudakz 0:fa952828e34c 243 wr_data8(0x13);
hudakz 0:fa952828e34c 244 wr_data8(0x00);
hudakz 0:fa952828e34c 245
hudakz 0:fa952828e34c 246 wr_cmd8(0xF6);
hudakz 0:fa952828e34c 247 wr_data8(0x00);
hudakz 0:fa952828e34c 248 wr_data8(0x08);
hudakz 0:fa952828e34c 249 wr_data8(0x00);
hudakz 0:fa952828e34c 250 wr_data8(0x00);
hudakz 0:fa952828e34c 251
hudakz 0:fa952828e34c 252 wr_cmd8(0xFD);
hudakz 0:fa952828e34c 253 wr_data8(0x02);
hudakz 0:fa952828e34c 254 wr_data8(0x01);//240*400
hudakz 0:fa952828e34c 255
hudakz 0:fa952828e34c 256 wait_ms(20);
hudakz 0:fa952828e34c 257 wr_cmd8(0x29); // display on
hudakz 0:fa952828e34c 258 wait_ms(20);
hudakz 0:fa952828e34c 259
hudakz 0:fa952828e34c 260 }