Core Debug Level in ESP32

Various Core Debug Levels on ESP32

If you have been observing the various configuration options in the Tools menu of Arduino IDE for ESP32, one setting may have caught your attention: Core Debug Level. It is set to ‘None’ by default, but there are several options to choose from:

So what are the different levels? In simple terms, these levels dictate the detail to which log statements will be printed in the Serial Monitor by the ESP32. The default option, “None”, ensures that only the user-defined logs are printed (the ones you define using Serial.print() or Serial.write() or some other variant).

If you choose any level other than ‘None’, then depending on the level chosen (Verbose indicating highest level of detail), other helpful statements are also printed by the ESP32. For instance, if you’ve chosen ‘Error’, all log statements added in ESP32’s source codes, whenever an error is encountered, are printed on the Serial Monitor.

These levels enable debugging, but they come at a cost: excessive prints on the Serial Monitor. This can slow down the code execution a bit, especially if you are debugging a computationally heavy process. The general practice is to keep the Core Debug Level to ‘None’ as long as the code is behaving as expected. If the code is showing some unexpected behavior, you can set the Core Debug Level to the required level of detail (most people directly go to the ‘Verbose’ level), till the problem is resolved.

Example

We will take the code from the Captive Portal using ESP32 tutorial and see the Serial Monitor output with the Core Debug Level set to Verbose.

The code can also be found here: https://github.com/yash-sanghvi/ESP32/blob/master/Captive_Portal/Captive_Portal.ino

The Serial Monitor output, with Core Debug Level as Verbose is shown below:

As you can see, while the normal Serial print statements are printed, all the event callbacks are also printed (WIFI_READY, indicating that the WiFi is ready; AP_STADISCONNECTED, indicating that the Station mode has been disconnected; AP_PROBEREQRECVED, indicating that a probe request has been received).

Interestingly, the exact line number of the file where this statement was present has been printed. Filename: WiFiGeneric.cpp. Line number: 337. In order to confirm this, I checked the WiFiGeneric.cpp file. On Windows, it can be found in C:\Users\<YourUserName>\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\WiFi\src

I found the following log_d (debug log) on line 337.

if(event->event_id < 26) {
        log_d("Event: %d - %s", event->event_id, system_event_names[event->event_id]);
    }

Thus, you can see that the logs which were otherwise disabled can be enabled by setting the Core Debug Level of ESP32.

Enjoyed this tutorial. Then you may enjoy other tutorials related to ESP32 as well. Check them out here: https://iotespresso.com/category/esp32/

In case you are looking for a full-fledged course on ESP32, check out this course on Udemy.

2 comments

  1. Hi, just a question: why does the verified code by IDE vary in size (space occupied in program storage and dynamic memory) if I select None instead of Verbose?
    To check, simply generate a new empty sketch (in the IDE ==> File-> New): then set the parameters for the board to be programmed (in my case: Board: MH ET Live ESP32MiniKit, Upload Speed: 256000, Flash Frequency: 80 MHz, partition scheme: minimum SPIFFS (large APP with OTA), main debug level: none). Then click on Verify button (top left). Take a note of the two values (program storage and dynamic memory). Now, change -ONLY- the Core debug Level to >Verbose< and then click again the Verify button. The two values are increased.

    1. Interesting observation. I’d suspect that when you set the core debug level to ‘None’, all the log statements are simply ignored while compiling the sketch, as if they were not written. The logger library itself would be discarded. Thus, your code size is smaller, and there are fewer global variables as the ones related to the logger library are not present. You can, in fact, refine your experiment further and try at different log levels. You’ll see that the difference in dynamic memory is always the same between ‘None’ and the selected level. However, the difference in program memory is highest for ‘Verbose’ and lowest for ‘Error’.

Leave a comment

Your email address will not be published. Required fields are marked *