VSCODE_LAUNCH_FILENAME = 'launch.json'
VSCODE_C_PROPERTIES_FILENAME = 'c_cpp_properties.json'
+VSCODE_CMAKE_KITS_FILENAME ='cmake-kits.json'
VSCODE_SETTINGS_FILENAME ='settings.json'
VSCODE_EXTENSIONS_FILENAME ='extensions.json'
VSCODE_TASKS_FILENAME ='tasks.json'
cmake_header1 = (f"# Generated Cmake Pico project file\n\n"
"cmake_minimum_required(VERSION 3.13)\n\n"
"set(CMAKE_C_STANDARD 11)\n"
- "set(CMAKE_CXX_STANDARD 17)\n\n"
+ "set(CMAKE_CXX_STANDARD 17)\n"
+ "set(CMAKE_EXPORT_COMPILE_COMMANDS ON)\n\n"
"# Initialise pico_sdk from installed location\n"
"# (note this can come from environment, CMake cache etc)\n\n"
)
# Get project name
for line in lines:
if "add_executable" in line:
- newProjectName = line.split('(')[1].strip().strip("()")
+ newProjectName = line.split('(')[1].split()[0].strip().strip("()")
if params["wantThreadsafeBackground"] or params["wantPoll"]:
newProjectName = newProjectName.replace("_background", "")
newProjectName = newProjectName.replace("_poll", "")
if debugger == "raspberrypi-swd.cfg":
shutil.copyfile(sourcefolder + "/" + "raspberrypi-swd.cfg", projectPath / "raspberrypi-swd.cfg")
- gdbPath = Path(codeToolchainPath(toolchainVersion)+"/bin/arm-none-eabi-gdb").as_posix() if isWindows else "gdb-multiarch" if isMac else "gdb"
+ gdbPath = Path(codeToolchainPath(toolchainVersion)+"/bin/arm-none-eabi-gdb").as_posix() if isWindows or isMac else "gdb"
# Need to escape windows files paths backslashes
# TODO: env in currently not supported in compilerPath var
#cPath = f"${{env:PICO_TOOLCHAIN_PATH_{envSuffix}}}" + os.path.sep + os.path.basename(str(compilerPath).replace('\\', '\\\\' ))
- cPath = compilerPath.as_posix()
+ cPath = compilerPath.as_posix() + (".exe" if isWindows else "")
# if this is a path in the .pico-sdk homedir tell the settings to use the homevar
user_home = os.path.expanduser("~").replace("\\", "/")
use_home_var = f"{user_home}/.pico-sdk" in ninjaPath
openocd_path = ""
+ server_path = "\n \"serverpath\"" # Because no \ in f-strings
openocd_path_os = Path(user_home, relativeOpenOCDPath(openOCDVersion).replace("/", "", 1), "bin", "openocd.exe")
if os.path.exists(openocd_path_os):
- openocd_path = f'\n"serverpath": "{codeOpenOCDPath(openOCDVersion)}/bin/openocd.exe",'
+ openocd_path = f'{codeOpenOCDPath(openOCDVersion)}/bin/openocd.exe'
for p in projects :
if p == 'vscode':
"executable": "${{command:raspberry-pi-pico.launchTargetPath}}",
"request": "launch",
"type": "cortex-debug",
- "servertype": "openocd",{openocd_path}
+ "servertype": "openocd",\
+{f'{server_path}: "{openocd_path}",' if openocd_path else ""}
"gdbPath": "{gdbPath}",
"device": "RP2040",
"configFiles": [
"continue"
],
"openOCDLaunchCommands": [
- "adapter speed 1000"
- ],
- "preLaunchTask": "Compile Project"
+ "adapter speed 5000"
+ ]
}},
{{
"name": "Pico Debug (Cortex-Debug with external OpenOCD)",
"postRestartCommands": [
"break main",
"continue"
- ],
- "preLaunchTask": "Compile Project"
+ ]
}},
{{
"name": "Pico Debug (C++ Debugger)",
"MIMode": "gdb",
"miDebuggerPath": "{gdbPath}",
"miDebuggerServerAddress": "localhost:3333",
- "debugServerPath": "openocd",
- "debugServerArgs": "-f interface/cmsis-dap.cfg -f target/rp2040.cfg -c \\"adapter speed 1000\\"",
+ "debugServerPath": "{openocd_path if openocd_path else "openocd"}",
+ "debugServerArgs": "-f {debugger} -f target/rp2040.cfg -c \\"adapter speed 5000\\"",
"serverStarted": "Listening on port .* for gdb connections",
"filterStderr": true,
- "stopAtEntry": true,
"hardwareBreakpoints": {{
"require": true,
"limit": 4
"name": "Pico",
"includePath": [
"${{workspaceFolder}}/**",
- "{propertiesSdkPath(sdkVersion)}/**"
+ "{codeSdkPath(sdkVersion)}/**"
],
"forcedInclude": [
- "{propertiesSdkPath(sdkVersion)}/src/common/pico_base/include/pico.h",
+ "{codeSdkPath(sdkVersion)}/src/common/pico_base/include/pico.h",
"${{workspaceFolder}}/build/generated/pico_base/pico/config_autogen.h"
],
"defines": [],
"compilerPath": "{cPath}",
+ "compileCommands": "${{workspaceFolder}}/build/compile_commands.json",
"cStandard": "c17",
"cppStandard": "c++14",
"intelliSenseMode": "linux-gcc-arm"
pythonExe = sys.executable.replace("\\", "/").replace(user_home, "${HOME}") if use_home_var else sys.executable
+ # kits
+ kits = f'''[
+ {{
+ "name": "Pico",
+ "compilers": {{
+ "C": "{cPath}",
+ "CXX": "{cPath}"
+ }},
+ "toolchainFile": "{propertiesSdkPath(sdkVersion)}/cmake/preload/toolchains/pico_arm_gcc.cmake",
+ "environmentVariables": {{
+ "PATH": "${{command:raspberry-pi-pico.getEnvPath}};${{env:PATH}}"
+ }},
+ "cmakeSettings": {{
+ "Python3_EXECUTABLE": "${{command:raspberry-pi-pico.getPythonPath}}"
+ }}
+ }}
+]'''
+
# settings
settings = f'''{{
"cmake.options.statusBarVisibility": "hidden",
"C_Cpp.debugShortcut": false,
"terminal.integrated.env.windows": {{
"PICO_SDK_PATH": "{propertiesSdkPath(sdkVersion, force_windows=True)}",
- "PICO_TOOLCHAIN_PATH": "{propertiesToolchainPath(sdkVersion, force_windows=True)}",
+ "PICO_TOOLCHAIN_PATH": "{propertiesToolchainPath(toolchainVersion, force_windows=True)}",
"Path": "{propertiesToolchainPath(toolchainVersion, force_windows=True)}/bin;{os.path.dirname(cmakePath.replace(user_home, "${env:USERPROFILE}") if use_home_var else cmakePath)};{os.path.dirname(ninjaPath.replace(user_home, "${env:USERPROFILE}") if use_home_var else ninjaPath)};${{env:PATH}}"
}},
"terminal.integrated.env.osx": {{
"PATH": "{propertiesToolchainPath(toolchainVersion, force_non_windows=True)}/bin:{os.path.dirname(cmakePath.replace(user_home, "${env:HOME}") if use_home_var else cmakePath)}:{os.path.dirname(ninjaPath.replace(user_home, "${env:HOME}") if use_home_var else ninjaPath)}:${{env:PATH}}"
}},
"raspberry-pi-pico.cmakeAutoConfigure": true,
+ "raspberry-pi-pico.useCmakeTools": false,
"raspberry-pi-pico.cmakePath": "{cmakePath.replace(user_home, "${HOME}") if use_home_var else cmakePath}",
"raspberry-pi-pico.ninjaPath": "{ninjaPath.replace(user_home, "${HOME}") if use_home_var else ninjaPath}"'''
"tasks": [
{{
"label": "Compile Project",
- "type": "shell",
+ "type": "process",
+ "isBuildCommand": true,
"command": "{ninjaPath.replace(user_home, "${userHome}") if use_home_var else ninjaPath}",
"args": ["-C", "${{workspaceFolder}}/build"],
"group": "build",
"reveal": "always",
"panel": "dedicated"
}},
- "problemMatcher": "$gcc"
+ "problemMatcher": "$gcc",
+ "windows": {{
+ "command": "{ninjaPath.replace(user_home, "${env:USERPROFILE}") if use_home_var else ninjaPath}.exe"
+ }}
+ }},
+ {{
+ "label": "Flash",
+ "type": "process",
+ "command": "{openocd_path if openocd_path else "openocd"}",
+ "args": [
+ "-f",
+ "{debugger}",
+ "-f",
+ "target/rp2040.cfg",
+ "-c",
+ "adapter speed 5000; program \\"${{command:raspberry-pi-pico.launchTargetPath}}\\" verify reset exit"
+ ],
+ "problemMatcher": [],
+ "windows": {{
+ "command": "{openocd_path.replace("${userHome}", "${env:USERPROFILE}") if openocd_path else "openocd"}",
+ }}
}}
]
}}
file.write(properties)
file.close()
+ file = open(VSCODE_CMAKE_KITS_FILENAME, 'w')
+ file.write(kits)
+ file.close()
+
file = open(VSCODE_SETTINGS_FILENAME, 'w')
file.write(settings)
file.close()
if args.cpath:
compilerPath = Path(args.cpath)
elif args.toolchainVersion:
- compilerPath = Path(propertiesToolchainPath(args.toolchainVersion)+"/bin/"+COMPILER_NAME)
+ compilerPath = Path(codeToolchainPath(args.toolchainVersion)+"/bin/"+COMPILER_NAME)
else:
compilerPath = Path(c)