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 "TFT_MIPI.h"
hudakz 0:fa952828e34c 7
hudakz 0:fa952828e34c 8 //////////////////////////////////////////////////////////////////////////////////
hudakz 0:fa952828e34c 9
hudakz 0:fa952828e34c 10 // display settings ///////////////////////////////////////////////////////
hudakz 0:fa952828e34c 11 /////////////////////////////////////////////////////////////////////////
hudakz 0:fa952828e34c 12 // put in constructor
hudakz 0:fa952828e34c 13 //#define LCDSIZE_X 320 // display X pixels, TFTs are usually portrait view
hudakz 0:fa952828e34c 14 //#define LCDSIZE_Y 480 // display Y pixels
hudakz 0:fa952828e34c 15 TFT_MIPI::TFT_MIPI
hudakz 0:fa952828e34c 16 (
hudakz 0:fa952828e34c 17 proto_t displayproto,
hudakz 0:fa952828e34c 18 PortName port,
hudakz 0:fa952828e34c 19 PinName CS,
hudakz 0:fa952828e34c 20 PinName reset,
hudakz 0:fa952828e34c 21 PinName DC,
hudakz 0:fa952828e34c 22 PinName WR,
hudakz 0:fa952828e34c 23 PinName RD,
hudakz 0:fa952828e34c 24 const char* name,
hudakz 0:fa952828e34c 25 unsigned int LCDSIZE_X,
hudakz 0:fa952828e34c 26 unsigned int LCDSIZE_Y
hudakz 0:fa952828e34c 27 ) :
hudakz 0:fa952828e34c 28 TFT(displayproto, port, CS, reset, DC, WR, RD, LCDSIZE_X, LCDSIZE_Y, name)
hudakz 0:fa952828e34c 29 {
hudakz 0:fa952828e34c 30 hw_reset();
hudakz 0:fa952828e34c 31 BusEnable(true);
hudakz 0:fa952828e34c 32 identify(); // will collect tftID, set mipistd flag
hudakz 0:fa952828e34c 33 init();
hudakz 0:fa952828e34c 34 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 35
hudakz 0:fa952828e34c 36 // 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 37 set_orientation(0);
hudakz 0:fa952828e34c 38
hudakz 0:fa952828e34c 39 // FastWindow(true); // most but not all controllers support this, even if datasheet tells they should. Give a try
hudakz 0:fa952828e34c 40 cls();
hudakz 0:fa952828e34c 41 locate(0, 0);
hudakz 0:fa952828e34c 42 }
hudakz 0:fa952828e34c 43
hudakz 0:fa952828e34c 44 /**
hudakz 0:fa952828e34c 45 * @brief
hudakz 0:fa952828e34c 46 * @note
hudakz 0:fa952828e34c 47 * @param
hudakz 0:fa952828e34c 48 * @retval
hudakz 0:fa952828e34c 49 */
hudakz 0:fa952828e34c 50 TFT_MIPI::TFT_MIPI
hudakz 0:fa952828e34c 51 (
hudakz 0:fa952828e34c 52 proto_t displayproto,
hudakz 0:fa952828e34c 53 PinName* buspins,
hudakz 0:fa952828e34c 54 PinName CS,
hudakz 0:fa952828e34c 55 PinName reset,
hudakz 0:fa952828e34c 56 PinName DC,
hudakz 0:fa952828e34c 57 PinName WR,
hudakz 0:fa952828e34c 58 PinName RD,
hudakz 0:fa952828e34c 59 const char* name,
hudakz 0:fa952828e34c 60 unsigned int LCDSIZE_X,
hudakz 0:fa952828e34c 61 unsigned int LCDSIZE_Y
hudakz 0:fa952828e34c 62 ) :
hudakz 0:fa952828e34c 63 TFT(displayproto, buspins, CS, reset, DC, WR, RD, LCDSIZE_X, LCDSIZE_Y, name)
hudakz 0:fa952828e34c 64 {
hudakz 0:fa952828e34c 65 // hw_reset();
hudakz 0:fa952828e34c 66
hudakz 0:fa952828e34c 67 // BusEnable(true);
hudakz 0:fa952828e34c 68 identify(); // will collect tftID and set mipistd flag
hudakz 0:fa952828e34c 69 init();
hudakz 0:fa952828e34c 70 auto_gram_read_format();
hudakz 0:fa952828e34c 71 set_orientation(0);
hudakz 0:fa952828e34c 72 cls();
hudakz 0:fa952828e34c 73 locate(0, 0);
hudakz 0:fa952828e34c 74 }
hudakz 0:fa952828e34c 75
hudakz 0:fa952828e34c 76 /**
hudakz 0:fa952828e34c 77 * @brief
hudakz 0:fa952828e34c 78 * @note
hudakz 0:fa952828e34c 79 * @param
hudakz 0:fa952828e34c 80 * @retval
hudakz 0:fa952828e34c 81 */
hudakz 0:fa952828e34c 82 TFT_MIPI::TFT_MIPI
hudakz 0:fa952828e34c 83 (
hudakz 0:fa952828e34c 84 proto_t displayproto,
hudakz 0:fa952828e34c 85 int Hz,
hudakz 0:fa952828e34c 86 PinName mosi,
hudakz 0:fa952828e34c 87 PinName miso,
hudakz 0:fa952828e34c 88 PinName sclk,
hudakz 0:fa952828e34c 89 PinName CS,
hudakz 0:fa952828e34c 90 PinName reset,
hudakz 0:fa952828e34c 91 PinName DC,
hudakz 0:fa952828e34c 92 const char* name,
hudakz 0:fa952828e34c 93 unsigned int LCDSIZE_X,
hudakz 0:fa952828e34c 94 unsigned int LCDSIZE_Y
hudakz 0:fa952828e34c 95 ) :
hudakz 0:fa952828e34c 96 TFT(displayproto, Hz, mosi, miso, sclk, CS, reset, DC, LCDSIZE_X, LCDSIZE_Y, name)
hudakz 0:fa952828e34c 97 {
hudakz 0:fa952828e34c 98 hw_reset(); //TFT class forwards to Protocol class
hudakz 0:fa952828e34c 99 BusEnable(true); //TFT class forwards to Protocol class
hudakz 0:fa952828e34c 100 identify(); // will collect tftID and set mipistd flag
hudakz 0:fa952828e34c 101 init(); // per display custom init cmd sequence, implemented here
hudakz 0:fa952828e34c 102 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 103
hudakz 0:fa952828e34c 104 // 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 105 set_orientation(0); //TFT class does for MIPI standard and some ILIxxx
hudakz 0:fa952828e34c 106
hudakz 0:fa952828e34c 107 // FastWindow(true); // most but not all controllers support this, even if datasheet tells they should. Give a try
hudakz 0:fa952828e34c 108 cls();
hudakz 0:fa952828e34c 109 locate(0, 0);
hudakz 0:fa952828e34c 110 }
hudakz 0:fa952828e34c 111
hudakz 0:fa952828e34c 112 /**
hudakz 0:fa952828e34c 113 * @brief
hudakz 0:fa952828e34c 114 * @note
hudakz 0:fa952828e34c 115 * @param
hudakz 0:fa952828e34c 116 * @retval
hudakz 0:fa952828e34c 117 */
hudakz 0:fa952828e34c 118 TFT_MIPI::TFT_MIPI
hudakz 0:fa952828e34c 119 (
hudakz 0:fa952828e34c 120 proto_t displayproto,
hudakz 0:fa952828e34c 121 PinName reset,
hudakz 0:fa952828e34c 122 const char* name,
hudakz 0:fa952828e34c 123 unsigned int LCDSIZE_X,
hudakz 0:fa952828e34c 124 unsigned int LCDSIZE_Y
hudakz 0:fa952828e34c 125 ) :
hudakz 0:fa952828e34c 126 TFT(displayproto, reset, LCDSIZE_X, LCDSIZE_Y, name)
hudakz 0:fa952828e34c 127 {
hudakz 0:fa952828e34c 128 hw_reset();
hudakz 0:fa952828e34c 129 identify(); // will collect tftID and set mipistd flag
hudakz 0:fa952828e34c 130 init();
hudakz 0:fa952828e34c 131 auto_gram_read_format();
hudakz 0:fa952828e34c 132 set_orientation(0);
hudakz 0:fa952828e34c 133 cls();
hudakz 0:fa952828e34c 134 locate(0, 0);
hudakz 0:fa952828e34c 135 }
hudakz 0:fa952828e34c 136
hudakz 0:fa952828e34c 137 // reset and init the lcd controller
hudakz 0:fa952828e34c 138 void TFT_MIPI::init()
hudakz 0:fa952828e34c 139 {
hudakz 0:fa952828e34c 140 /* Start Initial Sequence ----------------------------------------------------*/
hudakz 0:fa952828e34c 141
hudakz 0:fa952828e34c 142 /* Start Initial Sequence ----------------------------------------------------*/
hudakz 0:fa952828e34c 143 wr_cmd8(0xD0); // POWER SETTING
hudakz 0:fa952828e34c 144 wr_data8(0x07);
hudakz 0:fa952828e34c 145 wr_data8(0x42);
hudakz 0:fa952828e34c 146 wr_data8(0x18);
hudakz 0:fa952828e34c 147
hudakz 0:fa952828e34c 148 wr_cmd8(0xD1); // VCOM control
hudakz 0:fa952828e34c 149 wr_data8(0x00);
hudakz 0:fa952828e34c 150 wr_data8(0x07);
hudakz 0:fa952828e34c 151 wr_data8(0x10);
hudakz 0:fa952828e34c 152
hudakz 0:fa952828e34c 153 wr_cmd8(0xD2); // Power_Setting for Normal Mode
hudakz 0:fa952828e34c 154 wr_data8(0x01); // LCD power supply current
hudakz 0:fa952828e34c 155 wr_data8(0x02); // charge pumps
hudakz 0:fa952828e34c 156 wr_cmd8(0xC0); // Panel Driving Setting
hudakz 0:fa952828e34c 157 wr_data8(0x10); // 10 orig
hudakz 0:fa952828e34c 158 wr_data8(0x3B); //number of lines+1 *8
hudakz 0:fa952828e34c 159 wr_data8(0x00);
hudakz 0:fa952828e34c 160 wr_data8(0x02);
hudakz 0:fa952828e34c 161 wr_data8(0x11);
hudakz 0:fa952828e34c 162
hudakz 0:fa952828e34c 163 // C1 missing? Display_Timing_Setting for Normal Mode
hudakz 0:fa952828e34c 164 //renesas does not have this
hudakz 0:fa952828e34c 165 // wr_cmd8(0xC5); // Frame Rate and Inversion Control
hudakz 0:fa952828e34c 166 // wr_data8(0x03); // 72hz, datashet tells default 02=85hz
hudakz 0:fa952828e34c 167 wr_cmd8(0xC8); // Gamma settings
hudakz 0:fa952828e34c 168 wr_data8(0x00);
hudakz 0:fa952828e34c 169 wr_data8(0x32);
hudakz 0:fa952828e34c 170 wr_data8(0x36);
hudakz 0:fa952828e34c 171 wr_data8(0x45);
hudakz 0:fa952828e34c 172 wr_data8(0x06);
hudakz 0:fa952828e34c 173 wr_data8(0x16);
hudakz 0:fa952828e34c 174 wr_data8(0x37);
hudakz 0:fa952828e34c 175 wr_data8(0x75);
hudakz 0:fa952828e34c 176 wr_data8(0x77);
hudakz 0:fa952828e34c 177 wr_data8(0x54);
hudakz 0:fa952828e34c 178 wr_data8(0x0C);
hudakz 0:fa952828e34c 179 wr_data8(0x00);
hudakz 0:fa952828e34c 180
hudakz 0:fa952828e34c 181 wr_cmd8(0x36); // MEMORY_ACCESS_CONTROL (orientation stuff)
hudakz 0:fa952828e34c 182 wr_data8(0x0A); // 0A as per chinese example (vertical flipped)
hudakz 0:fa952828e34c 183 wr_cmd8(0x3A); // COLMOD_PIXEL_FORMAT_SET, not present in AN
hudakz 0:fa952828e34c 184 wr_data8(0x55); // 16 bit pixel
hudakz 0:fa952828e34c 185 wr_cmd8(0x13); // Nomal Displaymode
hudakz 0:fa952828e34c 186 wr_cmd8(0x11); // sleep out
hudakz 0:fa952828e34c 187 wait_ms(150);
hudakz 0:fa952828e34c 188
hudakz 0:fa952828e34c 189 wr_cmd8(0x29); // display on
hudakz 0:fa952828e34c 190 wait_ms(150);
hudakz 0:fa952828e34c 191 }