Espressif32 (ESP-IDF) - how to enable debug mode via `platformio.ini`?

Hello everyone,
EDIT 23.07.2017:
I think the issue I described below regarding error related to upload_flags is because --debug option applies to OTA uploader, not the standard USB one.

Then the question is how should I define the log level via config file?
I see for instance CONFIG_LOG_DEFAULT_LEVEL in sdkconfig.h. But this file is generated and in its header it is said Automatically generated file; DO NOT EDIT.

How about the correct approach then?
Is there a way to enable debug (modify the log level) via platformio.ini file without defining custom constants to be handled programmatically later?


Previously defined question below. I modified my question as above.

I use ESP32 in ESP-IDF framework variant.
Unfortunately I’ve faced an issue and reported it here: Upload fails when upload_flags debug is set · Issue #30 · platformio/platform-espressif32 · GitHub .
Please find more detailed description under the link above. I will shortly describe the problem here again.

The problem is I’m not able to upload compiled firmware with debug option enabled as described in specification.

I’ve tried to set upload_flags in platformio.ini as following:

[env:esp32dev]
platform = espressif32
framework = espidf
board = esp32dev
upload_flags = --debug

The device is connect via USB.
When I try to upload the compiled firmware with command:

platformio run --target upload

It fails as following:

Auto-detected: /dev/ttyUSB0
Uploading .pioenvs/esp32dev/firmware.bin
usage: esptool write_flash [-h] [--flash_freq {40m,26m,20m,80m}]
[--flash_mode {qio,qout,dio,dout}]
[--flash_size FLASH_SIZE] [--ucIsHspi]
[--ucIsLegacy] [--no-progress] [--verify]
[--compress | --no-compress]
<address> <filename> [<address> <filename> ...]
esptool write_flash: error: argument <address> <filename>: Must be pairs of an address and the binary filename to write there
*** [upload] Error 2

When I remove upload_flags from the platformio.ini everything is ok and it ends with something like [SUCCESS] Took 44.22 seconds.

I’ve tried to study the specification and the Authentication and upload options section. I followed the instructions, unfortunately I couldn’t get it working.

Could you please tell me how to enable debug from plaftormio.ini?

Ok, problem solved :slight_smile:
I tired to use OTA related flags for USB upload, thus something could fail and those errors appeared.
I should have been using build_flags instead of upload_flags.
Then it’s simple. ESP-IDF doc says that “log library has two ways of managing log verbosity: compile time, set via menuconfig; and runtime, using esp_log_set_level function”.

It works very well!
To mute all debug messages I set it properly by providing LOG_LOCAL_LEVEL flag.
Please see an example platformio.ini content below:

[env:esp32dev]
platform = espressif32
framework = espidf
board = esp32dev
build_flags = -DLOG_LOCAL_LEVEL=ESP_LOG_NONE

To enable logging again I change the flag as below and set DEBUG or whatever according to spec:

-DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG

That’s all. Problem solved! :slight_smile:

1 Like

Thanks for the info. Does -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG overrides the compile time setting that was done in menuconfig? (I presume that its’ a compile time setting, not a runtime setting).

I followed your suggestions but I have the Problem that I need monitor_speed set to 115200. Otherwise it produces garbage. Why is that so? Have someone a explanation to this? With monitor_speed set to 9600 the ESP_LOGI is also not working. I don’t get it.

Hopefully someon can give me some help.

Thanks and Greetings

The bootloader of the ESP32 initializes the UART to a baud rate of 115000 for the boot messages:

ets Jun  8 2016 00:22:57

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:1352
load:0x40078000,len:12380
ho 0 tail 12 room 4
load:0x40080400,len:4
load:0x40080404,len:2876
entry 0x40080574

If your terminal program / serial monitor is set to a different baudrate, then you will see this message as garbage.

monitor_speed = 9600 sets the speed which PlatformIO’s serial monitor should use. This will not configure the ESP’s UART speed!

Unfortunately I don’t know how the change the baud rate for ESP-IDF projects, cause I’m using the Arduino framework.

Hey and thank you for your reply!

Hmm how do I get this detailed compileinfos/bootinfos?

I know that monitor_speed is for the serial monitor, but isn’t that the the way ESP_LOG Messages is sent? I use UART as well but for different comunication with GPIO’s. For my understanding, this has nothing to do with the monitor_speed.

Thank you for your time in advance.
Greetings

This is the bootloader log. Not compile infos.

Unfortunately, I cannot explain the exact meanings of the individual values.
But maybe this will help you:

What I meant to say is that it sets the baud rate for receiving (PC side).
Not the baud rate that the ESP uses for sending.

Afaik the baud rate of the esp bootloader is fixed at 11500 and cannot be changed.

Ah thank you so much, I will read this post. So in the current state everything works fine. Propably nothing else to do here :smiley:

1 Like