STM32 임베디드 개발을 위한 통합 개발 환경을 구축합니다. STM32CubeMX로 프로젝트를 생성하고, GCC 컴파일러로 빌드하며, OpenOCD를 통해 디버깅하는 전체 워크플로우를 익힙니다.
# 1. ARM GCC 설치 확인
arm-none-eabi-gcc --version
# 2. OpenOCD 설치 확인
openocd --version
# 3. Make 도구 설치 (MinGW 또는 GNU Make)
make --version
# ARM GCC 툴체인 설치
sudo apt-get install gcc-arm-none-eabi
# OpenOCD 설치
sudo apt-get install openocd
# Make 설치
sudo apt-get install build-essential
System Core → RCC
- High Speed Clock (HSE): Crystal/Ceramic Resonator
System Core → SYS
- Debug: Serial Wire
Clock Configuration
- HCLK: 168MHz (최대 클럭)
Project Manager → Project
- Project Name: led_blink
- Toolchain/IDE: Makefile
Project Manager → Code Generator
- Generate peripheral initialization as a pair of '.c/.h' files per peripheral
cd led_blink
code .
.vscode/tasks.json 파일 생성:
{
"version": "2.0.0",
"tasks": [
{
"label": "Build",
"type": "shell",
"command": "make",
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": ["$gcc"]
},
{
"label": "Clean",
"type": "shell",
"command": "make clean"
},
{
"label": "Flash",
"type": "shell",
"command": "openocd -f interface/stlink.cfg -f target/stm32f4x.cfg -c 'program build/led_blink.elf verify reset exit'",
"dependsOn": ["Build"]
}
]
}
.vscode/launch.json 파일 생성:
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug (OpenOCD)",
"type": "cortex-debug",
"request": "launch",
"servertype": "openocd",
"cwd": "${workspaceRoot}",
"executable": "${workspaceRoot}/build/led_blink.elf",
"configFiles": [
"interface/stlink.cfg",
"target/stm32f4x.cfg"
],
"svdFile": "${workspaceRoot}/STM32F407.svd"
}
]
}
.vscode/c_cpp_properties.json 파일 생성:
{
"configurations": [
{
"name": "STM32",
"includePath": [
"${workspaceFolder}/Core/Inc",
"${workspaceFolder}/Drivers/STM32F4xx_HAL_Driver/Inc",
"${workspaceFolder}/Drivers/CMSIS/Device/ST/STM32F4xx/Include",
"${workspaceFolder}/Drivers/CMSIS/Include"
],
"defines": [
"STM32F407xx",
"USE_HAL_DRIVER"
],
"compilerPath": "/usr/bin/arm-none-eabi-gcc",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-arm"
}
],
"version": 4
}
위의 환경설정은 STM32CubeIDE를 사용하지 않고 VScode에서 STM32를 개발하고자 할 때 필요한 파일들로, STM32CubeIDE를 사용하는 이용자라면 스킵하셔도 됩니다.
make
출력 예시:
arm-none-eabi-gcc build/main.o ... -o build/led_blink.elf
arm-none-eabi-size build/led_blink.elf
text data bss dec hex filename
4824 108 1572 6504 1968 build/led_blink.elf
build/led_blink.elf: 실행 파일build/led_blink.bin: 바이너리 파일build/led_blink.hex: HEX 파일openocd -f interface/stlink.cfg -f target/stm32f4x.cfg \
-c "program build/led_blink.elf verify reset exit"
출력 예시:
Info : stm32f4x.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : Listening on port 3333 for gdb connections
target halted due to debug-request
...
** Programming Finished **
** Verify Started **
** Verified OK **
** Resetting Target **
Ctrl+Shift+P → Tasks: Run TaskCore/Src/main.c 파일의 main() 함수에 브레이크포인트 설정
F5 키 또는 Debug 패널에서 시작# PATH 환경 변수 확인
echo $PATH
# ARM GCC 경로 추가 (예시)
export PATH=$PATH:/usr/local/gcc-arm-none-eabi/bin
# ST-Link 드라이버 확인 (Windows)
# libusb 설치 확인 (Linux)
sudo apt-get install libusb-1.0-0-dev
# 권한 문제 (Linux)
sudo usermod -a -G plugdev $USER
오늘은 STM32 개발을 위한 기본 환경을 구축했습니다. 다음 시간에는 GPIO를 사용해 LED를 제어하는 첫 번째 프로그램을 작성하겠습니다.