ubuntu linux下建立stm32开发环境: 程序烧录 openocd+openjtag

http://blog.csdn.net/embbnux/article/details/17619621

参考:

How-to manual Installing a toolchain for Cortex-M3/STM32 on Ubuntu by Peter Seng

博主最近在电脑上自建了博客,以后会更多的用那个了,欢迎关注访问,里面也有很多有用资源:

http://www.embbnux.com

一 安装openocd

在ubuntu下安装openocd

sudo apt-get install openocd

也可以到官网下载源码包自己编译

二 安装openjtag驱动

插上openjtag

user@ubuntu:~/$ lsusbBus 002 Device 005: ID 093a:2521 Pixart Imaging, Inc. Bus 002 Device 003: ID 1457:5118 First International Computer, Inc. OpenMoko Neo1973 Debug board (V2+)

第二个就是了,记下ID 1457:5118

sudo gedit /etc/udev/rules.d/45-ftdi2232-libftdi.rules

在里面添加

SYSFS{idProduct}=="5118", SYSFS{idVendor}=="1457", MODE="666", GROUP="plugdev"

权限666,使用openocd就不用sudo了.

  sudo /etc/init.d/udev restart

拔下在插上就可以了.

三 使用openocd 连openjtag

JTAG接口配置文件openjtag.cfg.根据JTAG设备不同,修改下面

#interface configuration openjtag#############################interface ft2232ft2232_device_desc "USB<=>JTAG&RS232"ft2232_layout jtagkeyft2232_vid_pid 0x1457 0x5118

可以参考openocd目录下的文件:/usr/share/openocd/scripts/interface,主要是设备ID以及设备名字,可以通过dmesg | grep usb命令查看. 要烧录stm32f103就得有这个设备的相关配置,可以查看/usr/share/openocd/scripts/target/stm32f1x.cfg

这里把两个文件合在一起openocd.cfg

#daemon configuration###############################################################telnet_port 4444gdb_port 3333#interface configuration openjtag#############################interface ft2232ft2232_device_desc "USB<=>JTAG&RS232"ft2232_layout jtagkeyft2232_vid_pid 0x1457 0x5118#board configuration################################################################# Adjust Work-area size (RAM size) according to MCU in use:#STM32F103RB --> 20KB#set WORKAREASIZE 0x5000#STM32F103ZE --> 64KBset WORKAREASIZE 0x10000#target configuration################################################################ script for stm32f1x familyif { [info exists CHIPNAME] } {set _CHIPNAME $CHIPNAME} else {set _CHIPNAME stm32f1x}if { [info exists ENDIAN] } {set _ENDIAN $ENDIAN} else {set _ENDIAN little}# Work-area is a space in RAM used for flash programming# By default use 16kBif { [info exists WORKAREASIZE] } {  set _WORKAREASIZE $WORKAREASIZE} else {  set _WORKAREASIZE 0x4000}# JTAG speed should be <= F_CPU/6. F_CPU after reset is 8MHz, so use F_JTAG = 1MHzadapter_khz 500adapter_nsrst_delay 100jtag_ntrst_delay 100#jtag scan chainif { [info exists CPUTAPID] } { set _CPUTAPID $CPUTAPID} else {# See STM Document RM0008# div 31.6.3  set _CPUTAPID 0x3ba00477}jtag newtap $_CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id $_CPUTAPIDif { [info exists BSTAPID] } {# FIXME this never gets used to override defaults...  set _BSTAPID $BSTAPID} else {# See STM Document RM0008# div 31.6.2# Low density devices, Rev A set _BSTAPID1 0x06412041# Medium density devices, Rev A set _BSTAPID2 0x06410041# Medium density devices, Rev B and Rev Z set _BSTAPID3 0x16410041 set _BSTAPID4 0x06420041# High density devices, Rev A set _BSTAPID5 0x06414041# Connectivity line devices, Rev A and Rev Z set _BSTAPID6 0x06418041# XL line devices, Rev A set _BSTAPID7 0x06430041# VL line devices, Rev A and Z In medium-density and high-density value line devices set _BSTAPID8 0x06420041# VL line devices, Rev A set _BSTAPID9 0x06428041}jtag newtap $_CHIPNAME bs -irlen 5 -expected-id $_BSTAPID1 \-expected-id $_BSTAPID2 -expected-id $_BSTAPID3 \-expected-id $_BSTAPID4 -expected-id $_BSTAPID5 \-expected-id $_BSTAPID6 -expected-id $_BSTAPID7 \-expected-id $_BSTAPID8 -expected-id $_BSTAPID9set _TARGETNAME $_CHIPNAME.cputarget create $_TARGETNAME cortex_m -endian $_ENDIAN -chain-position $_TARGETNAME$_TARGETNAME configure -work-area-phys 0x20000000 -work-area-size $_WORKAREASIZE -work-area-backup 0# flash size will be probedset _FLASHNAME $_CHIPNAME.flashflash bank $_FLASHNAME stm32f1x 0x08000000 0 0 0 $_TARGETNAME# if srst is not fitted use SYSRESETREQ to# perform a soft resetcortex_m reset_config sysresetreq

开始烧录:

< 1 > 在一个终端下执行:

openocd -f openocd.cfg

出现:

Open On-Chip Debugger 0.7.0 (2013-05-15-17:28)Licensed under GNU GPL v2For bug reports, readhttp://openocd.sourceforge.net/doc/doxygen/bugs.htmlInfo : only one transport option; autoselect 'jtag'adapter speed: 500 kHzadapter_nsrst_delay: 100jtag_ntrst_delay: 100cortex_m3 reset_config sysresetreqInfo : clock speed 500 kHzInfo : JTAG tap: stm32f1x.cpu tap/device found: 0x3ba00477 (mfg: 0x23b, part: 0xba00, ver: 0x3)Info : JTAG tap: stm32f1x.bs tap/device found: 0x06414041 (mfg: 0x020, part: 0x6414, ver: 0x0)Info : stm32f1x.cpu: hardware has 6 breakpoints, 4 watchpoints

没有提示出错,就表示连接上STM32了 .如果出现出错,就在开发板上按下RESET 键复位,查看BOOT0和BOOT1有没有设置出错.

< 2 > 在另一个终端下,输入:

telnet localhost 4444

依次输入:

reset haltflash probe 0stm32f1x mass_erase 0flash write_bank 0 /you_stm32_project_dir/main.bin 0reset run

程序就烧好了,按下reset键,就开始运行了.

要输入这么多命令太麻烦了,写个perl脚本使它一步运行.

首先安装perl-telnet

sudo apt-get install libnet-telnet-perl

在工程目录下新建do_flash.pl文件

#!/usr/bin/perluse Net::Telnet;$numArgs = $#ARGV + 1;if($numArgs != 1){   die( "Usage ./do_flash.pl [main.bin] \n");}$file = $ARGV[0];$ip = "127.0.0.1";$port = 4444;$telnet = new Net::Telnet (   Port => $port,   Timeout=>10,   Errmode=>'die',   Prompt =>'/>/');$telnet->open($ip);print $telnet->cmd('reset halt');print $telnet->cmd('flash probe 0');print $telnet->cmd('stm32f1x mass_erase 0');print $telnet->cmd('flash write_bank 0 '.$file.' 0');print $telnet->cmd('reset halt');print $telnet->cmd('exit');print "\n";

在根目录下的Makefile文件里面加入这段语句:

flash:all./do_flash.pl $(TOP)/main.bin  

这样只要,执行make flash就可以直接运行第二步了,方便简介.

你挤进地铁时,西藏的山鹰一直盘旋云端,

ubuntu linux下建立stm32开发环境: 程序烧录 openocd+openjtag

相关文章:

你感兴趣的文章:

标签云: