Probably I'm doing something wrong. I'm writing an Arduino sketch for ESP32. Among the others I have this function:
#define HDR_MAX_LENGHT 4
#define CMD_MAX_LENGHT 5
#define ARG_MAX_LENGHT 5
#define ARG_MAX_NUMBER 8
void ProcessLine(HardwareSerial *serial, char *line)
{
int ret;
int argc;
char header[HDR_MAX_LENGHT + 1];
char cmd[CMD_MAX_LENGHT + 1];
char argv[ARG_MAX_NUMBER][ARG_MAX_LENGHT + 1];
return; // for debugging
}
Usage example:
void loop()
{
static char inBuf[64];
if (Serial.available())
{
size_t size = Serial.readBytes(inBuf, 64);
inBuf[size] = '\0';
ProcessLine(&Serial, inBuf);
}
}
In the last days all worked fine. After adding other code, I noticed that sometimes my program "hangs": nothing runs. Perhaps it goes in an exception trap.
Commenting out the different sections of the code, I discovered that if I remove the declarations of the variables in ProcessLine() no more hangs happen.
The current RAM consumption is negligible: 0.5%.
During the tests NO serial data was received! So the function ProcessLine() was never called.
Hence, only the declaration of the variables lead to the "hang".
I wonder if there are some mistakes in the code above. Otherwise, how I can further debug my code to understand what I've done wrong?