Skip to main content

ESP-IDF

This chapter includes the following sections; please read as needed:

ESP-IDF Getting Started Tutorial

New to ESP32 ESP-IDF development and looking to get started quickly? We have prepared a general Getting Started Tutorial for you.

Please Note: This tutorial uses the ESP32-S3-Zero as a teaching example, and all hardware code is based on its pinout. Before you start, it is recommended that you check the pinout of your development board to ensure the pin configuration is correct.

Setting up the Development Environment

info

For the ESP32-C6-Zero development board, you need to use ESP-IDF V5.1 or higher.

note

The following guide uses Windows as an example, demonstrating development using VS Code + the ESP-IDF extension. macOS and Linux users should refer to the official documentation.

Install the ESP-IDF Development Environment

  1. Download the installation manager from the ESP-IDF Installation Manager page. This is Espressif's latest cross-platform installer. The following steps demonstrate how to use its offline installation feature.

    Click the Offline Installer tab on the page, then select Windows as the operating system and choose your desired version from the filter bar.

    Download EIM and offline package

    After confirming your selection, click the download button. The browser will automatically download two files: the ESP-IDF Offline Package (.zst) and the ESP-IDF Installer (.exe).

    Download EIM and offline package 2

    Please wait for both files to finish downloading.

  2. Once the download is complete, double-click to run the ESP-IDF Installer (eim-gui-windows-x64.exe).

    The installer will automatically detect if the offline package exists in the same directory. Click Install from archive.

    Auto-detect offline package

    Next, select the installation path. We recommend using the default path. If you need to customize it, ensure the path does not contain Chinese characters or spaces. Click Start installation to proceed.

    Select installation path
  3. When you see the following screen, the ESP-IDF installation is successful.

    Installation successful
  4. We recommend installing the drivers as well. Click Finish installation, then select Install driver.

    Install drivers via ESP-IDF Installation Manager

Install Visual Studio Code and the ESP-IDF Extension

  1. Download and install Visual Studio Code.

  2. During installation, it is recommended to check Add "Open with Code" action to Windows Explorer file context menu to facilitate opening project folders quickly.

  3. In VS Code, click the Extensions icon Extensions Icon in the Activity Bar on the side (or use the shortcut Ctrl + Shift + X) to open the Extensions view.

  4. Enter ESP-IDF in the search box, locate the ESP-IDF extension, and click Install.

    Search and install ESP-IDF extension in VS Code

  5. For ESP-IDF extension versions ≥ 2.0, the extension will automatically detect and recognize the ESP-IDF environment installed in the previous steps, requiring no manual configuration.

Running Espressif Official Examples

Official Examples Tutorial

Creating an Example

  • Use the shortcut key F1, and enter:

    esp-idf:show examples projects

    ESP32-C6 TO Program 1.webp

  • Select your current IDF version.

    ESP32-C6 TO Program 2.webp

  • Taking the Hello World example as an instance:

    • ① Select the corresponding example.
    • ② Its readme will explain which chips the example applies to (how to use the example and the file structure are introduced below, so omitted here).
    • ③ Click Create Example using project.

    ESP32-C6 TO Program 3.webp
    Select the path to place the example; ensure no folder with the same name exists.
    ESP32-C6 TO Program 4.webp

Modifying COM Port

  • Here shows the corresponding COM port used; click to modify the corresponding COM port.

  • Please select based on the device's corresponding COM port. It is recommended to prioritize the COM port corresponding to the USB (check via Device Manager).

  • If the download fails, please press the reset button for more than 1 second, wait for the PC to re-recognize the device, and try downloading again.

    ESP32-C6 TO Program 5.webp

  • Select the project or example to use.

    ESP32-C6 TO Program 6.webp

  • Now the COM port is modified.

Modifying Target Device

  • Here shows the target device (driver object) used; click to modify the corresponding target device.

  • Select the project or example to use.

    ESP32-C6 TO Program 7.webp

  • Wait for a moment after clicking.

    ESP32-C6 TO Program 8.webp

  • Select the object we need to drive, which is our main chip ESP32C6.

    ESP32-C6 TO Program 9.webp

  • Select the OpenOCD path. This does not affect us here, so any selection will do.

    ESP32-C6 TO Program 10.webp

Introduction to Other Status Bar Items

  • ① SDK Configuration Editor: Many ESP-IDF functions and configurations can be modified here.
  • ② Full Clean: Clears all compiled files.
  • ③ Build.
  • ④ Current Flash Method: Defaults to UART.
  • ⑤ Flash: Burn the current firmware (please do this after building).
  • ⑥ Monitor: Open the Serial Monitor to view serial information.
  • ⑦ Build, Flash, and Monitor: All-in-one button (most commonly used during debugging).

ESP32-C6 TO Program 11.webp

Build, Flash, and Monitor

  • Click the Build, Flash, and Monitor button introduced earlier.

    ESP32-C6 TO Program 12.webp

  • Compiling may take a long time to complete, especially the first time.

    ESP32-C6 TO Program 13.webp

  • During this process, ESP-IDF may consume a large amount of CPU resources, which may cause system lag.

  • If flashing a new project for the first time, you will need to select the download method. Select UART.

    ESP32-C6 TO Program 14.webp

  • You can also modify it later in the Flash Method section (click to pop up options).

    ESP32-C6 TO Program 15.webp

  • Because of the onboard automatic download circuit, no manual operation is required for automatic downloading.

    ESP32-C6 TO Program 16.webp

  • After successful downloading, it automatically enters the Serial Monitor, where you can see the chip outputting corresponding information and prompting a restart after 10 seconds.

    ESP32-C6 TO Program 17.webp

Example Demonstration

Hello World

Official example path: get-started -> hello_world

Example effect: Output Hello world! in the TERMINAL window at 10-second intervals.

Software Operation
  • Create the official example hello_world according to the tutorial above (Creating an Example).
  • The program is compatible with ESP32-C6; no modification to the code is needed.
  • Modify the COM port and target device (It is recommended to prioritize the COM port corresponding to the USB, check via Device Manager), then click Build and Flash to run the program.

ESP32-C6 TO Program 17.webp

RGB

Official example path: get-started -> blink

Example effect: The onboard RGB LED blinks at 1-second intervals.

Software Operation
  • Create the official example blink according to the tutorial above (Creating an Example).
  • The program is compatible with ESP32-C6; no modification to the code is needed.
  • Modify the COM port and target device (It is recommended to prioritize the COM port corresponding to the USB, check via Device Manager), then click Build and Flash to run the program.

ESP32-C6 TO Sample 5.webp

UART

Official example path: peripherals -> uart -> uart_async_rxtxtasks

Example effect: Self-sending and receiving UART data with GPIO4 and GPIO5 shorted.

Hardware Connection
ESP32-C6ESP32-C6 (Same Board)
GPIO4GPIO5
Software Operation
  • Create the official example uart_async_rxtxtasks according to the tutorial above (Creating an Example).
  • The program is compatible with ESP32-C6; no modification to the code is needed.
  • Modify the COM port and target device (It is recommended to prioritize the COM port corresponding to the USB, check via Device Manager), then click Build and Flash to run the program.

ESP32-C6 TO Sample 8.webp

  • Make hardware connections according to the GPIOs used.

    ESP32-C6 TO Sample 6.webp

  • You can go to the definition file to view the actual GPIOs used (Select GPIO_NUM_4 -> Right-click -> Go to Definition).

    ESP32-C6 TO Sample 7.webp

Bluetooth

Official example path: bluetooth -> bluedroid -> ble -> gatt_server

Example effect: Data transmission between ESP32-C6 and a mobile Bluetooth debugging assistant.

Software Operation
  • Install the Bluetooth Debugging Assistant on your mobile phone.
  • Create the official example gatt_server according to the tutorial above (Creating an Example).
  • The program is compatible with ESP32-C6; no modification to the code is needed.
  • Bluetooth name and UUID: The Bluetooth name is ESP_GATTS_DEMO.

ESP32-C6 TO Sample 25.webp

  • Modify the COM port and target device (It is recommended to prioritize the COM port corresponding to the USB, check via Device Manager), then click Build and Flash to run the program.

    ESP32-C6 TO Sample 26.webp

  • Connect to the ESP_GATTS_DEMO Bluetooth device on your phone.

    ESP32-C6 TO Sample 27.webp

  • The successful connection effect is as follows.

    ESP32-C6 TO Sample 28.webp

  • Based on the UUID values in the program, identify the two servers below and select one for uplink transmission.

    ESP32-C6 TO Sample 29.webp

  • ESP32-C6 receives the data.

    ESP32-C6 TO Sample 30.webp

WIFI

Official example path: wifi -> getting_started -> station Example effect: ESP32-C6 connects to WiFi.

Software Operation
  • Create the official example station according to the tutorial above (Creating an Example).
  • Modify the program content to connect to the required WiFi.
  • Enter the Kconfig.projbuild file.

ESP32-C6 TO Sample 31.webp

  • Change the original WiFi SSID and WiFi Password to the WiFi information you want to connect to.

    ESP32-C6 TO Sample 32.webp

  • Modify the COM port and target device (It is recommended to prioritize the COM port corresponding to the USB, check via Device Manager), then click Build and Flash to run the program.

    ESP32-C6 TO Sample 33.webp

  • You can view the value of CONFIG_ESP_WIFI_SSID.

  • Enter the station example main.c file.

    ESP32-C6 TO Sample 34.webp

  • Right-click and Go to Definition.

    ESP32-C6 TO Sample 35.webp

  • You can see it is the value set previously.

    ESP32-C6 TO Sample 36.webp

Zigbee

Official Example 1 Path: Zigbee -> light_sample -> HA_on_off_switch

Official Example 2 Path: Zigbee -> light_sample -> HA_on_off_light

Example effect: Two ESP32-C6 boards. Use the BOOT button on one (flashed with HA_on_off_switch) to control the RGB LED on the other to turn on/off.

Note: Please flash the HA_on_off_switch program to one board first, then flash the HA_on_off_light program to the other.

Software Operation 1
  • Create the official example HA_on_off_switch according to the tutorial above (Creating an Example).
  • The program is compatible with ESP32-C6; no modification to the code is needed.
  • Modify the COM port and target device (It is recommended to prioritize the COM port corresponding to the USB, check via Device Manager), then click Build and Flash to run the program.

ESP32-C6 TO Sample 37.webp

Software Operation 2
  • Create the official example HA_on_off_light according to the tutorial above (Creating an Example).

  • The program is compatible with ESP32-C6; no modification to the code is needed.

  • Modify the COM port and target device, then click Build and Flash to run the program (Wait for a moment for the two chips to establish a connection).

    ESP32-C6 TO Sample 38.webp

  • If it remains in the unconnected state shown below, it may be due to residual network information on the device. You can erase the device information (Erase Tutorial) and form the network again.

    ESP32-C6 TO Sample 39.webp

JTAG Debugging

Software Operation
  • Create the example to be debugged. This example uses the official hello_world (Creating an Example).

  • Modify the launch.json file.

    ESP32-C6 TO JTAG 1.webp

  • Enter the following content:

    {
    "version": "0.2.0",
    "configurations": [
    {
    "name": "GDB",
    "type": "cppdbg",
    "request": "launch",
    "MIMode": "gdb",
    "miDebuggerPath": "${command:espIdf.getXtensaGdb}",
    "program": "${workspaceFolder}/build/${command:espIdf.getProjectName}.elf",
    "windows": {
    "program": "${workspaceFolder}\\build\\${command:espIdf.getProjectName}.elf"
    },
    "cwd": "${workspaceFolder}",
    "environment": [{ "name": "PATH", "value": "${config:idf.customExtraPaths}" }],
    "setupCommands": [
    { "text": "target remote :3333" },
    { "text": "set remote hardware-watchpoint-limit 2"},
    { "text": "mon reset halt" },
    { "text": "thb app_main" },
    { "text": "flushregs" }
    ],
    "externalConsole": false,
    "logging": {
    "engineLogging": true
    }
    }
    ]
    }

ESP32-C6 TO JTAG 2.webp

  • The program is compatible with ESP32-C6; no modification to the code is needed.
  • Modify the COM port and target device (Please use the USB interface; the UART interface does not support JTAG debugging. Check the corresponding COM port via Device Manager), then click Build and Flash to run the program.

ESP32-C6 TO Program 17.webp

  • Press the shortcut key F1, and enter:

    ESP-IDF:Device configuration

    ESP32-C6 TO JTAG 3.webp

  • Select OpenOcd Config Files.

    ESP32-C6 TO JTAG 4.webp

  • Enter board/esp32c6-builtin.cfg (if this is the default, just press Enter).

    board/esp32c6-builtin.cfg

    ESP32-C6 TO JTAG 5.webp

  • Stretch the window width until [OpenOCD Server] is displayed at the bottom.

    ESP32-C6 TO JTAG 6.webp

  • Click [OpenOCD Server], and select Start OpenOCD.

    ESP32-C6 TO JTAG 7.webp

  • Successful startup is as follows.

    ESP32-C6 TO JTAG 8.webp

  • Enter the debugging function and click Debug.

    ESP32-C6 TO JTAG 9.webp

  • Successfully entered the debugging interface.

    ESP32-C6 TO JTAG 10.webp

Erasing Device Flash

  • Unzip the software resource package (Flash Download Tool).

  • Open the flash_download_tool_3.9.5.exe software, select ESP32-C6 and UART.

    ESP32-C6 TO Erase Flash 0.webp

  • Select the UART port number and click START (Select no bin files).

    ESP32-C6 TO Erase Flash 1.webp

  • Wait for the flashing to complete (sync), then click ERASE.

    ESP32-C6 TO Erase Flash 2.webp

  • Wait for the erasure to complete.

    ESP32-C6 TO Erase Flash 3.webp