๐ŸŽ‰
ESPBoards Store is Now Open! Find the best ESP32, ESP8266 boards & accessories
Back to Blog
Learn how to flash, erase, and backup ESP32 firmware using `esptool.py`. This step-by-step guide covers installation, first-time flashing, and essential commands.

Flash ESP32 Firmware Like a Pro using esptool.py - Guide

Learn how to flash, erase, and backup ESP32 firmware using `esptool.py`. This step-by-step guide covers installation, first-time flashing, and essential commands.

Firmware & Frameworks
Last Updated:

If you've ever uploaded firmware to an ESP32 board using the Arduino IDE, ESPHome, PlatformIO, or MicroPython, chances are that esptool.py was working behind the scenes.

๐Ÿค” What is esptool.py? #

esptool.py is a command-line tool designed for ESP32 and ESP8266 chips, primarily used for flashing firmware, debugging, and performing low-level hardware operations. It is developed by Espressif and is widely used across different development environments.

โœจ When to Use esptool.py:

โœ“ Need manual control over flashing parameters
โœ“ Want to backup or restore flash memory
โœ“ Troubleshooting connection issues or erasing flash
โœ“ Need a quick ESP32 flash with minimal setup

๐Ÿ’ก Pro Tip: Since many ESP32 development boards come with different USB-to-UART bridge chips (learn more here), esptool.py allows setting the correct baud rate and connection settings when default options fail.

Setting Up esptool.py #

Before you can start using esptool.py to flash firmware, back up binaries, or manage your ESP32, you'll need to get it installed and ready to go on your computer. The process is straightforward and works across platforms like macOS, Windows, and Linux.

1 Install Python 3

Before using esptool.py, you need Python 3 installed on your system.

๐Ÿ–ฅ๏ธ

Windows

Download from python.org

โš ๏ธ Check "Add Python to PATH"
๐Ÿ

macOS

Using Homebrew:

brew install python
๐Ÿง

Linux

Using apt (Ubuntu/Debian):

sudo apt install python3 python3-pip

2 Verify Python Installation

Once installed, confirm Python is working by checking the version:

python3 --version

โœ… If you see output like Python 3.x.x, you're good to go!

3 Install esptool.py

Now that Python is set up, let's install esptool.py and get flashing! ๐Ÿš€

pip install esptool

Check that it's installed correctly:

esptool.py version

๐ŸŽ‰ If you see output like esptool.py v4.x.x, it's ready to use!

Flashing Your ESP32 with esptool.py for the First Time #

Now that you've installed esptool.py and set up your environment, it's time to flash your ESP32! If you're installing new firmware, updating an existing one, or troubleshooting, esptool.py gives you full control over the process.

1 Connect Your ESP32

Use a USB cable to connect your ESP32 development board to your computer.

โš ๏ธ Important: Ensure the cable supports data transfer, as some are power-only!

2 Identify the Serial Port

To communicate with your ESP32, find out which serial port it's connected to:

๐Ÿ–ฅ๏ธ

Windows

Command Prompt:

wmic path Win32_SerialPort get DeviceID,Name

Or use Device Manager โ†’ Ports (COM & LPT)

Look for: COM3, COM4, etc.

๐Ÿ

macOS

Terminal:

ls /dev/tty.*

Look for: /dev/tty.usbmodemXXXX

๐Ÿง

Linux

Terminal:

ls /dev/ttyUSB*

Look for: /dev/ttyUSB0

Find ESP32 port on MacOS

โŒ ESP32 not detected? Install USB-to-Serial drivers:

โ€ข CP210x (Silicon Labs): Download here

โ€ข CH340 (WCH): Download here

๐Ÿ“– For more details, check out this guide on USB-to-UART bridges.

3 Erase Flash Memory (Optional but Recommended)

Before flashing new firmware, it's good practice to erase the existing flash memory to prevent conflicts:

esptool.py --port <your-port> erase_flash

๐Ÿ’ก Replace <your-port> with your serial port (e.g., /dev/ttyUSB0 or COM3)

Expected output:

Connecting...
Chip erase completed successfully in 2.5s

โš™๏ธ Tip: You may need to hold down the BOOT/FLASH button on your ESP32 to establish a connection. Once erasing starts, you can release it.

4 Flash the Firmware

Now, it's time to upload your new firmware! Ensure you have the firmware binary file (e.g., firmware.bin) ready.

๐Ÿ“ฅ Where to Get ESP32 Firmware?

๐Ÿ’ก WLED โ€“ LED control firmware
๐Ÿ  ESPHome โ€“ Smart home automation
๐Ÿ MicroPython โ€“ Python on ESP32
๐Ÿ“ก Tasmota โ€“ MQTT automation
โš™๏ธ Arduino IDE โ€“ Custom firmware
๐Ÿ”ง PlatformIO โ€“ Advanced projects

๐Ÿ”ฅ Make sure to download the correct .bin file for your ESP32 board model!

Run the following command:

esptool.py --chip esp32 --port <your-port> --baud 460800 write_flash -z 0x1000 firmware.bin

๐Ÿ“Œ Explanation of flags:

--chip esp32 โ†’ Specifies the target chip (ESP32)

--port <your-port> โ†’ The serial port your ESP32 is connected to

--baud 460800 โ†’ Sets the baud rate for faster flashing (adjust if needed)

write_flash -z 0x1000 โ†’ Writes firmware to flash memory

Expected output:

Hash of data verified.
Leaving...
Hard resetting via RTS pin...

๐ŸŽ‰ Congratulations! Your ESP32 is now flashed and ready to go! โœ…

๐Ÿ“Œ esptool.py Cheat Sheet โ€“ Essential Commands #

Quick reference for the most common esptool.py commands. Bookmark this section for easy access! ๐Ÿ”–

๐Ÿ” Get ESP32 Chip and Flash Information

Before flashing, it's useful to check what ESP32 chip you're working with and verify flash memory details.

๐Ÿ“‹ Get chip information:

esptool.py --port <your-port> chip_id

Returns details about your ESP32, including its unique chip ID.

esptool chip info command result

๐Ÿ’พ Check flash memory size:

esptool.py --port <your-port> flash_id

Reads the flash chip's manufacturer, size, and speed.

๐Ÿ’พ Backup and Restore ESP32 Firmware

โš ๏ธ Pro Tip: Always back up your ESP32 firmware before making major changes!

๐Ÿ“ค Backup entire flash memory:

esptool.py --port <your-port> read_flash 0x00000 0x400000 backup.bin

๐Ÿ’ก Adjust 0x400000 based on your ESP32's flash size (4MB shown here)

Saves the full flash content into backup.bin, allowing you to restore later if needed.

๐Ÿ“ฅ Restore firmware from backup:

esptool.py --port <your-port> write_flash 0x00000 backup.bin

Writes the backup back onto the ESP32, restoring it to its previous state.

๐Ÿงน Erase and Flash Firmware

๐Ÿ—‘๏ธ Erase the entire flash memory:

โœจ Recommended before flashing new firmware to prevent conflicts
esptool.py --port <your-port> erase_flash
esptool erase flash command result

โšก Flash new firmware:

esptool.py --chip esp32 --port <your-port> --baud 460800 write_flash -z 0x1000 firmware.bin

Flag explanations:

--chip esp32 โ†’ Specifies the ESP32 chip

--port <your-port> โ†’ Your serial port (e.g., COM3, /dev/ttyUSB0)

--baud 460800 โ†’ Speeds up flashing (reduce if errors occur)

-z 0x1000 โ†’ Writes firmware starting at the correct memory offset

๐Ÿ“– For more details, check out using ESP32 with Arduino IDE

๐Ÿš€ Speed Up Flashing

If flashing takes too long, increase the baud rate for faster uploads:

esptool.py --port <your-port> --baud 921600 write_flash -z 0x1000 firmware.bin

โš ๏ธ Note: Higher baud rates can cause unstable flashing. If you encounter errors, lower it to 460800 or 115200

๐Ÿ’ก Tip: Most ESP32 boards work reliably at 460800, which offers a good balance between speed and stability.

Wrapping Up #

๐ŸŽ‰

You're Ready to Flash!

With esptool.py, you now have full control over flashing, backing up, and managing your ESP32 firmware. Whether you're installing ESPHome, setting up MicroPython, or troubleshooting a failed flash, these commands will help you get the job done efficiently.

โšก Quick Troubleshooting Checklist:

  • โœ“ Double-check your USB drivers are installed correctly
  • โœ“ Verify the correct serial port is selected
  • โœ“ Try adjusting the baud rate if flashing fails
  • โœ“ Hold the BOOT button if connection issues persist

๐Ÿ’ก Need help with connection issues? Check out our comprehensive guide on ESP32 USB-to-UART Bridges for in-depth troubleshooting.

Now go ahead and flash your ESP32 with confidence!