Skip to main content

Compiling & Flashing

This section describes how to go from TouchGFX application code to executing program, that is how to compile and flash in a specific setup.

Compiling TouchGFX Applications

When compiling a TouchGFX application, there are two options; compiling for the PC simulator or compiling for the target hardware.

Compiling for PC Simulator

There are two options for compiling projects for the PC Simulator; GCC and Visual Studio.
Both of these options are always available, since they are generated by TouchGFX Designer.

GCC

The makefile is located at <touchgfx_application_root_folder>/simulator/gcc/Makefile

TouchGFX includes a MinGW environment, that comes preinstalled with a GCC compiler and GNU Make, making it easy to execute the generated Makefile for the PC simulator.

The TouchGFX Environment can be launched either from C:/TouchGFX/4.18.0/env/MinGW/msys/1.0/msys.bat or from the shortcut added to the Windows start menu, named "TouchGFX x.y.z Environment" where x, y and z describe the version number.

After launching the TouchGFX Environment and navigating to the TouchGFX Application root folder, the simple command below can be executed to produce a simulator.exe file.

make -f simulator/gcc/Makefile

The simulator executable can then be launched from the TouchGFX Environment with the following command.

./build/bin/simulator.exe

The PC Simulator can also be compiled and launched from TouchGFX Designer, by using the Run Simulator command.

Visual Studio

To compile the PC Simulator using Visual Studio, simply open the generated solution file located at <touchgfx_application_root_folder>/simulator/msvs/Application.sln using Visual Studio.

The PC Simulator can be launched directly from Visual Studio, enabling code debugging.

Note
Before being able to compile with GCC or Visual Studio, Run the Generate command from TouchGFX Designer.

Compiling for Target Hardware

Compiling projects for STM32 Evaluation Kits is quite simple for TouchGFX Board Setup based applications.

Each TouchGFX Board Setup contains project files for GCC, STM32CubeIDE, IAR and Keil:

  • GCC: <project_root_folder>/gcc/MakeFile
  • STM32CubeIDE: <project_root_folder>/STM32CubeIDE/.cproject
  • IAR: <project_root_folder>/EWARM/Project.eww
  • Keil: <project_root_folder>/MDK-ARM/<STM32_evaluation_kit_name>.uvprojx

The active tool chain is set from STM32CubeMX and is set to STM32CubeIDE by default. Please note that all project files are not present at the same time. The generated project file depends on the selected tool chain in STM32CubeMX

TouchGFX includes a MinGW environment, that comes preinstalled with the GNU Embedded tool-chain for Arm and GNU Make, making it easy to execute the included Makefile for the target hardware.

The TouchGFX Environment can be launched either from C:/TouchGFX/4.18.0/env/MinGW/msys/1.0/msys.bat or from the shortcut added to the Windows start menu "TouchGFX x.y.z Environment"

After launching the TouchGFX Environment and navigating to the project root folder, the simple command below can be executed to compile the project for the target hardware.

make -f gcc/Makefile
Note
Before being able to compile with GCC, STM32CubeIDE, IAR or Keil, run the Generate command from TouchGFX Designer.

Flashing STM32 Evaluation Kits

Flashing projects to STM32 Evaluation Kits is quite simple with projects based on a premade TouchGFX Board Setup.

Each project, when built, produces a binary that can be flashed by either ST Link Utility or STM32CubeProgrammer.

Therefore these tools must be installed to proceed with flashing.

It is suggested to install these tools to their default location.

  • ST Link Utility default install location:
    C:/Program Files (x86)/STMicroelectronics/STM32 ST-LINK Utility/ST-LINK Utility
  • STM32CubeProgrammer default install location:
    C:/Program Files/STMicroelectronics/STM32Cube/STM32CubeProgrammer
Note
The TouchGFX Board Setups do not provide any flash loaders for flashing directly from within IAR, Keil, STM32CubeIDE or other IDEs.

GCC & TouchGFX Designer

The Makefile included with an TouchGFX Board Setup located at <project_root_folder>/gcc/MakeFile has a built-in flash command, as shown below, that uses either ST Link Utility or STM32CubeProgrammer (depending on the TBS) to flash the STM32 Evaluation Kit.

You can start the flashing from the command-line using the same command as TouchGFX Designer uses:

make -f gcc/Makefile flash

You can also use the desktop version of the flash tools to flash the boards with the generated .hex files. The .hex file is located at <project_root_folder>/TouchGFX/build/bin/target.hex

Flashing the internal flash only

Many development boards and products use two flashes. The internal flash of the micro controller and an external flash. Typically, the internal flash contains the code and small/often used data, whereas the external flash contains large data items like images, videos and fonts.

In many situations, you need to flash both flashes at the same time as the program in the internal flash contains addresses pointing to the data in the external flash. But in some cases it is possible to flash the internal flash without flashing the external flash, for example when you have made small modifications to the application code (like changing the color or position of a Box). In this case, all the data in the external flash is unmodified and there is no need to flash it again. This can reduce the flash time considerably if you have a large set of images.

However, you need to be sure that the content for the external flash has not changed since you wrote the external flash last time. If it has, and you do not flash it again, you will see strange behavior. In this case: flash both the internal and external flash.

make -f gcc/Makefile intflash

The .hex file for the internal flash is located at: <project_root_folder>/TouchGFX/build/bin/intflash.hex.

Linker script

The intflash make target first compiles and links the application. It then flashes the intflash.hex file. This file is produced after the linking step by removing the ExternalFlashSection, TextFlashSection, and FontFlashSection sections from the application elf file. This is done using the following command:

arm-none-eabi-objcopy -O ihex --remove-section=ExtFlashSection --remove-section=FontFlashSection --remove-section=TextFlashSection target.elf intflash.hex

The result of this command is a hex-file containing only the data that is located in the internal flash. This will only work if the linker script only puts the three aforementioned sections into the external flash. The gcc linker script for the TouchGFX Board Setups typically looks like:

...  /* Details skipped */

MEMORY
{
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 320K
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 1024K
QUADSPI (r) : ORIGIN = 0x90000000, LENGTH = 16M
SDRAM (xrw) : ORIGIN = 0xC0000000, LENGTH = 8M
}

SECTIONS
{
... /* Sections for RAM, Flash, SDRAM */

ExtFlashSection :
{
*(ExtFlashSection ExtFlashSection.*)
*(.gnu.linkonce.r.*)
. = ALIGN(0x4);
} >QUADSPI

FontFlashSection :
{
*(FontFlashSection FontFlashSection.*)
*(.gnu.linkonce.r.*)
. = ALIGN(0x4);
} >QUADSPI

TextFlashSection :
{
*(TextFlashSection TextFlashSection.*)
*(.gnu.linkonce.r.*)
. = ALIGN(0x4);
} >QUADSPI
}

The linker script first defines 4 memory regions: RAM, FLASH, QUADSPI, and SDRAM. The QUADSPI region is the external flash. The 3 sections ExtFlashSection, FontFlashSection, and TextFlashSections are linked into the QUADSPI region. Nothing else is put into the QUADSPI region. This is the reason that we can produce a hex file for the internal flash by removing these 3 section from the target.elf file, which contains everything. If the linker script also puts other data into the external flash, we would need to remove that data also to end up with the internal flash content only.

If you build your target elf file using other makefiles or compilers, you can reuse the technique above to create a hex file for the internal flash and flash it from TouchGFX Designer or the command-line.

TouchGFX Designer Configuration

The TouchGFX Board Setup provides the configuration for TouchGFX Designer to be able to flash projects via the Run Target Command. The command used by TouchGFX Designer to flash can be seen and overridden in the Build Section of the Config View in TouchGFX Designer.

STM32CubeIDE

TouchGFX Board Setups provide support for flashing project compiled with STM32CubeIDE, by using the .elf file output by STM32CubeIDE, with the STM32CubeProgrammer.

The .elf file is located at <project_root_folder>/STM32CubeIDE/Debug/<STM32_evaluation_kit_name>.elf

e.g. C:/TouchGFXProjects/MyApplication/STM32CubeIDE/Debug/STM32F746G_DISCO.elf

IAR

The TouchGFX Board Setups provide support for flashing project compiled with IAR, by using the .hex file output by IAR, with the STM32CubeProgrammer.

The .hex file is located at <project_root_folder>/EWARM/<STM32_evaluation_kit_name>/Exe/<STM32_evaluation_kit_name>.hex

e.g. C:/TouchGFXProjects/MyApplication/EWARM/STM32F469I-DISCO/STM32F469I-DISCO.hex

Keil

The TouchGFX Board Setups provide support for flashing project compiled with Keil, by using the .hex file output by Keil, with the STM32CubeProgrammer.

The .hex file is located at <project_root_folder>/MDK-ARM/<STM32_evaluation_kit_name>/<STM32_evaluation_kit_name>.hex

e.g. C:/TouchGFXProjects/MyApplication/MDK-ARM/STM32F469I-DISCO/STM32F469I-DISCO.hex

Flashing Custom Hardware

If instead what needs to be flashed is custom hardware, and not a predefined hardware setup like an STM32 Evaluation Kit, you can still use STM32CubeProgrammer. STM32CubeProgrammer does not necessarily come with a flash loading mechanism for your specific external memory. It is however possible to create a custom flash loader. Read the user manual on developing customized loaders for your external memory to find more info.