Ubuntu20.04+eclipse+jlink(openocd+SWD)+arm-none-eabi-gcc+STM32开发环境搭建
文件eclipse-cpp-2020-12-R-linux-gtk-x86_64.tar.gz
链接https://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/2020-12/R/eclipse-cpp-2020-12-R-linux-gtk-x86_64.tar.gz
安装sudo tar -xvf eclipse-cpp-2020-12-R-linux-gtk-x86_64.tar.gz -C /opt/
eclipse桌面快捷方式
gedit /home/hw/Desktop/eclipse.desktop,其中hw 是用户名
写入
[Desktop Entry]
Name=eclipse
Type=Application
Exec=/opt/eclipse/eclipse
Terminal=false
Icon=/opt/eclipse/icon.xpm
Comment=Integrated Development Environment
NoDisplay=false
Categories=Development;IDE;
Name[en]=eclipse
保存文件并关闭
右键,Allow launching
eclipse桌面快捷方式新建完成
文件gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux.tar.bz2
链接https://armkeil.blob.core.windows.net/developer/Files/downloads/gnu-rm/10-2020q4/gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux.tar.bz2
安装 sudo tar -xvf gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux.tar.bz2 -C /opt/
文件JLink_Linux_V672c_x86_64.deb
链接https://www.segger.com/downloads/jlink/JLink_Linux_x86_64.deb
安装依赖 sudo apt install libncurses5
安装sudo dpkg -i JLink_Linux_V672c_x86_64.deb
sudo apt install openocd
至此所需要的程序安装完毕。
eclipse→help → install new software…
Work with下拉选择 –All Available Sites-- ,等待载入软件列表
选中Mobile and Device Development,并安装软件包,软件包安装进度可在右下角查看,等待完成安装,并重启eclipse。
File → New → All → C Managed Build,下一步
输入project name,如stm32-test,选择目标芯片工程,以STM32F1xxC/C++ Project为例
配置芯片资源及工程选项,以STM32F103为例,不使用system calls,不跟踪调试输出
选择交叉编译链,编译链名称选择GNU Tools for ARM Embedded Processors (arm-none-eabi-gcc),编译链路径/opt/gcc-arm-none-eabi-10-2020-q4-major/bin
完成新建工程
可是点击CMSIS Packs,并刷新包列表使用
工程名称stm32-test右键单击,Build Project,如果编译出错,修复错误项目
在工程Debug目录下新建openocd-jlink-swd.cfg配置文件,写入
source [find interface/jlink.cfg]
transport select swd
source [find target/stm32f1x.cfg]
# write image and restart target
proc program () {
init
reset init
halt
flash write_image erase stm32-test.hex 0x08000000
reset run
shutdown
}
# reset target and attach to debug
proc attach () {
init
reset run
}
保存并关闭
确定openocd路径,which openocd,如 /usr/bin/openocd
Run → Run Configurations,打开配置对话框
双击GDB OpenOCD Debugging配置选项,新建调试配置
在Debugger选项卡中Actual executable:/undefined_path/openocd点击global更改openocd命令路径,填入openocd命令路径/usr/bin/,Config options中填入-f Debug/openocd-jlink-swd.cfg
在Common选项卡中选中Debug和Run,应用更改并关闭
点击Debug图标即可进行程序调试