Hello...sorry to put an ESP32 question in here, but I'm using the Arduino IDE.
I have some text files that I'm loading data from into variables, and it's all functioning properly. But when it comes to loading data into variables that are in a struct array table, I get a kernel panic message and a reboot.
I'll post a condensed version of the code (that still creates the error):
The array table:
struct Blocks
{
int blNum;
int blStatus;
int blWinds;
int blRPM;
int blAccel;
int blAreaL;
int blAreaR;
int blScatter;
int blWPS;
float ptArea;
float ptInterval;
int ptSpeed;
} const BlockTable[] =
{
{1, 1, 0, 0, 0, 0, 100, 0, 0, 0, 0, 0},
{2, 1, 0, 0, 0, 0, 100, 0, 0, 0, 0, 0},
{3, 1, 0, 0, 0, 0, 100, 0, 0, 0, 0, 0},
{4, 0, 0, 0, 0, 0, 100, 0, 0, 0, 0, 0},
{5, 0, 0, 0, 0, 0, 100, 0, 0, 0, 0, 0},
{6, 0, 0, 0, 0, 0, 100, 0, 0, 0, 0, 0},
{7, 0, 0, 0, 0, 0, 100, 0, 0, 0, 0, 0},
{8, 0, 0, 0, 0, 0, 100, 0, 0, 0, 0, 0},
{9, 0, 0, 0, 0, 0, 100, 0, 0, 0, 0, 0},
{10, 0, 0, 0, 0, 0, 100, 0, 0, 0, 0, 0},
{11, 0, 0, 0, 0, 0, 100, 0, 0, 0, 0, 0},
{12, 0, 0, 0, 0, 0, 100, 0, 0, 0, 0, 0},
{13, 0, 0, 0, 0, 0, 100, 0, 0, 0, 0, 0},
{14, 0, 0, 0, 0, 0, 100, 0, 0, 0, 0, 0},
{15, 0, 0, 0, 0, 0, 100, 0, 0, 0, 0, 0},
{16, 0, 0, 0, 0, 0, 100, 0, 0, 0, 0, 0},
{17, 0, 0, 0, 0, 0, 100, 0, 0, 0, 0, 0},
{18, 0, 0, 0, 0, 0, 100, 0, 0, 0, 0, 0},
{19, 0, 0, 0, 0, 0, 100, 0, 0, 0, 0, 0},
{20, 0, 0, 0, 0, 0, 100, 0, 0, 0, 0, 0},
};
The function for loading the data into the variables:
void loadPickup(){
//DELETE
puSelector = 5;
//DELETE
Serial.println("Load File");
String filePath = String ("/saves/save" + String(puSelector) + ".txt");
File f = SPIFFS.open(filePath, "r");
if (!f) {
Serial.println("File open failed.");
};
for (int i = 1; i < 31; i++) {
String s = f.readStringUntil('\n');
if (i == 1) {
s.toCharArray(c, 200);
int result = sscanf(c, "%i,%i", &puStatus, &puNum);
};
if (i == 2) {puName = s;};
if (i == 3) {puType = s;};
if (i == 4) {
s.toCharArray(c, 200);
float result = sscanf(c, "%f,%f,%f", &puBobbin[0], &puBobbin[1], &puBobbin[2]);
};
if (i == 5) {puMagnet = s;};
if (i == 6) {puPolarity = s;};
if (i == 7) {puAWG = s.toInt();};
if (i == 8) {puInsulation = s;};
if (i == 9) {
s.toCharArray(c, 200);
float result = sscanf(c, "%f,%f,%f,%f", &puDims[0], &puDims[1], &puDims[2], &puDims[3]);
};
if (i == 10) {
s.toCharArray(c, 200);
int result = sscanf(c, "%i,%i,%i", &puDir, &puTotalBlocks, &puTotalWinds);
};
if (i == 11) {
s.toCharArray(c, 200);
int result = sscanf(c, "%i,%i,%i,%i,%i,%i,%i,%i,%i,%f,%f,%i", &BlockTable[0].blNum, &BlockTable[0].blStatus, &BlockTable[0].blWinds, &BlockTable[0].blRPM, &BlockTable[0].blAccel, &BlockTable[0].blAreaL, &BlockTable[0].blAreaR, &BlockTable[0].blScatter, &BlockTable[0].blWPS, &BlockTable[0].ptArea, &BlockTable[0].ptInterval, &BlockTable[0].ptSpeed);
};
if (i == 12) {
s.toCharArray(c, 200);
int result = sscanf(c, "%i,%i,%i,%i,%i,%i,%i,%i,%i,%f,%f,%i", &BlockTable[1].blNum, &BlockTable[1].blStatus, &BlockTable[1].blWinds, &BlockTable[1].blRPM, &BlockTable[1].blAccel, &BlockTable[1].blAreaL, &BlockTable[1].blAreaR, &BlockTable[1].blScatter, &BlockTable[1].blWPS, &BlockTable[1].ptArea, &BlockTable[1].ptInterval, &BlockTable[1].ptSpeed);
};
if (i == 13) {
s.toCharArray(c, 200);
int result = sscanf(c, "%i,%i,%i,%i,%i,%i,%i,%i,%i,%f,%f,%i", &BlockTable[2].blNum, &BlockTable[2].blStatus, &BlockTable[2].blWinds, &BlockTable[2].blRPM, &BlockTable[2].blAccel, &BlockTable[2].blAreaL, &BlockTable[2].blAreaR, &BlockTable[2].blScatter, &BlockTable[2].blWPS, &BlockTable[2].ptArea, &BlockTable[2].ptInterval, &BlockTable[2].ptSpeed);
};
if (i == 14) {
s.toCharArray(c, 200);
int result = sscanf(c, "%i,%i,%i,%i,%i,%i,%i,%i,%i,%f,%f,%i", &BlockTable[3].blNum, &BlockTable[3].blStatus, &BlockTable[3].blWinds, &BlockTable[3].blRPM, &BlockTable[3].blAccel, &BlockTable[3].blAreaL, &BlockTable[3].blAreaR, &BlockTable[3].blScatter, &BlockTable[3].blWPS, &BlockTable[3].ptArea, &BlockTable[3].ptInterval, &BlockTable[3].ptSpeed);
};
if (i == 15) {
s.toCharArray(c, 200);
int result = sscanf(c, "%i,%i,%i,%i,%i,%i,%i,%i,%i,%f,%f,%i", &BlockTable[4].blNum, &BlockTable[4].blStatus, &BlockTable[4].blWinds, &BlockTable[4].blRPM, &BlockTable[4].blAccel, &BlockTable[4].blAreaL, &BlockTable[4].blAreaR, &BlockTable[4].blScatter, &BlockTable[4].blWPS, &BlockTable[4].ptArea, &BlockTable[4].ptInterval, &BlockTable[4].ptSpeed);
};
if (i == 16) {
s.toCharArray(c, 200);
int result = sscanf(c, "%i,%i,%i,%i,%i,%i,%i,%i,%i,%f,%f,%i", &BlockTable[5].blNum, &BlockTable[5].blStatus, &BlockTable[5].blWinds, &BlockTable[5].blRPM, &BlockTable[5].blAccel, &BlockTable[5].blAreaL, &BlockTable[5].blAreaR, &BlockTable[5].blScatter, &BlockTable[5].blWPS, &BlockTable[5].ptArea, &BlockTable[5].ptInterval, &BlockTable[5].ptSpeed);
};
if (i == 17) {
s.toCharArray(c, 200);
int result = sscanf(c, "%i,%i,%i,%i,%i,%i,%i,%i,%i,%f,%f,%i", &BlockTable[6].blNum, &BlockTable[6].blStatus, &BlockTable[6].blWinds, &BlockTable[6].blRPM, &BlockTable[6].blAccel, &BlockTable[6].blAreaL, &BlockTable[6].blAreaR, &BlockTable[6].blScatter, &BlockTable[6].blWPS, &BlockTable[6].ptArea, &BlockTable[6].ptInterval, &BlockTable[6].ptSpeed);
};
if (i == 18) {
s.toCharArray(c, 200);
int result = sscanf(c, "%i,%i,%i,%i,%i,%i,%i,%i,%i,%f,%f,%i", &BlockTable[7].blNum, &BlockTable[7].blStatus, &BlockTable[7].blWinds, &BlockTable[7].blRPM, &BlockTable[7].blAccel, &BlockTable[7].blAreaL, &BlockTable[7].blAreaR, &BlockTable[7].blScatter, &BlockTable[7].blWPS, &BlockTable[7].ptArea, &BlockTable[7].ptInterval, &BlockTable[7].ptSpeed);
};
if (i == 19) {
s.toCharArray(c, 200);
int result = sscanf(c, "%i,%i,%i,%i,%i,%i,%i,%i,%i,%f,%f,%i", &BlockTable[8].blNum, &BlockTable[8].blStatus, &BlockTable[8].blWinds, &BlockTable[8].blRPM, &BlockTable[8].blAccel, &BlockTable[8].blAreaL, &BlockTable[8].blAreaR, &BlockTable[8].blScatter, &BlockTable[8].blWPS, &BlockTable[8].ptArea, &BlockTable[8].ptInterval, &BlockTable[8].ptSpeed);
};
if (i == 20) {
s.toCharArray(c, 200);
int result = sscanf(c, "%i,%i,%i,%i,%i,%i,%i,%i,%i,%f,%f,%i", &BlockTable[9].blNum, &BlockTable[9].blStatus, &BlockTable[9].blWinds, &BlockTable[9].blRPM, &BlockTable[9].blAccel, &BlockTable[9].blAreaL, &BlockTable[9].blAreaR, &BlockTable[9].blScatter, &BlockTable[9].blWPS, &BlockTable[9].ptArea, &BlockTable[9].ptInterval, &BlockTable[9].ptSpeed);
};
if (i == 21) {
s.toCharArray(c, 200);
int result = sscanf(c, "%i,%i,%i,%i,%i,%i,%i,%i,%i,%f,%f,%i", &BlockTable[10].blNum, &BlockTable[10].blStatus, &BlockTable[10].blWinds, &BlockTable[10].blRPM, &BlockTable[10].blAccel, &BlockTable[10].blAreaL, &BlockTable[10].blAreaR, &BlockTable[10].blScatter, &BlockTable[10].blWPS, &BlockTable[10].ptArea, &BlockTable[10].ptInterval, &BlockTable[10].ptSpeed);
};
if (i == 22) {
s.toCharArray(c, 200);
int result = sscanf(c, "%i,%i,%i,%i,%i,%i,%i,%i,%i,%f,%f,%i", &BlockTable[11].blNum, &BlockTable[11].blStatus, &BlockTable[11].blWinds, &BlockTable[11].blRPM, &BlockTable[11].blAccel, &BlockTable[11].blAreaL, &BlockTable[11].blAreaR, &BlockTable[11].blScatter, &BlockTable[11].blWPS, &BlockTable[11].ptArea, &BlockTable[11].ptInterval, &BlockTable[11].ptSpeed);
};
if (i == 23) {
s.toCharArray(c, 200);
int result = sscanf(c, "%i,%i,%i,%i,%i,%i,%i,%i,%i,%f,%f,%i", &BlockTable[12].blNum, &BlockTable[12].blStatus, &BlockTable[12].blWinds, &BlockTable[12].blRPM, &BlockTable[12].blAccel, &BlockTable[12].blAreaL, &BlockTable[12].blAreaR, &BlockTable[12].blScatter, &BlockTable[12].blWPS, &BlockTable[12].ptArea, &BlockTable[12].ptInterval, &BlockTable[12].ptSpeed);
};
if (i == 24) {
s.toCharArray(c, 200);
int result = sscanf(c, "%i,%i,%i,%i,%i,%i,%i,%i,%i,%f,%f,%i", &BlockTable[13].blNum, &BlockTable[13].blStatus, &BlockTable[13].blWinds, &BlockTable[13].blRPM, &BlockTable[13].blAccel, &BlockTable[13].blAreaL, &BlockTable[13].blAreaR, &BlockTable[13].blScatter, &BlockTable[13].blWPS, &BlockTable[13].ptArea, &BlockTable[13].ptInterval, &BlockTable[13].ptSpeed);
};
if (i == 25) {
s.toCharArray(c, 200);
int result = sscanf(c, "%i,%i,%i,%i,%i,%i,%i,%i,%i,%f,%f,%i", &BlockTable[14].blNum, &BlockTable[14].blStatus, &BlockTable[14].blWinds, &BlockTable[14].blRPM, &BlockTable[14].blAccel, &BlockTable[14].blAreaL, &BlockTable[14].blAreaR, &BlockTable[14].blScatter, &BlockTable[14].blWPS, &BlockTable[14].ptArea, &BlockTable[14].ptInterval, &BlockTable[14].ptSpeed);
};
if (i == 26) {
s.toCharArray(c, 200);
int result = sscanf(c, "%i,%i,%i,%i,%i,%i,%i,%i,%i,%f,%f,%i", &BlockTable[15].blNum, &BlockTable[15].blStatus, &BlockTable[15].blWinds, &BlockTable[15].blRPM, &BlockTable[15].blAccel, &BlockTable[15].blAreaL, &BlockTable[15].blAreaR, &BlockTable[15].blScatter, &BlockTable[15].blWPS, &BlockTable[15].ptArea, &BlockTable[15].ptInterval, &BlockTable[15].ptSpeed);
};
if (i == 27) {
s.toCharArray(c, 200);
int result = sscanf(c, "%i,%i,%i,%i,%i,%i,%i,%i,%i,%f,%f,%i", &BlockTable[16].blNum, &BlockTable[16].blStatus, &BlockTable[16].blWinds, &BlockTable[16].blRPM, &BlockTable[16].blAccel, &BlockTable[16].blAreaL, &BlockTable[16].blAreaR, &BlockTable[16].blScatter, &BlockTable[16].blWPS, &BlockTable[16].ptArea, &BlockTable[16].ptInterval, &BlockTable[16].ptSpeed);
};
if (i == 28) {
s.toCharArray(c, 200);
int result = sscanf(c, "%i,%i,%i,%i,%i,%i,%i,%i,%i,%f,%f,%i", &BlockTable[17].blNum, &BlockTable[17].blStatus, &BlockTable[17].blWinds, &BlockTable[17].blRPM, &BlockTable[17].blAccel, &BlockTable[17].blAreaL, &BlockTable[17].blAreaR, &BlockTable[17].blScatter, &BlockTable[17].blWPS, &BlockTable[17].ptArea, &BlockTable[17].ptInterval, &BlockTable[17].ptSpeed);
};
if (i == 29) {
s.toCharArray(c, 200);
int result = sscanf(c, "%i,%i,%i,%i,%i,%i,%i,%i,%i,%f,%f,%i", &BlockTable[18].blNum, &BlockTable[18].blStatus, &BlockTable[18].blWinds, &BlockTable[18].blRPM, &BlockTable[18].blAccel, &BlockTable[18].blAreaL, &BlockTable[18].blAreaR, &BlockTable[18].blScatter, &BlockTable[18].blWPS, &BlockTable[18].ptArea, &BlockTable[18].ptInterval, &BlockTable[18].ptSpeed);
};
if (i == 30) {
s.toCharArray(c, 200);
int result = sscanf(c, "%i,%i,%i,%i,%i,%i,%i,%i,%i,%f,%f,%i", &BlockTable[19].blNum, &BlockTable[19].blStatus, &BlockTable[19].blWinds, &BlockTable[19].blRPM, &BlockTable[19].blAccel, &BlockTable[19].blAreaL, &BlockTable[19].blAreaR, &BlockTable[19].blScatter, &BlockTable[19].blWPS, &BlockTable[19].ptArea, &BlockTable[19].ptInterval, &BlockTable[19].ptSpeed);
};
};
Serial.println("Variables loaded.");
f.close();
};
The error:
Load File
Guru Meditation Error: Core 1 panic'ed (LoadStoreError). Exception was unhandled.
Core 1 register dump:
PC : 0x400efd4d PS : 0x00060c30 A0 : 0x800e9cec A1 : 0x3ffb2300
A2 : 0x3ffb2500 A3 : 0x00000001 A4 : 0x3ffb2500 A5 : 0x3ffb2301
A6 : 0x00000001 A7 : 0x3ffb2300 A8 : 0x00000000 A9 : 0x00000008
A10 : 0x3f400578 A11 : 0x00000001 A12 : 0x00000000 A13 : 0x0000000a
A14 : 0x00000068 A15 : 0x3ffb2690 SAR : 0x0000000a EXCCAUSE: 0x00000003
EXCVADDR: 0x3f400578 LBEG : 0x400864e5 LEND : 0x400864f5 LCOUNT : 0xfffffff9
Backtrace:0x400efd4a:0x3ffb23000x400e9ce9:0x3ffb2690 0x400d2715:0x3ffb2750 0x400d3355:0x3ffb27e0 0x400d50e5:0x3ffb2820
ELF file SHA256: 0000000000000000
Rebooting...
Relevant ESP32 error code:
**LoadStoreError**
This exception may happen in the following cases:
If the application has attempted to do an 8- or 16- bit read to, or write from, a memory region which only supports 32-bit reads/writes. For example, dereferencing a char* pointer to instruction memory (IRAM, IROM) will result in such an error.
If the application has attempted to write to a read-only memory region, such as IROM or DROM.
I've attached the entire sketch as well, it's just a big pile of SPIFFS loading/saving stuff, I just figured it might be apparent just looking at the relevant stuff up there though before subjecting anyone to my mess.
Any suggestions are appreciated - I tried a couple things, but no results.
LS_File.zip (48.8 KB)
EDIT: I did a little test just running this:
BlockTable[0].blNum = 5;
and I get this error:
error: assignment of member 'Blocks::blNum' in read-only object
BlockTable[0].blNum = 5;
^
exit status 1
assignment of member 'Blocks::blNum' in read-only object
So I suppose the question is...how do I make a writeable struct array table?
EDIT 2: It seems that I have a "const" in front of the BlockTable array set. I removed that, and the kernel panic is gone. It seems to load but I seem to have some other problems with the variables not having data loaded into them.