Have you ever wondered how to setup Visual studio code esp8266 setup (freeRTOS sdk) for freeRTOS sdk? I am learning how to program esp8266 chips (I know that there are esp32, but I have few 8266), but I couldn’t find a guide how to setup this editor for this chip. There exists an extension for esp32 (from espressif) for vsc but it doesn’t work with esp8266.

This guide is for a Fedora. This should work for different distros as well. I don’t know how it is going to be on windows.

Prerequisites:

  • esp8266 sdk installed (IDF_PATH)
  • esp8266 toolchain installed (XTENSA_PATH)
  • IntelliSense extension for Visual studio code installed
  • Tasks Buttons extension for Visual studio code installed

Only few things needs to be set up. First the the c_cpp_properties.json file. It is in a .vscode directory.

{
    "env": {
        "IDF_PATH": "~/dev/esp8266/ESP8266_RTOS",
        "XTENSA_PATH": "~/dev/esp8266/xtensa-lx106-elf_RTOS/bin"
    },
    "configurations": [
        {
            "name": "esp8266",
            "includePath": [
                "${workspaceFolder}/build/include",
                "${workspaceFolder}/components/**",
                "${XTENSA_PATH}/xtensa-lx106-elf_RTOS/xtensa-lx106-elf/include",
                "${XTENSA_PATH}/xtensa-lx106-elf_RTOS/xtensa-lx106-elf/sys-include",
                "${IDF_PATH}/components/**"
            ],
            "defines": [],
            "cStandard": "c99",
            "intelliSenseMode": "linux-gcc-x64",
            "compilerPath": "${XTENSA_PATH}/xtensa-lx106-elf-gcc"
        }
    ],
    "version": 4
}

Line “${IDF_PATH}/components/**” may cause problems if you name a directory in the same way as an existing idf component.

Next file is tasks.json:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "type": "shell",
            "command": "source ./.vscode/terminal-startup.sh && make -j4",
            "presentation": {
                "echo": true,
                "reveal": "always",
                "focus": true,
                "panel": "shared",
                "showReuseMessage": true,
                "clear": true
            }
        },
        {
            "label": "Clean",
            "type": "shell",
            "command": "source ./.vscode/terminal-startup.sh && make clean -j4",
            "presentation": {
                "echo": true,
                "reveal": "always",
                "focus": true,
                "panel": "shared",
                "showReuseMessage": true,
                "clear": true
            }
        },
        {
            "label": "flash",
            "type": "shell",
            "command": "source ./.vscode/terminal-startup.sh && make flash",
            "presentation": {
                "echo": true,
                "reveal": "always",
                "focus": true,
                "panel": "shared",
                "showReuseMessage": true,
                "clear": true
            }
        }
    ]
}

There are 3 tasks created in this file:

  • make
  • clean
  • flash

We will use above tasks in another file which is settings.json:

{
    "terminal.integrated.profiles.linux": {
        "default": {
            "path": "/bin/bash",
            "args": [
                "--init-file",
                "./.vscode/terminal-startup.sh"
            ]
        }
    },
    "terminal.integrated.defaultProfile.linux": "default",
    "C_Cpp.errorSquiggles": "enabled",
    "files.associations": {
        "transport_interface.h": "c",
        "tcp.h": "c",
        "mk_wifi.h": "c",
        "esp_log.h": "c",
        "esp_wifi.h": "c",
        "esp_wifi_types.h": "c",
        "esp_event.h": "c"
    },
    "VsCodeTaskButtons.showCounter": false,
    "VsCodeTaskButtons.tasks": [
        {
            "label": "$(wrench) Build",
            "task": "build",
            "tooltip": "🛠️ Start the \"build\" task"
        },
        {
            "label": "$(run) Flash",
            "task": "flash",
            "tooltip": "🛠️ Start the \"flash\" task"
        },
        {
            "label": "$(trash) Clean",
            "task": "clean",
            "tooltip": "🛠️ Start the \"clean\" task"
        }
    ]
}

Section “VsCodeTaskButtons.tasks” corresponds with the tasks.json file. Thanks to this we will have three buttons in the bottom panel of visual studio code: for build, for flash and for clean the project.

Task buttons in Visual studio code

There is one more file, terminal-startup.sh:

#!/bin/bash
source ~/.bashrc

export IDF_PATH=~/dev/esp8266/ESP8266_RTOS
export XTENSA_PATH=~/dev/esp8266/xtensa-lx106-elf_RTOS/bin
export PATH="$RTOS_SDK_PATH:$XTENSA_PATH:$PATH"

This file setups the terminal for running the tasks. It adds sdk and toolchain paths to the path variable.

Leave a Reply