Generating Code
This section describes what the TouchGFX Generator outputs when generating code in STM32CubeMX.
Generated project
Other than the GCC compiler that is bundled with TouchGFX and used when run target is pressed in TouchGFX Designer, TouchGFX also works with (at least) the following IDEs when generating code using the Generate Code button in STM32CubeMX:
- EWARM
- MDK-ARM
- STM32CubeIDE
For optimal project structure, navigate to Project Manager and select the following options for project generation:
- Application structure: Advanced
- Disable Generate under root (STM32CubeIDE only)
After pressing the Generate code button, STM32CubeMX will generate some code for the selected middlewares, utilities, drivers, toolchain etc.
STM32CubeMX will also generate a TouchGFX folder in the root of the project folder with the following structure:
- The App folder contains code to initialize and start TouchGFX.
- The target folder contains read-only generated code (inside generated/) and modifiable user classes (
STM32TouchController.cpp
,TouchGFXGPIO.cpp
andTouchGFXHAL.cpp
). - The .part file is opened with TouchGFX Designer in order to create a complete TouchGFX project with TouchGFX header files and libraries. The part file contains relevant application information such as pixel format and canvas dimensions that TouchGFX Designer uses when generating TouchGFX application code.
Once the code is generated through STM32CubeMX, the TouchGFX project can be opened with TouchGFX Designer in order to develop the UI. TouchGFX Designer automatically adds any additional generated code files to the target IDE project that is selected for the current project in STM32CubeMX.
Further reading
Generated Code Structure
Some files are always generated in the TouchGFX folder regardless of the configurations made in TouchGFX Generator, while others are only generated if certain features are enable/disabled (e.g. Video Decoders or Custom DMA2D class). The contents of the generated files are updated whenever developer generate code in STM32CubeMX, to reflect changes made in TouchGFX Generator AL configurations.
The listing below shows an overview of the content of a STM32CubeMX project with TouchGFX Generator enabled, with emphasis on TouchGFX related files that are always generated.
TouchGFX Folder
│ .mxproject
│ myproject.ioc
├───Core
├───Drivers
├───EWARM
├───Middlewares
└───TouchGFX
│ ApplicationTemplate.touchgfx.part
├───App
│ app_touchgfx.c
│ app_touchgfx.h
└───target
│ STM32TouchController.cpp
│ STM32TouchController.hpp
│ TouchGFXGPIO.cpp
│ TouchGFXHAL.cpp
│ TouchGFXHAL.hpp
│
└───generated
OSWrappers.cpp
TouchGFXConfiguration.cpp
TouchGFXGeneratedHAL.cpp
TouchGFXGeneratedHAL.hpp
The following table outlines the responsibility of the most important entries.
Folder | Responsibility |
---|---|
myproject.ioc | STM32CubeMX Project file |
Core | main.c and startup code |
Drivers | CMSIS, MCU family drivers, and Board Support Packages (BSP) |
EWARM | IDE project folder. Can be EWARM, MDK-ARM or STM32CubeIDE |
Middlewares | Contains TouchGFX library/headerfiles and third party software like FreeRTOS. |
ApplicationTemplate.touchgfx.part | The .part file is updated by STM32CubeMX with information that is relevant to TouchGFX Designer project, e.g. screen dimensions and bit depth |
App | X-CUBE interface to STM32CubeMX. app_touchgfx.c contains definitions for the functions MX_TouchGFX_Process(void) and MX_TouchGFX_Init(void) which are used to initialize TouchGFX and start its main loop. |
target/generated | This sub-folder contains the read-only files that get overwritten by STM32CubeMX when configurations change. TouchGFXGeneratedHAL.cpp is a sub-class of the TouchGFX class HAL and contains the code that STM32CubeMX can generate based on its current configuration. OSWrappers.cpp (The OSAL) contains the functions required to synchronize with TouchGFX Engine, and finally TouchGFXConfiguration.cpp which contains the code to construct and configure TouchGFX, including the HAL. |
target | Contains the bulk of files that can be modified by the user to extend the behavior of the HAL or to override configurations generated by STM32CubeMX. STM32TouchController.cpp contains an empty touch controller interface. TouchGFXHAL.cpp defines a sub-class, TouchGFXHAL , of TouchGFXGeneratedHAL . |
It is important to know that TouchGFXConfiguration.cpp
contains a function that constructs the HAL and a function
that starts the main loop of TouchGFX. Additional configuration can be done in the editable user-classes.