cancel
Showing results for 
Search instead for 
Did you mean: 

Enable touch screen on the STM32F746G-Discovery

ST Community
ST Employee

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.

Setup review:
- a CubeMX v4.26 graphic application project for STM32F746G-Discovery
- the chosen IDE is Atollic 
- the graphic library is STemWin 
- the Cube Firmware is the STM32Cube_FW_F7_V1.11.0 

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

671.png
In the configuration tab click on GRAPHICS

672.png

Click on the Execute button to launch the GUIDesigner

673.png

Add 2 buttons by clicking twice on the dedicated item in the list of widgets

674.png

Close the GUIDesigner and re-generate the project by clicking on the button hilighted below

675.png

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 

676.png

Select File System

677.png

Select the Drivers folder as the base folder and click OK

678.png

From this dialog box we will select all the required files

679.png

First the low-level touch driver ft5336.c/h

680.png

Then a higher level interface in the Common folder

681.png

The BSP driver common files and touch dedicated

682.png

Then click Finish to actually import the files, you should now have the following structure in your Atollic project

683.png

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

684.png

Then go to Tool Settings tab and C Compiler->Directories section

add the new folders containing include files:
../Drivers/BSP/Components/Common
../Drivers/BSP/Components/ft5336
../Drivers/BSP/STM32746G-Discovery

685.png


 

Open the ./src/main.c file and #include directives (between the USER tags) as below

686.png

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

687.png

Enable TIM3

688.png

Enable USART1 (not mandatory for the touch capability but needed because of an internal BSP dependency)

689.png

Configure TIM3 as follow (expiration every 1 ms)

690.png

and enable the interrupt

691.png

 

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:

692.png

  • In main.c file in USER CODE BEGIN/END 2 section add the call below:

693.png

  • In main.c file in USER CODE BEGIN/END 4 section add the definitions below

694.png

  • In main.c file in HAL_TIM_PeriodElapsedCallback USER CODE BEGIN/END Callback 1 section add

695.png

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 add696.png
  • In WindoDLG.c file in cbDialog function, case ID_BUTTON_0 and case WM_NOTIFICATION_CLICKED in USER START/END section add697.png

6. You can now rebuild the entire project and flash it to the board

699.png

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 here.
 

Customer Note:
1) You can contact the author of this article by clicking on name provided as “Created By” info.
2) All other comments or feedback you can post by email to community@st.com
3) If you need specific (product) support please refer to our Support Center(https://www.st.com/content/st_com/en/support/support-home.html) where you can choose from a variety of online support options and select a service which fits your requirements best.
 
Version history
Last update:
‎2018-07-23 04:29 AM
Updated by: