我正在使用 Nordic NRF52 为嵌入式开发设置 VSCode。我注意到在 nrf_sdk 中有几个板和几个软设备的示例。我已经看到可以引用先前在任务、启动和扩展属性中定义的环境变量,例如:c_cpp、stm32-for-vscode。但是在工作区文件中有一个部分定义为 my_vars 以使工作区文件看起来像这样呢?
{
"my_vars": {
"BOARD_NAME": "NRF52840_MDK_USB_DONGLE",
"MCU_NAME": "NRF52840",
"SOFT_DEVICE": "S140",
"BOARD_VARIANT_PATH": "/pca10059/mbr"
},
"launch": {
"version": "0.2.0",
"configurations": [
{
"name": "Cortex Debug",
"cwd": "${workspaceRoot}",
"executable": "${workspaceFolder}${my_vars:BOARD_VARIANT_PATH}/armgcc/_build/${my_vars:MCU_NAME}_xxaa.out",
"request": "launch",
"type": "cortex-debug",
"servertype": "jlink",
"device": "nrf52",
"interface": "swd",
"ipAddress": null,
"serialNumber": null,
"armToolchainPath": "${env:VSARM}/armcc/bin/"
},
]
},
"folders": [
{
"path": "."
}
],
"settings":{
// "C_Cpp.name": "nRF52840 DK",
"C_Cpp.default.includePath": [
"${workspaceFolder}/**",
"${env:GNU_GCC}/arm-none-eabi/include",
"${env:NRF_SDK}/modules/**",
"${env:NRF_SDK}/components/**"
],
"C_Cpp.default.defines": [
"${my_vars:BOARD_NAME}",
"CONFIG_GPIO_AS_PINRESET",
"INITIALIZE_USER_SECTIONS",
"FLOAT_ABI_HARD",
"NRF52",
"${my_vars:MCU_NAME}_XXAA",
"NRF_SD_BLE_API_VERSION=6",
"${my_vars:SOFT_DEVICE}",
"SOFTDEVICE_PRESENT",
"SWI_DISABLE0"
],
"C_Cpp.default.compilerPath": "${env:GNU_GCC}/bin/arm-none-eabi-gcc",
"C_Cpp.default.cStandard": "c11",
"C_Cpp.default.cppStandard": "c++17",
"C_Cpp.default.intelliSenseMode": "clang-x64"
},
"tasks": {
"version": "2.0.0",
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"tasks": [
{
"label": "nRF52 build",
"type": "shell",
"command": "make",
"options": {
"cwd": "${workspaceFolder}${my_vars:BOARD_VARIANT_PATH}/armgcc"
},
"problemMatcher": [],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "nRF52 build clean",
"type": "shell",
"command": "make clean",
"options": {
"cwd": "${workspaceFolder}${my_vars:BOARD_VARIANT_PATH}/armgcc"
},
"problemMatcher": [],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "nRF52 flash",
"type": "shell",
"command": "make flash",
"options": {
"cwd": "${workspaceFolder}${my_vars:BOARD_VARIANT_PATH}/armgcc"
},
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": []
},
{
"label": "nRF52 dfu upload",
"type": "shell",
"command": "make bootload",
"options": {
"cwd": "${workspaceFolder}${my_vars:BOARD_VARIANT_PATH}/armgcc"
},
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": []
},
{
"label": "nRF52 flash_softdevice",
"type": "shell",
"command": "make flash_softdevice",
"options": {
"cwd": "${workspaceFolder}${my_vars:BOARD_VARIANT_PATH}/armgcc"
},
"problemMatcher": [],
"group": {
"kind": "build",
"isDefault": true
},
},
{
"label": "nRF52 sdk_config",
"type": "shell",
"command": "make sdk_config",
"options": {
"cwd": "${workspaceFolder}${my_vars:BOARD_VARIANT_PATH}/armgcc"
},
"problemMatcher": []
},
{
"label": "nRF52 erase",
"type": "shell",
"command": "make erase",
"options": {
"cwd": "${workspaceFolder}${my_vars:BOARD_VARIANT_PATH}/armgcc"
},
"problemMatcher": [],
"group": {
"kind": "build",
"isDefault": true
},
}
]
}
}
我尝试了一个 set_env 任务,在我的情况下,因为我在 Windows 中,所以运行一个批处理脚本:
set BOARD_NAME=NRF52840_MDK_USB_DONGLE
set MCU_NAME=NRF52840
set SOFT_DEVICE=S140
set BOARD_VARIANT_PATH=/pca10059/mbr
这将大大简化 SDK 示例的使用,并且可能是 NRF52 VSCode 扩展的潜在工作,如https://marketplace.visualstudio.com/items?itemName=bmd.stm32-for-vscode所做的那样。