这段时间在研究怎么脱机实现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下的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字节有处有变化,暂时不清楚什么导致的,以后再说,只要是没有运行程序就没有问题,这个真是奇葩。