This guide walks you through setting up an ESP-IDF project, configuring your ESP32, and flashing the firmware. Complementary video: https://www.youtube.com/watch?v=zW9wOples-Q
First, install the ESP-IDF toolchain by following the official documentation for your operating system.
- Official Guide: ESP-IDF Get Started (Linux & macOS)
Once the environment is set up, navigate to your project directory and configure it for your specific board.
-
Set the target device. For this guide, we'll use the ESP32.
idf.py set-target esp32
-
Open the configuration menu.
idf.py menuconfig
-
Set the flash size. In the menu, navigate to
Serial Flasher Config→Flash Sizeand select 16MB. -
Increase the CPU frequency. Navigate to
Component config→ESP System Settings→CPU frequencyand change it to 240MHz. -
Save your changes and exit the menu.
Now, you'll connect the board and flash your code.
-
Find the device port.
Open a terminal and run
sudo udevadm monitor -u. Then, connect your ESP32 board using its USB-UART port. Look for a line in the output similar to this:UDEV [31840.395431] add /devices/.../tty/ttyACM0 (tty)This shows the device is connected at
/dev/ttyACM0. -
Flash the device.
Use the port you just found in the flash command:
idf.py -p /dev/ttyACM0 flash
-
Permission Denied Error
If you see the error
Error: Invalid value for '-p' / '--port': Path '/dev/ttyACM0' is not readable., you need to grant your user account permission to access the serial port.-
First, find your username:
whoami
-
Next, add your user to the
dialoutgroup (for most Linux distributions like Ubuntu) or theuucpgroup (for Arch Linux). Replaceyour_usernamewith the output from thewhoamicommand.# For Debian, Ubuntu, and most other distros sudo usermod -a -G dialout your_username # For Arch Linux sudo usermod -a -G uucp your_username
-
Log out and log back in for the group changes to take effect. You should now be able to run the flash command successfully.
-
-
Wrong Boot Mode Error
If you get
A fatal error occurred: Failed to connect to ESP32: Wrong Boot Mode, the board isn't in flashing mode. To fix it:- Press and hold the BOOT button on your ESP32 board.
- While holding it, run the flash command again.
- Release the button once you see the
Connecting...message in the terminal.
After flashing is complete, you can view the output from your ESP32.
-
Start the monitor:
idf.py -p /dev/ttyACM0 monitor
-
Exit the monitor:
Press the keyboard shortcut
Ctrl+]. You can also pressCtrl+Tfollowed byCtrl+Hto see a help menu with all available shortcuts.