Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VSCode works really well. Worth adding setup instructions in to the docs? (IDF-88) #303

Open
grisevg opened this Issue Jan 26, 2017 · 23 comments

Comments

Projects
None yet
@grisevg
Copy link

commented Jan 26, 2017

Hey guys,

I've tried configuring Visual Studio Code for IDF development on Linux and it works really well (for example Eclipse would fail to resolve portTICK_PERIOD_MS for me, while VSCode resolves it nicely).

Here's what I had to do to get basic functionality working:

  1. Install C/C++ extension for VSCode
  2. Create .vscode/c_cpp_properties.json with header search paths:
{
    "configurations": [
        {
            "name": "Linux",
            "includePath": ["/home/grisevg/esp/esp-idf/components/"],
            "browse" : {
                "limitSymbolsToIncludedHeaders" : true,
                "databaseFilename" : ""
            }
        }
    ]
}
  1. Create .vscode/tasks.json with a build task and error parser
{
    "version": "0.1.0",
    "command": "bash",
    "args": ["-c"],
    "isShellCommand": true,
    "showOutput": "always",
    "suppressTaskName": true,
    "options": {
        "cwd": "${workspaceRoot}",
        "env": { 
            "IDF_PATH" : "/home/grisevg/esp/esp-idf", 
            "PATH" : "${env.PATH}:/home/grisevg/esp/xtensa-esp32-elf/bin" 
        }
    },
    "tasks": [
        {
            "taskName": "build app",
            "args": ["make app"],
            "isBuildCommand": true,
            "problemMatcher": {
                "owner": "cpp",
                "fileLocation": "absolute",
                "pattern": {
                    "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
                    "file": 1,
                    "line": 2,
                    "column": 3,
                    "severity": 4,
                    "message": 5
                }
            }
        },
        {
            "taskName": "clean app",
            "args": ["make app-clean"]
        },
        {
            "taskName": "monitor",
            "args": ["make monitor"]
        },
        {
            "taskName": "flash app",
            "args": ["make app-flash"]
        }
    ]
}

It's not perfect, as you have to manually specify include path, path to IDF and path to the toolchain, but same goes for Eclipse.

Do you guys think it's worth adding to the docs? Of course question of what IDE is better is a personal choice, but considering that VSCode is very popular, cross-platform and works really well, I think it's worth adding to the getting started docs.

@krzychb

This comment has been minimized.

Copy link
Collaborator

commented Jan 26, 2017

Eclipse would fail to resolve portTICK_PERIOD_MS

I see the same on Eclipse (both Windows 7 and Ubuntu 16.04 LTS) and it gets me frustrated.

It's not perfect, as you have to manually specify include paths, path to IDF and path to the toolchain, but same goes for Eclipse.

@grisevg do you need to specify all include paths in VSCode or just one to the components folder as described in #157 (comment) ?

Regarding both issues above there is a branch together with testing report #157 (comment), that indicate possible resolution.

So far I did not have a chance to check VSCode to say what the good things I like about Eclipse are provided by VSCode as well, to justify the switch. People familiar with both VSCode and Eclipse should post their comments so Espressif team can gauge the interest.

@seopyoon

This comment has been minimized.

Copy link

commented Jan 30, 2017

@krzychb I also include up to components folder, and it resolves the functions very well.
I shall try the tasks.json file with my VSCode on Mac. It sounds like a good little shortcut. Thanks!

@grisevg

This comment has been minimized.

Copy link
Author

commented Jan 30, 2017

@krzychb @seopyoon cheers, including just components folder works. I've updated the example config.

@krzychb most VSCode C/C++ features are covered here: https://code.visualstudio.com/docs/languages/cpp

Looks like it could be even possible to setup an interactive debugging with GDB right in the editor, but I don't have a JTAG device atm to test it.

@seopyoon

This comment has been minimized.

Copy link

commented Feb 9, 2017

I set up the tasks.json. How do I use this functionality? @grisevg

@FayeY FayeY changed the title VSCode works really well. Worth adding setup instructions in to the docs? [TW#12206] VSCode works really well. Worth adding setup instructions in to the docs? May 2, 2017

@gojimmypi

This comment has been minimized.

Copy link

commented May 25, 2017

+1 on adding docs. VSCode is (er, will soon be) really awesome for ESP debugging!

Note that I am really close, but instead using launch.json and perhaps only need to know the value for TargetArchitecture. See: Microsoft/vscode-cpptools#763

I've been able to single step an STM32 using VSCode: very cool!
https://gojimmypi.blogspot.com/2017/05/vscode-remote-debugging-of-embedded.html
I really hope to be able to do this with ESP32 (and ESP8266?).

@FHFS

This comment has been minimized.

Copy link

commented May 27, 2017

if esp-idf is in the project folder symbols get found automatically. for windows you can also add the msys2, mingw32 and xtensa-esp32-elf bin folders to the path in tasks.json. make monitor has some trouble starting a console, you can edit the idf_monitor.py to output to stderr(task output window), or make a .cmd file with the python command in it and run that command from tasks.
You can see how I work with it esp-idf-VSCode-template

@heymind

This comment has been minimized.

Copy link

commented Jun 21, 2017

It doesn't work in my vscode(Version 1.13.1).
"PATH" : "${env.PATH}:/home/grisevg/esp/xtensa-esp32-elf/bin"
change it to
"PATH" : "${env:PATH}:/home/grisevg/esp/xtensa-esp32-elf/bin"

@FHFS

This comment has been minimized.

Copy link

commented Jun 21, 2017

@heymind Yeah, ${env.PATH} stopped working for me too after a update.
Thanks for the fix

@seopyoon

This comment has been minimized.

Copy link

commented Jun 21, 2017

Anyone use it on Mac?? It used to work well, but after an update, (Not sure VSCode update or esp-idf update) all of them get red underlines. But, when command + click function, or struct, it successfully finds the referring ones.

So functionally, it is fine, but it's red everywhere. Please give me advice. My paths included in c_cpp_properties.json are:
"/usr/include",
"/Users//Developer/esp-sdk/esp-idf/components",

@neilyoung

This comment has been minimized.

Copy link

commented Jun 21, 2017

@seopyoon Add this to your settings.json

"C_Cpp.intelliSenseEngine": "Tag Parser"

It is an issue with the new VSCode intellisense. This setting reverts it back to the old behavior.

See here Microsoft/vscode-cpptools#690

@asiby

This comment has been minimized.

Copy link

commented Oct 10, 2017

It works but it's not context sensitive. So for me, Eclipse CDT is unfortunately better so far. I don't know much about VSCode to try to help but I am reading about it. It's lighter in memory for obvious reasons and it works faster than Eclipse in my opinion.

I am willing to donate my time regarding this matter. Any pointers, guidance and help will be greatly appreciated.

Thanks guys.

@asiby

This comment has been minimized.

Copy link

commented Oct 10, 2017

Some additional information ...

With the current version of VSCode, the includePath is not recursive. It says it right in the editor when you hover the mouse over the word includePath.

@huming2207

This comment has been minimized.

Copy link

commented Nov 1, 2017

Hi guys,

I think it's possible to implement a tool which generates a compile_commands.json and use it in VSCode now, as the newest C/C++ plugin has added support for this, see here: https://github.com/Microsoft/vscode-cpptools/tree/v0.14.0

I'll have a research later when I finish my exam tomorrow.

Regards,
Jackson

@cranphin

This comment has been minimized.

Copy link

commented Apr 1, 2018

Any progress from anyone on this? VSCode seems very popular nowadays, it would be great if the IDF would support it better :)

@huming2207

This comment has been minimized.

Copy link

commented Apr 16, 2018

Hi all,

Maybe this is a bit off-topic, but I've made a CMake template for CLion users. Check here for more details: https://github.com/huming2207/esp32-cmake-helloworld

Currently this template can only used for CLion indexing, not ready for compiling the project.

Regards,
Jackson Hu

@HudsonProdigy

This comment has been minimized.

Copy link

commented Oct 23, 2018

This all seems to be deprecated in new version of visual code. as a result it is ignored. does anyone have an updated tasks.json for reference?

@huming2207

This comment has been minimized.

Copy link

commented Oct 24, 2018

Guess we should try the official CMake now. They are rolling out the official support for CMake build system since v3.1 and it works fine in CLion.

For VSCode using CMake, probably here is a solution: https://medium.com/audelabs/c-development-using-visual-studio-code-cmake-and-lldb-d0f13d38c563

@huming2207

This comment has been minimized.

Copy link

commented Oct 29, 2018

Sorry I need to correct my previous reply

Just try this: https://marketplace.visualstudio.com/items?itemName=vector-of-bool.cmake-tools

Works mostly perfect for ESP-IDF v3.1+ for now, although it is a bit slower than CLion.

@grahamehorner

This comment has been minimized.

Copy link

commented Jan 17, 2019

IMHO it would also be great to support #vscode given that #vscode free, availible on Window, Linux and iOS; and is extensibile with a growing set of tool, extensions and language support.

@JosuGZ

This comment has been minimized.

Copy link

commented Feb 5, 2019

Some additional information ...

With the current version of VSCode, the includePath is not recursive. It says it right in the editor when you hover the mouse over the word includePath.

"${env:IDF_PATH}/components/**" seems to work for me.

@AloyseTech

This comment has been minimized.

Copy link

commented Feb 8, 2019

Hi guys,

I have integrated ESP32 IDF development to VScode on windows. I'm only missing the make flash command that I can't make worw. At the moment I have to open a ming32 terminal and navigate to the project root and launch the make flash command manually.
I would like to have a VS code task to flash the device. Here is my current tasks.json :

{
    "version": "2.0.0",
    "command": "C:/Espressif/ESP32/msys32/usr/bin/bash",
    "args": ["--login","-c"],
    "type": "shell",
    "presentation": {
        "reveal": "always",
    },
    "suppresslabel": true,
    "options": {
        "cwd": "${workspaceRoot}",
        "env": {
            "CHERE_INVOKING": "enabled_from_arguments",
            "MSYSTEM": "MINGW32"
        }
    },
    "tasks": [
        {
            "label": "build all",
            "group": "build",
            "command": "C:/Espressif/ESP32/msys32/usr/bin/bash",
            "type": "shell",
            "args": [
                "--login","-c",
                "make",
                "all",
                "-j10"
            ],
            "presentation": {
                "reveal": "always",
            },
            "problemMatcher": {
                "owner": "cpp",
                "fileLocation": "absolute",
                "pattern": {
                    "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
                    "file": 1,
                    "line": 2,
                    "column": 3,
                    "severity": 4,
                    "message": 5
                }
            }
        },
        {
            "label": "build app",
            "group": "build",
            "command": "C:/Espressif/ESP32/msys32/usr/bin/bash",
            "type": "shell",
            "args": [
                "--login","-c",
                "make",
                "app",
                "-j10"
            ],
            "presentation": {
                "reveal": "always",
            },
            "problemMatcher": {
                "owner": "cpp",
                "fileLocation": "absolute",
                "pattern": {
                    "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
                    "file": 1,
                    "line": 2,
                    "column": 3,
                    "severity": 4,
                    "message": 5
                }
            }
        },
        {
            "label": "clean app",
            "command": "C:/Espressif/ESP32/msys32/usr/bin/bash",
            "type": "shell",
            "args": [
                "--login","-c",
                "make",
                "app-clean",
                "-j10"
            ],
            "presentation": {
                "reveal": "always",
            },
        },
        {
            "label": "flash app",
            "command": "C:/Espressif/ESP32/msys32/usr/bin/bash",
            "type": "shell",
            "args": [
                "--login","-c",
                "make",
                "app-flash"
            ],
            "presentation": {
                "reveal": "always",
            },
        },
        {
            "label": "monitor",
            "type":"process",
            "windows": {
                "command": "C:/Espressif/ESP32/msys32/mingw32.exe",
                "args": [
                    "make",
                    "monitor"
                ],                    
            },
            "presentation": {
                "reveal": "always",
            },
            "problemMatcher": []            
        },
        {
            "label": "menuconfig",
            "type":"process",
            "windows": {
                "command": "C:/Espressif/ESP32/msys32/mingw32.exe",
                "args": [
                    "make",
                    "menuconfig"
                ]
            },
            "presentation": {
                "reveal": "always",
            },
            "problemMatcher": []
        }
    ]
}

Launching the "flah app" task result in the following :

Toolchain path: /opt/xtensa-esp32-elf/bin/xtensa-esp32-elf-gcc
Toolchain version: crosstool-ng-1.22.0-80-g6c4433a5
Compiler version: 5.2.0
Python requirements from C:/Espressif/ESP32/msys32/home/theom/esp32/esp-idf/requirements.txt are satisfied.
Project is not inside a git repository, will not use 'git describe' to determine PROJECT_VER.
App "template" version: 1
To flash all build output, run 'make flash' or:
python /home/theom/esp32/esp-idf/components/esptool_py/esptool/esptool.py --chip esp32 --port COM29 --baud 921600 --before default_reset --after hard_reset write_flash
-z --flash_mode dio --flash_freq 40m --flash_size detect 0xd000 /home/theom/esp32/projects/template/build/ota_data_initial.bin 0x1000 /home/theom/esp32/projects/template/build/bootloader/bootloader.bin 0x10000 /home/theom/esp32/projects/template/build/template.bin 0x8000 /home/theom/esp32/projects/template/build/partitions_two_ota.bin

But nothing is uploaded. What can I do to integrate this functionnality to VScode?

@projectgus projectgus changed the title [TW#12206] VSCode works really well. Worth adding setup instructions in to the docs? VSCode works really well. Worth adding setup instructions in to the docs? (IDF-88) Mar 12, 2019

@arnold-b

This comment has been minimized.

Copy link

commented Apr 20, 2019

Hello, im using this for flash:
{
"label": "flash app",
"command": "idf.py",
"type": "shell",
"args": [
"-p",
"COM4",
"flash"
],
"presentation": {
"reveal": "always"
}
},

@arnold-b

This comment has been minimized.

Copy link

commented Apr 21, 2019

I have to agree. VSCode works much better as Eclipse

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.