When you declare a function returning a value, you must use a return statement to exit the function, otherwise the program crashes. The board is no longer visible on the COM port, and the colored LED flashes.
Example:
The following code runs perfectly on all my Arduino boards (Nano Every, Nano 33 BLE, nano 33 IoT and ESP 32):
bool light;
int test(void)
{
digitalWrite(13, light);
light=!light;
return 10; // This statement is necessary for ESP32 if
// the function returns a value
}
void setup()
{
pinMode(13, OUTPUT);
}
void loop()
{
test();
delay(500);
}
But if I remove the return statement (which is not a good practice), the code continues to work on all my boards except on the ESP 32 where it crashes.
So fix your code and move on. Or go down the rabbit hole of the ABI and figure out why it crashes. Probably has something to with loading something wrong into the return register or messing up the stack on the return.
Hi @frenchy22. The developers of the "esp32" boards platform recently adjusted the configuration of the platform so that the compilation will fail if there are missing return statements in non-void functions:
If you are using the "Arduino ESP32 Boards" platform of the Arduino Nano ESP32 board, that beneficial change should eventually be pulled in to the platform, since it is based on the "esp32" platform. However, the change is not yet present in Arduino ESP32 Boards because it is trailing behind the ongoing development work in the "esp32" platform.