原文出处: http://blog.csdn.net/embbnux/article/details/17619621


之前建立stm32开发环境,程序也已经编译好生成main.bin,接下来就是要把该文件烧录到stm32上.在linux下给arm烧录程序主要使用openocd,这个软件开源,而且支持众多芯片,从ARM9到A8都可以,当然STM32也可以.支持的JTAG工具也很多,JLINK ST-LINK OSBDM都可以,我这正好有一个openjtag基于FT2232C的,也是被支持的.
       个人原创,转载请注明
      参考:
           How-to manual  Installing a toolchain for Cortex-M3/STM32 on Ubuntu   by Peter Seng

一  安装openocd
      在ubuntu下安装openocd

sudo apt-get install openocd

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

二 安装openjtag驱动
      插上openjtag

user@ubuntu:~/$ lsusb
Bus 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 ft2232
ft2232_device_desc "USB<=>JTAG&RS232"
ft2232_layout jtagkey
ft2232_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 4444
gdb_port 3333

#interface configuration openjtag#############################
interface ft2232
ft2232_device_desc "USB<=>JTAG&RS232"
ft2232_layout jtagkey
ft2232_vid_pid 0x1457 0x5118

#board configuration################################################################
# Adjust Work-area size (RAM size) according to MCU in use:
#STM32F103RB --> 20KB
#set WORKAREASIZE 0x5000
#STM32F103ZE --> 64KB
set WORKAREASIZE 0x10000

#target configuration###############################################################
# script for stm32f1x family
if { [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 16kB
if { [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 = 1MHz
adapter_khz 500
adapter_nsrst_delay 100
jtag_ntrst_delay 100
#jtag scan chain
if { [info exists CPUTAPID] } {
set _CPUTAPID $CPUTAPID
} else {
# See STM Document RM0008
# Section 31.6.3
set _CPUTAPID 0x3ba00477
}
jtag newtap $_CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id $_CPUTAPID
if { [info exists BSTAPID] } {
# FIXME this never gets used to override defaults...
set _BSTAPID $BSTAPID
} else {
# See STM Document RM0008
# Section 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 $_BSTAPID9

set _TARGETNAME $_CHIPNAME.cpu
target 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 probed
set _FLASHNAME $_CHIPNAME.flash
flash bank $_FLASHNAME stm32f1x 0x08000000 0 0 0 $_TARGETNAME

# if srst is not fitted use SYSRESETREQ to
# perform a soft reset
cortex_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 v2
For bug reports, read
    http://openocd.sourceforge.net/doc/doxygen/bugs.html
Info : only one transport option; autoselect 'jtag'
adapter speed: 500 kHz
adapter_nsrst_delay: 100
jtag_ntrst_delay: 100
cortex_m3 reset_config sysresetreq
Info : clock speed 500 kHz
Info : 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 halt
flash probe 0
stm32f1x mass_erase 0
flash write_bank 0 /you_stm32_project_dir/main.bin 0
reset run

程序就烧好了,按下reset键,就开始运行了.
 要输入这么多命令太麻烦了,写个perl脚本使它一步运行.
首先安装perl-telnet

sudo apt-get install libnet-telnet-perl

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

#!/usr/bin/perl
use 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的更多相关文章

  1. ubuntu linux下建立stm32开发环境: GCC安装以及工程Makefile建立

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

  2. ubuntu下安装stm32开发环境

    在windowns下开发stm32刚开始学最烦的就是创建工程模板,都不知道为什么要那样设置,而且步骤繁多.现在我告诉大家一个好消息,在linux下配置stm32开发环境包括创建工程,使用JLink仿真 ...

  3. Windows10下配置Linux下C语言开发环境

    今天为大家介绍如在Windows10下配置Linux下C语言开发环境,首先安装linux子系统:启用开发者模式 1.打开设置 2.点击更新和安全3.点击开发者选项 4.启用开发人员模式 5.更改系统功 ...

  4. LibOpenCM3(一) Linux下命令行开发环境配置

    目录 LibOpenCM3(一) Linux下命令行开发环境配置 本文使用 Linux 环境, 硬件为 STM32F103 系列开发板 LibOpenCM3 介绍 LibOpenCM3 是GPL协议( ...

  5. Linux下配置PHP开发环境

    转载于: http://www.uxtribe.com/php/405.html 该站下有系列PHP文章. 在Linux下搭建PHP环境比Windows下要复杂得多.除了安装Apache,PHP等软件 ...

  6. Ubuntu系统下搭建Python开发环境

    之前演示了在Windows中安装Pycharm,很简单.下面介绍一下如何在Ubuntu中安装Pycharm 1.更新Python至3.5.1,执行以下命令: sudo add-apt-reposito ...

  7. Linux下配置Golang开发环境

    前几天无意间看到了微信推送的golang开发的消息,看到golang那么牛逼,突然心血来潮想学习一下go.工欲善其事必先利其器,想做go开发,必须先配置好go的开发环境(就像开发Java先安装配置jd ...

  8. Linux下搭建hadoop开发环境-超详细

    先决条件:开发机器需要联网 已安装java 已安装Desktop组 1.上传安装软件到linux上: 2.安装maven,用于管理项目依赖包:以hadoop用户安装apache-maven-3.0.5 ...

  9. C++14系列(1):Linux下C++14开发环境配置

    g++安装 參考地址: http://sysads.co.uk/2014/07/install-gcc-gnu-4-9-1-on-ubuntu-14-04/ 当前Ubuntu的LTS版本号为14.04 ...

随机推荐

  1. [NOIp2009] $Hankson$ 的趣味题

    类型:数论 传送门:>Here< 题意:给出四个数$a_0,a_1,b_0,b_1$,求满足$gcd(x,a_0)=a_1,lcm(x,b_0)=b_1$的$x$的个数 解题思路 显然$a ...

  2. 解决 phpstorm 运行卡,自动关闭等问题

    解决 phpstorm 自动关闭问题: 使用文件搜索工具(可在本博客搜索“管理工具”,或查找安装目录) 找到phpstorm.vmoptions文件,使用记事本打开. 添加以下两行代码: -Dawt. ...

  3. Hdoj 2188.悼念512汶川大地震遇难同胞——选拔志愿者 题解

    Problem Description 对于四川同胞遭受的灾难,全国人民纷纷伸出援助之手,几乎每个省市都派出了大量的救援人员,这其中包括抢险救灾的武警部队,治疗和防疫的医护人员,以及进行心理疏导的心理 ...

  4. 「HNOI2016」最小公倍数 解题报告

    「HNOI2016」最小公倍数 考虑暴力,对每个询问,处理出\(\le a,\le b\)的与询问点在一起的联通块,然后判断是否是一个联通块,且联通块\(a,b\)最大值是否满足要求. 然后很显然需要 ...

  5. Gym - 100989F

    You must have heard about Agent Mahone! Dr. Ibrahim hired him to catch the cheaters in the Algorithm ...

  6. An Introduction to OAuth 2

    PostedJuly 21, 2014 1.1mviews SECURITY API CONCEPTUAL Mitchell Anicas Introduction OAuth 2 is an aut ...

  7. 【SFA官方翻译】Spring WebFlux和Spring Cloud进行响应式微服务开发

    源码,修正一些错误: https://github.com/bigben0123/sample-spring-cloud-webflux 原创 SpringForAll社区 2018-05-18 作者 ...

  8. LOJ#2722 情报中心

    解:有个暴力是枚举两条链然后O(n)判定,可以得到15分. 还可以优化一下,枚举一条链,然后第二条链直接求两端点树上带权距离.可以做到O(m(n + m)),但是我用的树剖,跟上面那一档没啥区别Orz ...

  9. semantic ui框架学习笔记三

    网格系统 基本网格 <div class="ui grid"> <div class="column"></div> < ...

  10. c#UDP协议

    UDP协议是不可靠的协议,传输速率快 服务器端: using System; using System.Collections.Generic; using System.Linq; using Sy ...