This article is based on the STM32F429IGT6 + RGB (800 * 480) hardware platform, and records in detail how to use STM32CubeMX to port TouchGFX to STM32F429IGT6 and drive the RGB screen. For the installation of related software, please refer to the TouchGFX software installation article
The application framework of TouchGFX is shown in the figure below:
1. STM32CubeMX configuration
STM32CubeMX is mainly used to configure the hardware abstraction layer and middleware layer in the application framework diagram shown above
- RCC system clock: high-speed external clock (HSE) configured as an external crystal oscillator
- Since the FreeRTOS operating system is to be used, it is recommended to change the Timebase Source of the HAL library from SysTick to other timers. After the timer is selected, the system will automatically configure TIM, which is set to TIM7 here
- FMC setting: Configure external SDRAM as RGBLCD video memory, configure parameters and pins according to your own hardware
- DMA2D settings: activate DMA2D, configure the color mode as RGB565, and enable DMA2D interrupt
- LTDC parameter setting: Configure LTDC parameters according to the screen parameters used
- LTDC layer setting: choose to use layer 1 here, and set the frame buffer address to the first address of SDRAM 0XC0000000
- LTDC GPIO pin setting: According to the pin connection of the specific development board, configure GPIO, pay attention to set the output speed to "Very High"; and enable LTDC interrupt
- Clock tree configuration: the pixel clock size is 1056 x 705 x 60 / 1024 / 1024 = 42M, the maximum pixel clock is 42M, here is set to 33M (1056 is the total width, 705 is the total height)
- Backlight pin setting: The development board in this article uses PB5 as the backlight pin, which is set to push-pull output
- Activate CRC: TouchGFX needs to enable CRC function
- Activate the FreeRTOS system: set the heap size to 32768 bytes, and the rest of the default configuration; and add a TouchGFX task
- Select the Touchgfx component package
- TouchGFX parameter setting: select double buffer, RGB565, enable DMA2D acceleration
- Generate engineering code: the minimum stack size is set to 0x800
After STM32CubeMX generates the project, there is no need to open the Keil project. If you compile the Keil project at this time, there will be a lot of errors
2. TouchGFX Designer interface design
After the Keil project is generated, it is necessary to execute Touch Designer to design the UI part and improve the project
- After generating the project, there is an ApplicationTemplate.touchgfx.part in the TouchGFX directory, click to open TouchGFX Designer
- After dragging and dropping some controls, click Generate Code to generate the code, and the TouchGFX related code will be automatically added to the project
3. Add code to MKD-ARM Keil
- Add SDRAM driver source files and header files
- Add the SDRAM initialization function in the fmc.c file MX_FMC_Init() function to drive the external memory chip
- Light up the screen backlight in the touchgfxhal.cpp file
- Add the corresponding task, add TouchGFX processing function
4. Download test
After the compilation is correct, download it to the development board
If TouchGFX is transplanted successfully, the development board screen will display the interface designed in TouchGFX Designer