# Start a Project on Windows from Command Line

[中文]

This guide helps you to start a new project on the ESP32 and build, flash, and monitor the device output on Windows.

## Activate the Environment

Note

This section describes the default and recommended procedures to activate the environment from ESP-IDF v6.0. If you use the legacy method for updating ESP-IDF tools, skip this section.

Before using ESP-IDF tools in the terminal, you must activate the ESP-IDF environment. You can do this either via the GUI or CLI.

- Activate Using EIM GUI

- Activate Using EIM CLI

### Activate Using EIM GUI

Open the ESP-IDF Installation Manager application `eim`.

Under `Manage Installations`, click `Open Dashboard`.

EIM Manage Installations

In the dashboard, you will see all the installed ESP-IDF versions. Select the version you want to use, and click `Open IDF Terminal` to launch a terminal session with activated ESP-IDF environment.

EIM Open IDF Terminal

### Activate Using EIM CLI

Upon successful installation of ESP-IDF, the EIM places shortcuts on your desktop to launch a terminal with activated ESP-IDF environment.

For example, click the `IDF_v5.4.2_Powershell` shortcut to open a PowerShell session with the environment set up.

Once done, you have successfully activated the ESP-IDF environment in your terminal. All subsequent ESP-IDF commands should be run in this activated terminal.

## Start a Project

Now you are ready to prepare your application for ESP32. You can start with get-started/hello_world project from examples directory in ESP-IDF.

Important

The ESP-IDF build system does not support spaces in the paths to either ESP-IDF or to projects.

Copy the project get-started/hello_world to `~/esp` directory:

    cd %userprofile%\esp
    xcopy /e /i %IDF_PATH%\examples\get-started\hello_world hello_world

Note

There is a range of example projects in the examples directory in ESP-IDF. You can copy any project in the same way as presented above and run it. It is also possible to build examples in-place without copying them first.

## Connect Your Device

Now connect your ESP32 board to the computer and check under which serial port the board is visible.

Serial port names start with `COM` in Windows.

If you are not sure how to check the serial port name, please refer to Establish Serial Connection with ESP32 for full details.

Note

Keep the port name handy as it is needed in the next steps.

## Configure Your Project

Navigate to your `hello_world` directory, set ESP32 as the target, and run the project configuration utility `menuconfig`.

### Windows

    cd %userprofile%\esp\hello_world
    idf.py set-target esp32
    idf.py menuconfig

After opening a new project, you should first set the target with `idf.py set-target esp32`. Note that existing builds and configurations in the project, if any, are cleared and initialized in this process. The target may be saved in the environment variable to skip this step at all. See Select the Target Chip: set-target for additional information.

If the previous steps have been done correctly, the following menu appears:

Project configuration - Home window

You are using this menu to set up project specific variables, e.g., Wi-Fi network name and password, the processor speed, etc. Setting up the project with menuconfig may be skipped for "hello_word", since this example runs with default configuration.

Attention

If you use ESP32-DevKitC board with the ESP32-SOLO-1 module, or ESP32-DevKitM-1 board with the ESP32-MIN1-1/1U module, please enable single core mode (CONFIG_FREERTOS_UNICORE) in menuconfig before flashing examples.

Note

The colors of the menu could be different in your terminal. You can change the appearance with the option `--style`. Please run `idf.py menuconfig --help` for further information.

If you are using one of the supported development boards, you can speed up your development by using Board Support Package. See Additional Tips for more information.

## Build the Project

Build the project by running:

    idf.py build

This command compiles the application and all ESP-IDF components, then it generates the bootloader, partition table, and application binaries.

    $ idf.py build
    Running cmake in directory /path/to/hello_world/build
    Executing "cmake -G Ninja --warn-uninitialized /path/to/hello_world"...
    Warn about uninitialized values.
    -- Found Git: /usr/bin/git (found version "2.17.0")
    -- Building empty aws_iot component due to configuration
    -- Component names: ...
    -- Component paths: ...

    ... (more lines of build system output)

    [527/527] Generating hello_world.bin
    esptool v5.0.2

    Project build complete. To flash, run:
      idf.py flash
    or
      idf.py -p PORT flash
    or
      esptool -p (PORT) -b 921600 write-flash --flash-mode dio --flash-size detect --flash-freq 40m 0x10000 build/hello_world.bin  build 0x1000 build/bootloader/bootloader.bin 0x8000 build/partition_table/partition-table.bin

If there are no errors, the build finishes by generating the firmware binary .bin files.

## Flash onto the Device

To flash the binaries that you just built for the ESP32 in the previous step, you need to run the following command:

    idf.py -p PORT flash

Replace `PORT` with your ESP32 board's USB port name. If the `PORT` is not defined, the idf.py will try to connect automatically using the available USB ports.

For more information on `idf.py` arguments, see idf.py.

Note

The option `flash` automatically builds and flashes the project, so running `idf.py build` is not necessary.

Encountered Issues While Flashing? See the "Additional Tips" below. You can also refer to Flashing Troubleshooting page or Establish Serial Connection with ESP32 for more detailed information.

### Normal Operation

When flashing, you will see the output log similar to the following:

    ...
    esptool --chip esp32 -p /dev/ttyUSB0 -b 460800 --before=default-reset --after=hard-reset write-flash --flash-mode dio --flash-freq 40m --flash-size 2MB 0x8000 partition_table/partition-table.bin 0x1000 bootloader/bootloader.bin 0x10000 hello_world.bin
    esptool v5.0.2
    Connected to ESP32 on /dev/ttyUSB0:
    Chip type:          ESP32-U4WDH (revision v3.0)
    Features:           Wi-Fi, BT, Dual Core + LP Core, 240MHz, Embedded Flash, Vref calibration in eFuse, Coding Scheme None
    Crystal frequency:  40MHz
    MAC:                24:0a:c4:05:b9:14

    Stub flasher running.
    Changing baud rate to 460800...
    Changed.

    Configuring flash size...
    Flash will be erased from 0x00008000 to 0x00008fff...
    Flash will be erased from 0x00001000 to 0x00007fff...
    Flash will be erased from 0x00010000 to 0x00031fff...
    Wrote 3072 bytes (103 compressed) at 0x00008000 in 0.1 seconds (279.3 kbit/s).
    Hash of data verified.
    SHA digest in image updated.
    Wrote 26352 bytes (16660 compressed) at 0x00001000 in 0.9 seconds (239.3 kbit/s).
    Hash of data verified.
    Wrote 137312 bytes (78774 compressed) at 0x00010000 in 2.2 seconds (490.8 kbit/s).
    Hash of data verified.

    Hard resetting via RTS pin...

If there are no issues by the end of the flash process, the board will reboot and start up the "hello_world" application.

If you would like to use the Eclipse or VS Code IDE instead of running `idf.py`, check out Eclipse Plugin, VSCode Extension.

## Monitor the Output

To check if "hello_world" is indeed running, type `idf.py -p PORT monitor` (Do not forget to replace PORT with your serial port name).

This command launches the IDF Monitor application.

    $ idf.py -p <PORT> monitor
    Running idf_monitor in directory [...]/esp/hello_world/build
    Executing "python [...]/esp-idf/tools/idf_monitor.py -b 115200 [...]/esp/hello_world/build/hello_world.elf"...
    --- idf_monitor on <PORT> 115200 ---
    --- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
    ets Jun  8 2016 00:22:57

    rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
    ets Jun  8 2016 00:22:57
    ...

After startup and diagnostic logs scroll up, you should see "Hello world!" printed out by the application.

        ...
        Hello world!
        Restarting in 10 seconds...
        This is esp32 chip with 2 CPU core(s), WiFi/BT/BLE, silicon revision 1, 2 MB external flash
    Minimum free heap size: 298968 bytes
        Restarting in 9 seconds...
        Restarting in 8 seconds...
        Restarting in 7 seconds...

To exit IDF monitor use the shortcut `Ctrl+]`.

If IDF monitor fails shortly after the upload, or, if instead of the messages above, you see random garbage similar to what is given below, your board is likely using a 26 MHz crystal. Most development board designs use 40 MHz, so ESP-IDF uses this frequency as a default value.

If you have such a problem, do the following:

1. Exit the monitor.

2. Go back to `menuconfig`.

3. Go to `Component config` --> `Hardware Settings` --> `Main XTAL Config` --> `Main XTAL frequency`, then change CONFIG_XTAL_FREQ to 26 MHz.

4. After that, `build and flash` the application again.

In the current version of ESP-IDF, main XTAL frequencies supported by ESP32 are as follows:

- 26 MHz

- 40 MHz

Note

You can combine building, flashing and monitoring into one step by running:

    idf.py -p PORT flash monitor

See also:

- IDF Monitor for handy shortcuts and more details on using IDF monitor.

- idf.py for a full reference of `idf.py` commands and options.

That is all that you need to get started with ESP32!

Now you are ready to try some other examples, or go straight to developing your own applications.

Important

Some of examples do not support ESP32 because required hardware is not included in ESP32 so it cannot be supported.

If building an example, please check the README file for the `Supported Targets` table. If this is present including ESP32 target, or the table does not exist at all, the example will work on ESP32.

## Additional Tips

### Permission Denied Issue

With some Linux distributions, you may get the error message similar to `Could not open port <PORT>: Permission denied: '<PORT>'` when flashing the ESP32. This can be solved by adding the current user to the specific group, such as `dialout` or `uucp` group.

### Python Compatibility

ESP-IDF supports Python 3.10 or newer. It is recommended to upgrade your operating system to a recent version satisfying this requirement. Other options include the installation of Python from sources or the use of a Python version management system such as pyenv.

### Start with Board Support Package

To speed up prototyping on some development boards, you can use Board Support Packages (BSPs), which makes initialization of a particular board as easy as few function calls.

A BSP typically supports all of the hardware components provided on development board. Apart from the pinout definition and initialization functions, a BSP ships with drivers for the external components such as sensors, displays, audio codecs etc.

The BSPs are distributed via IDF Component Manager, so they can be found in ESP Component Registry.

Here is an example of how to add ESP-WROVER-KIT BSP to your project:

    idf.py add-dependency esp_wrover_kit

More examples of BSP usage can be found in BSP examples folder.

### Flash Erase

Erasing the flash is also possible. To erase the entire flash memory you can run the following command:

    idf.py -p PORT erase-flash

For erasing the OTA data, if present, you can run this command:

    idf.py -p PORT erase-otadata

The flash erase command can take a while to be done. Do not disconnect your device while the flash erasing is in progress.

## Related Documents

- Establish Serial Connection with ESP32

- IDF Monitor

Was this page helpful?

- Thank you! We received your feedback.
- If you have any comments, fill in Espressif Documentation Feedback Form.

- We value your feedback.
- Let us know how we can improve this page by filling in Espressif Documentation Feedback Form.