Initialization of ILI9341 LCD and STMPE811 TS for STM32F4

STM32F429I-DISCO comes with the Thin-film-transistor liquid-crystal display (TFT LCD) which is 2.41″ display of 262 K colours with 240×320 resolution. It includes the ILI9341 LCD controller which supports full colour, 8-color display mode for precise power control and a STMPE811 is a 4-wire resistive touch screen controller with a GPIO port expander.

In this tutorial it will be explained how to create project from scratch using STM32CubeMX with LCD and touch screen.

For this tutorial STM32CubeF4 libraries are mandatory which are obtainable from ST official page. However if you don’t want to download 310Mb you can use the link below to download only libraries that are necessary for this project. [download id=”5″ display=”name” display=”description” display=”both”]

Create new project in STM32F4CubeMX for STM32F429ZITx MCU as explained in the last tutorial. You can check it here. Find RCC and enable High Speed Clock (HSE), Crystal/Ceramic Resonator.  Set clock as in picture below and generate code.

Clock Configuration
Clock Configuration

Project setup

In project folder create two new folders, BSP in $Project_Name/Drivers/BSP and other one Utilities in $Project_name/Utilities folder. From the STM32Cube repository copy folders: Components and STM32F429I-Discovery into newly created BSP folder and Fonts into Utilities.

Path to Libraries
Path to Libraries

In project tree create new group named BSP. Right click on BSP folder and click on Add Existing Files to Group. Find $Project_name/Drivers/BPS folder and add files that are marked on the picture below.

The stm32f429i_discovery.c contains functions for all components on discovery kit (TS, GYROSCOPE, LCD…)


In µVision right click on Drivers/STM32F4xx_HAL_Driver and click on Add Existing Files to Group. Find $Project_name/Drivers/STM32F4xx_HAL_Driver/src folder and add files that are marked on the picture below.

Added Libraries
Added Libraries

Next the path needs to be set to the newly added files. Right click on project file->Options->C/C++ and under Define add: USE_STM32F429I_DISCO. In the same screen under Include Paths add: ..\Drivers\BSP\STM32F429I-Discovery, if you created BSP folder under Drivers.

 Define should look like USE_HAL_DRIVER, STM32F429xx, USE_STM32F429I_DISCO and

IncludePaths ../Inc;../Drivers/STM32F4xx_HAL_Driver/Inc;../Drivers/STM32F4xx_HAL_Driver/Inc/Legacy;../Drivers/CMSIS/Include;../Drivers/CMSIS/Device/ST/STM32F4xx/Include;..\Drivers\BSP\STM32F429I-Discovery


As the last thing HAL modules need to be enabled. Open stm32f4xx_hal_conf.h, under main.c, and uncomment files that were added.

HAL Modules
HAL Modules

How positioning in LCD actually works

As already said TFT LCD on STM32F429I-DISCO is 240×320 resolution. The library written by MCD Application Team from STMicroelectronics is using “pixel positioning” to draw various objects.

Pixel positioning on ILI9341
Pixel positioning on ILI9341

It is basically 2D matrix. Most functions work as an example below.

First argument is X1 as 1st coordinate on X AXIS and Y1 on Y AXIS. What we get from that is single dot. Two second parameters write second dot and in the function they are connected.

Example code

Below is an example code with LCD and TS initialization, 3 buttons and 3 “states”. With each button being pressed LCD writes/changes colour of the letters and buttons. The code below can be used to test if project is set correctly.

Related posts

  • Space Engineer

    Nice one!

    • Michael Barton

      hi – thanks for helping 🙂
      just a small point, your checking of touch positions needs tweaking eg:
      if(y > 245 & y 245 && y < 315)

  • Martin-Michael Kunkies

    Thx for your Blog, but you missed a couple of things!

  • Martin-Michael Kunkies
  • 馮天懋

    sorry,I have a question for this project. When I compiler it and the errors are occurred as below:
    “Undefined symbol BSP_TS_Init(referred from main.o)”not enough information to list image symbols
    “Undefined symbol BSP_TS_GetState(referred from main.o)”

    • Hey, sorry for late response. It means that compiler can’t find functions from #include “stm32f429i_discovery_ts.h”. Are you sure file is included and path to it is set?

      • 馮天懋

        Thanks for your advice. A big hand give for my problems, I found that I just include the HEX file but none of C file is in it path(define but no declare), so I add new C file and fix it.

        Thanks for your reply,
        Benefited a lot ^^