Skip to content

M5Unified with Arduino-as-Component in ESP-IDF fails on ESP32-P4 (Tab5) #231

@RamyaManjunath003

Description

@RamyaManjunath003

Issue: M5Unified with Arduino-as-Component in ESP-IDF fails on ESP32-P4 (Tab5)

Important Context

  • Works with: Arduino IDE (pure Arduino framework)
  • Fails with: ESP-IDF using Arduino as a component
  • Board: M5Stack Tab5 P4 (ESP32-P4 + ESP32-C6)

Environment

  • Framework: ESP-IDF v5.5.1 with Arduino as component

  • Board: M5Stack Tab5 P4

  • MCU: ESP32-P4 (RISC-V) + ESP32-C6 co-processor

  • PSRAM: 32MB detected and working

  • Compiler: riscv32-esp-elf-g++ 14.2.0

  • M5Unified: v0.2.13

  • M5GFX: v0.2.19

Problem

M5Unified display initialization works in Arduino IDE but fails when using Arduino as a component in ESP-IDF. The display is not initialized (width=0, height=0) and crashes when used.

Key Differences Observed

  1. Arduino IDE: Display works correctly
  2. ESP-IDF + Arduino component: Display fails with exceptions followed by reboot
  3. Same code, same board, different framework integration

Minimal Test Code

#include "Arduino.h"

#include "M5Unified.h"
#include "M5GFX.h"

void setup() {
    Serial.begin(115200);
    printf("=== Tab5 P4 Display Debug ===\n");
    
    printf("M5 object size: %d\n", sizeof(M5));
    printf("M5.Display address: %p\n", &M5.Display);
    
    auto cfg = M5.config();
    cfg.clear_display = false;
    cfg.serial_baudrate = 0;
    
    printf("Calling M5.begin()...\n");
    M5.begin(cfg);
    
    delay(2000);
    
    printf("After begin - width: %ld, height: %ld\n", 
                  M5.Display.width(), M5.Display.height());
    
    printf("Calling M5.Display.init()...\n");
    bool init_result = M5.Display.init();
    printf("init() returned: %d\n", init_result);
    
    delay(1000);
    
    printf("After init - width: %ld, height: %ld\n",
                  M5.Display.width(), M5.Display.height());
    
    if (M5.Display.width() > 0) {
        printf("Attempting fillScreen...\n");
        M5.Display.fillScreen(TFT_RED);
        printf("fillScreen completed\n");
    }
    
    printf("=== Debug Complete ===\n");
}

void loop()
{
    M5.update();
    delay(1000);
} 

Error Messages

=== Tab5 P4 Display Debug ===
M5 object size: 1780
M5.Display address: 0x4ff19c60
Calling M5.begin()...
Guru Meditation Error: Core  1 panic'ed (Load access fault). Exception was unhandled.

--- Stack dump detected
Core  1 register dump:
MEPC    : 0x4002a600  RA      : 0x4002a5fa  SP      : 0x4ff36f90  GP      : 0x4ff15d00
--- 0x4002a600: setup() at C:/.../espidf-project/main/main.cpp:25
--- 0x4002a5fa: lgfx::v1::LGFXBase::width() const at C:/.../espidf-project/managed_components/M5GFX/src/lgfx/v1/LGFXBase.hpp:311
--- (inlined by) setup() at C:/.../espidf-project/main/main.cpp:25
TP      : 0x4ff37020  T0      : 0x4fc0a9f8  T1      : 0x4ff36bec  T2      : 0x00000000
S0/FP   : 0x00000001  S1      : 0x4ff19c5c  A0      : 0x1f000000  A1      : 0x00000000
A2      : 0x7f000000  A3      : 0x00000004  A4      : 0x00000004  A5      : 0x00000000
A6      : 0x4000e266  A7      : 0x0000000a  S2      : 0x4ff1a000  S3      : 0x00000000  
--- 0x4000e266: usb_serial_jtag_write at C:/Espressif/frameworks/esp-idf-v5.5.1/components/esp_driver_usb_serial_jtag/src/usb_serial_jtag_vfs.c:184
S4      : 0x00000000  S5      : 0x00000000  S6      : 0x00000000  S7      : 0x00000000
S8      : 0x00000000  S9      : 0x00000000  S10     : 0x00000000  S11     : 0x00000000
T3      : 0x00000000  T4      : 0x00000000  T5      : 0x00000000  T6      : 0x00000000
MSTATUS : 0x00011880  MTVEC   : 0x4ff00003  MCAUSE  : 0x00000005  MTVAL   : 0x00000012
--- 0x4ff00003: _vector_table at ??:?
MHARTID : 0x00000001

--- Backtrace:

add symbol table from file "C:\...\espidf-project\build\bootloader\bootloader.elf"
warning: could not convert 'main' from the host encoding (CP1252) to UTF-32.
This normally should not happen, please file a bug report.
setup () at C:/.../espidf-project/managed_components/M5GFX/src/lgfx/v1/Panel.hpp:96
96          uint16_t height(void) const { return _height; }
#0  setup () at C:/.../espidf-project/managed_components/M5GFX/src/lgfx/v1/Panel.hpp:96
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

ELF file SHA256: cb7b38184

Rebooting...
ESP-ROM:esp32p4-eco2-20240710
Build:Jul 10 2024
rst:0xc (SW_CPU_RESET),boot:0x20c (SPI_FAST_FLASH_BOOT)
Core0 Saved PC:0x4ff044d0
--- 0x4ff044d0: esp_cpu_wait_for_intr at C:/Espressif/frameworks/esp-idf-v5.5.1/components/esp_hw_support/cpu.c:57
Core1 Saved PC:0x4ff043ae
--- 0x4ff043ae: esp_cpu_reset at C:/Espressif/frameworks/esp-idf-v5.5.1/components/esp_hw_support/cpu.c:50
SPI mode:DIO, clock div:1
load:0x4ff33ce0,len:0x164c
load:0x4ff29ed0,len:0xdfc
--- 0x4ff29ed0: esp_bootloader_get_description at C:/Espressif/frameworks/esp-idf-v5.5.1/components/esp_bootloader_format/esp_bootloader_desc.c:39
load:0x4ff2cbd0,len:0x336c
--- 0x4ff2cbd0: esp_flash_encryption_enabled at C:/Espressif/frameworks/esp-idf-v5.5.1/components/bootloader_support/src/flash_encrypt.c:89
entry 0x4ff29eda
--- 0x4ff29eda: call_start_cpu0 at C:/Espressif/frameworks/esp-idf-v5.5.1/components/bootloader/subproject/main/bootloader_start.c:25

Observations

  • M5 object size: 1780 bytes
  • M5.Display address: 0x4ff19c60
  • Crash occurs when trying to access display properties after/during M5.begin()
  • Stack appears corrupted after crash
  • System reboots successfully after panic

What I've tried:

  • Minimal config with clear_display = false
  • Checking display address before initialization
  • Calling M5.Display.init() separately (crashes at same location)

Expected behavior: Display should initialize without crashing.

Similar Issue: #199 Although it is not specific to esp32p4.

Questions

  1. Is there a known compatibility issue with Arduino-as-component in ESP-IDF?
  2. Should M5Unified initialization be different for ESP-IDF vs Arduino framework?
  3. Are there specific configuration flags needed for ESP-IDF integration?
  4. Could this be related to FreeRTOS queue/mutex differences between frameworks?
  5. Any workarounds for ESP-IDF users who need Arduino libraries?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions