Hi ESP_Angus,
Thank you very much for the Link about Heap Memory Debugging.
---
I've followed the instructions as the docu said: Turned on "Assertion level" to "Enable" & make sure "Optimization Level" to "-Og", but didn't change my code. After manually clean and recompile the code base, I still get crashed in the same place but without
Code: Select all
CORRUPT HEAP: multi_heap.c:225 detected at 0x3ffbb71c
Because the crash happened in the API call of a opensourced library (op62541.org), I've tried to add one line above the place where the crash get triggered, the statement I added:
Code: Select all
ESP_LOGW(TAG,"freeheap before crash: %d",esp_get_free_heap_size());
And this log I've never get logged till the whole programm get crashed.
And this part of code looks like this:
Code: Select all
35234 ESP_LOGW(TAG,"freeheap before crash: %d",esp_get_free_heap_size());
35235
35236 /* Add to the list of pending acks */
35237 UA_Client_NotificationsAckNumber *tmpAck =
35238 (UA_Client_NotificationsAckNumber*)UA_malloc(sizeof(UA_Client_NotificationsAckNumber));
35239 ORRUPT HEAP: multi_heap.c:225 detected at 0x3ffbb71c
35240 UA_LOG_WARNING(client->config.logger, UA_LOGCATEGORY_CLIENT,
35241 "Not enough memory to store the acknowledgement for a publish "
35242 "message on subscription %u", sub->subscriptionID);
35243 return;
35244 }
35245 tmpAck->subAck.sequenceNumber = msg->sequenceNumber;
35246 tmpAck->subAck.subscriptionId = sub->subscriptionID;
35247 LIST_INSERT_HEAD(&client->pendingNotificationsAcks, tmpAck, listEntry);
35248 }
And my crash log:
Code: Select all
Guru Meditation Error: Core 1 panic'ed (StoreProhibited)
. Exception was unhandled.
Core 1 register dump:
PC : 0x4000c2ff PS : 0x00060730 A0 : 0x800e8a5c A1 : 0x3ffe2290
A2 : 0x00000000 A3 : 0x3ffe2590 A4 : 0x00000008 A5 : 0x00000000
A6 : 0x00000001 A7 : 0x00000000 A8 : 0x00000000 A9 : 0x3ffe2290
A10 : 0x00000000 A11 : 0x00001800 A12 : 0x00000000 A13 : 0x00000003
A14 : 0x00000000 A15 : 0x00000000 SAR : 0x0000000c EXCCAUSE: 0x0000001d
EXCVADDR: 0x00000000 LBEG : 0x4000c2e0 LEND : 0x4000c2f6 LCOUNT : 0xffffffff
Backtrace: 0x4000c2ff:0x3ffe2290 0x400e8a59:0x3ffe22a0 0x400e9309:0x3ffe22c0 0x400ec82d:0x3ffe2300 0x40102a68:0x3ffe2330 0x401120d3:0x3ffe2930 0x401123e2:0x3ffe2960 0x40114cda:0x3ffe2b30 0x400d500d:0x3ffe2b50
0x400e8a59: UInt64_encodeBinary at /home/gfast2/workspace/ioc-110-ethernet/components/open62541/./open62541.c:35242 (discriminator 3)
0x400e9309: UA_encodeBinaryInternal at /home/gfast2/workspace/ioc-110-ethernet/components/open62541/./open62541.c:35242 (discriminator 3)
0x400ec82d: UA_encodeBinary at /home/gfast2/workspace/ioc-110-ethernet/components/open62541/./open62541.c:35242 (discriminator 3)
0x40102a68: function_ua_namespace0_53 at /home/gfast2/workspace/ioc-110-ethernet/components/open62541/./open62541.c:35242 (discriminator 3)
0x401120d3: ua_namespace0 at /home/gfast2/workspace/ioc-110-ethernet/components/open62541/./open62541.c:35242 (discriminator 3)
0x401123e2: UA_Server_initNS0 at /home/gfast2/workspace/ioc-110-ethernet/components/open62541/./open62541.c:35242 (discriminator 3)
0x40114cda: UA_Server_new at /home/gfast2/workspace/ioc-110-ethernet/components/open62541/./open62541.c:35242 (discriminator 3)
0x400d500d: opcua_task at /home/gfast2/workspace/ioc-110-ethernet/main/./opcua_task.c:31
CPU halted.
I know very possibly is this crash not related to heap out-of-usage (From the Assertion level detection result), and if the crash really happend on line 35242, the main reason is from the "return;" on line 35243. But please look at line 35240: "Not enough memory to store the acknowledgement for a plublish message on subscription %d".
This whole open62541 library takes about 102kB memory as a freeRTOS task (Tested in other project), and in this project, before the initialization of the same open62541 task, "esp_get_free_heap_size()" return me 126156Byte free heap. This let me thinking, how to tell out of memory. Is that means about 26kB free Heap should also OK on theory?