Showing results for 
Search instead for 
Did you mean: 

How to Set up TouchGFX For STM32CubeMX Generated CMake Project Using Visual Studio Code?

Associate II

Software Using:

  1. STM32CubeMX 6.11.1
  2. STM32 VS Code Extension v2.0.1
  3. STM32CubeCLT 1.15.1
  4. TouchGFX 4.23.2
  5. Visual Studio Code 1.89.1
  • 1, 2, 5 always auto update itself.

Hardware Using:

  • MCU: STM32F411CEU
  • Board: A third party development board, "BlackPill" to be specific.
  • Display: GC9A01 240x240 round display.

Tips: Don't use SPACES in the path of any STM software and your projects, sometimes it will warn you but the other time it will create problems without your notice.

Here is my progress:

  1. Generate a CMake project with X-CUBE-TOUCHGFX selected using STM32CubeMX, open the .part file with TouchGFX Designer and create a UI, before clicking Generate Code go to Config->Build->Post Generate Command and delete the command there, after deletion, click Generate Code, the code then can be successfully generated.
  2. But if you try to build, it will complain a lot about "No such file or directory", mainly some header files, go to ./cmake/stm32cubemx/CMakeLists.txt, add the following code extracted from to a suitable place.


set(root_tgfx_dir ../../TouchGFX)


file(GLOB_RECURSE graphics_core_generated_SRCS

set(graphics_core_generated_SRCS ${graphics_core_generated_SRCS})

list(FILTER graphics_core_generated_SRCS EXCLUDE REGEX ".*/simulator/.*")
list(FILTER touchgfx_include_DIRS EXCLUDE REGEX ".*/simulator/.*")


and add these to their corresponding places:

  • Note when adding libtouchgfx: under the directory ./Middlewares/ST/touchgfx/lib/core, there are different folders for different CPUs, choose the one that you are using and change the path showing below accordingly. 


target_include_directories(stm32cubemx INTERFACE

target_sources(stm32cubemx INTERFACE
add_library(touchgfx INTERFACE)
target_link_libraries(stm32cubemx INTERFACE
    touchgfx ${CMAKE_SOURCE_DIR}/Middlewares/ST/touchgfx/lib/core/cortex_m4f/gcc/libtouchgfx-float-abi-hard.a


Beware if you generate code again using STM32CubeMX, the above addition will be deleted, you'll have to add it again or just use git.

Build again and you will get these error:


undefined reference to `touchgfxDisplayDriverTransmitActive'
undefined reference to `touchgfxDisplayDriverTransmitBlock'


After some reading I fond out you have to implement these yourself, so I created some dummy function for it, and the build successes.


After the successful build, I ported my display driver and set up some code for simple test purpose, and it indeed can run, turns out all you need to do is just disable one command and edit one CMake file.



ST Employee

Hello @Aquamarine ,


It would be nice to mention the board and display you use as well as the version of the softwares you use and make sure you use the most recent ones.


Interestingly, when I try to build using CubeIDE, it too failed with the similar error.

I think you should try to fix that before processing further. Projects should be working on CubeIDE (especially if this one of the board setup we provide).



Gaetan Godart
Software engineer at ST (TouchGFX)

Updated and updating.