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 <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 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

.


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM