STM32F746_Discovery: bug in touch screen library?

Working libraries, libraries being ported and related hardware
Post Reply
jremington
Posts: 10
Joined: Thu Jun 18, 2020 2:19 pm

STM32F746_Discovery: bug in touch screen library?

Post by jremington »

The TS library appears to perform unexpected, unauthorized writes to at least two distinct RAM memory locations, when the first call to .getPoint() is executed.

I'm using this branch of the 1.9.0 core: https://github.com/fpistm/Arduino_Core_ ... TEST_1.9.0

The offending code is the unmodified TS library example, TouchDisplayTemplate. Upon program startup, I consistently observe two white pixels appear, center left on the screen, immediately after the first call to ts.getpoint(). I suspect that the touch routine is writing directly to the screen RAM. Subsequent calls to .getPoint(), following screen erase, do not generate those white pixels.

I've looked through the library source code and can't see how this might be happening. As far as I can tell, the touchscreen driver has no access to display memory. Uninitialized pointer?

Code follows:

Code: Select all

*
   Touch example for STM32F476 Discvery

   using Adafruit compatible API

   June 2017, ChrisMicro
*/

#include "LTDC_F746_Discovery.h" // TFT
#include "TouchScreen_F7_Discovery.h" // TOUCH

LTDC_F746_Discovery tft;
TouchScreen         ts;

void setup()
{
  // The buffer is memory mapped
  // You can directly draw on the display by writing to the buffer
  uint16_t *buffer = (uint16_t *)malloc(LTDC_F746_ROKOTECH.width * LTDC_F746_ROKOTECH.height);

  tft.begin((uint16_t *)buffer);
  
  tft.fillScreen(LTDC_BLACK);
  //tft.setRotation(0);
  tft.setCursor(0, 0);
  tft.setTextColor(LTDC_BLUE);  tft.setTextSize(3);
  tft.println("STM32F746 Discovery Touch");
}

#define CURSOR_SIZE 100

TSPoint OldPoint;

void loop()
{
    TSPoint p = ts.getPoint();
    
    if( OldPoint != p )
    {
      OldPoint=p;
      
      tft.fillScreen( LTDC_BLACK );

      tft.setCursor(0, 0);

      tft.print(p.x); tft.print(" , "); tft.print(p.y);
      tft.print(" pressure: "); tft.println( p.z );

      if ( p.z )
      {
        tft.fillRect(p.x - CURSOR_SIZE/2, p.y - CURSOR_SIZE/2, CURSOR_SIZE, CURSOR_SIZE, LTDC_GREEN);
      }

      delay(10);
    }
}
User avatar
fpiSTM
Posts: 1723
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: STM32F746_Discovery: bug in touch screen library?

Post by fpiSTM »

Hi
this branch is only for test/example purpose and provided as it is using the LCD and TS libraries from @danieleff and @ChrisMicro.

Your best bet is to try to debug them.
jremington
Posts: 10
Joined: Thu Jun 18, 2020 2:19 pm

Re: STM32F746_Discovery: bug in touch screen library?

Post by jremington »

Problem solved!

I discovered that clearing the screen overwrote some critical program variable. The issue was resolved by specifically declaring the screen buffer as a global variable. Evidently malloc() does not properly observe some heap or stack boundary of program ram usage.

Fix: don't use malloc()

This code from the provided library example sometimes leads to program crashes:

Code: Select all

void setup() {
  // The buffer is memory mapped
  // You can directly draw on the ss by writing to the buffer
   uint16_t *buffer = (uint16_t *)malloc(LTDC_F746_ROKOTECH.width * LTDC_F746_ROKOTECH.height);
   tft.begin((uint16_t *) buffer);
This works correctly:

Code: Select all

 
uint16_t screen_buf[LTDC_F746_ROKOTECH.width * LTDC_F746_ROKOTECH.height];
   void setup() {
   tft.begin(screen_buf);
Post Reply

Return to “Libraries & Hardware”