Why does my heap_caps_malloc() crash?

vritzka
Posts: 22
Joined: Wed Sep 07, 2022 5:33 am

Why does my heap_caps_malloc() crash?

Postby vritzka » Tue Oct 25, 2022 6:06 am

Hello,

I'm running a 7-inch Display with an ESP32-S3 and LVGL.

I can allocate my draw buffer like this and it works, but the display flickers.

Code: Select all

// this works, but display flickers.
static lv_color_t buf1[screenWidth * 80];   
static lv_color_t buf2[screenWidth * 80];

//static lv_color_t buf1[screenWidth * 100];   //buffer overrun
//static lv_color_t buf2[screenWidth * 100]; // buffer overrun
So I try to use a bigger draw buffer with heap_caps_malloc() like this:

Code: Select all

void *buf1 = heap_caps_malloc(screenWidth * screenHeight, MALLOC_CAP_DMA );
void *buf2 = heap_caps_malloc(screenWidth * screenHeight , MALLOC_CAP_DMA );
But that causes a Guru Meditation error:

Code: Select all

13:48:53.304 -> Guru Meditation Error: Core  1 panic'ed (StoreProhibited). Exception was unhandled.
13:48:53.304 -> 
13:48:53.304 -> Core  1 register dump:
13:48:53.304 -> PC      : 0x4204e448  PS      : 0x00060430  A0      : 0x820142c9  A1      : 0x3fce26c0  
13:48:53.336 -> A2      : 0x00000000  A3      : 0x00000010  A4      : 0x00000320  A5      : 0x0000031f  
13:48:53.336 -> A6      : 0x00000000  A7      : 0x00000000  A8      : 0x10a310a3  A9      : 0x000010a3  
13:48:53.336 -> A10     : 0x00000000  A11     : 0x0000031f  A12     : 0x8037d78d  A13     : 0x3fce25c0  
13:48:53.368 -> A14     : 0x00060023  A15     : 0x00000003  SAR     : 0x0000001f  EXCCAUSE: 0x0000001d  
13:48:53.368 -> EXCVADDR: 0x00000000  LBEG    : 0x400570e8  LEND    : 0x400570f3  LCOUNT  : 0x00000000  
13:48:53.368 -> 
13:48:54.346 -> Backtrace:0x4204e445:0x3fce26c00x420142c6:0x3fce26e0 0x42013f8b:0x3fce2760 0x42016705:0x3fce2790 0x42017a2d:0x3fce2830 0x4204dd75:0x3fce2900 0x4200ac4b:0x3fce2920 0x4200b3bb:0x3fce29d0 0x4204d722:0x3fce2a00 0x42008a48:0x3fce2a20 0x42008bf2:0x3fce2a40 0x4200fb1d:0x3fce2a80 0x4200fbd9:0x3fce2ad0 0x4200fe46:0x3fce2b40 0x4200ff5b:0x3fce2b70 0x420109c3:0x3fce2c40 0x42022d04:0x3fce2c90 0x420022d3:0x3fce2cc0 0x4202d0f9:0x3fce2ce0 
13:48:54.379 -> 
13:48:54.379 -> 
13:48:54.379 -> 
13:48:54.379 -> ELF file SHA256: 0000000000000000
13:48:54.379 -> 
13:48:54.379 -> Rebooting...

Can somebody see why this crashes?


My display code looks like this:

Code: Select all

  static lv_disp_drv_t disp_drv;
  lv_disp_drv_init(&disp_drv);

  esp_lcd_panel_handle_t panel_handle = NULL;
  esp_lcd_rgb_panel_config_t panel_config = {
    .clk_src = LCD_CLK_SRC_PLL160M,
    .timings = {
      .pclk_hz = EXAMPLE_LCD_PIXEL_CLOCK_HZ,
      .h_res = screenWidth,
      .v_res = screenHeight,
      .hsync_pulse_width = 1,
      .hsync_back_porch = 46,
      .hsync_front_porch = 210,
      .vsync_pulse_width = 1,
      .vsync_back_porch = 23,
      .vsync_front_porch = 147,
      .flags{
        //.hsync_idle_low = 1,
        //.vsync_idle_low = 1,
        .de_idle_high = 0,
        .pclk_active_neg = 1,
        .pclk_idle_high = 0 } },
    .data_width = 16,  // RGB565 in parallel mode, thus 16bit in width
    .psram_trans_align = 64,
    //.hsync_gpio_num = EXAMPLE_PIN_NUM_HSYNC,
    //.vsync_gpio_num = EXAMPLE_PIN_NUM_VSYNC,
    .de_gpio_num = EXAMPLE_PIN_NUM_DE, 
    .pclk_gpio_num = EXAMPLE_PIN_NUM_PCLK,
    .data_gpio_nums = {
      EXAMPLE_PIN_NUM_DATA0,
      EXAMPLE_PIN_NUM_DATA1,
      EXAMPLE_PIN_NUM_DATA2,
      EXAMPLE_PIN_NUM_DATA3,
      EXAMPLE_PIN_NUM_DATA4,
      EXAMPLE_PIN_NUM_DATA5,
      EXAMPLE_PIN_NUM_DATA6,
      EXAMPLE_PIN_NUM_DATA7,
      EXAMPLE_PIN_NUM_DATA8,
      EXAMPLE_PIN_NUM_DATA9,
      EXAMPLE_PIN_NUM_DATA10,
      EXAMPLE_PIN_NUM_DATA11,
      EXAMPLE_PIN_NUM_DATA12,
      EXAMPLE_PIN_NUM_DATA13,
      EXAMPLE_PIN_NUM_DATA14,
      EXAMPLE_PIN_NUM_DATA15,
    },
    .disp_gpio_num = EXAMPLE_PIN_NUM_DISP_EN,
    .on_frame_trans_done = example_notify_lvgl_flush_ready,
    .user_ctx = &disp_drv,
    .flags{ .disp_active_low = 1, .relax_on_idle = 0, .fb_in_psram = 1 }
  };

  ESP_ERROR_CHECK(esp_lcd_new_rgb_panel(&panel_config, &panel_handle));
  ESP_ERROR_CHECK(esp_lcd_panel_reset(panel_handle));
  ESP_ERROR_CHECK(esp_lcd_panel_init(panel_handle));

  lv_init();

 //lv_disp_draw_buf_init(&draw_buf, buf1, buf2, screenWidth * 80);   ///<----WORKS, but too slow
  lv_disp_draw_buf_init(&draw_buf, buf1, buf2, screenWidth * screenHeight);   ///<---- CRASHES with GURU Meditation Error

  /*Initialize the display*/
  disp_drv.hor_res = screenWidth;
  disp_drv.ver_res = screenHeight;
  disp_drv.flush_cb = my_disp_flush;
  disp_drv.draw_buf = &draw_buf;
  disp_drv.user_data = panel_handle;
  lv_disp_drv_register(&disp_drv);


Thanks

ESP_igrr
Posts: 2071
Joined: Tue Dec 01, 2015 8:37 am

Re: Why does my heap_caps_malloc() crash?

Postby ESP_igrr » Tue Oct 25, 2022 4:45 pm

vritzka wrote:But that causes a Guru Meditation error:
From the panic handler output, this looks like an attempt to write to a NULL pointer (https://docs.espressif.com/projects/esp ... prohibited). Could you try checking if buf1 and buf2 (results of calling malloc) are not NULL?

vritzka
Posts: 22
Joined: Wed Sep 07, 2022 5:33 am

Re: Why does my heap_caps_malloc() crash?

Postby vritzka » Thu Oct 27, 2022 4:43 am

ESP_igrr wrote:
Tue Oct 25, 2022 4:45 pm
Could you try checking if buf1 and buf2 (results of calling malloc) are not NULL?
It seems to be NULL.

This code:

Code: Select all

void *buf3 = heap_caps_malloc(screenWidth * screenHeight, MALLOC_CAP_DMA);

 if(buf3 == NULL) {
    Serial.printf("data is %d", buf3);
  }
produces this output:

Code: Select all

data is 0

vritzka
Posts: 22
Joined: Wed Sep 07, 2022 5:33 am

Re: Why does my heap_caps_malloc() crash?

Postby vritzka » Thu Oct 27, 2022 5:01 am

I found a solution in this post.

This works:

Code: Select all

  void *buf3 = heap_caps_malloc(screenWidth * screenHeight, MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM);
Thank you!

Who is online

Users browsing this forum: Majestic-12 [Bot] and 98 guests