Page 1 of 1

malloc memory crashing for spi but global/static working fine

Posted: Sun Dec 08, 2019 7:03 am
by vinodstanur
Hi,

I am using esp-idf 3.3.

If I use malloc to allocate a 3KB buffer, then the system is crashing. I already have around 60KB heap.
I am using this buffer for LCD via spi. SPI is pushing it via DMA.

If I use static/global 3KB instead, it works fine.

Code: Select all

ILI9341 initialization.
Guru Meditation Error: Core  0 panic'ed (LoadProhibited). Exception was unhandled.
Core 0 register dump:
PC      : 0x40095d57  PS      : 0x00060f33  A0      : 0x80095b2b  A1      : 0x3ffbb420  
0x40095d57: block_data_size at /home/vinod/esp/esp-idf/components/heap/multi_heap.c:699

A2      : 0xffffffff  A3      : 0x00060f23  A4      : 0x00060f20  A5      : 0x00000001  
A6      : 0x3ffbd8d0  A7      : 0x0000013f  A8      : 0xc002fd78  A9      : 0xc002fd74  
A10     : 0x3ffcb0f0  A11     : 0x00060f23  A12     : 0x00060f20  A13     : 0xb33fffff  
A14     : 0x0000002a  A15     : 0x3ffce780  SAR     : 0x0000001e  EXCCAUSE: 0x0000001c  
EXCVADDR: 0xffffffff  LBEG    : 0x4000c2e0  LEND    : 0x4000c2f6  LCOUNT  : 0xffffffff  

ELF file SHA256: d5bfe723743f08b06c063aff7d0a345ac585e1dd6e9531818db895e0beda60cc

Backtrace: 0x40095d57:0x3ffbb420 0x40095b28:0x3ffbb440 0x400853c2:0x3ffbb470 0x4009450a:0x3ffbb4a0 0x4010620f:0x3ffbb4e0 0x400d0896:0x3ffbb510
0x40095d57: block_data_size at /home/vinod/esp/esp-idf/components/heap/multi_heap.c:699

0x40095b28: multi_heap_malloc_impl at /home/vinod/esp/esp-idf/components/heap/multi_heap.c:699

0x400853c2: heap_caps_malloc at /home/vinod/esp/esp-idf/components/heap/heap_caps.c:232

0x4009450a: xTaskCreatePinnedToCore at /home/vinod/esp/esp-idf/components/freertos/tasks.c:3507

0x4010620f: xTaskCreate at /home/vinod/esp/esp-idf/components/freertos/include/freertos/task.h:440
 (inlined by) app_main at /home/vinod/workspace/myproject/project1/main/main.c:133

0x400d0896: main_task at /home/vinod/esp/esp-idf/components/esp32/cpu_start.c:542
I tried all combinations of heap cap.
uint8_t *buf1 = heap_caps_malloc(3200, MALLOC_CAP_DMA);
uint8_t *buf2 = heap_caps_malloc(3200, MALLOC_CAP_DMA);

or

uint8_t *buf1 = heap_caps_malloc(3200, MALLOC_CAP_32BIT|MALLOC_CAP_DMA);
uint8_t *buf2 = heap_caps_malloc(3200, MALLOC_CAP_32BIT|MALLOC_CAP_DMA);

or
uint8_t *buf1 = heap_caps_malloc(3200, MALLOC_CAP_32BIT);
uint8_t *buf2 = heap_caps_malloc(3200, MALLOC_CAP_32BIT);

etc

BUT result is same, crashing while using the memory for lcd spi.

I tried printing the memory after malloc and printing it as below after

Code: Select all

I (0) cpu_start: App cpu up.
I (630) heap_init: Initializing. RAM available for dynamic allocation:
I (636) heap_init: At 3FFAFF10 len 000000F0 (0 KiB): DRAM
I (642) heap_init: At 3FFB6388 len 00001C78 (7 KiB): DRAM
I (649) heap_init: At 3FFB9A20 len 00004108 (16 KiB): DRAM
I (655) heap_init: At 3FFBDB5C len 00000004 (0 KiB): DRAM
I (661) heap_init: At 3FFCD910 len 000126F0 (73 KiB): DRAM
I (667) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (673) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (680) heap_init: At 40096C64 len 0000939C (36 KiB): IRAM
I (686) cpu_start: Pro cpu start user code
I (33) cpu_start: Chip Revision: 1
W (33) cpu_start: Chip revision is higher than the one configured in menuconfig. Suggest to upgrade it.
I (36) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
I (282) gpio: GPIO[2]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 
I (282) gpio: GPIO[34]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:1 
E (292) gpio: io_num=34 can only be input
E (292) gpio: gpio_set_level(176): GPIO output gpio_num error
ILI9341 initialization.
memory buf1 = 3ffce930
memory buf2 = 3ffcf5b4

Instead if I use
static uint8_t buf1[3200];
static uint8_t buf2[3200];
It works fine.

What could be the problem ?

Re: malloc memory crashing for spi but global/static working fine

Posted: Mon Dec 09, 2019 2:30 am
by ESP_Sprite
That's very hard to say without seeing your code or at the very least the backtrace for the crash.