Dictionary
Dictionary copied to clipboard
ESP32 PANIC - Unhandled debug exception
Im looking for some help, I think its related to my lack of c++ knowledge and pointers. I have the below code (cutdown version of it) and whenever I include the dictionary code inside the RFID task ( ... if (d[rfid_uid.substring(1)] != "") ), the esp32 panic's with the below message. The panic only happens sporadically, after a random number of minutes of playing mp3's, so I think what is happening is my RFID task is trying to access the dictionary which was populated during the setup() function and possibly these memory addresses have now been overwritten? I thought that since I had created the dictionary in the global section, this would not be the case, but this is my lack of knowledge.
Do you have any ideas how I can make this play nicely? Essentially I have a json file with key value pair (UID and SONG) and I am populating a dictionary which then maps the UID of a RFID card to a MP3 file. I'm using a ESP32 wroom dev board and Platformio
########## PANIC ############## Guru Meditation Error: Core 0 panic'ed (Unhandled debug exception). Debug exception reason: Stack canary watchpoint triggered (RFID Task) Core 0 register dump: PC : 0x40084f25 PS : 0x00060c36 A0 : 0x00060c30 A1 : 0x3ffaefb0 A2 : 0x3ffb945c A3 : 0xffffffff A4 : 0x00000000 A5 : 0x00000001 A6 : 0x00060620 A7 : 0x00000001 A8 : 0x8008c88e A9 : 0xffffffff A10 : 0x00000003 A11 : 0x00060c23 A12 : 0x00060c20 A13 : 0x00060623 A14 : 0x007b945c A15 : 0x003fffff SAR : 0x0000001b EXCCAUSE: 0x00000001 EXCVADDR: 0x00000000 LBEG : 0x40084a95 LEND : 0x40084a9d LCOUNT : 0x00000027
Backtrace:0x40084f22:0x3ffaefb00x00060c2d:0x3ffaf0b0 |<-CORRUPTED
ELF file SHA256: 0000000000000000
Rebooting...
############# END PANIC ##############
#include <Dictionary.h>
#include <DictionaryDeclarations.h>
// RFID UID mapping dictionary
Dictionary &d = *(new Dictionary(20));
// RFID Task
void RFIDTask(void *parameters) {
Serial.println("Starting RFID Task");
// Loop forever
while (1) {
// RFID testing
if (rfid.PICC_IsNewCardPresent()) { // new tag is available
if (rfid.PICC_ReadCardSerial()) { // NUID has been readed
MFRC522::PICC_Type piccType = rfid.PICC_GetType(rfid.uid.sak);
Serial.print("RFID/NFC Tag Type: ");
Serial.println(rfid.PICC_GetTypeName(piccType));
// print UID in Serial Monitor in the hex format
Serial.print("UID:");
String rfid_uid = "";
for (int i = 0; i < rfid.uid.size; i++) {
Serial.print(rfid.uid.uidByte[i] < 0x10 ? " 0" : " ");
Serial.print(rfid.uid.uidByte[i], HEX);
rfid_uid.concat(String(rfid.uid.uidByte[i] < 0x10 ? " 0" : " "));
rfid_uid.concat(String(rfid.uid.uidByte[i], HEX));
}
Serial.println();
rfid.PICC_HaltA(); // halt PICC
rfid.PCD_StopCrypto1(); // stop encryption on PCD
rfid_uid.toUpperCase();
// Check dictionary for UID value and send MP3 to audio queue
if (d[rfid_uid.substring(1)] != "") {
Serial.print("RFID matched the song: ");
Serial.println(d[rfid_uid.substring(1)]);
String story = d[rfid_uid.substring(1)];
String storyPath = "/stories/" + story;
Serial.println(storyPath);
next_song(storyPath);
} else {
Serial.print("No RFID match found for: ");
Serial.println(rfid_uid.substring(1));
Serial.println(d[rfid_uid.substring(1)]);
}
}
}
}
}
void setup() {
// Serial setup
Serial.begin(115200);
// Load RFID UID Dictionary
File myFile = SD.open("/stories/uid_mapping.json");
if (myFile) {
d.jload(myFile);
// d("04 17 67 A2 4C 68 80", "Goldilocks and the Three Bears.mp3");
// d("04 17 67 A2 4C 68 81", "Jack and the Beanstalk.mp3");
Serial.println("RFID Dictionary");
Serial.println(d["04 5A DC A2 4C 68 81"]);
myFile.close();
} else {
Serial.println("error opening /stories/uid_mapping.json");
}
// Start RFID Task
Serial.println("Starting RFID Task...");
xTaskCreatePinnedToCore(RFIDTask,
"RFID Task",
1024,
NULL,
0,
NULL,
0);
}
Increase stack to 2048 or even more
xTaskCreatePinnedToCore(RFIDTask,
"RFID Task",
2048,
NULL,
0,
NULL,
0);
1K is too little. Should help.
From: jasonrepos @.> Sent: Wednesday, July 6, 2022 5:07 PM To: arkhipenko/Dictionary @.> Cc: Subscribed @.***> Subject: [arkhipenko/Dictionary] ESP32 PANIC - Unhandled debug exception (Issue #11)
Im looking for some help, I think its related to my lack of c++ knowledge and pointers. I have the below code (cutdown version of it) and whenever I include the dictionary code inside the RFID task ( ... if (d[rfid_uid.substring(1)] != "") ), the esp32 panic's with the below message. The panic only happens sporadically, after a random number of minutes of playing mp3's, so I think what is happening is my RFID task is trying to access the dictionary which was populated during the setup() function and possibly these memory addresses have now been overwritten? I thought that since I had created the dictionary in the global section, this would not be the case, but this is my lack of knowledge.
Do you have any ideas how I can make this play nicely? Essentially I have a csv file with 2 columns (UID and SONG) and I am populating a dictionary which then maps the UID of a RFID card to a MP3 file. I'm using a ESP32 wroom dev board and Platformio
########## PANIC ############## Guru Meditation Error: Core 0 panic'ed (Unhandled debug exception). Debug exception reason: Stack canary watchpoint triggered (RFID Task) Core 0 register dump: PC : 0x40084f25 PS : 0x00060c36 A0 : 0x00060c30 A1 : 0x3ffaefb0 A2 : 0x3ffb945c A3 : 0xffffffff A4 : 0x00000000 A5 : 0x00000001 A6 : 0x00060620 A7 : 0x00000001 A8 : 0x8008c88e A9 : 0xffffffff A10 : 0x00000003 A11 : 0x00060c23 A12 : 0x00060c20 A13 : 0x00060623 A14 : 0x007b945c A15 : 0x003fffff SAR : 0x0000001b EXCCAUSE: 0x00000001 EXCVADDR: 0x00000000 LBEG : 0x40084a95 LEND : 0x40084a9d LCOUNT : 0x00000027
Backtrace:0x40084f22:0x3ffaefb00x00060c2d:0x3ffaf0b0 |<-CORRUPTED
ELF file SHA256: 0000000000000000
Rebooting...
############# END PANIC ##############
#include <Dictionary.h> #include <DictionaryDeclarations.h>
// RFID UID mapping dictionary Dictionary &d = *(new Dictionary(20));
// RFID Task void RFIDTask(void *parameters) { Serial.println("Starting RFID Task");
// Loop forever while (1) { // RFID testing if (rfid.PICC_IsNewCardPresent()) { // new tag is available if (rfid.PICC_ReadCardSerial()) { // NUID has been readed MFRC522::PICC_Type piccType = rfid.PICC_GetType(rfid.uid.sak); Serial.print("RFID/NFC Tag Type: "); Serial.println(rfid.PICC_GetTypeName(piccType));
// print UID in Serial Monitor in the hex format
Serial.print("UID:");
String rfid_uid = "";
for (int i = 0; i < rfid.uid.size; i++) {
Serial.print(rfid.uid.uidByte[i] < 0x10 ? " 0" : " ");
Serial.print(rfid.uid.uidByte[i], HEX);
rfid_uid.concat(String(rfid.uid.uidByte[i] < 0x10 ? " 0" : " "));
rfid_uid.concat(String(rfid.uid.uidByte[i], HEX));
}
Serial.println();
rfid.PICC_HaltA(); // halt PICC
rfid.PCD_StopCrypto1(); // stop encryption on PCD
rfid_uid.toUpperCase();
// Check dictionary for UID value and send MP3 to audio queue
if (d[rfid_uid.substring(1)] != "") {
Serial.print("RFID matched the song: ");
Serial.println(d[rfid_uid.substring(1)]);
String story = d[rfid_uid.substring(1)];
String storyPath = "/stories/" + story;
Serial.println(storyPath);
next_song(storyPath);
} else {
Serial.print("No RFID match found for: ");
Serial.println(rfid_uid.substring(1));
Serial.println(d[rfid_uid.substring(1)]);
}
}
}
} }
void setup() {
// Serial setup
Serial.begin(115200);
// Load RFID UID Dictionary
File myFile = SD.open("/stories/uid_mapping.json");
if (myFile) {
d.jload(myFile);
// d("04 17 67 A2 4C 68 80", "Goldilocks and the Three Bears.mp3");
// d("04 17 67 A2 4C 68 81", "Jack and the Beanstalk.mp3");
Serial.println("RFID Dictionary");
Serial.println(d["04 5A DC A2 4C 68 81"]);
myFile.close();
} else {
Serial.println("error opening /stories/uid_mapping.json");
}
// Start RFID Task
Serial.println("Starting RFID Task...");
xTaskCreatePinnedToCore(RFIDTask,
"RFID Task",
1024,
NULL,
0,
NULL,
0);
}
— Reply to this email directly, view it on GitHubhttps://github.com/arkhipenko/Dictionary/issues/11, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AACMMTMU7INF2BUX3IVKRJDVSXYS5ANCNFSM523EXTFA. You are receiving this because you are subscribed to this thread.Message ID: @.***>
Thank you very much for your quick reply. I can confirm that after increasing the task stack size to 2048, everything has been running smoothly for the last hour and continues to do so. Thank you again!