SPIRAM malloc issues

chegewara
Posts: 2207
Joined: Wed Jun 14, 2017 9:00 pm

SPIRAM malloc issues

Postby chegewara » Fri Oct 19, 2018 10:48 pm

Hi,
i am trying to allocate pretty big memory amount in SPIRAM with every known to me configuration combinations + malloc functions.
Ive been trying malloc() with proper settings in menuconfig, and heap_caps_malloc

Code: Select all

	
	uint8_t *buffer = heap_caps_malloc(1024*150, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT); // <-- with and without 8BIT CAP
always max allocated value for SPIRAM with one call is 30720 bytes, and because i am trying to write more to this buffer i am getting multi heap error.

Code: Select all

// heap_caps_print_heap_info(MALLOC_CAP_SPIRAM);
Heap summary for capabilities 0x00000400:
  At 0x3f800000 len 4194303 free 4163508 allocated 30720 min_free 4163508
    largest_free_block 4163508 alloc_blocks 1 free_blocks 1 total_blocks 2
  Totals:
    free 4163508 allocated 30720 min_free 4163508 largest_free_block 4163508
    
Guru Meditation Error: Core  0 panic'ed (LoadProhibited). Exception was unhandled.
Core 0 register dump:
PC      : 0x40091f7b  PS      : 0x00060633  A0      : 0x800924e6  A1      : 0x3fffd150
0x40091f7b: is_free at D:/msys32/home/imper/esp/esp-idf/components/heap/multi_heap.c:377
 (inlined by) multi_heap_malloc_impl at D:/msys32/home/imper/esp/esp-idf/components/heap/multi_heap.c:429

A2      : 0x3f800000  A3      : 0x00025810  A4      : 0x3f80782c  A5      : 0x00000000
A6      : 0x3ffae9b4  A7      : 0x00000000  A8      : 0x00000001  A9      : 0x86443c1a
A10     : 0x3f80782c  A11     : 0x00000001  A12     : 0x3f807830  A13     : 0x3f800010
A14     : 0x8829ee44  A15     : 0x00000000  SAR     : 0x00000004  EXCCAUSE: 0x0000001c
EXCVADDR: 0x86443c1a  LBEG    : 0x40096f6d  LEND    : 0x40096f7d  LCOUNT  : 0xfffffffc
0x40096f6d: strlen at /home/jeroen/esp8266/esp32/newlib_xtensa-2.2.0-bin/newlib_
xtensa-2.2.0/xtensa-esp32-elf/newlib/libc/machine/xtensa/../../../../.././newlib
/libc/machine/xtensa/strlen.S:84

0x40096f7d: strlen at /home/jeroen/esp8266/esp32/newlib_xtensa-2.2.0-bin/newlib_
xtensa-2.2.0/xtensa-esp32-elf/newlib/libc/machine/xtensa/../../../../.././newlib
/libc/machine/xtensa/strlen.S:96


Backtrace: 0x40091f7b:0x3fffd150 0x400924e3:0x3fffd170 0x40084ee1:0x3fffd190 0x4
00854c9:0x3fffd1b0 0x4008571d:0x3fffd210 0x400d608f:0x3fffd230 0x400d5c0a:0x3fff
d2c0 0x4008ff3d:0x3fffd2f0
0x40091f7b: is_free at D:/msys32/home/imper/esp/esp-idf/components/heap/multi_heap.c:377
 (inlined by) multi_heap_malloc_impl at D:/msys32/home/imper/esp/esp-idf/components/heap/multi_heap.c:429

0x400924e3: multi_heap_malloc at D:/msys32/home/imper/esp/esp-idf/components/heap/multi_heap_poisoning.c:370

0x40084ee1: heap_caps_malloc at D:/msys32/home/imper/esp/esp-idf/components/heap/heap_caps.c:351

0x400854c9: trace_malloc at D:/msys32/home/imper/esp/esp-idf/components/heap/heap_trace.c:324

0x4008571d: __wrap_heap_caps_malloc at D:/msys32/home/imper/esp/esp-idf/components/heap/heap_trace.c:419

0x400d608f: https at D:/esp32_camera/task1/ESP32_CAMERA_QR/main/esp_https_client.c:72

0x400d5c0a: get_cam_data at D:/esp32_camera/task1/ESP32_CAMERA_QR/main/app_main.c:69

0x4008ff3d: vPortTaskWrapper at D:/msys32/home/imper/esp/esp-idf/components/freertos/port.c:435
Any advice or help, or maybe its bug? Thanks in advance.

PS 30720 is SPIRAM heap used before malloc() call, my bad, but still if i try to malloc big amount of heap im getting multi heap error

ESP_Sprite
Posts: 8921
Joined: Thu Nov 26, 2015 4:08 am

Re: SPIRAM malloc issues

Postby ESP_Sprite » Sat Oct 20, 2018 7:29 am

Smells like you're corrupting memory somewhere and the heap allocator only finds out later that its metadata is a mess, to be honest.

chegewara
Posts: 2207
Joined: Wed Jun 14, 2017 9:00 pm

Re: SPIRAM malloc issues

Postby chegewara » Sat Oct 20, 2018 8:52 am

@ESP_Sprite
I can avoid this heap corruption errors, but i have to create task with 100kB stack and obviously it is not what i want.

It is very simple app, client app reading data from I2S camera and http client sending base64 data to server. Even if i turn on in menuconfig option to allocate memory with heap_caps_malloc and only allocated memory is the one i want to allocate still im getting this error. I dont see how it can be corrupted in other part of code.

chegewara
Posts: 2207
Joined: Wed Jun 14, 2017 9:00 pm

Re: SPIRAM malloc issues

Postby chegewara » Sat Oct 20, 2018 9:37 am

Looks like it was my code, with heap_caps_malloc it works now.

Who is online

Users browsing this forum: No registered users and 139 guests