element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
    About the element14 Community
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      •  Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Embedded and Microcontrollers
  • Technologies
  • More
Embedded and Microcontrollers
Blog STM32H7B3I - Create a TouchGFX Project with support for the Designer, CubeIDE and Debugger - Pt 2: Touch Works
  • Blog
  • Forum
  • Documents
  • Quiz
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Embedded and Microcontrollers to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Jan Cumps
  • Date Created: 4 Aug 2020 6:36 PM Date Created
  • Views 6611 views
  • Likes 5 likes
  • Comments 16 comments
  • stm32h7b3i
  • rt
  • stm32h7b3i-dk
Related
Recommended

STM32H7B3I - Create a TouchGFX Project with support for the Designer, CubeIDE and Debugger - Pt 2: Touch Works

Jan Cumps
Jan Cumps
4 Aug 2020

Continued from Pt 1: Screen Works.

We left off at the point where the LCD shows out TouchGFX design, but touch screen doesn't work yet.

We'll fix that.

 

5. Add Touch Screen init and handling

 

The two methods in TouchGFX/target/STM32TouchController.cpp aren't implemented by the wizards.

Open the file and implement them as below:

 

#include <stm32h7b3i_discovery_ts.h>
#include <TouchGFXHAL.hpp>
#include <cmsis_os.h>

 

void STM32TouchController::init()
{
    /**
     * Initialize touch controller and driver
     *
     */
    TS_Init_t hTS;

    hTS.Orientation = TS_SWAP_XY;
    hTS.Accuracy = 0;
    hTS.Width = touchgfx::HAL::FRAME_BUFFER_WIDTH;
    hTS.Height = touchgfx::HAL::FRAME_BUFFER_HEIGHT;
    BSP_TS_Init(0, &hTS);
}

 

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_State_t TS_State = { 0 };

    /* This should never fail !! */
    if (BSP_TS_GetState(0, &TS_State) != BSP_ERROR_NONE)
    {
        configASSERT(0);
    }

    if (TS_State.TouchDetected)
    {
        x = TS_State.TouchX;
        y = TS_State.TouchY;

        return true;
    }

    return false;
}

 

The logic is dependent on the board definition files. We can import them from the firmware support package.

If you don't know where that is installed, check via the IDE  Windows -> Preferences menu

image

 

Right-click on the Drivers folder and select Import -> File System

Navigate to where you installed the firmware - In our case, it's version 1.6.0 because that's the one used in the TouchGFX .ioc file. Look for the folder Drivers and select these:

image

image

 

Then select the project's BSP folder, right-click and select Import

image

 

Rename Drivers/BSP/STM32H7B3I-DK/stm32h7b3i_discovery_conf_template.h to stm32h7b3i_discovery_conf.h.

Rename Drivers/BSP/Components/mx25lm51245g/mx25lm51245g_conf_template.h to mx25lm51245g_template.h.

 

Rename Drivers/BSP/Components/ft5336/ft5336_conf_template.h to ft5336_conf.h.

Then edit it:

#define FT5336_MAX_X_LENGTH                  480U
#define FT5336_MAX_Y_LENGTH                  272U

 

Create a new header file Drivers/STM32H7xx_HAL_Driver/Inc/stm32xxxx_hal.h.

Enter these contents:

#ifndef STM32H7XX_HAL_DRIVER_INC_STM32XXXX_HAL_H_
#define STM32H7XX_HAL_DRIVER_INC_STM32XXXX_HAL_H_

#include "stm32h7xx_hal.h"

#endif /* STM32H7XX_HAL_DRIVER_INC_STM32XXXX_HAL_H_ */

 

 

Adapt the include settings, by right-clicking the project, then select properties:

image

 

Build and Debug again. The touch screen should now work. It does for me image.

Again, the project, now with touch screen working, is attached.

 

Related Posts
First Experience with CubeIDE
Create a TouchGFX Project with support for the Designer, CubeIDE and Debugger - Pt 1: Screen Works
Create a TouchGFX Project with support for the Designer, CubeIDE and Debugger - Pt 2: Touch Works
TouchGFX Simple Example: react on a button click
USB, freeRTOS ,Task Notifications and Interrupts
the Development Kit STMod+ Connector and Using UART2
TouchGFX Application Framework: Model, View, Presentation, Message Queue
TouchGFX Application Framework: A Mock GUI - Show Statuses, Switch Screens
TouchGFX Application Framework: MVP and the ModelListener
Write a CubeIDE MX application: Hardware Cryptography with DMA
Attachments:
STM32H7B3I-DK-roadtest_pt2_touch_works.zip
  • Sign in to reply

Top Comments

  • Jan Cumps
    Jan Cumps over 5 years ago +2
    for the next post: players.brightcove.net/.../index.html
  • jomoenginer
    jomoenginer over 5 years ago in reply to Former Member +2
    With this particular kit, when creating a project for it with TouchGFX, even the latest version, the .project file for STM32CubeIDE does not include the reference to the IOC file for the kit, thus the…
  • Jan Cumps
    Jan Cumps over 5 years ago in reply to DAB +1
    It wasn't. For some reason, the current toolset does not include touch functionality. Not easy if it's your first experiene with this paricular family.
  • Jan Cumps
    Jan Cumps over 5 years ago in reply to Former Member

    I tried to sum this up in the Issues section of STM32H7B3I-DK -  DISCOVERY KIT - Review .

    Except for the first 4 lines, the section is my report on the state of the software.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Former Member
    Former Member over 5 years ago in reply to jomoenginer

    Seems like a bit of a mess.

     

    But I must constrain my frustration and remember that these very awesome tools are provided for free. I have actually only paid for the kit. It is nothing worth though if I can't use it. And it seems that all chipmanufacturers are finding out that they don't sell silicium if the tools are not provided as well. I am convinced that Atmel have had a boost in sales after the arduino came out (not that I am especially fund of the software).

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Former Member
    Former Member over 5 years ago in reply to Jan Cumps

    Got it working! And without freezing. I compared your working example from the zipfile provided with my own generated code. And here is my finding:

     

    The second import should be into the folder Drivers/BSP/STM32H7B3I_DK which is not allready there. So make the folder and then import the files mentioned, also with FileSystem.

    I was right about the naming. All the 3 files should be changed from ...conf_template.h to ...conf.h and then one of them should be changed with content as described. :-)

     

    Now I will try to put in some functionality as descibed in the next article. :-)

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • jomoenginer
    jomoenginer over 5 years ago in reply to Former Member

    With this particular kit, when creating a project for it with TouchGFX, even the latest version, the .project file for STM32CubeIDE does not include the reference to the IOC file for the kit, thus the STM32CubeMX stuff does not get imported.  However, once this is included, a change to the clocks is required to get everything working properly.  I'm not sure why it is a thing with this kit, but as far as I know, it has not been corrected. Also, the kit name is not consistent in the TouchGFX/STM32CubeIDE code, so sometimes it is called a '-DISCO' and others a '-DK'.  Again, not sure why this is but it does seem to muck things up at times.

     

    This is the post I added to the STM Community page:

    https://community.st.com/s/question/0D53W00000EHBmpSAH/touchgfx-4140-does-not-include-ioc-file-reference-in-project-file-for-stm32h7b3idk

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 5 years ago in reply to Former Member

    I agree that this should work. I spent the majority of my road test dealing with these difficulties.

    What helped me was a good working example I received fro jomoenginer. That's what I used as a start point for the stable designs later in my road test.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
<>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2026 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube