본문 바로가기

개발/VS Visual Studio Code

stm32cubeIDE 에서 build 하던거 vs code 에서 build/debug 하기-1

 

stm32 를 vs code에서 build/debug 하기 

   2가지를 해 보았읍니다.  필요 한거 쓰셔요.

 

1.  stm32cubeIDE 에서 build 하던거 vs code 에서 build/debug 하기-1 - 본글   https://bahk33.tistory.com/191

    ( stm32cubeCLT , make.exe 를 설치 )

2.  stm32cubeIDE 에서 build 하던거 vs code 에서 build/debug 하기 2              https://bahk33.tistory.com/192

    ( stm32cubeCLT , make.exe 를 설치 안하고 하기 )


 

==========================


본글 순서

 

0. 개념

1. 사전 작업

2. stm32cubeCLT 설치 
3. make.exe 설치

4. plugin  "c/c++ for Visual studio code"  설치    

5. plugin  "makefile tools" 설치

6. ".vscode/settings.json"  만들기

7. Build 하기

8.  "./Debug/compile_commands.json" 만들기

9. Plugin "Cortex-Debug" 설치

10. "./.vscode/launch.json" 만들기

11. Debug 실행

 

 

==========================

0. 개념

stm32cubeIDE 에서 build 하던거 vs code 에서 edit/build/debug 하기 

즉 여태 까지 stm32cubeIDE 를 이용 하여 edit/build/debug 하던것을 vs code 에서 edit/build/debug 하는 것으로 바꾸는 것입니다.

 

1. 사전 작업

> stm32cubeIDE 설치

> stm32cubeIDE 에서 프로젝트 만들기

> stm32cubeIDE 에서 build 한번 하기 -> makefile 만들기 위함 입니다.

> 이후 이렇게 만들어진    makefile 을 이용 하여 build 합니다.

> 이상의 것들은 설명 하지 않읍니다.

 

2. stm32cubeCLT 설치 :

> 포함 하는 것들

1)  arm-none-abi-gcc (compiler), arm-none-abi-nm (symbol viewer) 과 같은 GNU C/C++ for Arm® toolchain 을 포함 하여 Compile 을 할 수 있게 합니다.

2)   GDB debugger client and server 를 포함 합니다.

3)   STM32CubeProgrammer (STM32CubeProg) utility 

4)   System view descriptor files (.SVD) for the entire STM32 MCU portfolio

 

> 다운 받는 곳
 - https://www.st.com/en/development-tools/stm32cubeclt.html
  에서

   st-stm32cubeclt_1.17.0_23554_20241124_1810_x86_64.exe  (504M) 등 필요 한거 받으셔요, 

 

 

> 적당 한데 설치 합니다.

   504 메가 짜리가 2기가가 넘게 설치 되는 군요

 

> 설치 된 디렉토리 가서 보면,

- CMake, GNU-tools-for-STM32, STLink-gdb-server, STM32CubeProgrammer 등이 설치 된것을 확인 할 수 있읍니다.

 

> 설치 완료 되면 환경 변수 PATH 에 gcc 경로등 몇가지 경로가 추가 되는 군요

PATH=

C:\Program Files (x86)\STMicroelectronics\stlink_server;

E:\_t\_d\_stm\STM32CubeCLT_1.17.0;

E:\_t\_d\_stm\STM32CubeCLT_1.17.0\CMake\bin;

E:\_t\_d\_stm\STM32CubeCLT_1.17.0\Ninja\bin;

E:\_t\_d\_stm\STM32CubeCLT_1.17.0\GNU-tools-for-STM32\bin;

E:\_t\_d\_stm\STM32CubeCLT_1.17.0\STLink-gdb-server\bin;

E:\_t\_d\_stm\STM32CubeCLT_1.17.0\STM32CubeProgrammer\bin;

 

> CMD 창을 열어 gcc ( arm-none-eabi-gcc ) 가 실행  되는지 확인 합니다


3. make.exe 설치  ( xPack Windows Build Tools 을 설치 합니다 )

> 다운 받기
https://github.com/xpack-dev-tools/windows-build-tools-xpack/releases/
  에서 

https://github.com/xpack-dev-tools/windows-build-tools-xpack/releases/download/v4.4.1-3/xpack-windows-build-tools-4.4.1-3-win 를 다운 받아

> 적당한데, 압축 풀고 path 에 bin 추가 합니다.  ( 참 :  win11 환경 변수 설정 하기   https://bahk33.tistory.com/182  ) 
> 확인 : CMD 창 띄워 "make --version" 

 


4. vscode 에서 프로젝트 디렉토리 열기

> VS Code 를 실행 하여

> 소스 디렉토리를 오픈 합니다 

    File > Open Folder...   [ Ctrl+K  Ctrl+O ]

 

 


4. "c/c++ for Visual studio code" plugin 을 설치 합니다.  

- C program 할때 보조 기능 입니다.

 


5. "makefile tools" plugin  설치
- make.exe 이용할때 사용

 

 

> 설치 가 끝나면 왼쪽 아래 아이콘이 하나 생긴다

 

 

 

6. ".vscode/settings.json"  만들기

> Vs Code 를 실행 할 때 적용 되는 내용
> ".vscode" 라는  dir 을 만들고, 

> "settings.json" 이라는 파일을 아래와 같이 만들고 저장 합니다.

 
{
    "makefile.configurations": [
        {
            "name": "build",
            "makeArgs": ["-j20"]
        }
    ],
    "makefile.makeDirectory": "Debug",
    "makefile.compileCommandsPath": "Debug/compile_commands.json"
}

 

 

> 파일을 만든뒤 , 위 5에서 설치했던 plugin "makefile tools" 을 설치 할때 생긴 왼쪽 아래 아이콘 을 누르면, 

 

> makefile 설정이 나오는 데 각 값을 확인, 변경 합니다

  file " settings.json" 에서 저장된 값들이 자동으로 나오는 것도 있고, 넣어 줘야 하는 것도 있읍니다.

1) Configuration : [Build]

2) BUild Target: [all]

3)  Make: [E:/_t/_d/_VSCode/xpack-windows-build-tools-4.3.0-1/bin\make.exe"  는 ,  위 3 에서 make.exe 의 경로를 PATH 에 정상 적으로 넣었으면, 자동으로 나옵니다.

 

7. Build 하기

> makefile tool 의 오른쪽 위 점 3개 [...] 를 누르면 나오는 풀다운 메뉴에서

>  "Makefile: Build clean the current Target" 을 선택하면 빌드가 된다.

 

 

> 또는 "Build Target: [all] " 을 마우스 오른쪽 버튼 으로 누르면 나오는 옵션을 선택 해 도 build 됩니다.

 

> 빌드가 성공적으로 끝나면,   ~.elf  와 ~.bin 이 Debug 디렉토리 안에 만들어 지는것을 확인 할 수 있읍니다.

> 참고로 이 Debug directory에 파일 "compile_commands.json" 도 만들어져 있음을 확인 할 수 있읍니다.

 

8.  ./Debug/compile_commands.json 파일 만들기

> 참조, 해더 파일 추적 하기 위하여 만듭니다.

> 아래 내용을 넣으셔요

{
    "configurations": [
      {
        "name": "Win32",
        "includePath": ["${myIncludePath}", "${workspaceFolder}/**" ],
        "defines": [
            "${myDefines}", "_DEBUG", "UNICODE"
        ],
        "compilerPath": "E:/_t/_d/_stm/STM32CubeCLT_1.17.0/GNU-tools-for-STM32/bin/arm-none-eabi-gcc.exe",
        "intelliSenseMode": "windows-gcc-x86",
        "configurationProvider": "ms-vscode.makefile-tools",
        "compileCommands": "./Debug/compile_commands.json",
        "cStandard": "c17",
        "cppStandard": "gnu++14",
        "browse": {
          "path": ["${myIncludePath}", "${workspaceFolder}"]
        }
      }
    ],
    "version": 4,
    "enableConfigurationSquiggles": true
}

 

 

> 그러면 변수 디파인 된것을 F12 눌러 찾어 갈수 있읍니다.

 

 

9. Plugin "Cortex-Debug" 를 설치 합니다.

> 이제는 디버그 하기 위한것 입니다.

> Plugin "Cortex-Debug"  를 설치 합니다.

 

 

10. "./.vscode/launch.json" 만들기

> Plugin "Cortex-Debug" 설정 파일 launch.json 을 만듭니다.

> 왼쪽 아래 "Run And Debug"  [Ctrl + Chift + D] 아이콘을 누르고

> "Cortex-Debog" 선택

> "ST-Link" 선택 

 

> 그러면 기본적으로 launch.json 파일을 만들어 줍니다.

> 이것을 아래와 같이 수정 합니다.

 

{
    // 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",
    "configurations": [
        {
            "cwd": "${workspaceRoot}",
            "executable": "./Debug/plasma2023.elf",
            "name": "Debug Prj1",
            "request": "launch",
            "type": "cortex-debug",
            "showDevDebugOutput": "none",
            "servertype": "stlink",
            "windows": {
                "serverpath":  "E:/_t/_d/_stm/STM32CubeCLT_1.17.0/STLink-gdb-server/bin/ST-LINK_gdbserver.exe",
                "stm32cubeprogrammer": "E:/_t/_d/_stm/STM32CubeCLT_1.17.0/STM32CubeProgrammer/bin",
                "svdFile": "E:/_t/_d/_stm/STM32CubeCLT_1.17.0/STMicroelectronics_CMSIS_SVD/STM32F217.svd"
            }
        }
    ]
}

 

> 물론, ~elf 파일명 이나 경로 등은 그 파일들이 설치 된 곳으로 바꾸어 주셔요.

 

11. Debug 실행

> 디버그 아이콘 선택

> 디버그 하고자 하는 거 선택

> 시작 버튼

 

그럼 디버그가 시작 됩니다.

 

 

c_cpp_properties.json
0.00MB
launch.json
0.00MB
settings.json
0.00MB

 

 

 

관련된 큰 파일은

https://1024terabox.com/s/14o6ublK_ChNyk_kNX44mLA

 

에서 받을 수 있읍니다.

 

========================== 
수고 하셨읍니다.
도움이 되셨으면, 댓글 부탁합니다. 댓글 하나에 힘이 됩니다. 

고맙읍니다.