Skip to content

EngineerMark-C/stm32-opensource-env

Repository files navigation

STM32开源开发环境搭建

这是一个使用开源工具链的STM32开发环境配置方案。本项目使用CMake, ARM GCC工具链和OpenOCD调试工具,实现了STM32单片机的编程开发全流程。

开发环境

  • Visual Studio Code
  • arm-none-eabi-gcc
  • CMake
  • make
  • OpenOCD
  • STLink驱动

目录结构

.
├── build
│   ├── CMakeFiles
│   │   ├── 3.31.3/
│   │   ├── pkgRedirects
│   │   ├── Project.elf.dir/
│   │   ├── cmake.check_cache
│   │   ├── CMakeConfigureLog.yaml
│   │   ├── CMakeDirectoryInformation.cmake
│   │   ├── Makefile.cmake
│   │   ├── Makefile2
│   │   ├── progress.marks
│   │   └── TargetDirectories.txt
│   ├── cmake_install.cmake
│   ├── CMakeCache.txt
│   ├── compile_commands.json
│   ├── Makefile
│   ├── Project.bin
│   ├── Project.elf
│   └── Project.hex
├── CORE
│   ├── core_cm3.c
│   ├── core_cm3.h
│   ├── startup_stm32f10x_md.s
│   ├── STM32F103C8Tx_FLASH.ld
│   ├── stm32f10x.h
│   ├── system_stm32f10x.c
│   └── system_stm32f10x.h
├── Hardware    //个人代码
│   ├── OLED_Font.h
│   ├── OLED.c
│   ├── OLED.h
│   ├── serial.c
│   └── serial.h
├── STM32F10x_StdPeriph_Driver   //STM32固件库
│   ├── inc
│   │   ├── misc.h
│   │   ├── stm32f10x_adc.h
│   │   ├── stm32f10x_bkp.h
│   │   ├── stm32f10x_can.h
│   │   ├── stm32f10x_cec.h
│   │   ├── stm32f10x_crc.h
│   │   ├── stm32f10x_dac.h
│   │   ├── stm32f10x_dbgmcu.h
│   │   ├── stm32f10x_dma.h
│   │   ├── stm32f10x_exti.h
│   │   ├── stm32f10x_flash.h
│   │   ├── stm32f10x_fsmc.h
│   │   ├── stm32f10x_gpio.h
│   │   ├── stm32f10x_i2c.h
│   │   ├── stm32f10x_iwdg.h
│   │   ├── stm32f10x_pwr.h
│   │   ├── stm32f10x_rcc.h
│   │   ├── stm32f10x_rtc.h
│   │   ├── stm32f10x_sdio.h
│   │   ├── stm32f10x_spi.h
│   │   ├── stm32f10x_tim.h
│   │   ├── stm32f10x_usart.h
│   │   └── stm32f10x_wwdg.h
│   ├── src
│   │   ├── misc.c
│   │   ├── stm32f10x_adc.c
│   │   ├── stm32f10x_bkp.c
│   │   ├── stm32f10x_can.c
│   │   ├── stm32f10x_cec.c
│   │   ├── stm32f10x_crc.c
│   │   ├── stm32f10x_dac.c
│   │   ├── stm32f10x_dbgmcu.c
│   │   ├── stm32f10x_dma.c
│   │   ├── stm32f10x_exti.c
│   │   ├── stm32f10x_flash.c
│   │   ├── stm32f10x_fsmc.c
│   │   ├── stm32f10x_gpio.c
│   │   ├── stm32f10x_i2c.c
│   │   ├── stm32f10x_iwdg.c
│   │   ├── stm32f10x_pwr.c
│   │   ├── stm32f10x_rcc.c
│   │   ├── stm32f10x_rtc.c
│   │   ├── stm32f10x_sdio.c
│   │   ├── stm32f10x_spi.c
│   │   ├── stm32f10x_tim.c
│   │   ├── stm32f10x_usart.c
│   │   └── stm32f10x_wwdg.c
│   └── Release_Notes.html
├── SYSTEM
│   ├── Delay.c
│   ├── Delay.h
│   ├── Timer.c
│   └── Timer.h
├── User
│   ├── main.c
│   ├── stm32f10x_conf.h
│   ├── stm32f10x_it.c
│   └── stm32f10x_it.h
├── CMakeLists.txt
├── keilkill.bat
├── README.md
├── stlink-v2.cfg
├── stlink.cfg
├── STM32F103.svd
└── stm32f1x.cfg

使用方法

  1. 安装所需工具:
  • Visual Studio Code
  • arm-none-eabi-gcc
  • CMake
  • make
  • OpenOCD
  • STLink驱动 推荐使用Scoop安装,方便快捷
  1. scoop下载 以管理员身份打开 Windows Terminal/PowerShell,允许执行本地脚本
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

设置环境变量修改安装路径

$env:SCOOP='D:\Scoop'
$env:SCOOP_GLOBAL='D:\Scoop\Global'

在 Windows Terminal/PowerShell中输入以下命令安装scoop

Invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://get.scoop.sh')

添加相关bucket并安装所需软件

scoop bucket add extras main
scoop install extras/vscode extras/gcc-arm-none-eabi main/cmake main/make main/openocd
  1. 克隆项目
git clone https://github.com/EngineerMark-C/stm32-opensource-env.git
  1. 打开VSCode,安装C/C++和Cortex-Debug插件

  2. 编译项目

mkdir build
cd build
cmake ..
make
  1. 连接STLink
openocd -f stlink-v2.cfg -f stm32f1x.cfg -c "program build/Project.elf verify reset exit"

工程目录下执行该命令实现烧录

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published