最靠谱的UBUNTU下配置STM32+stlinkV2开发环境

5 篇文章 0 订阅
2 篇文章 0 订阅

1. 安装固件库

建立安装目录

2. 安装cubemx,这个可以自动生成对应项目的makefile,墙裂推荐

先要安装oracle jre

Java Downloads | Oracle

需注册登录

JRE没看出有什么用?待确认

STM32CUBEMX下载目录,需注册或登录

STM32CubeMX - STM32Cube initialization code generator - STMicroelectronics

配置完,可以在设置选择工程生成样式,选择makefile,就不用为makefile模板揪心了。

生成的工程目录就不用操心makefile和用到的库导入问题了,只需要像keil下开发一样,关注自己编写的代码就可以了

代码的文件结构:

有时间再研究下makefile的编辑和配置

3.stlink驱动安装

github上的实用项目

https://github.com/texane/stlink

git到本地后,make

4. 修改例程,下载运行

按HAL库的编程模式修改代码,在工程目录下make可以生成build目录,下面有elf,hex,bin格式的文件

st-flash可以烧录

hy@hy-ThinkPad-X201:~/st-dev/F103-test/F103-TEST02/build$ st-flash write ./F103-TEST02.bin 0x8000000
st-flash 1.5.1-38-gc3577b5
2019-10-03T10:30:14 INFO common.c: Loading device parameters....
2019-10-03T10:30:14 INFO common.c: Device connected is: F1 Medium-density device, id 0x20036410
2019-10-03T10:30:14 INFO common.c: SRAM size: 0x5000 bytes (20 KiB), Flash: 0x20000 bytes (128 KiB) in pages of 1024 bytes
2019-10-03T10:30:14 INFO common.c: Attempting to write 2860 (0xb2c) bytes to stm32 address: 134217728 (0x8000000)
Flash page at addr: 0x08000800 erased
2019-10-03T10:30:14 INFO common.c: Finished erasing 3 pages of 1024 (0x400) bytes
2019-10-03T10:30:14 INFO common.c: Starting Flash write for VL/F0/F3/F1_XL core id
2019-10-03T10:30:14 INFO flash_loader.c: Successfully loaded flash loader in sram
  3/3 pages written
2019-10-03T10:30:14 INFO common.c: Starting verification of write complete
2019-10-03T10:30:14 INFO common.c: Flash written and verified! jolly good!
hy@hy-ThinkPad-X201:~/st-dev/F103-test/F103-TEST02/build$

这之后的工作有两条:

目前用sublime作为编辑器也挺好用,轻量化,速度快,不过后续为了提高效率,考虑在eclipse下导入stm32插件,得到IDE的便利;

研究makefile的配置,解决更深层次的问题,不过感觉意义不是很大

4.工程生成和编译下载都搞定了,接下来还要搞定调试

命令行调试,启动gdb server 有两种方式

st-link驱动自带的st-util:

hy@hy-ThinkPad-X201:~$ st-util
st-util 1.5.1-38-gc3577b5
2019-10-04T02:05:06 INFO common.c: Loading device parameters....
2019-10-04T02:05:06 INFO common.c: Device connected is: F1 Medium-density device, id 0x20036410
2019-10-04T02:05:06 INFO common.c: SRAM size: 0x5000 bytes (20 KiB), Flash: 0x20000 bytes (128 KiB) in pages of 1024 bytes
2019-10-04T02:05:06 INFO gdb-server.c: Chip ID is 00000410, Core ID is  1ba01477.
2019-10-04T02:05:06 INFO gdb-server.c: Listening at *:4242...


主要端口是4242,不知道为什么一定要把所有窗口关了,才能正常运行

设置st-link介入usb端口的命令: export STLINK_DEVICE=001:002(lsusb命令看到的bus和dev)

另外一个方式是调用openocd

openocd -f /usr/share/openocd/scripts/interface/stlink-v2.cfg -f /usr/share/openocd/scripts/target/stm32f1x.cfg
Open On-Chip Debugger 0.9.0 (2018-01-24-01:05)
Licensed under GNU GPL v2
For bug reports, read
    http://openocd.org/doc/doxygen/bugs.html
Info : auto-selecting first available session transport "hla_swd". To override use 'transport select <transport>'.
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
adapter speed: 1000 kHz
adapter_nsrst_delay: 100
none separate
Info : Unable to match requested speed 1000 kHz, using 950 kHz
Info : Unable to match requested speed 1000 kHz, using 950 kHz
Info : clock speed 950 kHz
Info : STLINK v2 JTAG v17 API v2 SWIM v4 VID 0x0483 PID 0x3748
Info : using stlink api v2
Info : Target voltage: 3.227913
Info : stm32f1x.cpu: hardware has 6 breakpoints, 4 watchpoints


然后在elf文件目录载入调试文件:

~/st-dev/F103-test/F103-TEST01/build$ arm-none-eabi-gdb F103-TEST01.elf
GNU gdb (7.10-1ubuntu3+9) 7.10
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-linux-gnu --target=arm-none-eabi".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from F103-TEST01.elf...done.
(gdb)


链接gdbserver:

(gdb) target remote localhost:3333
Remote debugging using localhost:3333
0x00000000 in ?? ()
(gdb)

接下来就可以用gdb命令调试了。

疑问是:为什么需要 boot0拉高才能正常启动st-util或st-flash等应用?发现按下复位键也可以

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

海里的鱼2022

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值