How to enable the touch capability of the STM32F746G-Discovery board screen for GUI application ?
By default the touch capability of the display is not enabled and this is not handled by the CubeMX tool.
This document will guide you through the few steps needed to get a functional touch screen based on an existing GUI application.
1. Create a basic GUI application starting from the configured CubeMX project for F746
In this section wil will quickly create a basic GUI composed of 2 buttons and generate the corresponding Atollic project.
This part is covered quickly since it is described in more details in the dedicated FAQ: STM32F746G-Discovery : Create a basic Graphical Application using CubeMX, feel free to refer to it.
Open the already configured CubeMX project for F746
In the configuration tab click on GRAPHICS
Click on the Execute button to launch the GUIDesigner
Add 2 buttons by clicking twice on the dedicated item in the list of widgets
Close the GUIDesigner and re-generate the project by clicking on the button hilighted below
2. Import Touch drivers (low-level, BSP interface and HAL interface)
Import the generated project in Atollic TrueStudio, right-click on the Drivers folder and select Import
Select File System
Select the Drivers folder as the base folder and click Ok
From this dialog box we will select all the required files
First the low-level touch driver ft5336.c/h
Then a higher level interface in the Common folder
The BSP driver common files and touch dedicated
Then click Finish to actually import the files, you should now have the following structure in your Atollic project
3. Update Include files search path
Since some include files have been imported you must add their parent folder in the include folder list.
Open project properties and go to C/C++ Build -> Settings
Then go to Tool Settings tab and C Compiler->Directories section
add the new folders containing include files:
Open the ./src/main.c file and #include directives (between the USER tags) as below
4. Go back to the CubeMX project to enable and configure required peripherals
First enable the I2C peripheral on which the Touch interface is plugged
Enable USART1 (not mandatory for the touch capability but needed because of an internal BSP dependency)
Configure TIM3 as follow (expiration every 1 ms)
and enable the interrupt
5. Back to the Atollic project edit the source code
Note that the added include directives are kept despite the re-generation of source code !
Let's keep on adding the specific code between the USER tags.
Initialize the touch screen and timer so that on each expiration the touch status is retrieved (polling mode)
- In main.c file in USER CODE BEGIN/END PFP section add the declaration below:
- In main.c file in USER CODE BEGIN/END 2 section add the call below:
- In main.c file in USER CODE BEGIN/END 4 section add the definitions below
- In main.c file in HAL_TIM_PeriodElapsedCallback USER CODE BEGIN/END Callback 1 section add
Implement the action to be achieved when touching one of the button (i.e. make the other one invisible)
First declare some variables
- In WindoDLG.c file in cbDialog function in USER START/END Callback 1 section add
- In WindoDLG.c file in cbDialog function, case ID_BUTTON_0 and case WM_NOTIFICATION_CLICKED in USER START/END section add
6. You can now rebuild the entire project and flash it to the board
Touching the Button 0 (top left corner of the screen) will hide the second button, clicking it again will make the second button appear again !
You now have a functional graphic application with the touch screen capabilities enabled and since all the additional source code has been added in specific user sections you are free to enable and configure other peripherals from the CubeMX tool and re-generate the source code without loosing it.
The full final project is provided in attachment.