linux环境使用openocd+Jlink烧录stm32

测试环境

  • VM虚拟机Ubuntu20
  • 基于STM32F103C8T6的开发板
  • J-LINK(V9版本)使用SWD调试口和CDC串口
  • 配置使能jlink 并安装好的openocd
  • test.bin烧录固件(简单的串口打印)
  • 任一串口工具(minicom/picocom/putty/cutecom)

操作步骤

将J-LINK连接到ubuntu中

在VMware->可移动设备 选择上Segger J-LINK,连接好后,终端执行命令

lsusb

出现如下SEGGER USB字样表示J-LINK已连接上

image-20210706214236585

接下来确认JLINK的CDC串口也连接上

ls /dev/ttyACM*

image-20210706214612260

配置openocd cfg
cd ~
mkdir test
wget http://mcai.oss-cn-shenzhen.aliyuncs.com/conf/jlink-swd-stm32f10x.cfg
openocd -f jlink-swd-stm32f10x.cfg

出现如下starting gdb server 信息表示已经启动调试

image-20210706221848043

附上jlink-swd-stm32f10x.cfg内容,可以修改更换bin文件名和烧录地址

# openocd setup

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 USART.bin 0x08000000
        reset run
        shutdown
}
# reset target and attach to debug
proc attach {}  {
        init
        reset run
}
烧录

新开一个终端(注意要新开)先下载bin文件

cd ~/test
wget http://mcai.oss-cn-shenzhen.aliyuncs.com/bin/stm32f103c8t6/USART.bin

然后通过telnet连接gdb server

telnet 127.0.0.1 4444

如下可以顺利进入

image-20210706222642261

telnet下输入

halt
program

出现如下,直接输入program无法halt住,最后执行了shutdown退出了telnet,由于bin文件很小烧录很快

image-20210706223851667

验证

使用picocom串口工具,设置波特率115200,串口为/dev/ttyACM0

picocom -b 115200 /dev/ttyACM0

复位目标板,出现“uart loop test ok.”字样表示程序烧录ok

image-20210706224038932

REF参考内容

  • 2
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值