Visual Studio Code

From KONNEKTING Wiki
Jump to navigation Jump to search

Setup

TODO

Hotkeys

  • F1 - InputConsole
  • F5 - Start Debugging
  • CTRL+ALT+R - Verify Arduino Project
  • CTRL+ALT+U - Upload Arduino Project
  • CTRL-Shift+O - Current outline: Shows list of variables and methods of current opened file

User-Settings

 1{
 2    "arduino.path": "/home/achristian/arduino-1.8.5", // <-- Your Arduino IDE folder
 3    "arduino.logLevel": "verbose",
 4    "C_Cpp.intelliSenseEngine": "Tag Parser",
 5    "C_Cpp.clang_format_fallbackStyle": "LLVM", // <-- For using the correct code formatter when doing auto-format
 6    "arduino.additionalUrls": [
 7         // Arduino 3rd party core download URLs you use
 8        "http://digistump.com/package_digistump_index.json",
 9        "http://downloads.arduino.cc/Hourly/samd/package_samd-hourly-build_index.json",
10        "https://github.com/esp8266/Arduino/releases/download/2.4.0-rc2/package_esp8266com_index.json"
11    ],
12    "C_Cpp.default.browse.path": [
13        "/media/bigdisk/Programming/Arduino/Sketchbook/libraries",         // <-- Path to the Arduino Libraries Folder (typically in Sketchbook folder)
14        "/home/achristian/arduino-1.8.5/hardware/arduino",                 // <-- Path to base Arduino hardware folder for common Arduino API
15        "/home/achristian/.arduino15/packages",                            // <-- Path to the downloaded Arduino Cores like ESP8266, Arduino Zero, ...
16        "${workspaceRoot}"                                                 // <-- Variable pointing to your current project workspace root
17    ],
18    "editor.wordWrap": "on"    
19}

Debugging

Visual Studio Code is storing the debug configuration in ${workspaceRoot}/.vscode/launch.json.

 1{
 2    // Verwendet IntelliSense zum Ermitteln möglicher Attribute.
 3    // Zeigen Sie auf vorhandene Attribute, um die zugehörigen Beschreibungen anzuzeigen.
 4    // Weitere Informationen finden Sie unter https://go.microsoft.com/fwlink/?linkid=830387
 5    "version": "0.2.0",
 6    "configurations": [
 7        {
 8            "name": "Arduino - STLink v2",
 9            "type": "arduino",
10            "request": "launch",
11            "program": "${file}",
12            "cwd": "${workspaceFolder}",
13            "MIMode": "gdb",
14            "targetArchitecture": "arm",
15            "miDebuggerPath": "/home/achristian/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-gdb",
16            "debugServerPath": "/home/achristian/.arduino15/packages/arduino/tools/openocd/0.9.0-arduino6-static/bin/openocd",
17            "debugServerArgs": " -f /home/achristian/.arduino15/packages/arduino/tools/openocd/0.9.0-arduino6-static/share/openocd/scripts/interface/stlink-v2.cfg -f /media/bigdisk/Programming/Arduino/at91samdXXZero.cfg -s /home/achristian/.arduino15/packages/arduino/tools/openocd/0.9.0-arduino6-static/share/openocd/scripts",
18
19            "customLaunchSetupCommands": [
20                {
21                    "text": "target remote localhost:3333"
22                },
23                {
24                    "text": "file \"${file}\""
25                },
26                {
27                    "text": "load"
28                },
29                {
30                    "text": "monitor reset halt"
31                },
32                {
33                    "text": "monitor reset init"
34                }
35            ],
36            "stopAtEntry": true,
37            "serverStarted": "Info\\ :\\ [\\w\\d\\.]*:\\ hardware",
38            "launchCompleteCommand": "exec-continue",
39            "filterStderr": true,
40            "args": []
41        },
42        {
43            "name": "Arduino - Atmel ICE - SAMD",
44            "type": "arduino",
45            "request": "launch",
46            "program": "${file}",
47            "cwd": "${workspaceFolder}",
48            "MIMode": "gdb",
49            "targetArchitecture": "arm",
50            "miDebuggerPath": "/home/achristian/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-gdb",
51            "debugServerPath": "/home/achristian/.arduino15/packages/arduino/tools/openocd/0.9.0-arduino6-static/bin/openocd",
52            "debugServerArgs": " -d2 -s /home/achristian/.arduino15/packages/arduino/tools/openocd/0.9.0-arduino6-static/share/openocd/scripts/ -f /home/achristian/.arduino15/packages/arduino/hardware/samd/1.6.19/variants/arduino_zero/openocd_scripts/arduino_zero.cfg",
53            "customLaunchSetupCommands": [
54                {
55                    "text": "target remote localhost:3333"
56                },
57                {
58                    "text": "file \"${file}\""
59                },
60                {
61                    "text": "load"
62                },
63                {
64                    "text": "monitor reset halt"
65                },
66                {
67                    "text": "monitor reset init"
68                }
69            ],
70            "stopAtEntry": true,
71            "serverStarted": "Info\\ :\\ [\\w\\d\\.]*:\\ hardware",
72            "launchCompleteCommand": "exec-continue",
73            "filterStderr": true,
74            "args": [],
75            "logging": { "trace": true, "traceResponse": true, "engineLogging": true }
76        }
77    ]
78}

Copy & paste the content shown here to you file and adapt the paths contained in the following parameters to match your system/installation:

  • miDebuggerPath
  • debugServerPath
  • debugServerArgs

ST-Link v2

For ST-Link v2 there's an extra file that you need to download to your harddrive and set the path accordingly:

https://raw.githubusercontent.com/DeqingSun/Debug-Arduino-Zero-with-ST-Link-V2/master/at91samdXXZero.cfg

For more information about VSC with STLinkv2, see: https://github.com/DeqingSun/Debug-Arduino-Zero-with-ST-Link-V2

Global Debug Config

It is possible to have the debug config global, for all projects. See: https://github.com/Microsoft/vscode/issues/18401#issuecomment-272400316