树莓派 st-link master使用ST-LINK V2下载STM32程序 支持F0 F1 F2 等
這段時間在研究怎么脫機實現STM32的下載,同時也了解了Windows和Linux的下載方式,st官方只提供了Windows的下載工具,Linux的版本并未提供,這里網上搜索后找到了st-link master這個Linux的工具,未提供bin文件,是開源的軟件可以直接下載編譯(git clone https://github.com/texane/stlink stlink.git),如果沒有git那么瀏覽器訪問https://github.com/texane/stlink進行下載。
我使用的是Ubuntu14.04 64位版系統,編譯過程簡單,如下:
./autogen.sh?
./configure
make
如果第一步都不通過,使用下面的命令安裝工具:
sudo apt-get install autoconf automake libtool
安裝后如果提示libusb的版本低,使用:sudo apt-get install libusb-1.0安裝即可。
還有一個USB的配置文件需要拷貝到系統中,文件是49-stlinkv2.rules,拷貝到的位置是:/etc/udev/rules.d/
然后重啟udev即可。
成功下載STM32程序如下所示:下載的命令是:st-flash write stm32.bin 0x8000000
2015-08-25T16:43:27 INFO src/stlink-common.c: Loading device parameters.... 2015-08-25T16:43:27 INFO src/stlink-common.c: Device connected is: F2 device, id 0x201f6411 2015-08-25T16:43:27 INFO src/stlink-common.c: SRAM size: 0x20000 bytes (128 KiB), Flash: 0x80000 bytes (512 KiB) in pages of 131072 bytes 2015-08-25T16:43:27 INFO src/stlink-common.c: Attempting to write 155420 (0x25f1c) bytes to stm32 address: 134217728 (0x8000000) EraseFlash - Sector:0x0 Size:0x4000 Flash page at addr: 0x08000000 erasedEraseFlash - Sector:0x1 Size:0x4000 Flash page at addr: 0x08004000 erasedEraseFlash - Sector:0x2 Size:0x4000 Flash page at addr: 0x08008000 erasedEraseFlash - Sector:0x3 Size:0x4000 Flash page at addr: 0x0800c000 erasedEraseFlash - Sector:0x4 Size:0x10000 Flash page at addr: 0x08010000 erasedEraseFlash - Sector:0x5 Size:0x20000 Flash page at addr: 0x08020000 erased 2015-08-25T16:43:31 INFO src/stlink-common.c: Finished erasing 6 pages of 131072 (0x20000) bytes 2015-08-25T16:43:31 INFO src/stlink-common.c: Starting Flash write for F2/F4/L4 2015-08-25T16:43:31 INFO src/stlink-common.c: Successfully loaded flash loader in sram enabling 32-bit flash writes size: 32768 size: 32768 size: 32768 size: 32768 size: 24348 2015-08-25T16:43:35 INFO src/stlink-common.c: Starting verification of write complete 2015-08-25T16:43:37 INFO src/stlink-common.c: Flash written and verified! jolly good! burn application successfully.既然Ubuntu可以實現下載,那么同為Linux的樹莓派是不是也可以下載呢,為此又開始了使用樹莓派來下載程序,代替電腦,這個對于批量生產來說比較好用,開始整。
首先Ubuntu下的st-flash等工具是不能再樹莓派上使用的,有這想法的放棄吧,平臺架構都不一樣。為此唯一的辦法就是讓樹莓派自己編譯(想用Ubuntu編譯arm版本的可執行文件?我試了,很麻煩,最后也沒搞定),拷貝st-link master源碼到樹莓派(注意,一定要是原封的源碼,自己未做修改的,就是直接下載下來的那個源碼),解壓進入配置,編譯安裝。
配置編譯安裝的方法同上,沒有什么區別。
最后也成功了,下載的界面同上。
這里也有一個問題,Ubuntu和樹莓派都存在,就是如果stm32在運行中下載程序的話,會失敗,具體的打印如下:
2015-08-25T17:23:21 INFO src/stlink-common.c: Loading device parameters.... 2015-08-25T17:23:21 INFO src/stlink-common.c: Device connected is: F2 device, id 0x201f6411 2015-08-25T17:23:21 INFO src/stlink-common.c: SRAM size: 0x20000 bytes (128 KiB), Flash: 0x80000 bytes (512 KiB) in pages of 131072 bytes 2015-08-25T17:23:21 INFO src/stlink-common.c: Attempting to write 155420 (0x25f1c) bytes to stm32 address: 134217728 (0x8000000) EraseFlash - Sector:0x0 Size:0x4000 Flash page at addr: 0x08000000 erasedEraseFlash - Sector:0x1 Size:0x4000 Flash page at addr: 0x08004000 erasedEraseFlash - Sector:0x2 Size:0x4000 Flash page at addr: 0x08008000 erasedEraseFlash - Sector:0x3 Size:0x4000 Flash page at addr: 0x0800c000 erasedEraseFlash - Sector:0x4 Size:0x10000 Flash page at addr: 0x08010000 erasedEraseFlash - Sector:0x5 Size:0x20000 Flash page at addr: 0x08020000 erased 2015-08-25T17:23:24 INFO src/stlink-common.c: Finished erasing 6 pages of 131072 (0x20000) bytes 2015-08-25T17:23:24 INFO src/stlink-common.c: Starting Flash write for F2/F4/L4 2015-08-25T17:23:24 INFO src/stlink-common.c: Successfully loaded flash loader in sram enabling 32-bit flash writes size: 32768 size: 32768 size: 32768 size: 32768 size: 24348 2015-08-25T17:23:28 INFO src/stlink-common.c: Starting verification of write complete 2015-08-25T17:23:28 ERROR src/stlink-common.c: Verification of flash failed at offset: 0 stlink_fwrite_flash() == -1 查了燒寫進的程序前16字節有處有變化,暫時不清楚什么導致的,以后再說,只要是沒有運行程序就沒有問題,這個真是奇葩。
總結
以上是生活随笔為你收集整理的树莓派 st-link master使用ST-LINK V2下载STM32程序 支持F0 F1 F2 等的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ubuntu14.04管理员密码忘记的解
- 下一篇: NTRIP/ SUPL