From 6499597586c9e5aff76bf4d58f8389c4d2fca0ee Mon Sep 17 00:00:00 2001 From: hedger Date: Wed, 3 Aug 2022 19:32:31 +0300 Subject: [PATCH] vscode: initial development configuration (#1520) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * vscode: initial development configuration; fbt: `vscode_dist` target for deploying vscode config * vscode: fixed fbt blackmagic command Co-authored-by: あく --- .vscode/.gitignore | 4 + .vscode/example/c_cpp_properties.json | 32 ++++++++ .vscode/example/launch.json | 87 ++++++++++++++++++++++ .vscode/example/settings.json | 22 ++++++ .vscode/example/tasks.json | 103 ++++++++++++++++++++++++++ .vscode/extensions.json | 15 ++++ SConstruct | 7 +- documentation/fbt.md | 15 +++- 8 files changed, 283 insertions(+), 2 deletions(-) create mode 100644 .vscode/.gitignore create mode 100644 .vscode/example/c_cpp_properties.json create mode 100644 .vscode/example/launch.json create mode 100644 .vscode/example/settings.json create mode 100644 .vscode/example/tasks.json create mode 100644 .vscode/extensions.json diff --git a/.vscode/.gitignore b/.vscode/.gitignore new file mode 100644 index 000000000..670df7d48 --- /dev/null +++ b/.vscode/.gitignore @@ -0,0 +1,4 @@ +./c_cpp_properties.json +./launch.json +./settings.json +./tasks.json diff --git a/.vscode/example/c_cpp_properties.json b/.vscode/example/c_cpp_properties.json new file mode 100644 index 000000000..db08320c9 --- /dev/null +++ b/.vscode/example/c_cpp_properties.json @@ -0,0 +1,32 @@ +{ + "configurations": [ + { + "name": "Win32", + "compilerPath": "${workspaceFolder}/toolchain/i686-windows/bin/arm-none-eabi-gcc.exe", + "intelliSenseMode": "gcc-arm", + "compileCommands": "${workspaceFolder}/build/latest/compile_commands.json", + "configurationProvider": "ms-vscode.cpptools", + "cStandard": "gnu17", + "cppStandard": "c++17" + }, + { + "name": "Linux", + "compilerPath": "${workspaceFolder}/toolchain/x86_64-linux/bin/arm-none-eabi-gcc", + "intelliSenseMode": "gcc-arm", + "compileCommands": "${workspaceFolder}/build/latest/compile_commands.json", + "configurationProvider": "ms-vscode.cpptools", + "cStandard": "gnu17", + "cppStandard": "c++17" + }, + { + "name": "Mac", + "compilerPath": "${workspaceFolder}/toolchain/x86_64-darwin/bin/arm-none-eabi-gcc", + "intelliSenseMode": "gcc-arm", + "compileCommands": "${workspaceFolder}/build/latest/compile_commands.json", + "configurationProvider": "ms-vscode.cpptools", + "cStandard": "gnu17", + "cppStandard": "c++17" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/example/launch.json b/.vscode/example/launch.json new file mode 100644 index 000000000..bdad04285 --- /dev/null +++ b/.vscode/example/launch.json @@ -0,0 +1,87 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "inputs": [ + { + "id": "BLACKMAGIC", + "type": "command", + "command": "shellCommand.execute", + "args": { + "command": "./fbt get_blackmagic", + "description": "Get Blackmagic device", + } + } + ], + "configurations": [ + { + "name": "Attach FW (ST-Link)", + "cwd": "${workspaceFolder}", + "executable": "./build/latest/firmware.elf", + "request": "attach", + "type": "cortex-debug", + "servertype": "openocd", + "device": "stlink", + "svdFile": "./debug/STM32WB55_CM4.svd", + "rtos": "FreeRTOS", + "configFiles": [ + "interface/stlink.cfg", + "./debug/stm32wbx.cfg", + ], + "postAttachCommands": [ + // "attach 1", + "compare-sections", + ] + // "showDevDebugOutput": "raw", + }, + { + "name": "Attach FW (blackmagic)", + "cwd": "${workspaceFolder}", + "executable": "./build/latest/firmware.elf", + "request": "attach", + "type": "cortex-debug", + "servertype": "external", + "gdbTarget": "${input:BLACKMAGIC}", + "svdFile": "./debug/STM32WB55_CM4.svd", + "rtos": "FreeRTOS", + "postAttachCommands": [ + "monitor swdp_scan", + "attach 1", + "set confirm off", + "set mem inaccessible-by-default off", + "compare-sections", + ] + // "showDevDebugOutput": "raw", + }, + { + "name": "Attach FW (JLink)", + "cwd": "${workspaceFolder}", + "executable": "./build/latest/firmware.elf", + "request": "attach", + "type": "cortex-debug", + "servertype": "jlink", + "interface": "swd", + "device": "STM32WB55RG", + "svdFile": "./debug/STM32WB55_CM4.svd", + "rtos": "FreeRTOS", + // "showDevDebugOutput": "raw", + }, + { + "name": "fbt debug", + "type": "python", + "request": "launch", + "program": "./lib/scons/scripts/scons.py", + "args": [ + "sdk" + ] + }, + { + "name": "python debug", + "type": "python", + "request": "launch", + "program": "${file}", + "args": [] + } + ] +} \ No newline at end of file diff --git a/.vscode/example/settings.json b/.vscode/example/settings.json new file mode 100644 index 000000000..925c2e076 --- /dev/null +++ b/.vscode/example/settings.json @@ -0,0 +1,22 @@ +{ + "C_Cpp.default.cStandard": "gnu17", + "C_Cpp.default.cppStandard": "c++17", + "python.formatting.provider": "black", + "workbench.tree.indent": 12, + "cortex-debug.enableTelemetry": false, + "cortex-debug.variableUseNaturalFormat": true, + "cortex-debug.showRTOS": true, + "cortex-debug.armToolchainPath.windows": "${workspaceFolder}/toolchain/i686-windows/bin", + "cortex-debug.armToolchainPath.linux": "${workspaceFolder}/toolchain/x86_64-linux/bin", + "cortex-debug.armToolchainPath.osx": "${workspaceFolder}/toolchain/x86_64-darwin/bin", + "cortex-debug.openocdPath.windows": "${workspaceFolder}/toolchain/i686-windows/openocd/bin/openocd.exe", + "cortex-debug.openocdPath.linux": "${workspaceFolder}/toolchain/x86_64-linux/openocd/bin/openocd", + "cortex-debug.openocdPath.osx": "${workspaceFolder}/toolchain/x86_64-darwin/openocd/bin/openocd", + "editor.formatOnSave": true, + "files.associations": { + "*.scons": "python", + "SConscript": "python", + "SConstruct": "python", + "*.fam": "python", + } +} \ No newline at end of file diff --git a/.vscode/example/tasks.json b/.vscode/example/tasks.json new file mode 100644 index 000000000..c124305cb --- /dev/null +++ b/.vscode/example/tasks.json @@ -0,0 +1,103 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + { + "label": "[Release] Build", + "group": "build", + "type": "shell", + "command": "./fbt COMPACT=1 DEBUG=0" + }, + { + "label": "[Debug] Build", + "group": "build", + "type": "shell", + "command": "./fbt" + }, + { + "label": "[Release] Flash (ST-Link)", + "group": "build", + "type": "shell", + "command": "./fbt COMPACT=1 DEBUG=0 FORCE=1 flash" + }, + { + "label": "[Debug] Flash (ST-Link)", + "group": "build", + "type": "shell", + "command": "./fbt FORCE=1 flash" + }, + { + "label": "[Release] Flash (blackmagic)", + "group": "build", + "type": "shell", + "command": "./fbt COMPACT=1 DEBUG=0 FORCE=1 flash_blackmagic" + }, + { + "label": "[Debug] Flash (blackmagic)", + "group": "build", + "type": "shell", + "command": "./fbt FORCE=1 flash_blackmagic" + }, + { + "label": "[Release] Flash (JLink)", + "group": "build", + "type": "shell", + "command": "./fbt COMPACT=1 DEBUG=0 FORCE=1 jflash" + }, + { + "label": "[Debug] Flash (JLink)", + "group": "build", + "type": "shell", + "command": "./fbt FORCE=1 jflash" + }, + { + "label": "[Release] Build update bundle", + "group": "build", + "type": "shell", + "command": "./fbt update_package COMPACT=1 DEBUG=0" + }, + { + "label": "[Debug] Build update bundle", + "group": "build", + "type": "shell", + "command": "./fbt update_package" + }, + { + "label": "[Release] Build updater", + "group": "build", + "type": "shell", + "command": "./fbt updater_all COMPACT=1 DEBUG=0" + }, + { + "label": "[Debug] Build updater", + "group": "build", + "type": "shell", + "command": "./fbt updater_all" + }, + { + "label": "[Debug] Flash (USB, w/o resources)", + "group": "build", + "type": "shell", + "command": "./fbt FORCE=1 flash_usb" + }, + { + "label": "[Release] Flash (USB, w/o resources)", + "group": "build", + "type": "shell", + "command": "./fbt COMPACT=1 DEBUG=0 FORCE=1 flash_usb" + }, + { + "label": "[Debug:unit_tests] Flash (USB)", + "group": "build", + "type": "shell", + "command": "./fbt FIRMWARE_APP_SET=unit_tests FORCE=1 flash_usb" + }, + { + "label": "[Release] Flash (USB, with resources)", + "group": "build", + "type": "shell", + "command": "./fbt COMPACT=1 DEBUG=0 FORCE=1 flash_usb_full" + }, + ] +} \ No newline at end of file diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 000000000..b53ffc24c --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,15 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations. + // Extension identifier format: ${publisher}.${name}. Example: vscode.csharp + // List of extensions which should be recommended for users of this workspace. + "recommendations": [ + "ms-python.black-formatter", + "ms-vscode.cpptools", + "amiralizadeh9480.cpp-helper", + "marus25.cortex-debug", + "zxh404.vscode-proto3", + "augustocdias.tasks-shell-input" + ], + // List of extensions recommended by VS Code that should not be recommended for users of this workspace. + "unwantedRecommendations": [] +} \ No newline at end of file diff --git a/SConstruct b/SConstruct index fe731e357..52fe75a6a 100644 --- a/SConstruct +++ b/SConstruct @@ -274,8 +274,13 @@ distenv.PhonyTarget("cli", "${PYTHON3} scripts/serial_cli.py") # Find blackmagic probe - distenv.PhonyTarget( "get_blackmagic", "@echo $( ${BLACKMAGIC_ADDR} $)", ) + +# Prepare vscode environment +vscode_dist = distenv.Install("#.vscode", distenv.Glob("#.vscode/example/*")) +distenv.Precious(vscode_dist) +distenv.NoClean(vscode_dist) +distenv.Alias("vscode_dist", vscode_dist) diff --git a/documentation/fbt.md b/documentation/fbt.md index c658ce20e..53fc4b5e3 100644 --- a/documentation/fbt.md +++ b/documentation/fbt.md @@ -24,12 +24,25 @@ To build with FBT, call it specifying configuration options & targets to build. To run cleanup (think of `make clean`) for specified targets, add `-c` option. +## VSCode integration + +`fbt` includes basic development environment configuration for VSCode. To deploy it, run `./fbt vscode_dist`. That will copy initial environment configuration to `.vscode` folder. After that, you can use that configuration by starting VSCode and choosing firmware root folder in "File > Open Folder" menu. + + * On first start, you'll be prompted to install recommended plug-ins. Please install them for best development experience. _You can find a list of them in `.vscode/extensions.json`._ + * Basic build tasks are invoked in Ctrl+Shift+B menu. + * Debugging requires a supported probe. That includes: + * Wi-Fi devboard with stock firmware (blackmagic), + * ST-Link and compatible devices, + * J-Link for flashing and debugging (in VSCode only). _Note that J-Link tools are not included with our toolchain and you have to [download](https://www.segger.com/downloads/jlink/) them yourself and put on your system's PATH._ + * Without a supported probe, you can install firmware on Flipper using USB installation method. + + ## FBT targets FBT keeps track of internal dependencies, so you only need to build the highest-level target you need, and FBT will make sure everything they depend on is up-to-date. ### High-level (what you most likely need) - + - `fw_dist` - build & publish firmware to `dist` folder. This is a default target, when no other are specified - `updater_package`, `updater_minpackage` - build self-update package. Minimal version only inclues firmware's DFU file; full version also includes radio stack & resources for SD card - `copro_dist` - bundle Core2 FUS+stack binaries for qFlipper