stm32f4 tft lcd example supplier
STM32F429 has also LTDC driver for LCD like that, but this driver we will use later. For now we will use SPI for driving in serial mode and some other pins for controlling.
Remember: This library can also be used, if you are not using STM32F429 Discovery. It can be used in previous STM32F4 Discovery board. All pins can be changed in defines.h file which is included in project.
It’s time to write about a more complex but interesting connection with the STM32F4-Discovery board. Since I started developing with electronics, I’ve found a lot of applications in which an LCD is needed or can be an added value, specially if it includes a Touchscreen.
Last week I received a 3.2″ TFT LCD with Touchscreen from waveshare, model HY32D. It is based on SSD1289 display controller and also includes a touchscreen interface based on XPT2046 which communicates over SPI link. With a QVGAresolution (320×240 pixels) is enough for many applications and, more important, it is very affordable.
Well, fortunately Waveshare(LCD module supplier) includes some code to drive different kinds of displays and touchscreens. On Waveshare module’s page there is also a very helpful table that indicates the pinout (also the module itself has named pins on bottom side) that helps wiring to the board. Basically I have connected in this way:
The LCD I am using is a 2.8″ TFT LCD with SPI communication. I also have another 16-bit Parallel TFT LCD but it will be another story for another time. For this post, let’s focus on how to display what you want on the 2.8″ LCD. You can find all details about this LCD from this page:http://www.lcdwiki.com/2.8inch_SPI_Module_ILI9341_SKU:MSP2807
First thing first, this LCD use SPI as the main communication protocol with your MCU. For STM32 users, HAL Library has already implemented this protocol which makes this project easier for us. But, a little knowledge about this protocol does not hurt anyone. SPI is short for Serial Peripheral Interface which, aside from two data lines, also has a clock line and select lines to choose between devices you want to communicate with.
This LCD uses ILI9341 as a single-chip SOC driver for a display with a resolution of 240×320. More details can be found in the official document of ILI9341. But the most important thing is that we have to establish astart sequencein order for this LCD to work. The “start sequence” includes many other sequences which are also defined in the datasheet. Each sequence starts when you send a command to ILI9341 and then some parameters to follow up. This sequence is applied for all communication between MCU and ILI9341.
For this project, I recommend using theSystem Workbench for STM32for coding and building the code. After installing and open the program, go to the source code you have just downloaded and double click the.cprojectfile. It will automatically be open in your IDE. Then build the program by right click on the folder you just open (TFTLCD) and chooseBuild Project. Wait for it to finish and upload it to the board by right clicking the folder, choose Run As and then clickAc6 STM32C/C++ Application. And that’s it for running the example.
The most important library for this project is obviously the ILI9341_Driver. This driver is built from the provided source code in the lcdwiki.com page. I only choose the part that we need to use the most in many applications like writing string, displaying image and drawing symbols. Another library from the wiki page is the TOUCH library. Most of the libraries I got from the Internet were not working properly due to some adjustments to the original one.
To draw symbols or even display images, we need a “byte array” of that image or symbol. As an illustration, to display an image from a game called Transistor, I have a “byte array” of that image stored in a file named transistor.h. You can find this file in the link below. Then, I draw each pixel from the image to the LCD by adding the code in the Display_Picture() function in the Display folder.void Display_Picture()
The above example is just only for displaying black and white image. In order to show a color image, we need to a little bit different. First, go tothis websiteto generate the array of the colour image. Remember to change your size to 320×240 and choose the 65K color option. Because it now takes up two bytes for one pixel, we need to send two bytes at once. You can check the Display_Color_Picture() function in the Display folder.void Display_Color_Picture()
Ahh yeah look at that! If you look closely, top right of the LCD, that’s obviously a flex connector for a resistive touch overlay (4 contacts running to the 4 sides of the LCD overlay).
Agreed! I will be picking one up. I’ve been happy developing for the stm32f4discovery (and other stm32 chips) with gcc, openocd and gdb. It is all free.
The STM32F4 cores are pretty well supported by libopencm3 and Code Sourcery and summon-arm-toolchain both build working toolchains and openOCD supports the stlink natively now.
A fair number of inexpensive baseboards/motherboards/accessories have also appeared for earlier versions. I hope Olimex puts out a couple nice STM32F429/427 boards.
I can see there is only a STLINK usb connector on board, so there is even no FS to expect. beside HS, I suppose does mean High Speed (480mbps). but HS anyway needs a separate physical layer USB chip for addition to STM32F4 chip and most likely this is chip is not present on this board anyway, because this is STM32F4+LCD+SDRAM demoboard and there is no need for USB at all.
The data brief bullet-points “USB OTG with micro-AB connector”. Looks like the micro-usb is on the underside, sticking out at the bottom of the photo. With matching T/H mounting tabs on the topside, labelled USB USER. But like you said, the STM32F4 requires an external PHY for HS, and it seems unlikely they’d include one on this board.
I think Farnell’s 21€ will be accurate, as ST’s suggested USD price is $24. The placeholders for the STM32F429I-DISCO on element14 (a division of Farnell) and mouser show $42, which I think predates the later ST announcement. I think the ST announced $24 will hold, and the distributor prices will match that, as they have in the past.
I wouldn’t expect TI to hack profits from their calculator range, and HP have always been expensive, but ST could easily change their format to calculator-friendly. Clamshell design, LCD & battery in top half, CPU & keypad in bottom half, expansion pins to left / right of keypad makes a self contained unit.
HP Palm – Love the idea, hate the baguette (french bread loaf) layout. If I could get custom key covers, and surface-mount key switches, I’d be designing my own low-profile keypad to go with an LCD module. Top side keypad, bottom side CPU / RAM / USB / LCD driver / power regulation / expansion port.
Great find, thanks! Man, could they have buried the details on that guy any farther down into the document? I can’t help but feel like a quick pointer in the LCD section to “oh by the way there’s a touch screen, here’s how to talk to it” would have been a good idea.
It’s certainly useable in any other project where you have an onboard LCD controller. Especially any other project that happens to use a STM32F4. What difference would it have made if it had an external controller? Surely it’d have been on the same PCB. Were you hoping for a removeable SPI-interfaced module?
Look in the UM1670 user manual, paragraph 4.8: the tft includes an ILI9341 controller. The ILI9341 has it’s own graphics ram inside, it is not mapped into the STM32 address space. It is connected to the STM32 via a parallel bus. The ILI9341 and similar controllers are common on cheap chinese tfts. So it is no problem to source similar tfts for your final product after developing on the discovery board.
UM1670 in paragraph 4.8 also says that “The TFT LCD is a 2.41″ display of 262 K colors. Its definition is QVGA (240 x 320 dots) and is directly driven by the STM32F429ZIT6 using the RGB protocol”. ILI9341 has multiple modes of operation including direct RGB/HSYNC/VSYNC mode which bypasses internal GRAM. I don’t have the board yet but I assume display buffer is located in external SDRAM which is also on the board. The whole point of this kit is to show TFT and SDRAM interface in new STM32F4x9.
I’ve checked this discovery board firmware available from ST’s site (“STM32F429 discovery firmware package UM1662” number: STSW-STM32138, btw. finding it is a bit difficult – ST’s site is terrible):
They are using FreeRTOS, FatFs, STemWinLibrary which is ST’s version of Segger’s emWin graphic library and STM32F4xx_StdPeriph_Driver v1.2.1 which includes F429/439 support (FMC, LTDC and DMA2D added).
Check again martin. Those lines have pullups to vdd and are connected to cpu pins. I have this board for some time and I can confirm that lcd is driven by lcd controller from cpu and frame buffer is in external dram which is also on the board.
GPIO configuration is done similiar way as in example for SDRAM. But unfortuneatly TFT controller pins are shared in two alternate functions group (9 and 14), so there is third table with AF initialization values.
At this moment easiest way to display antything on LCD is use random content that SDRAM holds after power-up. Go to sdram.c file and comment following lines:
LVDS displays can vary a lot. LVDS displays are not governed by a set of well defined rules like MIPI DSI displays are. Therefore, it is up to the LCD manufacturer and the LVDS display driver IC manufacturer to use LVDS interface as they please, as long as they follow the physical interface and logic levels.
Based on this data, we can pick an LVDS transmitter IC. SN75LVDS84 from Texas Instruments is great for use with LCD displays that can be driven by an STM32.
As you learn about more of your microcontroller’s peripherals and start to work with more types of sensors and actuators, you will probably want to add small displays to your projects. Previously, I wrote about creating a simple program to draw data to an SSD1331 OLED display, but while they look great, the small size and low resolution can be limiting. Fortunately, the larger (and slightly cheaper) ILI9341 TFT display module uses a nearly-identical SPI communication protocol, so this tutorial will build on that previous post by going over how to draw to a 2.2″ ILI9341 module using the STM32’s hardware SPI peripheral.
We’ll cover the basic steps of setting up the required GPIO pins, initializing the SPI peripheral, starting the display, and then finally drawing pixel colors to it. This tutorial won’t read any data from the display, so we can use the hardware peripheral’s MISO pin for other purposes and leave the TFT’s MISO pin disconnected. And as with my previous STM32 posts, example code will be provided for both the STM32F031K6 and STM32L031K6 ‘Nucleo’ boards.
There are actually multiple sets of pins mapped to the SPI1 peripheral, even on the 32-pin STM32xKx chips. I’ll use pin B3 for SCK and pin B5 for MOSI. Pin B4 is mapped to MISO, but I’ll use it as a general-purpose output to drive the D/C pin on the TFT. As long as the MISO pin is not configured as ‘alternate function’, the peripheral will ignore it and we can use pin B4 as a normal GPIO pin. Finally, pins A12 and A15 are mapped to CS and RST respectively:
If you run into issues and want to get a better look at the signals on an oscilloscope or logic analyzer, you can slow the peripheral down by setting the three BR (Baud Rate) bits; they default to zero, and the peripheral’s clock speed is divided by two to the power of their value plus one. So for example, you can slow things down by a factor of 256 by setting all of those bits before enabling the peripheral:
To refresh the entire 240 x 320 display, we can set the drawing area to be between (0, 0) and (239, 319) and then draw 320 * 240 = 76,800 pixels of data. That’s a lot of data – even at one bit per pixel, the small chips used in this example would not have enough RAM to store a full framebuffer. You’d need over 600KB of RAM to store a full 16 bits of color per pixel, so we’ll only draw some solid colors in this tutorial.