Getting started with TouchGFX || STM32F750

TouchGFX is a very powerful and easy to use GUI designing software by ST. Specially if you are using a STM32 controller, it is very convenient to use the TouchGFX for designing the GUI.

This tutorial series will cover different components in the TouchGFX, and how do we use them with our MCU.

This particular tutorial is going to be very basic, and today we will see how to use the button on the display to control the LED on the MCU.

We will create the project from the TouchGFX and later modify it in the IDE.

TouchGFX Setup

Create a new Project in TouchGFX

  1. Click on the create tab to create the project
  2. Search for the controller board
  3. Out of the results shown, choose your board
  4. Give the name to the project
  5. click create to create the project

Add the background Image

First thing we will do is, add the background image to our project. Make sure the image is in the PNG format and is of same resolution the display supports.

  • Here we will hover on the Image tab and select the Image from the options. Once we do that an image icon will be added to the display.
  • Click on the image icon to edit the properties of this image.
  • In the properties, under the image section, click on no image.
  • Now click on the ‘+’ button to choose the image.
  • Once the image is visible in the image Picker, click on the image.
  • The image will automatically be added to the display.

You can see below how the image is going to look.

Add the Toggle Button

Now we have added the background image to our display, the next element we add is the toggle button. This button will be used to toggle the LED on the controller.

Here we will again hover on the button tab, and choose the Toggle Button from the list of buttons.

You can adjust the positioning on the button by dragging it on the display. If you click on the button, you can see the properties on the right side of the screen.

Here you can choose the type of button you need. For example, if the button is going to be round, or rectangle, etc.

Add the Interaction to the screen

Now we have the button on our screen, but what exactly will happen when we click this button ?

Well we can define this in the interaction part.

Interactions are basically limited to the screens on which you are adding them. So for example, if you have 2 screens, the all the interactions added on screen 1 will only work on screen 1.

The image above adds the interaction to screen 1.

  • Click on the Interaction tab
  • click on the ‘+’ button to add the interaction
  • Once the interaction is added, click on it to modify it
  • Now we have to choose what kind of interaction we need on the screen.

Here the Trigger is set when the button is clicked, and the button is the toggleButton1.

So when the toggle button is clicked, we will call a new virtual function, ToggleLED, which we will write later in our IDE.

Inside this function we will write a code to toggle the LED connected to the controller.

Generate the Project

This is all the setup we need to do in the touchGFX. Now we will generate the project.

The following options can be seen on the bottom right corner of the software.

Here we have the options to Generate the code, or Run the simulator, or Flash the project to the board.

Since we still need to write the code in the IDE, we will simply generate the code for now.

Once the code is generated, we can open the project folder by clicking the Files button on the bottom left corner of the software.

Open the cubeIDE

Clicking on the Files button will take you to the TouchGFX folder of the project.

We will navigate to the main project folder, and then enter inside the STM32cubeIDE folder.

Now double click on the .project file to open the project in the cubeIDE.

The images below shows the Project structure in the cubeIDE.

Here all the assets are placed in the generated folder. All the files in the generated folder are not modifiable, so we can only view them for reference. We will mainly work with the gui folder in all of our touchGFX projects.

CubeMX Setup

Since we need to add a LED to our project, we have to open the cubeMX and set the pin output from there.

Here in the cubeMX I have set the pin PA0 as the output pin. I will connect the LED to this pin.

Click save to generate the project.

The code

As I mentioned earlier, we will be mainly working with the gui folder.

Open the file Screen1View.cpp in the gui folder.

Here we need to first define the function we created in the interaction i.e ToggleLED ().
So right click on the Screen1View.hpp definition on the top and click “open declaration”.

class Screen1View : public Screen1ViewBase
    virtual ~Screen1View() {}
    virtual void setupScreen();
    virtual void tearDownScreen();

    virtual void ToggleLED();  // from the interaction


Above the code shows the entire Screen1View.hpp file. Here I have added the function virtual void ToggleLED();, which we defined in the interaction.

Now we will write the source code for this function in the Screen1View.cpp file.

#include "stm32f7xx_hal.h"

// LED Toggle function
void Screen1View::ToggleLED()
	if (toggleButton1.getState()) HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0, GPIO_PIN_SET);

Before writing the function make sure you include the header file for your controller, or else the HAL functions will be undefined.

We will first read the state of the toggle button (getState()). If the state is true, we will turn the LED ON, or else turn the LED OFF.
Here toggleButton1 is the name of the toggle button and is defined in the touchGFX designer when we added the button.

That is all the code we need to write. Now you can either flash the project using the touchGFX, or the cubeIDE itself.

If you are flashing using the IDE, you need to select the respective loader in the debugger (If it is not selected by default). This is shown in the image below.


Below are the images showing the toggle button and the LED attached to pin PA0.

The first image shows when the button is in the OFF state, the LED is also OFF. The button state has been changed to ON in the second image, and so does the LED.

Check out the Video Below


You can help with the development by DONATING
To download the code, click DOWNLOAD button and view the Ad. The project will download after the Ad is finished.

5 Comments. Leave new

  • Hello Prabhu, i have the same problem!
    Have u found a solution for this error?

  • Hi I tried the same with STM32F769NI DISCO board. I am getting an error:
    no declaration matches ‘void Screen1View::Led()’ Screen1View.cpp /STM32F769I_DISCO/Application/User/gui line 158 C/C++ Problem

    • You missed some definition, probably the LED() function’s definition in the view.cpp file.

    • Hi Prabhu,
      I have the same problem even I followed every step
      Have you found the solution for this error?
      Tks in advanced,

  • Hello
    Your tutorials are excellent
    I have a problem, which is that I can’t write a graphic program to control the light intensity, and by writing GUI, you are teaching about ADC modules such as loadcell and PMW contorell.


Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.


Adblocker detected! Please consider reading this notice.

We've detected that you are using AdBlock Plus or some other adblocking software which is preventing the page from fully loading.

We don't have any banner, Flash, animation, obnoxious sound, or popup ad. We do not implement these annoying types of ads!

We need money to operate the site, and almost all of it comes from our online advertising.

Please add to your ad blocking whitelist or disable your adblocking software.