element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • 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 Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • 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
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • 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 6068 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 4 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.
  • jomoenginer
    jomoenginer over 4 years ago in reply to Former Member

    Did you create the project in TouchGFX and then attempting to change something in CubeMX?

     

    If so, try to make the changes in STM32CubeIDE instead.

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

    Found another interesting thing:

     

    If I change something in the CubeMX (*.ioc file) an interesting thing happens.

     

    I wanted to start the project with the two LED's off. And in the CubeMX they are set to start low (which is on), but I want to start them off and change that setting to high in GPIO setting for the two LED's.

     

    But when doing so, and regenerate the ioc file, the file stm32xxxx_hal.h gets deleted, and hence getting a number of compiler errors.

     

    Is that normal? I mean this is not something I can put in between "USER" tags in code. This is in the filesystem. I can't protect my own user-written files from being deleted by the configurator.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • jomoenginer
    jomoenginer over 4 years ago in reply to Jan Cumps

    I would guess it is a priority thing, in that if it is a part that someone is using with a single dev kit just to mess around with and not produce a shipping product, then the issue in that area may just get put in the back log.  However, if it were an issue with a customer who purchases a 1000 or more chips on a regular basis and there is something like a vehicle running into walls or an Infotainment system acting funky, then I would image they would be looking to address the issue with more urgency.  I suppose if the issues with STM32H7B3i-DK and the tools resulted in significant revenue loss, then perhaps they would get a fix sooner rather than later.  It all comes down to the pain point for them.

    But, then again, a bad experience with one product could result in someone not looking at that vendor in the future.

     

    I do have a STM32F769I-DISCO and using the same tools, TouchGFX, STM32CubeMX and STM32CubeIDE versions, I do not see the same issue as with the STM32H7B3i-DK. Perhaps the board is too new or just not something they focused much on and just tossed it in the mix. It'll get fixed eventually, or they will just drop support for the board, which tends to be norm with these things. 

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 4 years ago in reply to jomoenginer

    jomoenginer  wrote:

    ...

    However, they can not fix these if they do not know about them, which is why I tend to post on the manufactures forums or the related GitHub. Heck, even Arduino is not perfect. Sometimes it seems they are in a race to get to market without fully airing out the tools and boards.  This is what makes it fun and all.

    For STM, it's a frequently flagged subject on their forum. Many STM/TouchGFX videos spend half the time explaining how to fix it for a particular version.

    You'd think they would also read the road test reports of their device. All testers flagged the issue and it has not been addressed. It is a fixable issue that keeps lingering on across new releases.

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

    neumann1  wrote:

     

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

    Perhaps in the Maker Space but I would suspect not so much in the professional arena.  Also, a good number of the Arduino boards these days are none Atmel, or rather Microchip, so the use of the older Atmel device have gone down in recent years.

     

    Board bring-up tends to be difficult, so STM offering some sort of dev environment, tools and examples is a plus.  I just think STM has a wide range of boards to cover and having just recently absorbed TouchGFX, there are still things to iron out.  However, they can not fix these if they do not know about them, which is why I tend to post on the manufactures forums or the related GitHub. Heck, even Arduino is not perfect. Sometimes it seems they are in a race to get to market without fully airing out the tools and boards.  This is what makes it fun and all.

    • 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 © 2025 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