Skip to main content
vince
Associate III
January 23, 2020
Solved

Where did the touch driver code go?

  • January 23, 2020
  • 29 replies
  • 7450 views

I’ve updated to IDE 1.2.1 and GFX 4.13. After a HARD uphill struggle, I finally figured out how to get a screen running on a 746 Discovery board. I can’t find how to enable the touch controller, though. In the previous software, this functionality was generated in a cpp file in the TouchGFX folder. That file contains nothing but comments now, with no code to initialize or service touch events. How do we get the touch function going? We need some clear example code or instruction. (And may I vent a bit here? This release can not possibly have been regression tested. I’ve done this long enough to recognize a train wreck when I see one. ST “broke the build�?, and left their base to suffer the consequences. It is inexcusable.)

This topic has been closed for replies.
Best answer by Martin KJELDSEN

Hi @vince​,

Did you read the documentation on developing for STM32 display kits?

"Generally, two different project types exist when developing TouchGFX applications:

  1. Prototype (perhaps using STM32 display kits)
  2. Product

When developing prototype applications the main focus is almost always UI Application development getting an overview over the capabilities of TouchGFX, not having to worry about hardware. In this scenario the TouchGFX Designer is the starting point where applications can be based on an existing Application Template (AT) for a particular STM32 display kit. This gives developers a chance to try their UI applications on real hardware quickly. In this case the TouchGFX Generator and CubeMX, generally, are used when changes to the hardware is required."

"For custom STM32 based boards the entry point will typically be CubeMX and the TouchGFX Generator."

I could go on. If you'd bothered searching this community you would also find this information in many posts.

Think of CubeMX (Cube Micro eXplorer) as an MCU configurator. Despite knowing about existing display kits, it won't care what peripherals you have on your board, including your touch controller. It can initialize your controllers according to sdram and qspi and whatever else might be on your board but it won't provide the code to set them up because, from an MCU perpective, it does not make sense to talk about touch controllers.

It's late here, but your vent triggered me enough to pull out my laptop and reply. If you've "done this long enough" may i suggest that you read the documentation before calling something a "train wreck"?

/Martin

29 replies

Martin KJELDSEN
Martin KJELDSENBest answer
Principal III
January 23, 2020

Hi @vince​,

Did you read the documentation on developing for STM32 display kits?

"Generally, two different project types exist when developing TouchGFX applications:

  1. Prototype (perhaps using STM32 display kits)
  2. Product

When developing prototype applications the main focus is almost always UI Application development getting an overview over the capabilities of TouchGFX, not having to worry about hardware. In this scenario the TouchGFX Designer is the starting point where applications can be based on an existing Application Template (AT) for a particular STM32 display kit. This gives developers a chance to try their UI applications on real hardware quickly. In this case the TouchGFX Generator and CubeMX, generally, are used when changes to the hardware is required."

"For custom STM32 based boards the entry point will typically be CubeMX and the TouchGFX Generator."

I could go on. If you'd bothered searching this community you would also find this information in many posts.

Think of CubeMX (Cube Micro eXplorer) as an MCU configurator. Despite knowing about existing display kits, it won't care what peripherals you have on your board, including your touch controller. It can initialize your controllers according to sdram and qspi and whatever else might be on your board but it won't provide the code to set them up because, from an MCU perpective, it does not make sense to talk about touch controllers.

It's late here, but your vent triggered me enough to pull out my laptop and reply. If you've "done this long enough" may i suggest that you read the documentation before calling something a "train wreck"?

/Martin

vince
vinceAuthor
Associate III
January 23, 2020

Martin, my apology to you personally if my critique of the product offended, but after hours of head banging (which included reading literally everything published on this topic, including the material you reiterated, plus scouring the forums in an attempt to piece together a coherent path to success), I had to express my dissatisfaction to someone. I actually feel sorry for you, as I have been following your posts regularly and know for certain you have been a VERY busy man, thrown into quite a mess. But yes, I have done this for many years, and I detect an air of emergency in the boards lighting up out there. When a system that was working no longer does after a new release, this tells me that, indeed, there is not adequate testing in place, as I know that regression testing in software is designed to ensure that such things do not catch an installed user base off guard. So, again, my critique is not aimed at you specifically, an employee of ST doing the best you can to put out fires, and "train wreck" is less a value judgement, and more a description of what I take to have been an avoidable problem on ST's part. Live and learn, I guess.

That said, I have read everything I can get my hands on about this new release, and spent several hours bringing up a demo on a Discovery board. Part of the problem, I think, is that the “Templates�? are nowhere to be found within my installation of Designer 4.13 (I have installed/repaired it three times now; only the simulator is available to select. I do not know why this is. It certainly contradicts the published guides I have seen.) Even so, I managed to go in from the Cube side and get a screen up and running, using the .part file that was generated there, but without the touch facility. This is when I discovered that the cpp file which formerly implemented this feature apparently no longer does. This is pretty much dead in the water at this point, as there are no examples without the template. Perhaps I missed a step along the way. Taking what I can from various users out there, I have learned much, but I'm not finding a single source that shows how this last piece is done. Again, I could have missed something that in retrospect will seem obvious, but from the trenches, it is hidden at this point.

Best regards to you and your support team, and thanks for any insight you might provide. Eventually these things settle out, and I can wait until the next clean release if necessary.

-Vince

HP_it
Senior II
January 23, 2020

Hey @vince​ 

I just did a video on the setup : https://www.youtube.com/watch?v=o42r4xXOnbo

I know it's without the touch drivers that you ask about but I believe that it should be the same procedure as fore the previous versions:

https://www.youtube.com/watch?v=ZQA2lAsIdZA

If you start at around 10:40'ish I'm talking about how to add the touch driver.

Now, I haven't tried this on the 4.13.0 version (and 1.2.1 for CubeIDE) and since it's pretty late for me I will have to wait after the weekend until I try. But it SHOULD be the same procedure :) Maybe you can give it a go?

And sorry for the poor audio quality :\

HP_it
Senior II
January 24, 2020

I was curious about this so I found a few minutes to do some digging. TL;DR - I got it working.

@Martin KJELDSEN​ There seems to indeed be some code missing here - I'm not sure if this falls in the soft-config category, but if it's possible to have the AT generate these few snippets again it would make the process 'work like the old versions' :D

So what I did:

I started off by copying the drivers from the F7 repository as per my old videos.

Then, in the STM32TouchController.cpp (in TouchGFX->target->generated folder) I've written essentially what was there before:

/**
 ******************************************************************************
 * File Name : STM32TouchController.cpp
 ******************************************************************************
 * @attention
 *
 * <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
 * All rights reserved.</center></h2>
 *
 * This software component is licensed by ST under Ultimate Liberty license
 * SLA0044, the "License"; You may not use this file except in compliance with
 * the License. You may obtain a copy of the License at:
 * www.st.com/SLA0044
 *
 ******************************************************************************
 */
 
/* USER CODE BEGIN STM32TouchController */
 
#include <STM32TouchController.hpp>
#include "stm32746g_discovery_ts.h"
 
extern "C"
{
uint32_t LCD_GetXSize();
uint32_t LCD_GetYSize();
 
}
 
 
void STM32TouchController::init()
{
 /**
 * Initialize touch controller and driver
 *
 */
	BSP_TS_Init(480, 272);
}
 
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_StateTypeDef state = { 0 };
	 BSP_TS_GetState(&state);
	 if (state.touchDetected)
	 {
	 x = state.touchX[0];
	 y = state.touchY[0];
 
	 return true;
	 }
 return false;
}
 
/* USER CODE END STM32TouchController */
 
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

Do note that skipped the LCD_GetXsize() and LCD_GetYSize() since they will just return a static value (hardcoded by the generator). I'm sure I could find the values somewhere if I went digging, but for now I just put the screensize directly in the BSP_TS_Init call

That's basically it. I 'just' took what was written in the old code and it seems to work fine. I can do a video on this topic if needed but it's fairly straightforward.

Martin KJELDSEN
Principal III
January 27, 2020

I don't get it, sorry :) What "snippets" are you talking about?

Here's the STM32TouchController.cpp you get from the F746G-DISCO Application template. Works fine, i just tested it (again) :)

#include <STM32TouchController.hpp>
#include <TouchGFXHAL.hpp>
#include <ft5336.h>
#include <stm32f7xx_hal.h>
#include <touchgfx/hal/OSWrappers.hpp>
 
static TS_DrvTypeDef* tsDriver;
extern I2C_HandleTypeDef hi2c3;
 
void STM32TouchController::init()
{
 /* Initialize the TS driver structure */
 tsDriver = &ft5336_ts_drv;
 
 /* Initialize the TS driver */
 tsDriver->Start(TS_I2C_ADDRESS);
}
 
bool STM32TouchController::sampleTouch(int32_t& x, int32_t& y)
{
 /* Checking if the screen has been touched */
 
 if (tsDriver)
 {
 if (tsDriver->DetectTouch(TS_I2C_ADDRESS))
 {
 /* Get each touch coordinates */
 tsDriver->GetXY(TS_I2C_ADDRESS, (uint16_t*)&y, (uint16_t*)&x);
 return true;
 }
 }
 return false;
}
 
/**
 * @brief Manages error callback by re-initializing I2C.
 * @param i2c_handler : I2C handler
 * @param Addr: I2C Address
 * @retval None
 */
static void I2Cx_Error(I2C_HandleTypeDef* i2c_handler, uint8_t Addr)
{
 /* De-initialize the I2C communication bus */
 HAL_I2C_DeInit(i2c_handler);
 
 /* Re-Initialize the I2C communication bus */
 //I2Cx_Init(i2c_handler);
}
 
/**
 * @brief Reads multiple data.
 * @param i2c_handler : I2C handler
 * @param Addr: I2C address
 * @param Reg: Reg address
 * @param MemAddress: Memory address
 * @param Buffer: Pointer to data buffer
 * @param Length: Length of the data
 * @retval Number of read data
 */
static HAL_StatusTypeDef I2Cx_ReadMultiple(I2C_HandleTypeDef* i2c_handler,
 uint8_t Addr,
 uint16_t Reg,
 uint16_t MemAddress,
 uint8_t* Buffer,
 uint16_t Length)
{
 HAL_StatusTypeDef status = HAL_OK;
 
 status = HAL_I2C_Mem_Read(i2c_handler, Addr, (uint16_t)Reg, MemAddress, Buffer, Length, 1000);
 
 /* Check the communication status */
 if (status != HAL_OK)
 {
 /* I2C error occurred */
 I2Cx_Error(i2c_handler, Addr);
 }
 return status;
}
 
/**
 * @brief Writes a value in a register of the device through BUS in using DMA mode.
 * @param i2c_handler : I2C handler
 * @param Addr: Device address on BUS Bus.
 * @param Reg: The target register address to write
 * @param MemAddress: Memory address
 * @param Buffer: The target register value to be written
 * @param Length: buffer size to be written
 * @retval HAL status
 */
static HAL_StatusTypeDef I2Cx_WriteMultiple(I2C_HandleTypeDef* i2c_handler,
 uint8_t Addr,
 uint16_t Reg,
 uint16_t MemAddress,
 uint8_t* Buffer,
 uint16_t Length)
{
 HAL_StatusTypeDef status = HAL_OK;
 
 status = HAL_I2C_Mem_Write(i2c_handler, Addr, (uint16_t)Reg, MemAddress, Buffer, Length, 1000);
 
 /* Check the communication status */
 if (status != HAL_OK)
 {
 /* Re-Initiaize the I2C Bus */
 I2Cx_Error(i2c_handler, Addr);
 }
 return status;
}
 
/**
 * @brief Writes a single data.
 * @param Addr: I2C address
 * @param Reg: Reg address
 * @param Value: Data to be written
 * @retval None
 */
void TS_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value)
{
 I2Cx_WriteMultiple(&hi2c3, Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT, (uint8_t*)&Value, 1);
}
 
/**
 * @brief Reads a single data.
 * @param Addr: I2C address
 * @param Reg: Reg address
 * @retval Data to be read
 */
uint8_t TS_IO_Read(uint8_t Addr, uint8_t Reg)
{
 uint8_t read_value = 0;
 
 I2Cx_ReadMultiple(&hi2c3, Addr, Reg, I2C_MEMADD_SIZE_8BIT, (uint8_t*)&read_value, 1);
 
 return read_value;
}
 
/**
 * @brief TS delay
 * @param Delay: Delay in ms
 * @retval None
 */
void TS_IO_Delay(uint32_t Delay)
{
 HAL_Delay(Delay);
}

HP_it
Senior II
January 27, 2020

The problem for me was that this code simply wasn't in the file. I guess the reason for this is that I've taken the custom approach? My STM32TouchController.cpp generated by the designer in my video example was empty - well it was there, but it didn't contain more than comments. I can see that the code you've just posted is maybe less reliant on repository code and hooks directly to the touch driver

BO Re.1
Associate III
January 27, 2020

Hi Vince,

im having same issues, tried to open and compile in both Keil IDE and cubeIDE after using template In TouchGFXDesigner. But loads of errors, I have managed to open in visual studio and wrote code in main.c , file created by CubeMX to set up my ADC, I wrote necessary code to sample input and ran in visual studio , then downloaded to board through TouchGFXDesigner.. my only issue is getting my adc value to touch screen, which is separate to this thread, ;), unless someone has some guidance?

im no expert , just a mature student, so not sure if it’s 100%... of note I deliberately went back and created syntax errors in the CubeMX main file and they were highlighted in TouchGFXDesigner when downloading to board .

i don’t know if this helps or not. :face_with_tears_of_joy:

But I’ve been banging my head for a while now trying to get something working and I now seem to be getting somewhere, hopefully it’s not a false positive :thinking_face:

Barry

Lagodolio
Associate III
February 19, 2020

Hello!

I have a problem with my "STM32TouchController.cpp" . It's the same of Martin KJELDSEN , but CubeIDE give me an error:

void STM32TouchController::init()
{
 /* Initialize the TS driver structure */
 tsDriver = &ft5336_ts_drv;
 
 /* Initialize the TS driver */
 tsDriver->Start(TS_I2C_ADDRESS);
}

" TouchGFX/target/STM32TouchController.cpp:36:21: error: 'TS_I2C_ADDRESS' was not declared in this scope".

I think I have to declare TouchScreen I2C Address, but .... where?

Thanks a lot!

P.S. : My configuration is:

Board STM32F746G-Discovery

CubeIDE 1.2.1

TouchGFX 4.13.0

HP_it
Senior II
February 19, 2020

Have you included the component folder and the TS driver?

All the variables and addresses should be available when you tab-complete otherwise there's something missing

Lagodolio
Associate III
February 19, 2020

I have included :

\STM32Cube_FW_F7_V1.15.0\Drivers\BSP\STM32746G-Discovery\stm32746g_discovery_ts.c & .h

Components directory with three subdir:

->Common

->ft5336

->ts3510

I think that the last one is for TouchScreen but probably it's wrong...

I included (as test) in my STM32TouchController.cpp also

//#include <STM32746G-Discovery/stm32746g_discovery.h>
#include <STM32746G-Discovery/stm32746g_discovery_ts.h>

but other errors (multiple declarations) made me understand it's not the right way so I removed it.