Ubuntu16.04下的stm32环境配置

安装stlink

必须安装libusb-1.0-0-dev, 其他安装不起作用

sudo apt-get install libusb-1.0-0-dev
git clone https://github.com/texane/stlink.git
cd stlink/
make clean
make
cd build/Release/
sudo make install


安装openocd

tar zxvf openocd-0.10.0.tar.gz
cd openocd-0.10.0/
./configure
make
sudo make install

Update 2018-05-11: 在Ubuntu18.04下, 无法使用tar包编译安装, 如果带 --enable-stlink会报错误 configure: error: libusb-1.x is required for the ST-Link JTAG Programmer, 但是不带这个参数一样无法通过编译, 经apt-cache show openocd发现版本是 0.10.0-4, 于是直接通过apt-get install安装

安装 gcc-arm-none-eabi

tar xvf gcc-arm-none-eabi-5_4-2016q3-20160926-linux.tar.bz2
cd /opt/
sudo mkdir gcc-arm
cd gcc-arm/
sudo mv ~/Backup/linux/gcc-arm-none-eabi-5_4-2016q3/ .
sudo chown -R root:root gcc-arm-none-eabi-5_4-2016q3/
/opt/gcc-arm/gcc-arm-none-eabi-5_4-2016q3/bin/arm-none-eabi-gcc -v

Update 2018-05-11: 在Ubuntu18.04下, 自带的版本是 Version: 15:6.3.1+svn253039-1build1, 这个应该是比2016q4还更新的版本, 从官方下载的版本是 https://armkeil.blob.core.windows.net/developer/Files/downloads/gnu-rm/7-2017q4/gcc-arm-none-eabi-7-2017-q4-major-linux.tar.bz2 . 使用2017q4这个版本编译安装后工作正常


将gcc-arm-none-eabi executables添加到PATH

edit ~/.profile, edit the last line

PATH="$HOME/bin:$HOME/.local/bin:/opt/gcc-arm/gcc-arm-none-eabi-5_4-2016q3/bin/:$PATH"

then run: source .prifle to make it take effect

硬件准备

.

硬件连接
st-link pin to STM32F103C8T6 mini board(SWD)
GND     G
SWCLK   CLK
SWDIO   IO
3.3V    V3

连接到PC后的dmesg输出

[10371.046367] usb 2-1.2: new full-speed USB device number 3 using ehci-pci
[10371.157440] usb 2-1.2: New USB device found, idVendor=0483, idProduct=3748
[10371.157448] usb 2-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[10371.157453] usb 2-1.2: Product: STM32 STLink
[10371.157457] usb 2-1.2: Manufacturer: STMicroelectronics
[10371.157461] usb 2-1.2: SerialNumber: VÿkIfHV'Fg


写入

$:~/ArmProjects/simple-gcc-stm32-project$ openocd -f /usr/local/share/openocd/scripts/interface/stlink-v2.cfg  -f /usr/local/share/openocd/scripts/target/stm32f1x.cfg -c init -c halt -c "flash write_image erase LED_project.hex" -c reset -c shutdown
Open On-Chip Debugger 0.10.0
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 '.
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 v21 API v2 SWIM v4 VID 0x0483 PID 0x3748
Info : using stlink api v2
Info : Target voltage: 3.256122
Info : stm32f1x.cpu: hardware has 6 breakpoints, 4 watchpoints
target halted due to debug-request, current mode: Thread
xPSR: 0x61000000 pc: 0x0800026e msp: 0x200003f0
auto erase enabled
Info : device id = 0x20036410
Info : flash size = 64kbytes
target halted due to breakpoint, current mode: Thread
xPSR: 0x61000000 pc: 0x2000003a msp: 0x200003f0
wrote 7168 bytes from file LED_project.hex in 0.431739s (16.213 KiB/s)
shutdown command invoked

.

你可能感兴趣的:(Ubuntu16.04下的stm32环境配置)