Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tft.drawString (or sprint.drawString)using font 1 causes crash on decodeUTF8 in TFT_eSPI.cpp line 3117 #3565

Open
JooJooBee666 opened this issue Nov 23, 2024 · 1 comment

Comments

@JooJooBee666
Copy link

JooJooBee666 commented Nov 23, 2024

Simply using Font size 1 crashes everything. Repeatedly. All I need to do is switch to font size 2 and the crashes stop. This makes no sense to me and I can't even trace it it. The farthest I get is the decodeUTF8 section of code but just calling that alone causes the crash...so I'm stuck.

I should also note the tft.print() causes the same crash...

MC: ESP32 S3 N16R8
TFT: 9341 w.8" with touch (XPT 2046)

Here's my setup for the 9431 TFT:

#define ILI9341_DRIVER

#define USE_HSPI_PORT
#define TFT_SPI_MODE SPI_MODE0

#define TFT_WIDTH   240
#define TFT_HEIGTH  320

#define TFT_MOSI  10  // Intput
#define TFT_MISO  46  // Output
#define TFT_SCLK  9   // CLock line
#define TFT_CS    13  // Chip select control pin
#define TFT_DC    11  // Data Command control pin
#define TFT_RST   12  // Reset pin (could connect to RST pin)

// Optional touch screen chip select
#define TOUCH_CS    3
#define TOUCH_DIN   10
#define TOUCH_DO    46


#define LOAD_GLCD    // Font 1. Original Adafruit 8 pixel font needs ~1820 bytes in FLASH
#define LOAD_FONT2   // Font 2. Small 16 pixel high font, needs ~3534 bytes in FLASH, 96 characters
#define LOAD_FONT4   // Font 4. Medium 26 pixel high font, needs ~5848 bytes in FLASH, 96 characters
#define LOAD_FONT6   // Font 6. Large 48 pixel font, needs ~2666 bytes in FLASH, only characters 1234567890:-.apm
#define LOAD_FONT7   // Font 7. 7 segment 48 pixel font, needs ~2438 bytes in FLASH, only characters 1234567890:.
#define LOAD_FONT8   // Font 8. Large 75 pixel font needs ~3256 bytes in FLASH, only characters 1234567890:-.
#define LOAD_GFXFF   // FreeFonts. Include access to the 48 Adafruit_GFX free fonts FF1 to FF48 and custom fonts

#ifdef TFT_ALT
    #define TFT_RGB_ORDER TFT_RGB //2.4 IL9341
#else
    #define TFT_RGB_ORDER TFT_BGR //Better IL9341
#endif
// #define TFT_INVERSION_ON // ST7789?
#define SMOOTH_FONT

// TFT SPI clock frequency
#define SPI_FREQUENCY  27000000

// SPI clock frequency for touch controller
#define SPI_TOUCH_FREQUENCY  2500000

And here's the psuedo code I used to test this:

#include <TFT_eSPI.h> // Hardware-specific TFT library
#include "Free_Fonts.h"

uint16_t SCREEN_WIDTH = 320;
uint16_t SCREEN_HEIGHT = 240;

TFT_eSPI tft = TFT_eSPI(SCREEN_HEIGHT,SCREEN_WIDTH); 
int counter = 0;

void setup() {
  //Enable serial output
  Serial.flush();
  Serial.begin(115200);
  Serial.println('\n');
  Serial.println("Initialized.");
  tft.init();                   // Initialize the ILI9341 TFT Screen
  tft.setRotation(1);      // rotate 90 dgrees for the IL9341 cuz its stupid like that
tft.fillScreen(TFT_BLACK);
}

void loop() {  
  Serial.printf("loop clickT:%i\r\n", clickT);
  if (millis() > prevMillis + 1000) {
    prevMillis = millis();
    counter = counter + 1;
    char disp[20];
    sprintf(disp, "%i", counter);
    Serial.println(disp);
    tft.setTextColor(TFT_WHITE);
    tft.fillRect(30, 30, 120, 50, 0x0);
    tft.drawString(disp, 0, 0, 1);
  }
  delay(500);
}

This is the error that I get. Mind you, this does not happen every time but I have tried on multiple MCU's all with the same result now:

ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0xc (RTC_SW_CPU_RST),boot:0x8 (SPI_FAST_FLASH_BOOT)
Saved PC:0x42069f32
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fce3808,len:0x4bc
load:0x403c9700,len:0xbd8
load:0x403cc700,len:0x2a0c
entry 0x403c98d0


Initialized.
loop clickT:0
loop clickT:0
1
Guru Meditation Error: Core  1 panic'ed (LoadProhibited). Exception was unhandled.

Core  1 register dump:
PC      : 0x420079e0  PS      : 0x00060630  A0      : 0x82007a54  A1      : 0x3fcedd20  
A2      : 0x3fcedda8  A3      : 0x3fcedf39  A4      : 0x00000000  A5      : 0x3fcedea8  
A6      : 0x00000078  A7      : 0x3fcedda8  A8      : 0x820079da  A9      : 0xb33fffff  
A10     : 0x00000031  A11     : 0x00000031  A12     : 0x00000014  A13     : 0x3fcede88  
A14     : 0x00ff0000  A15     : 0x00000001  SAR     : 0x00000001  EXCCAUSE: 0x0000001c  
EXCVADDR: 0xb3400007  LBEG    : 0x400570e8  LEND    : 0x400570f3  LCOUNT  : 0x00000000  


Backtrace: 0x420079dd:0x3fcedd20 0x42007a51:0x3fcedd50 0x420032fd:0x3fcedda0 0x4200d3e9:0x3fcedf70

ELF file SHA256: 54b099c758db831a

Ignoring line numbers for main(because I basically bypassed thousands of lines of code to narrow this down), here's the backtrace:

fm-devkit$ xtensa-esp32-elf-addr2line -e firmware.elf 0x420079dd:0x3fcedd20 0x42007a51:0x3fcedd50 0x420032fd:0x3fcedda0 0x4200d3e9:0x3fcedf70
/home/plebian/Arduino/projects/PlatformIO/SecretProject/.pio/libdeps/fm-devkit/TFT_eSPI/TFT_eSPI.cpp:3117
/home/plebian/Arduino/projects/PlatformIO/SecretProject/.pio/libdeps/fm-devkit/TFT_eSPI/TFT_eSPI.cpp:5508
/home/plebian/Arduino/projects/PlatformIO/SecretProject/src/main.cpp:4324
/home/plebian/.platformio/packages/framework-arduinoespressif32/cores/esp32/main.cpp:50

So basically, I cannot use Font size 1 without crashing my devices here. The strange thing is that this was not a problem until recently. Maybe it is caused by an update from espressif? I'm not sure. Either wayt, the decodeUtf8 function is purely a TFT_eSPI function. I even added the following null checks to the top of the functions to see if it would help:

uint16_t TFT_eSPI::decodeUTF8(uint8_t c)
{
  if (NULL == c) return 0;  //ADDED THIS

AND

uint16_t TFT_eSPI::decodeUTF8(uint8_t *buf, uint16_t *index, uint16_t remaining)
{
  if (NULL == &buf) return 0;  //ADDED THIS

...sadly, it does not. I'm currently stuck and am running out of ideas. My current idea is to search for another very small font to include and use it instead to bypass this issue.

Again, if I change tft.drawString(disp, 0, 0, 1); to tft.drawString(disp, 0, 0, 2);, the crash no longer happens. Also, If try even something simpler like tft.drawString(d"Test", 0, 0, 1); it STILL crashes. 😢

Any other ideas or thoughts would be greatly appreciated. :)

@JooJooBee666
Copy link
Author

JooJooBee666 commented Nov 24, 2024

As an aside, I am now using FreeFont FM9 without incident here in the same code with no crashes. I still just don't get it; if font 1 was somehow not compiled with the program, it should crash immediately. Instead, it actually works(shows the text!)...for an indeterminate amount of time, before creating it's own untimely demise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant