1. Introduction
使用的是源码安装,参考了[1][2][3]。
2. Requirements
Common requirements
Install the following packages from your package repository:
git
gcc or clang or mingw32-gcc or mingw64-gcc (C-compiler; very likely gcc is already present)
build-essential (on Debian based distros (Debian, Ubuntu))
cmake (3.4.2 or later, use the latest version available from the repository)
rpm (on Debian based distros (Debian, Ubuntu), needed for package build with make package)
libusb-1.0
libusb-1.0-0-dev (development headers for building)
libgtk-3-dev (optional, needed for stlink-gui)
pandoc (optional, needed for generating manpages from markdown)
汇总一下,执行下面这条命令,安装所需要的库:
sudo apt-get install gcc build-essential cmake libusb-1.0 libusb-1.0-0-dev libgtk-3-dev pandoc
(Replace gcc with the intended C-compiler if necessary or leave out any optional package not needed.)
3.Installation
一定要有复制.so 到lib32这一个步骤,不然容易出现ubuntu st-flash undefine "libusb_set_option"的错误,一开始用make install 发现一只有问题,后来换成这种手动安装的方式后,正常的。
# download source code
git clone https://github.com/stlink-org/stlink
cd stlink
# build
cmake .
make
# install
cd bin
sudo cp st-* /usr/local/bin
cd ../lib
sudo cp *.so* /lib32
# add rules
sudo cp stlink/config/udev/rules.d/49-stlinkv* /etc/udev/rules.d/
sudo udevadm control --reload-rules
sudo udevadm trigger
4.flash code
#check if st-link is plugged
sudo st-info --probe
# write hex
sudo st-flash --format ihex write myapp.hex
一般下载一次,会失败,需要刷入两次;
# write bin
sudo st-flash write in.bin 0x8000000 #stm32f4xx
# read bin
st-flash read out.bin 0x8000000 0x1000
# restart
向嵌入式控制器中下载一次,控制器就不运行了,需要重启一下,才能正常工作
sudo st-flash reset
5. gdb debugger
需要truestudio生成一个myapp.elf文件,安装gdb-multiarch[4]
# open gdb server
st-util
gdb-multiarch mmyapp.elf
target extended localhost:4242
load
# use gdb command
step
continue
References
[1] https://freeelectron.ro/installing-st-link-v2-to-flash-stm32-targets-on-linux/
[2] https://github.com/stlink-org/stlink/blob/develop/doc/compiling.md
[3] https://github.com/stlink-org/stlink/blob/develop/doc/tutorial.md