環境
- WSL2のUbuntu 20.04
- VSCode(WSL2内から
code .
で開いたリモートモード)
前提
- VSCodeのC/C++エクステンションの
.vscode/c_cpp_properties.json
がなんとなく設定できる
QMKのインクルードパス等
QMKは~/qmk_firmware
で
make *keyboard*:*layout*
とやるとバイナリ(ファームウェア)がビルドされる。
どの*keyboard*
と*layout*
を選択するかによって、コンパイラのインクルードパス等が大きく変わってくる。VSCodeのC/C++エクステンションの機能を使うには、まず*keyboard*
と*layout*
を決めて、そのインクルードパス等を.vscode/c_cpp_properties.json
に設定しなければならない。
コンパイラのインクルードパス等は、バイナリをビルドしたときに生成される.build/obj_*keyboard*_*layout*
のcflags.txtに書いてある。
追記:
GCCが暗黙に追加するインクルードパスがあり、そこにstdint.h
等々がある。もしARM GCCが~/gcc-arm-none-eabi
にインストールされているなら、~/gcc-arm-none-eabi/arm-none-eabi/include
となる。
VSCodeに設定
cd .build/obj_*keyboard*_*layout*
して、
# includePath
cat cflags.txt | sed -e 's/ \-/\n\-/g' | sed -e 's/\-I/\${workspaceFolder}\//g' | sed -e 's/\.\///g' | grep workspaceFolder | awk '!a[$0]++' | sed -e 's/\(.*\)/"\1",/g'
# defines
cat cflags.txt | sed -e 's/ \-/\n\-/g' | grep '\-D' | awk '!a[$0]++' | sed -e 's/\-D\(.*\)/\"\1\",/g'
# forcedInclude
cat cflags.txt | sed -e 's/ \-/\n\-/g' | sed -e 's/\-include \(\S*\).*/\${workspaceFolder}\/\1/g' | sed -e 's/\.\///g' | grep workspaceFolder | awk '!a[$0]++' | sed -e 's/\(\S*\)/"\1",/g'
これで.vscode/c_cpp_properties.json
のincludePath / defines / forcedIncludeの原型が得られる。「原型」というのは、存在しないディレクトリを指定している行があるから。そうした行が残っていると.vscode/c_cpp_properties.json
が文句を言う。
結果の一例:
"includePath": [
"~/gcc-arm-none-eabi/arm-none-eabi/include",
"${workspaceFolder}/keyboards/retro_75/keymaps/default",
"${workspaceFolder}/keyboards/.",
"${workspaceFolder}/keyboards/retro_75",
"${workspaceFolder}/lib/printf",
"${workspaceFolder}/tmk_core/common",
"${workspaceFolder}/tmk_core/common/chibios",
"${workspaceFolder}/tmk_core/protocol",
"${workspaceFolder}/tmk_core/protocol/chibios",
"${workspaceFolder}/tmk_core/protocol/chibios/lufa_utils",
"${workspaceFolder}/lib/chibios/os/license",
"${workspaceFolder}/lib/chibios/os/oslib/include",
"${workspaceFolder}/platforms/chibios/GENERIC_STM32_F072XB/configs",
"${workspaceFolder}/lib/chibios/os/common/portability/GCC",
"${workspaceFolder}/lib/chibios/os/common/startup/ARMCMx/compilers/GCC",
"${workspaceFolder}/lib/chibios/os/common/startup/ARMCMx/devices/STM32F0xx",
"${workspaceFolder}/lib/chibios/os/common/ext/ARM/CMSIS/Core/Include",
"${workspaceFolder}/lib/chibios/os/common/ext/ST/STM32F0xx",
"${workspaceFolder}/lib/chibios/os/rt/include",
"${workspaceFolder}/lib/chibios/os/common/ports/ARMCMx",
"${workspaceFolder}/lib/chibios/os/common/ports/ARMCMx/compilers/GCC",
"${workspaceFolder}/lib/chibios/os/hal/osal/rt",
"${workspaceFolder}/lib/chibios/os/hal/include",
"${workspaceFolder}/lib/chibios/os/hal/ports/common/ARMCMx",
"${workspaceFolder}/lib/chibios/os/hal/ports/STM32/STM32F0xx",
"${workspaceFolder}/lib/chibios/os/hal/ports/STM32/LLD/ADCv1",
"${workspaceFolder}/lib/chibios/os/hal/ports/STM32/LLD/CANv1",
"${workspaceFolder}/lib/chibios/os/hal/ports/STM32/LLD/DACv1",
"${workspaceFolder}/lib/chibios/os/hal/ports/STM32/LLD/DMAv1",
"${workspaceFolder}/lib/chibios/os/hal/ports/STM32/LLD/EXTIv1",
"${workspaceFolder}/lib/chibios/os/hal/ports/STM32/LLD/GPIOv2",
"${workspaceFolder}/lib/chibios/os/hal/ports/STM32/LLD/I2Cv2",
"${workspaceFolder}/lib/chibios/os/hal/ports/STM32/LLD/RTCv2",
"${workspaceFolder}/lib/chibios/os/hal/ports/STM32/LLD/SPIv2",
"${workspaceFolder}/lib/chibios/os/hal/ports/STM32/LLD/TIMv1",
"${workspaceFolder}/lib/chibios/os/hal/ports/STM32/LLD/USARTv2",
"${workspaceFolder}/lib/chibios/os/hal/ports/STM32/LLD/USBv1",
"${workspaceFolder}/lib/chibios/os/hal/ports/STM32/LLD/xWDGv1",
"${workspaceFolder}/platforms/chibios/GENERIC_STM32_F072XB/board",
"${workspaceFolder}/lib/chibios/os/hal/lib/streams",
"${workspaceFolder}/lib/chibios/os/various",
"${workspaceFolder}/.",
"${workspaceFolder}/tmk_core",
"${workspaceFolder}/quantum",
"${workspaceFolder}/quantum/keymap_extras",
"${workspaceFolder}/quantum/audio",
"${workspaceFolder}/quantum/process_keycode",
"${workspaceFolder}/quantum/api",
"${workspaceFolder}/drivers",
"${workspaceFolder}/drivers/chibios"
],
"defines": [
"THUMB_PRESENT",
"THUMB_NO_INTERWORKING",
"THUMB",
"KEYBOARD_",
"KEYBOARD_retro_75",
"EEPROM_ENABLE",
"EEPROM_VENDOR",
"EEPROM_EMU_STM32F072xB",
"STM32_EEPROM_ENABLE",
"RGBLIGHT_ENABLE",
"WS2812_DRIVER_BITBANG",
"USE_CIE1931_CURVE",
"SPACE_CADET_ENABLE",
"MAGIC_KEYCODE_ENABLE",
"GRAVE_ESC_ENABLE",
"PRINTF_DISABLE_SUPPORT_FLOAT",
"PRINTF_DISABLE_SUPPORT_EXPONENTIAL",
"PRINTF_DISABLE_SUPPORT_LONG_LONG",
"PRINTF_DISABLE_SUPPORT_PTRDIFF_T",
"BOOTMAGIC_LITE",
"MAGIC_ENABLE",
"MOUSEKEY_ENABLE",
"MOUSE_ENABLE",
"MOUSE_SHARED_EP",
"EXTRAKEY_ENABLE",
"NO_PRINT",
"NO_DEBUG",
"SHARED_EP_ENABLE",
"CORTEX_USE_FPU=FALSE",
"PROTOCOL_CHIBIOS",
"PORT_IGNORE_GCC_VERSION_CHECK=1",
"FIXED_CONTROL_ENDPOINT_SIZE=64",
"FIXED_NUM_CONFIGURATIONS=1 ",
"QMK_KEYBOARD=\"retro_75\"",
"QMK_KEYBOARD_H=\"retro_75.h\"",
"QMK_KEYBOARD_CONFIG_H=\"keyboards/retro_75/config.h\"",
"QMK_KEYMAP=\"default\"",
"QMK_KEYMAP_H=\"default.h\"",
"QMK_KEYMAP_CONFIG_H=\"keyboards/retro_75/keymaps/default/config.h\"",
"QMK_SUBPROJECT",
"QMK_SUBPROJECT_H",
"QMK_SUBPROJECT_CONFIG_H"
],
"forcedInclude": [
"${workspaceFolder}/platforms/chibios/GENERIC_STM32_F072XB/configs/bootloader_defs.h",
"${workspaceFolder}/keyboards/retro_75/config.h",
"${workspaceFolder}/quantum/rgblight_post_config.h"
],
でもいいの? 本当にこれで?
知らんがな。組み込みって厳しいわ。