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.
Below is the brief story of what I did:
- Created a project for my STM32F407VE board in the STM32CubeIDE
- Set the
Clock Configuration
to match the one used by Mbed for the Seeed Arch Max board:
- Selected
FSMC
in theConnectivity
category and configured it as below: - 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 themain.c
content of theSTM32CubeIDE
project. Copy & Pasted
the other files with codes from theSTM32CubeIDE
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 aFSMC_8
protocol and replaced theTFT::set_orientation(int orient)
function with the one used bymcufriend
for arduino. - Modified the
main.cpp
as needed.
Wiring
STM32F407VE | TFT LCD module |
---|---|
+3.3V | 3V3 |
GND | GND |
PB_12 | LCD_RST |
GND | LCD_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 protocol | BUS_8 | FSMC_8 |
Operation \ Time | ms | ms |
Clear | 2283.980 | 38.454 |
Plot | 192.066 | 11.365 |
8bit BMP | 63.805 | 41.338 |
Large Font | 163.872 | 7.895 |
Sparce pixels | 2072.265/1458.051 | 74.107/52.168 |
16bit BMP | 2288.589 | 59.904 |
UniGraphic/Inits/ILI9486.cpp@1:47c996032a9e, 2020-09-25 (annotated)
- Committer:
- hudakz
- Date:
- Fri Sep 25 14:52:27 2020 +0000
- Revision:
- 1:47c996032a9e
- Parent:
- 0:fa952828e34c
3.5" inch TFT LCD Display Module 480X320 driven with FSMC.
Who changed what in which revision?
User | Revision | Line number | New 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 "ILI9486.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 320 // display X pixels, TFTs are usually portrait view |
hudakz | 0:fa952828e34c | 14 | //#define LCDSIZE_Y 480 // display Y pixels |
hudakz | 0:fa952828e34c | 15 | |
hudakz | 0:fa952828e34c | 16 | |
hudakz | 0:fa952828e34c | 17 | |
hudakz | 0:fa952828e34c | 18 | ILI9486::ILI9486(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 and 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 | set_orientation(0); |
hudakz | 0:fa952828e34c | 27 | // FastWindow(true); // most but not all controllers support this, even if datasheet tells they should. ILI9486 does not, at least in par mode |
hudakz | 0:fa952828e34c | 28 | cls(); |
hudakz | 0:fa952828e34c | 29 | locate(0,0); |
hudakz | 0:fa952828e34c | 30 | } |
hudakz | 0:fa952828e34c | 31 | ILI9486::ILI9486(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 | 32 | : TFT(displayproto, Hz, mosi, miso, sclk, CS, reset, DC, LCDSIZE_X, LCDSIZE_Y, name) |
hudakz | 0:fa952828e34c | 33 | { |
hudakz | 0:fa952828e34c | 34 | hw_reset(); //TFT class forwards to Protocol class |
hudakz | 0:fa952828e34c | 35 | BusEnable(true); //TFT class forwards to Protocol class |
hudakz | 0:fa952828e34c | 36 | identify(); // will collect tftID and set mipistd flag |
hudakz | 0:fa952828e34c | 37 | init(); // per display custom init cmd sequence, implemented here |
hudakz | 0:fa952828e34c | 38 | 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 | 39 | set_orientation(0); //TFT class does for MIPI standard and some ILIxxx |
hudakz | 0:fa952828e34c | 40 | // FastWindow(true); // most but not all controllers support this, even if datasheet tells they should. ILI9486 does not, at least in par mode |
hudakz | 0:fa952828e34c | 41 | cls(); |
hudakz | 0:fa952828e34c | 42 | locate(0,0); |
hudakz | 0:fa952828e34c | 43 | } |
hudakz | 0:fa952828e34c | 44 | // reset and init the lcd controller |
hudakz | 0:fa952828e34c | 45 | void ILI9486::init() |
hudakz | 0:fa952828e34c | 46 | { |
hudakz | 0:fa952828e34c | 47 | /* Start Initial Sequence ----------------------------------------------------*/ |
hudakz | 0:fa952828e34c | 48 | |
hudakz | 0:fa952828e34c | 49 | wr_cmd8(0xF1); |
hudakz | 0:fa952828e34c | 50 | wr_data8(0x36); |
hudakz | 0:fa952828e34c | 51 | wr_data8(0x04); |
hudakz | 0:fa952828e34c | 52 | wr_data8(0x00); |
hudakz | 0:fa952828e34c | 53 | wr_data8(0x3C); |
hudakz | 0:fa952828e34c | 54 | wr_data8(0x0F); |
hudakz | 0:fa952828e34c | 55 | wr_data8(0x8F); |
hudakz | 0:fa952828e34c | 56 | |
hudakz | 0:fa952828e34c | 57 | |
hudakz | 0:fa952828e34c | 58 | wr_cmd8(0xF2); |
hudakz | 0:fa952828e34c | 59 | wr_data8(0x18); |
hudakz | 0:fa952828e34c | 60 | wr_data8(0xA3); |
hudakz | 0:fa952828e34c | 61 | wr_data8(0x12); |
hudakz | 0:fa952828e34c | 62 | wr_data8(0x02); |
hudakz | 0:fa952828e34c | 63 | wr_data8(0xb2); |
hudakz | 0:fa952828e34c | 64 | wr_data8(0x12); |
hudakz | 0:fa952828e34c | 65 | wr_data8(0xFF); |
hudakz | 0:fa952828e34c | 66 | wr_data8(0x10); |
hudakz | 0:fa952828e34c | 67 | wr_data8(0x00); |
hudakz | 0:fa952828e34c | 68 | |
hudakz | 0:fa952828e34c | 69 | wr_cmd8(0xF8); |
hudakz | 0:fa952828e34c | 70 | wr_data8(0x21); |
hudakz | 0:fa952828e34c | 71 | wr_data8(0x04); |
hudakz | 0:fa952828e34c | 72 | |
hudakz | 0:fa952828e34c | 73 | wr_cmd8(0xF9); |
hudakz | 0:fa952828e34c | 74 | wr_data8(0x00); |
hudakz | 0:fa952828e34c | 75 | wr_data8(0x08); |
hudakz | 0:fa952828e34c | 76 | |
hudakz | 0:fa952828e34c | 77 | wr_cmd8(0xC0); |
hudakz | 0:fa952828e34c | 78 | wr_data8(0x0f); //13 |
hudakz | 0:fa952828e34c | 79 | wr_data8(0x0f); //10 |
hudakz | 0:fa952828e34c | 80 | |
hudakz | 0:fa952828e34c | 81 | wr_cmd8(0xC1); |
hudakz | 0:fa952828e34c | 82 | wr_data8(0x42); //43 |
hudakz | 0:fa952828e34c | 83 | |
hudakz | 0:fa952828e34c | 84 | wr_cmd8(0xC2); |
hudakz | 0:fa952828e34c | 85 | wr_data8(0x22); |
hudakz | 0:fa952828e34c | 86 | |
hudakz | 0:fa952828e34c | 87 | wr_cmd8(0xC5); |
hudakz | 0:fa952828e34c | 88 | wr_data8(0x01); //00 |
hudakz | 0:fa952828e34c | 89 | wr_data8(0x29); //4D |
hudakz | 0:fa952828e34c | 90 | wr_data8(0x80); |
hudakz | 0:fa952828e34c | 91 | |
hudakz | 0:fa952828e34c | 92 | wr_cmd8(0xB6); |
hudakz | 0:fa952828e34c | 93 | wr_data8(0x00); |
hudakz | 0:fa952828e34c | 94 | wr_data8(0x02); //42 |
hudakz | 0:fa952828e34c | 95 | wr_data8(0x3b); |
hudakz | 0:fa952828e34c | 96 | |
hudakz | 0:fa952828e34c | 97 | wr_cmd8(0xB1); |
hudakz | 0:fa952828e34c | 98 | wr_data8(0xB0); //C0 |
hudakz | 0:fa952828e34c | 99 | wr_data8(0x11); |
hudakz | 0:fa952828e34c | 100 | |
hudakz | 0:fa952828e34c | 101 | wr_cmd8(0xB4); |
hudakz | 0:fa952828e34c | 102 | wr_data8(0x02); //01 |
hudakz | 0:fa952828e34c | 103 | |
hudakz | 0:fa952828e34c | 104 | wr_cmd8(0xE0); |
hudakz | 0:fa952828e34c | 105 | wr_data8(0x0F); |
hudakz | 0:fa952828e34c | 106 | wr_data8(0x18); |
hudakz | 0:fa952828e34c | 107 | wr_data8(0x15); |
hudakz | 0:fa952828e34c | 108 | wr_data8(0x09); |
hudakz | 0:fa952828e34c | 109 | wr_data8(0x0B); |
hudakz | 0:fa952828e34c | 110 | wr_data8(0x04); |
hudakz | 0:fa952828e34c | 111 | wr_data8(0x49); |
hudakz | 0:fa952828e34c | 112 | wr_data8(0x64); |
hudakz | 0:fa952828e34c | 113 | wr_data8(0x3D); |
hudakz | 0:fa952828e34c | 114 | wr_data8(0x08); |
hudakz | 0:fa952828e34c | 115 | wr_data8(0x15); |
hudakz | 0:fa952828e34c | 116 | wr_data8(0x06); |
hudakz | 0:fa952828e34c | 117 | wr_data8(0x12); |
hudakz | 0:fa952828e34c | 118 | wr_data8(0x07); |
hudakz | 0:fa952828e34c | 119 | wr_data8(0x00); |
hudakz | 0:fa952828e34c | 120 | |
hudakz | 0:fa952828e34c | 121 | wr_cmd8(0xE1); |
hudakz | 0:fa952828e34c | 122 | wr_data8(0x0F); |
hudakz | 0:fa952828e34c | 123 | wr_data8(0x38); |
hudakz | 0:fa952828e34c | 124 | wr_data8(0x35); |
hudakz | 0:fa952828e34c | 125 | wr_data8(0x0a); |
hudakz | 0:fa952828e34c | 126 | wr_data8(0x0c); |
hudakz | 0:fa952828e34c | 127 | wr_data8(0x03); |
hudakz | 0:fa952828e34c | 128 | wr_data8(0x4A); |
hudakz | 0:fa952828e34c | 129 | wr_data8(0x42); |
hudakz | 0:fa952828e34c | 130 | wr_data8(0x36); |
hudakz | 0:fa952828e34c | 131 | wr_data8(0x04); |
hudakz | 0:fa952828e34c | 132 | wr_data8(0x0F); |
hudakz | 0:fa952828e34c | 133 | wr_data8(0x03); |
hudakz | 0:fa952828e34c | 134 | wr_data8(0x1F); |
hudakz | 0:fa952828e34c | 135 | wr_data8(0x1B); |
hudakz | 0:fa952828e34c | 136 | wr_data8(0x00); |
hudakz | 0:fa952828e34c | 137 | |
hudakz | 0:fa952828e34c | 138 | wr_cmd8(0x20); // display inversion OFF |
hudakz | 0:fa952828e34c | 139 | |
hudakz | 0:fa952828e34c | 140 | wr_cmd8(0x36); // MEMORY_ACCESS_CONTROL (orientation stuff) |
hudakz | 0:fa952828e34c | 141 | wr_data8(0x48); |
hudakz | 0:fa952828e34c | 142 | |
hudakz | 0:fa952828e34c | 143 | wr_cmd8(0x3A); // COLMOD_PIXEL_FORMAT_SET |
hudakz | 0:fa952828e34c | 144 | wr_data8(0x55); // 16 bit pixel |
hudakz | 0:fa952828e34c | 145 | |
hudakz | 0:fa952828e34c | 146 | wr_cmd8(0x13); // Nomal Displaymode |
hudakz | 0:fa952828e34c | 147 | |
hudakz | 0:fa952828e34c | 148 | wr_cmd8(0x11); // sleep out |
hudakz | 0:fa952828e34c | 149 | wait_ms(150); |
hudakz | 0:fa952828e34c | 150 | |
hudakz | 0:fa952828e34c | 151 | wr_cmd8(0x29); // display on |
hudakz | 0:fa952828e34c | 152 | wait_ms(150); |
hudakz | 0:fa952828e34c | 153 | } |