Skip to content

Enable Core dump for ESP Arduino Core 3.0.1 #9808

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

Closed
1 task done
michelelenci opened this issue Jun 8, 2024 · 2 comments · Fixed by espressif/esp32-arduino-lib-builder#183
Closed
1 task done

Enable Core dump for ESP Arduino Core 3.0.1 #9808

michelelenci opened this issue Jun 8, 2024 · 2 comments · Fixed by espressif/esp32-arduino-lib-builder#183
Assignees
Labels
Status: Awaiting triage Issue is waiting for triage

Comments

@michelelenci
Copy link

Board

all boards

Device Description

ESP32 S3

Hardware Configuration

no

Version

v3.0.1

IDE Name

Arduino IDE

Operating System

Windows

Flash frequency

80

PSRAM enabled

no

Upload speed

115200

Description

Please enable the core dump and core dump to flash (#define CONFIG_ESP_COREDUMP_ENABLE) in the new Arduino SDK.
At the moment the function in #include "esp_core_dump.h" are only place holder.
Before Arduino edf core 3.0.0 the functionality was enabled.

I think it is very important to have this function enabled by default, so that when there are crashes in the ESP32 it is possible to dump the coredump flash sector and analise it.

The sketch provided below works perfectly with Arduino core 2.0.17, doesnt work at all (aka dump is FF FF FF.. ) on Arduino core 3.0.1

Sketch

#include <esp_task_wdt.h>
#include "Brd_Config.h"
#include "CD.h"
#include "Dbg.h"
#include "esp_partition.h"
#include "esp_log.h"
#include "esp_core_dump.h"
#include "Srv_Config.h"

#define COREDUMP_FILE "/coredump.bin"
#define READ_CHUNKS 4096 /* Core dump partition size must be amultiple of READ_CHUNKS */

static const char* TAG = "CDModule";

bool CD_ReadCoreD(void);

void CD_Init(void) {
  CD_ReadCoreD();
}

bool CD_ReadCoreD(void) {

  const esp_partition_t* pt = NULL;
  size_t bytestoread = READ_CHUNKS;
  size_t bytesread = 0;
  uint8_t str_dst[READ_CHUNKS];
  bool append = false;

#if CONFIG_ESP_COREDUMP_ENABLE
   esp_core_dump_init();

   if (esp_core_dump_image_check() != ESP_OK) {
     Dbg_Printf("CoreDump: not found\n");
     return false;
   }
#endif

  pt = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_COREDUMP, "coredump");

  if (pt == NULL)
    return false;

  Dbg_Printf("CoreDump: starting partition read\n");
  size_t size = pt->size;
  /* Check that size is a multiple of READ_CHUNKS. We dont wat to read beyond our partition */
  if (size % READ_CHUNKS != 0) {
    Dbg_Printf("CoreDump: ERROR partition not aligned!\n");
    return false;
  }

  while (bytestoread > 0) {
    /* This loop is dumping 64KB, reset the WD... */
    esp_task_wdt_reset();
    //Dbg_Printf("Remaining partition size : %zu \n", size); //Too many printf! this loop is long

    esp_err_t er = esp_partition_read(pt, bytesread, str_dst, bytestoread);
    //Dbg_Printf("Dumping to bin file...\n"); //Too many printf! this loop is long
    if (!FS_WriteBinaryFile(COREDUMP_FILE, str_dst, READ_CHUNKS, append)) {
      Dbg_Printf("CoreDump: cannot write CoreDump...\n");
      return false;
    }
    append = true;

    if (er != ESP_OK) {
      Dbg_Printf("READ IS NOT OK!\n");
      ESP_LOGE(TAG, "CoreDump: partition read error : %s", esp_err_to_name(er));
      return false;
    } else if (er == ESP_OK) {
      bytesread = bytesread + READ_CHUNKS;
      size = size - READ_CHUNKS;

      if (size <= READ_CHUNKS) {
        bytestoread = size;
      }
    }
  }
  Dbg_Printf("CoreDump: written to bin file succesfully.\n");
  //esp_core_dump_image_erase();
  return true;
}

Debug Message

no debegu massage, just run the snipped on 2.0.17 and run it with 3.0.1

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.
@michelelenci michelelenci added the Status: Awaiting triage Issue is waiting for triage label Jun 8, 2024
@michelelenci michelelenci changed the title Enable Core dump Enable Core dump for ESP Arduino Core 3.0.1 Jun 8, 2024
@me-no-dev
Copy link
Member

I have added a PR to enable coredump to flash, but be aware that: Core dumps to Flash are not available if PSRAM is used for task stacks.

@michelelenci
Copy link
Author

Thanks a lot @me-no-dev , in my case PSRAM is not used at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Awaiting triage Issue is waiting for triage
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants