Skip to content

Commit 61678b9

Browse files
authored
Merge pull request #3679 from sg-/feature-vscode
Feature vscode
2 parents 450701f + 9b732a3 commit 61678b9

File tree

5 files changed

+181
-2
lines changed

5 files changed

+181
-2
lines changed

tools/export/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
from tools.export import codered, ds5_5, iar, makefile
1919
from tools.export import embitz, coide, kds, simplicity, atmelstudio
20-
from tools.export import sw4stm32, e2studio, zip, cmsis, uvision, cdt
20+
from tools.export import sw4stm32, e2studio, zip, cmsis, uvision, cdt, vscode
2121
from tools.targets import TARGET_NAMES
2222

2323
EXPORTERS = {
@@ -41,7 +41,10 @@
4141
'eclipse_iar' : cdt.EclipseIAR,
4242
'eclipse_armc5' : cdt.EclipseArmc5,
4343
'zip' : zip.ZIP,
44-
'cmsis' : cmsis.CMSIS
44+
'cmsis' : cmsis.CMSIS,
45+
'vscode_gcc_arm' : vscode.VSCodeGcc,
46+
'vscode_iar' : vscode.VSCodeIAR,
47+
'vscode_armc5' : vscode.VSCodeArmc5
4548
}
4649

4750
ERROR_MESSAGE_UNSUPPORTED_TOOLCHAIN = """

tools/export/vscode/__init__.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
from os.path import join, exists, realpath, relpath, basename
2+
from os import makedirs
3+
4+
from tools.export.makefile import Makefile, GccArm, Armc5, IAR
5+
6+
class VSCode(Makefile):
7+
"""Generic VSCode project. Intended to be subclassed by classes that
8+
specify a type of Makefile.
9+
"""
10+
def generate(self):
11+
"""Generate Makefile and VSCode launch and task files
12+
"""
13+
super(VSCode, self).generate()
14+
ctx = {
15+
'name': self.project_name,
16+
'elf_location': join('BUILD', self.project_name)+'.elf',
17+
'c_symbols': self.toolchain.get_symbols(),
18+
'asm_symbols': self.toolchain.get_symbols(True),
19+
'target': self.target,
20+
'include_paths': self.resources.inc_dirs,
21+
'load_exe': str(self.LOAD_EXE).lower()
22+
}
23+
24+
if not exists(join(self.export_dir, '.vscode')):
25+
makedirs(join(self.export_dir, '.vscode'))
26+
27+
28+
self.gen_file('vscode/tasks.tmpl', ctx,
29+
join('.vscode', 'tasks.json'))
30+
self.gen_file('vscode/launch.tmpl', ctx,
31+
join('.vscode', 'launch.json'))
32+
33+
34+
class VSCodeGcc(VSCode, GccArm):
35+
LOAD_EXE = True
36+
NAME = "VSCode-GCC-ARM"
37+
38+
class VSCodeArmc5(VSCode, Armc5):
39+
LOAD_EXE = True
40+
NAME = "VSCode-Armc5"
41+
42+
class VSCodeIAR(VSCode, IAR):
43+
LOAD_EXE = True
44+
NAME = "VSCode-IAR"
45+
46+

tools/export/vscode/launch.tmpl

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "C++ Launch",
6+
"type": "cppdbg",
7+
"request": "launch",
8+
"program": "${workspaceRoot}/BUILD/${workspaceRootFolderName}.elf",
9+
"args": [],
10+
"stopAtEntry": true,
11+
"cwd": "${workspaceRoot}",
12+
"environment": [],
13+
"externalConsole": false,
14+
"debugServerArgs": "",
15+
"serverLaunchTimeout": 20000,
16+
"filterStderr": true,
17+
"filterStdout": false,
18+
"serverStarted": "GDB\\ server\\ started",
19+
"preLaunchTask": "make",
20+
"setupCommands": [
21+
{ "text": "-target-select remote localhost:3333", "description": "connect to target", "ignoreFailures": false },
22+
{ "text": "-file-exec-and-symbols ${workspaceRoot}/BUILD/${workspaceRootFolderName}.elf", "description": "load file", "ignoreFailures": false},
23+
{ "text": "-interpreter-exec console \"monitor endian little\"", "ignoreFailures": false },
24+
{ "text": "-interpreter-exec console \"monitor reset\"", "ignoreFailures": false },
25+
{ "text": "-interpreter-exec console \"monitor halt\"", "ignoreFailures": false },
26+
{ "text": "-interpreter-exec console \"monitor arm semihosting enable\"", "ignoreFailures": false },
27+
{ "text": "-target-download", "description": "flash target", "ignoreFailures": false }
28+
],
29+
"logging": {
30+
"moduleLoad": true,
31+
"trace": true,
32+
"engineLogging": true,
33+
"programOutput": true,
34+
"exceptions": true
35+
},
36+
"linux": {
37+
"MIMode": "gdb",
38+
"MIDebuggerPath": "/usr/bin/arm-none-eabi-gdb",
39+
"debugServerPath": "/usr/local/bin/pyocd-gdbserver"
40+
},
41+
"osx": {
42+
"MIMode": "gdb",
43+
"MIDebuggerPath": "/usr/local/bin/arm-none-eabi-gdb",
44+
"debugServerPath": "/usr/local/bin/pyocd-gdbserver"
45+
},
46+
"windows": {
47+
"MIMode": "gdb",
48+
"MIDebuggerPath": "${workspaceRoot}\\.vscode\\bin\\windows\\gcc\\arm-none-eabi-gdb.exe",
49+
"debugServerPath": "${workspaceRoot}\\.vscode\\bin\\windows\\gdb_server.exe",
50+
"setupCommands": [
51+
{ "text": "-target-select remote localhost:3333", "description": "connect to target", "ignoreFailures": false },
52+
{ "text": "-file-exec-and-symbols z:\\\\mbed-os-example-blinky\\\\BUILD\\\\${workspaceRootFolderName}.elf", "description": "load file", "ignoreFailures": false},
53+
{ "text": "-target-download", "description": "flash target", "ignoreFailures": false }
54+
]
55+
}
56+
}
57+
]
58+
}

tools/export/vscode/tasks.tmpl

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
// See https://go.microsoft.com/fwlink/?LinkId=733558
3+
// for the documentation about the tasks.json format
4+
"version": "0.1.0",
5+
"isShellCommand": true,
6+
"showOutput": "always",,
7+
"tasks": [
8+
{
9+
"taskName": "make",
10+
"problemMatcher": {
11+
"owner": "cpp",
12+
"fileLocation": ["relative", "${workspaceRoot}/mbed-os"],
13+
"pattern": {
14+
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
15+
"file": 1,
16+
"line": 2,
17+
"column": 3,
18+
"severity": 4,
19+
"message": 5
20+
}
21+
}
22+
}
23+
],
24+
"linux": {
25+
"command": "make",
26+
"args": ["-j"]
27+
},
28+
"osx": {
29+
"command": "make",
30+
"args": ["-j"]
31+
},
32+
"windows": {
33+
"command": "${workspaceRoot}\\.vscode\\bin\\windows\\make.bat"
34+
}
35+
}

tools/export/vscode/vscode.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# VSCode exporter
2+
Exporting for Microsoft Visual Studio code works on Windows, Mac and Linux but will expect a few system dependnecies to be installed. The exporter creates task files and launch files that make it easy to compile and debug within the IDE. Building is done using the created makefile. Debugging with GDB and pyOCD
3+
4+
## Setup
5+
- compiler
6+
- GNU ARM Embedded
7+
- IAR
8+
- ARMC5
9+
- mbed CLI
10+
- mbed tools requirement (pip install -U requirements.txt)
11+
- make
12+
13+
```
14+
mbed config [--global] target <board_name>
15+
mbed export -i vscode_armc5
16+
mbed export -i vscode_iar
17+
mbed export -i vscode_gcc_arm
18+
```
19+
20+
## Quickstart
21+
- Windows
22+
- compile: ctrl + shift + B
23+
- Mac
24+
- compile: cmd + shift + B
25+
- Linux
26+
- compile: ctrl + shift + B
27+
28+
# ToDo
29+
- launch GDB for Windows
30+
- verify Linux installation location for pyOCD
31+
- verify Mac installation location for pyOCD
32+
- verify Windows installation location for pyOCD
33+
- document udev rule for pyOCD on Linux
34+
- .vscode added to .gitignore for all applications etc.
35+
- filtered code completion in settings.json for the specific target that is exported for
36+
- keybindings.json for common mbed actions (possibly to match the online IDE key bindings)
37+
- add pictures!

0 commit comments

Comments
 (0)