SPIFFS mysteriously crash after adding unrelated code
Posted: Wed Sep 28, 2016 3:05 am
I am encountering a strange behavior. I am using ESP8266 arduino SPIFFS to store configuration settings. Here is the relevant part of mycode;
In the above code, the UART will receive a command "XXX\r", then run saveConfig() which will save the config parameters ssid and parameters into SPIFSS. This code works perfectly fine until I add more code which is totally unrelated.
This is how the new code looks like.
After adding the additional else clause, sending "XXX\r" to the UARt and causing saveConfig() will cause an exception error. This is puzzling since the new code did not even get to run.
The exception error is as below;
[i]Exception (3):
epc1=0x401002f0 epc2=0x00000000 epc3=0x00000000 excvaddr=0x400072f6 depc=0x00000
000
ctx: sys
sp: 3fff06b0 end: 3fffffb0 offset: 01a0
Code: Select all
void loop()
{
handleUartRxOk();
}
void handleUartRxOk() {
String cmd;
char charBuff[3200];
char char_print[50];
static bool terminatorReceived = false;
char incomingChar = 0; // for incoming serial data
if (Serial.available()) {
incomingChar = Serial.read();
saveChar(incomingChar);
if (incomingChar == '\r') {
terminatorReceived = true;
}
if (terminatorReceived) {
buffer[buffer_index - 1] = '\0';
cmd = String(buffer);
if (cmd == "XXX") {
ConfigSettings.ssid = "SSID_XX";
ConfigSettings.password = "PASSWORD_XX";
saveConfig();
}
buffer_index = 0;
terminatorReceived = false;
}
}
}
In the above code, the UART will receive a command "XXX\r", then run saveConfig() which will save the config parameters ssid and parameters into SPIFSS. This code works perfectly fine until I add more code which is totally unrelated.
This is how the new code looks like.
Code: Select all
void handleUartRxOk() {
String cmd;
char charBuff[3200];
char char_print[50];
static bool terminatorReceived = false;
char incomingChar = 0; // for incoming serial data
if (Serial.available()) {
incomingChar = Serial.read();
saveChar(incomingChar);
if (incomingChar == '\r') {
terminatorReceived = true;
}
if (terminatorReceived) {
buffer[buffer_index - 1] = '\0';
cmd = String(buffer);
if (cmd == "XXX") {
ConfigSettings.ssid = "SSID_XX";
ConfigSettings.password = "PASSWORD_XX";
saveConfig();
}
//Why does adding this else statement cause saveConfig() to crash?
else {
strcat(charBuff, cmd.c_str());
}
buffer_index = 0;
terminatorReceived = false;
}
}
}
After adding the additional else clause, sending "XXX\r" to the UARt and causing saveConfig() will cause an exception error. This is puzzling since the new code did not even get to run.
The exception error is as below;
[i]Exception (3):
epc1=0x401002f0 epc2=0x00000000 epc3=0x00000000 excvaddr=0x400072f6 depc=0x00000
000
ctx: sys
sp: 3fff06b0 end: 3fffffb0 offset: 01a0