Thursday, December 7, 2017

Demo 38: How to decode error/exception "CPU halted" of ESP on Arduino

1. Introduction
When developing software for ESP8266 or ESP32, you often face error(s) that caused the ESP halt.  At that moment, looking the Serial Monitor window, you will see the error/exception like below:
Figure: error that caused ESP CPU halt
It is not easy to know what was happening with our software. Actually, the string that is highlighted has meaning; it is the called stack of software when the CPU halted. There is a tool that supports you to decode the ESP error/exception above. It called EspExceptionDecoder. It is tool that is attached with Arduino IDE.
In order to install it, please follow these steps:
    - Install Arduino IDE with ESP8266/ESP32 core.
    - Download the tool here.
    - Create tools directory under Arduino directory if it is not exist.
    - Unpack the downloaded tool into tools directory (the path will look like /Arduino/tools/EspExceptionDecoder/tool/EspExceptionDecoder.jar).
    - Restart Arduino IDE.



Figure: Under Tools menu, new entry ESP Exception Decoder
2. Demo
I will make a simple program demo for this tool.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
void setup() {
  Serial.begin(115200);
  char *buf = NULL;
  buf[2] = 4;
  Serial.printf("val %d\n", buf[2]);
}

/* the forever loop() function is invoked by Arduino ESP32 loopTask */
void loop() {
}
Here the bug is that buf is not initialized buf buf[2] is assigned to 4.
Loading the software to ESP and look the Serial Monitor:
Figure: error in software
After that choosing Tools->ESP Exception Decoder, a window will occur.
 Figure: Exception Decoder window

Copy and paste the string "Backtrace: 0x400d05be:0x3ffc77c0 0x400d9b1a:0x3ffc77e0 " to it and you will see the output:
 Figure: the result after decoding stacktrace
So you see the CPU halted executing the code at line 4: buf[2] = 4; as we knew.
This is just a simple application. In real world, you may face a more difficult situation than this, but at least you could know where your application is halted.

5 comments:

Usman Shahid said...

does it works on windows??
i am unable to find exception decoder in my arduino
help me

iotsharing dotcom said...

Hi friend

I think it should work because it is written in Java.
please check the path where you copy the pluggin to:

- Create tools directory under Arduino directory if it is not exist.
- Unpack the downloaded tool into tools directory (the path will look like where_to_install_Arduino/Arduino/tools/EspExceptionDecoder/tool/EspExceptionDecoder.jar).

Victor said...

Works for me in Windows 10 x64

iotsharing dotcom said...

thanks :)

Anonymous said...

Hello,

I wanto also ust the decoder on Windows 10 x64.

But when starting the decoder I get the following error message in Arduino:

ERROR: xtensa-lx106-elf-gbd.exe not found!

Does anyone know a solution?

Thanks