Debug Problem with a more complex Project (ESP32)

Hello
Yesterday I wrote a little RGB Blink Project for my ESP-Wrover Kit and I was happy that Debugging was working well. This Morning I tried a more complex Project with a Interrupt Timer routine and
I got the following Error

Error: Target not halted
Error: auto_probe failed
Error: Connect failed. Consider setting up a gdb-attach event for the target to prepare target for GDB connect, or use ‘gdb_memory_map disable’.
Error: attempted ‘gdb’ connection rejected
Error: error during select: Unknown error
Warn : Flash driver of esp32.flash does not support free_driver_priv()
Warn : Flash driver of irom does not support free_driver_priv()
Warn : Flash driver of drom does not support free_driver_priv()
.pioinit:15: Error in sourced command file:
Remote communication error. Target disconnected.: No error.

Any Clue, whats up here THX Martin

Code, platformio.ini and hardware setup for reproduction?

Oh sure Nice weekend

[env:esp wrover kit]
platform = espressif32
framework = arduino
board = esp-wrover-kit
monitor_speed = 115200
debug_tool = esp-prog
debug_init_break = tbreak setup
monitor_port = COM20
upload_port = COM20

Again, code for reproduction? If you’re using timer interrupt and that’s what breaks it, your code is critical here.

I tried a Project without Timers same result

#include "Arduino.h"
#include "WString.h"
#include "SPI.h"
#include <WROVER_KIT_LCD.h>
#include <Adafruit_GFX.h> // Hardware-specific library
#include <WiFiUdp.h>
#include <WiFi.h>
#include <ESPmDNS.h>
#include "Tabelle.h"
#include <time.h>
#include "StatusBar4Time.h"
#include "WiFi_config.h"
#include "comic8pt.c"
#include "comici10pt.c"
#include "comici_grad10pt.c"
#include "Fonts/FreeMonoBoldOblique12pt7b.h"

WROVER_KIT_LCD tft = WROVER_KIT_LCD();
WiFiUDP udp;
TabelleClass Table;
StatusBar4TimeClass * StatusBar;
tm timeinfo;
time_t now;
uint32_t ZeitCounterNew = 0;
uint32_t ZeitCounterOld = 0;
// Prototypes ***************************************************
void InitILI9341();
void GetNPTime();
bool GetNTP_Time(int sec);
String GetTime(tm localTime);
void Gradient(uint16_t X, uint16_t Y, uint16_t width, uint16_t heigth, uint16_t Farbe, uint16_t ColorMask);
void connectToWiFi(const char * ssid,
  const char * pwd);
void WiFiEvent(system_event_id_t event);
/*
template<typename ... Args>
String Format( String& format, Args ... args );
*/
String GetUDPDatas(void);
void SentUDPPacket(const char Text[]);
void ScanWiFiSSID();
String authModeToText(wifi_auth_mode_t authMode);
void PrintText(uint16_t X, uint16_t Y,
  const char * Text, uint16_t Color);
// End Prototypes *************************************************
// Callback function to be called when the button is pressed.
void onPressed() {
  Serial.printf("Status is %d", CountMerker);
}
///////////////////////***********************************************
///      SETUP----SETUP----SETUP----SETUP----SETUP
///////////////////////***********************************************
void setup()
{
  Serial.begin(115200);
  #
  ifdef ILI9341 // Init LCD Display
  InitILI9341();
  #
  endif
  connectToWiFi(sBufferSSID, sBufferPASS);
  uint32_t Versuch = 0;
  while ((WiFiConnected == false) & (Versuch++ < 500))
  {
    Serial.printf(". %d - %d", Versuch, WiFiConnected);
    delay(100);
  }
  if (WiFiConnected == false)
  {
    Serial.println("Fuck the SYstem");
    Serial.println("Restart the SYstem");
    ESP.restart();
  }
  tft.fillScreen(ILI9341_DARKGREEN);
  Table.initTable( & tft, 1, ILI9341_WHITESMOKE, ILI9341_BROWN, ILI9341_NAVY);
  ScanWiFiSSID();
  delay(3000);
  tft.fillScreen(ILI9341_NAVY);
  tft.setFont( & FreeMonoBoldOblique12pt7b);
  StatusBar = new(StatusBar4TimeClass);
  StatusBar - > init( & tft, ILI9341_AQUAMARINE, ILI9341_RED, ILI9341_RED);
  StatusBar - > SetTime(0, 0xffffffff);
  GetNPTime();
}
///////////////////////***********************************************
///      LOOP----LOOP----LOOP----LOOP----LOOP----
///////////////////////***********************************************
void loop()
{
  String Result = "";
  StatusBar - > SetTime(ZeitCounterNew, ZeitCounterOld);
  ZeitCounterOld = ZeitCounterNew;
  ZeitCounterNew++;
  if (WiFiConnected)
  {
    GetNTP_Time(10);
    GetTime(timeinfo);
    delay(100);
    bTriggerSNMP = false;
  }
  /// UDP SentUDPPacket(Datum);
  Result = "";
  Result = GetUDPDatas();
  if (Result != "")
  {
    Serial.print("---->");
    Serial.println(Result);
  } /// End WiFiConnected
} /// End Loop
void Gradient(uint16_t X, uint16_t Y, uint16_t width, uint16_t heigth, uint16_t Farbe, uint16_t ColorMask)
{
  uint16_t dx, rgb;
  uint8_t n;
  dx = width / 32;
  for (n = 0; n < 33; n++) {
    rgb = n * 8;
    rgb = tft.color565(rgb, rgb, rgb);
    tft.fillRect(n * dx, Y - 3, dx, heigth, rgb & ColorMask);
  }
  tft.drawRoundRect(X, Y, width - 1, heigth, 10, Farbe);
}
void connectToWiFi(const char * ssid,
  const char * pwd)
{
  Serial.printf(Buffer, "Connecting to WiFi network : %s", ssid);
  // delete old config
  WiFi.disconnect(true);
  //register event handler
  WiFi.onEvent(WiFiEvent);
  //Initiate connection
  WiFi.begin(ssid, pwd);
  WiFi.setHostname("ESP32_Login");
}
//wifi event handler
void WiFiEvent(system_event_id_t event)
{
  Serial.print("event ");
  Serial.print(event);
  switch (event)
  {
  case SYSTEM_EVENT_WIFI_READY:
    Serial.print("Wifi Ready");
    break;
  case SYSTEM_EVENT_STA_START:
    Serial.print("Wifi Event Start");
    break;
  case SYSTEM_EVENT_STA_STOP:
    Serial.print("Wifi Event Stop");
    break;
  case SYSTEM_EVENT_STA_CONNECTED:
    Serial.print("WiFi connected");
    break;
  case SYSTEM_EVENT_STA_DISCONNECTED:
    Serial.print("Wifi Disconnected");
    break;
  case SYSTEM_EVENT_STA_GOT_IP:
    Serial.println(WiFi.localIP());
    udp.begin(WiFi.localIP(), UDP_PORT);
    WiFiConnected = true;
    break;
  case SYSTEM_EVENT_STA_LOST_IP:
    Serial.print("Wifi lost IP");
    WiFiConnected = false;
    break;
  default:
    Serial.print("Not recognized Wifi Event ");
  }
}
void SentUDPPacket(const char Text[])
{
  //only send data when connected
  if (WiFiConnected)
  {
    //Send a packet
    udp.beginPacket(UDP_SERVER_IP, UDP_PORT);
    udp.print(Text);
    udp.endPacket();
  }
}
String GetUDPDatas(void)
{
  char buffer[50] = "";
  udp.parsePacket();
  //receive response from server, it will be HELLO WORLD
  if (udp.read(buffer, 50) > 0) {
    Serial.print("Server to client: ");
    Serial.println((char * ) buffer);
  }
  return (buffer);
}
void PrintText(uint16_t X, uint16_t Y,
  const char * Text, uint16_t Color)
{
  tft.setTextColor(Color, ILI9341_Background); // Navy is Background
  tft.setCursor(X, Y);
  tft.print(Text);
}
void ScanWiFiSSID()
{
  #
  define LineY1 175
  # define LineY2 225
  String S;
  tft.fillScreen(ILI9341_Background);
  tft.setTextSize(1);
  Serial.println("Suche läuft.");
  const uint8_t n = WiFi.scanNetworks();
  Table.Init_Table_Items(n, Table.Items3);
  Table.initHeadline("SSID", "RSSI", "Auth-Mode", ILI9341_WHITESMOKE);
  if (n == 0) {
  } else {
    Serial.print(n);
    Serial.println(" Networks probed");
    Serial.println("---------------------------------+------+----------------");
    Serial.println("               SSID              | RSSI |    AUTH MODE   ");
    Serial.println("---------------------------------+------+----------------");
    for (uint8_t i = 0; i < n; i++)
    {
      S = WiFi.SSID(i);
      Serial.printf("%32.32s | ", S.c_str());
      Table.AddItem(S, Table.Items1);
    }
    for (uint8_t i = 0; i < n; i++)
    {
      int32_t RSSI = WiFi.RSSI(i);
      Serial.printf("%4d | ", RSSI);
      S = RSSI;
      Table.AddItem(S, Table.Items2);
    }
    for (uint8_t i = 0; i < n; i++)
    {
      S = WiFi.encryptionType(i);
      Serial.printf("%15s\n", S.c_str());
      Table.AddItem(S, Table.Items3);
    }
    Table.ShowItems();
  }
}
String authModeToText(wifi_auth_mode_t authMode)
{
  switch (authMode) {
  case WIFI_AUTH_OPEN:
    return "Offen";
  case WIFI_AUTH_WEP:
    return "WEP";
  case WIFI_AUTH_WPA_PSK:
    return "WPA PSK";
  case WIFI_AUTH_WPA2_PSK:
    return "WPA2 PSK";
  case WIFI_AUTH_WPA_WPA2_PSK:
    return "WPA/WPA2 PSK";
  case WIFI_AUTH_WPA2_ENTERPRISE:
    return "WPA2 ENTERPRISE";
  case WIFI_AUTH_MAX:
    return "MAX";
  default:
    return "Unbekannt";
  }
}
void InitILI9341()
{
  Serial.print("****** TFT Mode  ******");
  tft.begin();
  pinMode(TFT_LED, OUTPUT);
  digitalWrite(TFT_LED, HIGH);
  // read diagnostics (optional but can help debug problems)
  uint8_t x = tft.readcommand8(WROVER_RDDST);
  Serial.print("Status:          0x");
  Serial.println(x, HEX);
  x = tft.readcommand8(WROVER_RDDPM);
  Serial.print("Power Mode:      0x");
  Serial.println(x, HEX);
  x = tft.readcommand8(WROVER_RDDMADCTL);
  Serial.print("MADCTL Mode:     0x");
  Serial.println(x, HEX);
  x = tft.readcommand8(WROVER_RDDCOLMOD);
  Serial.print("Pixel Format:    0x");
  Serial.println(x, HEX);
  x = tft.readcommand8(WROVER_RDDIM);
  Serial.print("Image Format:    0x");
  Serial.println(x, HEX);
  x = tft.readcommand8(WROVER_RDDSDR);
  Serial.print("Self Diagnostic: 0x");
  Serial.println(x, HEX);
  tft.setTextSize(1);
  tft.fillScreen(ILI9341_NAVY);
  tft.setTextWrap(false);
  tft.setRotation(1); // horizontal display
}
void GetNPTime()
{
  configTime(0, 0, NTP_SERVER);
  // See https://github.com/nayarsystems/posix_tz_db/blob/master/zones.csv for Timezone codes for your region
  setenv("TZ", TZ_INFO, 1);
  if (GetNTP_Time(10)) { // wait up to 10sec to sync
    Serial.println("NPT OK !");
  } else {
    Serial.println("Time not set");
    ESP.restart();
  }
  GetTime(timeinfo);
  lastNTPtime = time( & now);
  lastEntryTime = millis();
}
bool GetNTP_Time(int sec)
{
  {
    uint32_t start = millis();
    do {
      time( & now);
      localtime_r( & now, & timeinfo);
      delay(10);
    } while (((millis() - start) <= (1000 * sec)) && (timeinfo.tm_year < (2016 - 1900)));
    if (timeinfo.tm_year <= (2016 - 1900)) return false; // the NTP call was not successful
    Serial.print("now ");
    Serial.println(now);
    char time_output[30];
    strftime(time_output, 30, "%a  %d-%m-%y %T", localtime( & now));
    Serial.println(time_output);
    Serial.println();
  }
  return true;
}
String GetTime(tm localTime)
{
  Serial.print(localTime.tm_mday);
  Serial.print('/');
  Serial.print(localTime.tm_mon + 1);
  Serial.print('/');
  Serial.print(localTime.tm_year - 100);
  Serial.print('-');
  Serial.print(localTime.tm_hour);
  Serial.print(':');
  Serial.print(localTime.tm_min);
  Serial.print(':');
  Serial.print(localTime.tm_sec);
  Serial.print(" Day of Week ");
  if (localTime.tm_wday == 0) Serial.println(7);
  else Serial.println(localTime.tm_wday);
  return ("Hallo");
}

Thanks for posting the code. But it’s almost impossible to read the code in its current form.

So please take some time to format it properly, i.e. put triple backquotes (```) on a separate line before and after code blocks and remove the blank lines inserted on every other line.

An alternative is to publish the code in GitHub and provide the link instead.

I’ve taking the liberty of formatting and de-duplicating (you pasted it twice?).

This project is still fairly complex. What is the most minimal example you can give which reproduces the problem?

First thank you for helping me. Since I switched from PICs to Arduino, I missed my PICKit for debugging so much.

I wrote a little Example with a display and a timer and it still works fine, so what I do tomorrow, I will integrate WiFi so we will see. Thank you for this wonderful piece of Tool.

Still looking for a smaller Program to show, until now the debugger works fine