Creating a TouchGFX demo project from scratch in STM32CubeIDE on STM32F429I-Discovery board. -------------------------------------------------------------------------------------------- In CubeIDE Start a new project either through the Help/Information Center or File/New/STM32 Project In Board Selector tab pick 32F429IDISCOVERY and click next. Add a project name and select C++ as the target language and click finish. Initialize all peripherals with their default mode ? click Yes. also confirm yes to change perspective if shown. Once the project is created, the integral CubeMX designer appears. System Core: select GPIO. Then in "Configuration" tab select "SPI", set "Maximum Output Speed" to "Very High" for each signal. In Connectivity: SPI5: Set Mode to Half-Duplex Master, then below in "Parameter Settings" tab/Clock Parameters, Select "Prescaler (for Baud Rate)" to 2 and Set "Clock Phase (CPHA)" 1 Edge. USART1: Disable. USB_OTG_HS/External Phy and Internal FS Phy : Disable. In MultiMedia LTDC: In the Layer Settings tab set "Alpha Constant" for both "Layer 0 - Blending Factor" 1 and 2. DMS2D: In Parameter Settings/Color Mode = RGB565. Middleware: FREERTOS: Interface: Disable. USB_HOST: Disable. Select "Additional Software" tab at the top Open up the tree view for "STMicroelectronics X-CUBE-TOUCHFX" until you see Application and select "TouchGFX Generator" then click OK. A new item "Additional Software" should now have appeared on the left. Open it and click on "STMicroelectronics X-CUBE-TOUCHFX". In the adjacent section, tick "Graphics Application". Now in the "TouchGFX Generator" tab under "Display" change "Interface" to Parallel RGB (LTDC). Then change Buffer Location to "By Address" and set Start Address to "0xD0000000". Then under "Driver" set "Application Tick Source" to LTDC and Real Time Operating System to No OS. "Clock Configuration" tab: The HSE input frequency should already be set to 8 and selected as the source. Then set /M = /4 *N = X180 /P = /2 (/Q should be greyed out) Then over to the right: APB1 Prescaler = /4 APB2 Prescaler = /2 Now none of the boxes should be red and the output frequencies should be: 180 Ethernet PTP Clock 180 HCLK to AHB 180 To Cortex system timer 180 FCLK Cortex clocks 45 APB1 peripheral clocks 90 APB1 timer clocks 90 APB2 peripheral clocks 180 APB2 timer clocks Finally, at the bottom, in the PLL SAI section: *N = X54 /R = /3 PLLCDCLK = /4 giving 9 as the "LCD-TFT clocks" output frequency As an alternative to the above you can just enter 180 into the "HCLK (MHz)" box and hit enter, and 9 into the "LCT-TFT clocks (MHz)" and it should calculate everything for you as above. Now click "Generate Code" from the "Project" menu Now close the tab with your project name.ioc, which will switch back to normal Eclipse perspective. Open the TouchGFX folder in the tree view and double click "ApplicationTemplate.touchgfx.part". This opens up TouchGFX designer (assuming it's installed). Select "Matching UI Templates" and click on TouchGFX Demo 3" and click "Select". Then click "Generate Code" top right button. Once done close the App. Right click the Project and select refresh. You now see a file with your project name.touchgfx. The project should now build without errors. Check by selecting: Project/Build All. However, it will do nothing if you download to the board and you'd just get a white screen. At this point CubeMX has created the low-level code and TouchGFX has created its high-level code. But we need to manually add the intermediate layer called the BSP (board support package). For this we need to copy some files from firmware package from ST. (en.STM32Cube_FW_F4_V1.24.0.zip). Download it and unzip to your hard drive. Back in CubeIDE, create a folder under Drivers called BSP (right click on Drivers and select New/Folder and enter BSP in the "Folder Name" box). Now using Windows Explorer (or equivelent) browse to the unzipped STM32Cube_FW_F4_V1.24.0\Drivers\BSP and select "Components" and "STM32F429I-Discovery" folders. Now drag them over to the BSP folder in CubeIDE, and then confirm "Copy files and folders". Now locate STM32Cube_FW_F4_V1.24.0\Utilities and drag drop it onto the project name in CubeIDE , and then confirm "Copy files and folders". Now we need to tell the compiler where we just put the new files: Right click the project name and select Properties. Navigate to C/C++ General/Paths and Symbols and click the "Includes" tab. Below "Languages" select GNU C++. Click Add and enter: Drivers/BSP/STM32F429I-Discovery Click OK then Apply and Close. From the project tree view open file: TouchGFX/target/STM32TouchController.cpp. Edit the user code section to look like this: /* USER CODE BEGIN STM32TouchController */ #include #include #include void STM32TouchController::init() { /** * Initialize touch controller and driver * */ BSP_LCD_Init(); BSP_TS_Init(BSP_LCD_GetXSize(), BSP_LCD_GetYSize()); } bool STM32TouchController::sampleTouch(int32_t& x, int32_t& y) { /** * By default sampleTouch returns false, * return true if a touch has been detected, otherwise false. * * Coordinates are passed to the caller by reference by x and y. * * This function is called by the TouchGFX framework. * By default sampleTouch is called every tick, this can be adjusted by HAL::setTouchSampleRate(int8_t); * */ TS_StateTypeDef state; BSP_TS_GetState(&state); if (state.TouchDetected) { x = state.X; y = state.Y; return true; } return false; } /* USER CODE END STM32TouchController */ Once done you can build the project. Now run it in debug: Right click the project, select "Debug As" and pick "STM32 Cortex M C/C++ Application" Leave the defaults and just click "OK" Once downloaded, the code will stop at HAL_Init(); Now just click the "resume" button and the display should show the TouchGFX demo.