Embedded Pi(http://www.coocox.org/epi.html)是CooCox官方专门为Rspberry Pi的爱好者推出的一款扩展板,它板载STM32F103RB处理器,在兼容Arduino接口的同时也扩展了其他接口,丰富了可接入的设备类型,大大扩展了树莓派的控制功能。但是作为一个Linux用户,对STM32下载是件很困扰的事情,因为Embedded Pi的手册中提到可以用SWD接口和ISP方式下载,但是SWD方式下载会需要一个调试器和Windows操作系统!而ISP方式,手册中并没有提到树莓派下的ISP工具!所以提供一种下载方式很有必要,本文主要介绍如何安装并使用树莓派下的ISP工具。
Usage: ./stm32loader.py [-hqVewvr] [-l length] [-p port] [-b baud] [-a addr] [file.bin]
-h This help
-q Quiet
-V Verbose
-e Erase
-w Write
-v Verify
-r Read
-l length Length of read
-p port Serial port (default: /dev/tty.usbserial-ftCYPMYJ)
-b baud Baud speed (default: 115200)
-a addr Target address
In isp mode raspberry pi can programs the MCU onboard via the serial port(JP7-TX1 and JP7-RX1).refer to 3.6.1(in embedded pi manual).
To use this mode,you need to do the following things:
1. you need to set BOOT0 to 1 (high level), and BOOT1 to 0 (low level) – which has been done on hardware. In this case, you only need to press the BOOT0 button to enter this mode when Embedded Pi is powered on.
2. you need to connect raspberry pi's uart to embedded pi's uart1 by wires,show as the image:
Then open a Terminal session, 'cd' to wherever you downloaded STM32Loader and then issue the following command to dowmload bin file to embedded pi.
sudo python stm32loader.py -e -w -v Test.bin
这时,会提示错误,原因是没有安装PySerial 库(系统默认已经安装了python2.7版本,如果你的树莓派没装,需要安装,这里不给安装过程),下面介绍如何安装 PySerial 库 :
Install PySerial
Whatever your operating system, download the .tar.gz install package for PySerial 2.6 from
https://pypi.python.org/pypi/pyserialThis will give you a file called: pyserial-2.6.tar.gz
If you are using windows you need to uncompress this into a folder. Unfortunately, it is not a normal zip file, so you may need to download a tool such as 7-zip (http://www.7-zip.org/).
If you are using a Mac or Linux computer, then open a Terminal session, 'cd' to wherever you downloaded pyserial-2.6.tar.gz and then issue the following command to unpack the installation folder.
- $ tar -xzf pyserial-2.6.tar.gz
The rest of the procedure is the same whatever your operating system. Use you Comamnd Prompt / Terminal session and “cd” into the pyserial-2.6 folder, then run the command:
- sudo python setup.py install
sudo python stm32loader.py -e -w -v Test.bin
如果一直提示“NONE”,请重新执行上面的步骤一(按住boot0,reset MCU)。
如果提示NACK之类的错误,请再次执行这个命令。
This will pre-erase flash, write Test.bin to the flash on the device, and then perform a verification after writing is finished.
如下所示,看到Verification OK表示下载成功。