이 글은 VSCode + arm-none-eabi-gcc 크로스 컴파일 + Makefile 빌드 + OpenOCD 기반 STM32 표준 라이브러리 개발 환경 구축 강좌에서 파생된 내용입니다. .vscode 디렉토리에 포함된 각 설정 파일에서 수정해야 할 부분을 상세히 설명합니다.
Ⅰ. tasks.json
tasks.json의 주요 역할은 특정 이름을 사용하여 명령어와 인자를 실행하는 것입니다. 프로그램 빌드, 대상 및 빌드 파일 정리, 전체 재빌드, 그리고 CMSIS-DAP-Link / ST-Link / J-Link를 통한 펌웨어 다운로드 기능을 포함합니다.
수정 필요 항목: ① 다음 부분에서
"args": ["-f","interface/cmsis-dap.cfg","-f","target/stm32f4x.cfg","-c","program build/${workspaceRootFolderName}.elf verify reset", //프로젝트 루트 디렉토리 이름을 실행 파일 이름으로 사용"-c","reset run","-c","exit"]의target/stm32f4x.cfg를 해당 MCU 설정 파일로 변경합니다(OpenOCD 디렉토리 내 존재). ② J-Link JSON 블록의interface/jlink-swd.cfg수정을 주의해야 합니다. OpenOCD의 J-Link 다운로드 관련 문서를 참고하세요.
………………ST-Link 및 J-Link JSON 블록도 동일한 방식으로 수정합니다.
{
"tasks": [
{
"type": "shell",
"label": "build",
"command": "make -j 8",
"args": [],
"problemMatcher": [
"$gcc"
],
"group": "build"
},
{
"type": "shell",
"label": "clean",
"command": "make clean",
"args": [],
"problemMatcher": [
"$gcc"
],
"group": "build"
},
{
"type": "shell",
"label": "rebuild",
"dependsOrder": "sequence",
"dependsOn": [
"clean",
"build"
],
"problemMatcher": [
"$gcc"
],
"group": "build"
},
{
"type": "shell",
"label": "flash with cmsis-dap-link",
"command": "openocd",
"args": [
"-f",
"interface/cmsis-dap.cfg",
"-f",
"target/stm32f4x.cfg",
"-c",
"program build/${workspaceRootFolderName}.elf verify reset",
"-c",
"reset run",
"-c",
"exit"
],
"problemMatcher": [
"$gcc"
],
"group": "build",
"dependsOn": [
"build"
]
},
{
"type": "shell",
"label": "flash with ST-link",
"command": "openocd",
"args": [
"-f",
"interface/stlink.cfg",
"-f",
"target/stm32f4x.cfg",
"-c",
"program build/${workspaceRootFolderName}.elf verify reset",
"-c",
"reset run",
"-c",
"exit"
],
"problemMatcher": [
"$gcc"
],
"group": "build",
"dependsOn": [
"build"
]
},
{
"type": "shell",
"label": "flash with J-link",
"command": "openocd",
"args": [
"-f",
"interface/jlink-swd.cfg",
"-f",
"target/stm32f4x.cfg",
"-c",
"program build/${workspaceRootFolderName}.elf verify reset",
"-c",
"reset run",
"-c",
"exit"
],
"problemMatcher": [
"$gcc"
],
"group": "build",
"dependsOn": [
"build"
]
}
],
"version": "2.0.0"
}
Ⅱ. launch.json
launch.json은 MCU 디버깅 및 디버깅 장비 선택을 위한 설정 파일입니다.
수정 필요 항목: CMSIS-DAP-Link 디버그 JSON 블록의 경우, ①
"device": "STM32F401CC"를 개발에 사용할 MCU 모델로 변경합니다. ② 다음 부분에서"configFiles": ["interface/cmsis-dap.cfg","target/stm32f4x.cfg"]의target/stm32f4x.cfg를 해당 MCU 설정 파일로 변경합니다(OpenOCD 디렉토리 내 존재). ③"svdFile": "./STM32F401.svd"를 해당 MCU 모델의 레지스터 파일 경로로 수정합니다. ④"preLaunchTask": "flash with stlink"의 사전 작업 이름flash with stlink를tasks.json파일의label과 일치하도록 변경합니다. ⑤ J-Link 디버그 JSON 블록의interface/jlink-swd.cfg수정을 주의해야 합니다.
………………ST-Link 및 J-Link 디버그 JSON 블록도 동일한 방식으로 수정합니다.
{
"configurations": [
{
"name": "Debug with CMSIS-DAP-link",
"cwd": "${workspaceRoot}",
"executable": "./build/${workspaceRootFolderName}.elf",
"request": "launch",
"type": "cortex-debug",
"servertype": "openocd",
"device": "STM32F401CC",
"configFiles": [
"interface/cmsis-dap.cfg",
"target/stm32f4x.cfg"
],
"svdFile": "./STM32F401.svd",
"liveWatch": {
"enabled": true,
"samplesPerSecond": 4
},
"searchDir": [],
"runToEntryPoint": "main",
"showDevDebugOutput": "none",
"preLaunchTask": "flash with cmsis-dap-link"
},
{
"name": "Debug with ST-link",
"cwd": "${workspaceRoot}",
"executable": "./build/${workspaceRootFolderName}.elf",
"request": "launch",
"type": "cortex-debug",
"servertype": "openocd",
"device": "STM32F401CC",
"configFiles": [
"interface/stlink.cfg",
"target/stm32f4x.cfg"
],
"svdFile": "./STM32F401.svd",
"liveWatch": {
"enabled": true,
"samplesPerSecond": 4
},
"searchDir": [],
"runToEntryPoint": "main",
"showDevDebugOutput": "none",
"preLaunchTask": "flash with stlink"
},
{
"name": "Debug with J-link",
"cwd": "${workspaceRoot}",
"executable": "./build/${workspaceRootFolderName}.elf",
"request": "launch",
"type": "cortex-debug",
"servertype": "openocd",
"device": "STM32F401CC",
"configFiles": [
"interface/jlink-swd.cfg",
"target/stm32f4x.cfg"
],
"interface": "swd",
"svdFile": "./STM32F401.svd",
"liveWatch": {
"enabled": true,
"samplesPerSecond": 4
},
"runToEntryPoint": "main",
"showDevDebugTimestamps": true,
"showDevDebugOutput": "none",
"preLaunchTask": "flash with J-link"
}
],
"version": "2.0.0"
}
Ⅲ. settings.json
settings.json은 VSCode의 단축 기능과 Task Buttons 확장 프로그램을 활용한 빌드, 재빌드, 다운로드, 디버깅 등의 UI 버튼 표시를 설정합니다.
수정 필요 항목: 없습니다. Task Buttons 확장 프로그램과 material-icon-theme 확장 프로그램을 설치하면 즉시 사용할 수 있습니다.
{
"files.encoding": "utf8",
"files.autoSave": "afterDelay",
"workbench.iconTheme": "material-icon-theme",
"workbench.colorTheme": "Default Dark Modern",
"editor.formatOnPaste": true,
"editor.formatOnSave": true,
"editor.fontSize": 15,
"editor.fontWeight": "500",
"editor.mouseWheelZoom": true,
"terminal.integrated.mouseWheelZoom": true,
"workbench.editor.enablePreview": false,
"search.followSymlinks": false,
"security.workspace.trust.enabled": false,
"VsCodeTaskButtons.showCounter": true,
"VsCodeTaskButtons.tasks": [
{
"label": "$(tools) Build",
"task": "build",
"tooltip": "🛠️ build"
},
{
"label": "$(notebook-delete-cell) Clean",
"task": "clean",
"tooltip": "🧹 clean"
},
{
"label": "$(notebook-delete-cell) $(tools) Re-bulid",
"task": "rebuild",
"tooltip": "🛠️ rebuild"
},
{
"label": "$(zap) Download",
"tasks": [
{
"label": "⚓ CMSIS-dap-link",
"task": "flash with cmsis-dap-link"
},
{
"label": "⤵️ ST-link",
"task": "flash with ST-link"
},
{
"label": "🚀 J-link",
"task": "flash with J-link"
}
],
"tooltip": "⚡ Download"
}
],
}
Ⅳ. c_cpp_properties.json
c_cpp_properties.json은 함수 간 이동, 코드 내 매크로 정의展開, MCU의 gcc 컴파일 경로, MCU의 컴파일 옵션 매개변수(또는 MCU의 하드웨어 매개변수) 설정을 담당합니다.
수정 필요 항목: ①
"name": "STM32F401CCU6_ARM_GCC"의 이름을 프로젝트 및 개인 선호도에 따라 수정합니다. ② 다음 부분에서"defines": ["__GNUC__","USE_STDPERIPH_DRIVER","STM32F401xx"]의"USE_STDPERIPH_DRIVER"와"STM32F401xx"를 MCU 모델에 따라 수정합니다. ③ 다음 부분에서"compilerArgs": ["-mcpu=cortex-m4","-mthumb","-mfpu=fpv4-sp-d16","-mfloat-abi=hard"]컴파일 옵션 매개변수를 MCU 모델에 따라 수정합니다.
{
"configurations": [
{
"name": "STM32F401CCU6_ARM_GCC",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"__GNUC__",
"USE_STDPERIPH_DRIVER",
"STM32F401xx"
],
"compilerPath": "arm-none-eabi-gcc",
"cStandard": "gnu17",
"cppStandard": "gnu++17",
"intelliSenseMode": "gcc-arm"
}
],
"version": 4
}