Slow Arduino IDE with ESP-32 Devices

Slow Arduino IDE with ESP-32 Devices

There is a noticeable difference on how long it takes for a sketch for the ESP-32 to compile when using a Windows based system, versus using a Linux based system. Depending on the sketch, this difference can be up to 10 times, which could frustrate developers. The suggestions online point to anti virus as the cause, with disabling the anti virus or adding exceptions as the workaround. Others recommend using Visual Studio instead of the Arduino IDE. This post will point out some other workarounds without introducing potential risk to the hosting system.

The Arduino IDE had some options available that will provide insights into its inner workings. From the menu File > Preferences, checking the boxes for Show verbose output during compilation or upload, will provide much of this detail. With those options set, running a compilation on the Windows system reveals the heavy lifting going on. The processes listed in task manager also reflect this. There is a large reliance on Python with references to libraries and boot loaders which appear in the verbose output screen.

The interesting item from the compilation is that it creates temporary binaries which are then flashed to the ESP-32 module. Here is an example.

esptool.exe --chip esp32 --port COM4 --baud 460800 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size detect 0xe000 C:\Users\CloudACM\Documents\Linux-IDE\binaries\boot_app0.bin 0x1000 C:\Users\CloudACM\Documents\Linux-IDE\binaries\bootloader_qio_80m.bin 0x10000 C:\Users\CloudACM\Documents\Linux-IDE\binaries\esp-32-firmware.ino.bin 0x8000 C:\Users\CloudACM\Documents\Linux-IDE\binaries\esp-32-firmware.ino.partitions.bin

The above example uses a permanent path, that the original was copied to from its temp path. This command can be ran later without the delays of recompilation. Here is a set of commands that have been adopted from other ESP flashing, namely ESPurna firmware flashing, which used esptool.py. Be sure to set the working path for the esptool.exe that work for your environment.

: ESPToolPath = C:\Users\CloudACM\AppData\Local\Arduino15\packages\esp32\tools\esptool_py\3.0.0\
: serial comm port is COM4
: it's recommended to erase the flash before loading new firmware
%ESPToolPath%esptool.exe --chip esp32 --port COM4 erase_flash
%ESPToolPath%esptool.exe --chip esp32 --port COM4 --baud 460800 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size detect 0xe000 C:\Users\CloudACM\Documents\Linux-IDE\binaries\boot_app0.bin 0x1000 C:\Users\CloudACM\Documents\Linux-IDE\binaries\bootloader_qio_80m.bin 0x10000 C:\Users\CloudACM\Documents\Linux-IDE\binaries\esp-32-firmware.ino.bin 0x8000 C:\Users\CloudACM\Documents\Linux-IDE\binaries\esp-32-firmware.ino.partitions.bin

This method does have some drawbacks. In order to get the necessary binaries, the compilation will need to run at least one time, which will be slow. The IDE must remain open when copying the newly created binaries from the temp directory. This is because the temp directory is deleted when the IDE is closed.

However, flashing from the command line will take less than a minute, compared with the 5 minutes using the IDE. This can add up when flashing multiple devices with the same firmware.

This command line flashing can also be done on Linux systems, with some changes to the commands.

: Locate and copy the esptool.py script to the permenent binaries folder
: serial comm port is /dev/ttyUSB0 because it uses a USB to serial adapter in this instance
: as before, it's recommended to erase the flash before loading new firmware
: the process will need to be run elevated due to system dependencies
sudo python esptool.py --port /dev/ttyUSB0 --before default_reset --after hard_reset erase_flash
sudo python esptool.py --chip esp32 --port /dev/ttyUSB0 --baud 460800 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size detect 0xe000 /home/local/Documents/Docs/ESPTool/Linux-IDE/binaries/boot_app0.bin 0x1000 /home/local/Documents/Docs/ESPTool/Linux-IDE/binaries/bootloader_qio_80m.bin 0x10000 /home/local/Documents/Docs/ESPTool/Linux-IDE/binaries/esp-32-firmware.ino.bin 0x8000 /home/local/Documents/Docs/ESPTool/Linux-IDE/binaries/esp-32-firmware.ino.partitions.bin

The Arduino IDE is well suited for development, but it does have performance issues under some circumstances. Knowing how the IDE works using its verbose output, developers can speed up this process by cutting out redundant workload without adding additional software or compromising the system’s protection mechanisms.

Comments are closed.