openMSP430之openmsp430-loader

openmsp430-loader

  This simple program allows the user to load the openMSP430 program memory with an executable file (ELF or Intel-HEX format) provided as argument.

  It is typically used in conjunction with ‘make‘ in order to automatically load the program after the compile step (see ‘Makefile‘ from software examples provided with the project‘s FPGA implementation).

  openmsp430-loader.tcl  

  1 #!/usr/bin/tclsh
  2 #------------------------------------------------------------------------------
  3 # File Name: openmsp430-loader.tcl
  4 #------------------------------------------------------------------------------
  5
  6 global omsp_conf
  7 global omsp_info
  8
  9 ###############################################################################
 10 #                            SOURCE LIBRARIES                                 #
 11 ###############################################################################
 12
 13 # Get library path
 14 set current_file [info script]
 15 if {[file type $current_file]=="link"} {
 16     set current_file [file readlink $current_file]
 17 }
 18 set lib_path [file dirname $current_file]/../lib/tcl-lib
 19
 20 # Source library
 21 source $lib_path/dbg_functions.tcl
 22 source $lib_path/dbg_utils.tcl
 23
 25 ###############################################################################
 26 #                            PARAMETER CHECK                                  #
 27 ###############################################################################
 28 #proc GetAllowedSpeeds
 29
 30 proc help {} {
 31     puts ""
 32     puts "USAGE   : openmsp430-loader.tcl \[-device   <communication port>\]"
 33     puts "                                \[-adaptor  <adaptor type>\]"
 34     puts "                                \[-speed    <communication speed>\]"
 35     puts "                                \[-i2c_addr <cpu address>\]           <elf/ihex-file>"
 36     puts ""
 37     puts "DEFAULT : <communication port>  = /dev/ttyUSB0"
 38     puts "          <adaptor type>        = uart_generic"
 39     puts "          <communication speed> = 115200 (for UART) / I2C_S_100KHZ (for I2C)"
 40     puts "          <core address>        = 42"
 41     puts ""
 42     puts "EXAMPLES: openmsp430-loader.tcl -device /dev/ttyUSB0 -adaptor uart_generic -speed 9600  leds.elf"
 43     puts "          openmsp430-loader.tcl -device COM2:        -adaptor i2c_usb-iss  -speed I2C_S_100KHZ -i2c_addr 75 ta_uart.ihex"
 44     puts ""
 45 }
 46
 47 # Default values
 48 set omsp_conf(interface)  uart_generic
 49 set omsp_conf(device)     /dev/ttyUSB0
 50 set omsp_conf(baudrate)   [lindex [GetAllowedSpeeds] 1]
 51 set omsp_conf(0,cpuaddr)  42
 52 set elf_file              -1
 53 set bin_file              "[clock clicks].bin"
 54
 55 # Parse arguments
 56 for {set i 0} {$i < $argc} {incr i} {
 57     switch -exact -- [lindex $argv $i] {
 58         -device   {set omsp_conf(device)    [lindex $argv [expr $i+1]]; incr i}
 59         -adaptor  {set omsp_conf(interface) [lindex $argv [expr $i+1]]; incr i}
 60         -speed    {set omsp_conf(baudrate)  [lindex $argv [expr $i+1]]; incr i}
 61         -i2c_addr {set omsp_conf(0,cpuaddr) [lindex $argv [expr $i+1]]; incr i}
 62         default   {set elf_file             [lindex $argv $i]}
 63     }
 64 }
 65
 66 # Make sure arugments were specified
 67 if {[string eq $elf_file -1]} {
 68     puts "\nERROR: ELF/IHEX file isn‘t specified"
 69     help
 70     exit 1
 71 }
 72
 73 # Make sure the elf file exists
 74 if {![file exists $elf_file]} {
 75     puts "\nERROR: Specified ELF/IHEX file doesn‘t exist"
 76     help
 77     exit 1
 78 }
 79
 80 # Make sure the selected adptor is valid
 81 if {![string eq $omsp_conf(interface) "uart_generic"] &
 82     ![string eq $omsp_conf(interface) "i2c_usb-iss"]} {
 83     puts "\nERROR: Specified adaptor is not valid (should be \"uart_generic\" or \"i2c_usb-iss\")"
 84     help
 85     exit 1
 86 }
 87
 88 # Make sure the I2C address is an integer
 89 if {![string is integer $omsp_conf(0,cpuaddr)]} {
 90     puts "\nERROR: Specified I2C address is not an integer"
 91     help
 92     exit 1
 93 }
 94
 95 # Make sure the I2C address is valid
 96 if {($omsp_conf(0,cpuaddr)<8) | ($omsp_conf(0,cpuaddr)>119)} {
 97     puts "\nERROR: Specified I2C address should lay between 7 and 120"
 98     help
 99     exit 1
100 }
101
102 # If the selected interface is a UART, make sure the selected speed is an integer
103 if {[string eq $omsp_conf(interface) "uart_generic"]} {
104     if {![string is integer $omsp_conf(baudrate)]} {
105         puts "\nERROR: Specified UART communication speed is not an integer"
106         help
107         exit 1
108     }
109 } elseif {[string eq $omsp_conf(interface) "i2c_usb-iss"]} {
110     if {[lsearch [lindex [GetAllowedSpeeds] 2] $omsp_conf(baudrate)]==-1} {
111         puts "\nERROR: Specified I2C communication speed is not valid."
112         puts "         Allowed values are:"
113         foreach allowedVal [lindex [GetAllowedSpeeds] 2] {
114             puts "                              - $allowedVal"
115         }
116         puts ""
117         exit 1
118     }
119 }
120
122 ###############################################################################
123 #                  CREATE AND READ BINARY EXECUTABLE FILE                     #
124 ###############################################################################
125
126 # Detect the file format depending on the fil extention
127 set fileType [file extension $elf_file]
128 set fileType [string tolower $fileType]
129 regsub {\.} $fileType {} fileType
130 if {![string eq $fileType "ihex"] & ![string eq $fileType "hex"] & ![string eq $fileType "elf"]} {
131     puts "\nERROR: [string toupper $fileType] file format not supported"
132     return 0
133 }
134 if {[string eq $fileType "hex"]} {
135     set fileType "ihex"
136 }
137 if {[string eq $fileType "elf"]} {
138     set fileType "elf32-msp430"
139 }
140
141 # Generate binary file
142 if {[catch {exec msp430-objcopy -I $fileType -O binary $elf_file $bin_file} errMsg]} {
143     puts $errMsg
144     exit 1
145 }
146
147 # Wait until bin file is present on the filesystem
148 set timeout 100
149 for {set i 0} {$i <= $timeout} {incr i} {
150     after 500
151     if {[file exists $bin_file]} {
152         break
153     }
154 }
155 if {$i>=$timeout} {
156     puts "\nTimeout: ELF to BIN file conversion problem with \"msp430-objcopy\" executable"
157     puts "$errMsg"
158     exit 1
159 }
160
161 # Read file
162 set fp [open $bin_file r]
163 fconfigure $fp -translation binary
164 binary scan [read $fp] H* hex_data yop
165 close $fp
166
167 # Cleanup
168 file delete $bin_file
169
170 # Get program size
171 set hex_size  [string length $hex_data]
172 set byte_size [expr $hex_size/2]
173 set word_size [expr $byte_size/2]
174
175 # Format data
176 for {set i 0} {$i < $hex_size} {set i [expr $i+4]} {
177     set hex_msb "[string index $hex_data [expr $i+2]][string index $hex_data [expr $i+3]]"
178     set hex_lsb "[string index $hex_data [expr $i+0]][string index $hex_data [expr $i+1]]"
179     lappend DataArray "0x$hex_msb$hex_lsb"
180 }
181
183 ###############################################################################
184 #                      LOAD PROGRAM TO OPENMSP430 TARGET                      #
185 ###############################################################################
186
187 # Connect to target and stop CPU
188 puts            ""
189 puts -nonewline "Connecting with the openMSP430 ($omsp_conf(device), $omsp_conf(baudrate)\ bps)... "
190 flush stdout
191 if {![GetDevice 0]} {
192     puts "failed"
193     puts "Could not open $omsp_conf(device)"
194     puts "Available serial ports are:"
195     foreach port [utils::uart_port_list] {
196     puts "                             -  $port"
197     }
198     if {[string eq $omsp_conf(interface) "i2c_usb-iss"]} {
199         puts "\nMake sure the specified I2C device address is correct: $omsp_conf(0,cpuaddr)\n"
200     }
201     exit 1
202 }
203 ExecutePOR_Halt 0
204 puts "done"
205 set sizes [GetCPU_ID_SIZE 0]
206
207 if {$omsp_info(0,alias)!=""} {
208     puts "Connected: target device identified as $omsp_info(0,alias)."
209 }
210 puts "Connected: target device has [lindex $sizes 0]B Program Memory and [lindex $sizes 1]B Data Memory"
211 puts ""
212
213 # Make sure ELF program size is the same as the available program memory
214 if {[lindex $sizes 0] != [expr $hex_size/2]} {
215     puts "ERROR: ELF program size ($byte_size B) is different than the available program memory ([lindex $sizes 0] B)"
216     exit 1
217 }
218
219 # Load Program Memory
220 set StartAddr [format "0x%04x" [expr 0x10000-$byte_size]]
221 puts -nonewline "Load Program Memory... "
222 flush stdout
223 WriteMemQuick 0 $StartAddr $DataArray
224 after 500
225 puts "done"
226
227 # Check Data
228 puts -nonewline "Verify Program Memory... "
229 flush stdout
230 if {[VerifyMem 0 $StartAddr $DataArray 1]} {
231     puts "done"
232 } else {
233     puts "ERROR"
234     exit 1
235 }
236
237 # Release device
238 ReleaseDevice 0 0xfffe
时间: 2024-09-20 16:41:58

openMSP430之openmsp430-loader的相关文章

openMSP430之instruction

Byte and word issues 1 Appending “.b” to an instruction makes it a byte operation. A byte instruction with a register destination clears the high 8 bits of the register to 0. Thus, the following would clear the top byte of the register, leaving the l

Loader详解

1.装载器API概述 Class/Interface 说明 LoaderManager 一个抽像类,关联到一个Activity或Fragment,管理一个或多个装载器的实例.这帮助一个应用管理那些与Activity或Fragment的生命周期相关的长时间运行的的操作.最常见的方式是与一个CursorLoader一起使用,然而应用是可以随便写它们自己的装载器以加载其它类型的数据. 每个activity或fragment只有一个LoaderManager.但是一个LoaderManager可以拥有多

webpack加载postcss,以及autoprefixer的loader

webpack2.0加载postcssloader以及autoprefixer实现自动根据兼容性的需求给css加私有前缀的功能,给开发带来便利, 下面是我的配置信息,亲测有效: 1.webpack.config.js的配置: module: { rules: [ { test: /\.vue$/, loader: 'vue-loader', options: { // vue-loader options go here postcss: [require('autoprefixer')({ b

Android Image Loader 第三方库对比测试

预热知识 测试前,我们需要先明白这样一个问题 Java Heap / Native Heap 各自代表什么? Bitmap 到底是分配在Java heap上 还是分配到了Native heap上 Java Heap 大小一般是多大,有限制吗? Native Heap大小一般是多大,有限制吗? Java OOM 一般是发生在什么时候,和Java Heap有关还是和 Native Heap有关 如果以上问题不是很清楚的话可以参考这个链接,自己恶补一下基础知识:Android进程的内存管理分析 关于上

webpack配置常用loader加载器

webapck中使用loader的方法有三种 使用loader之前必须运行安装 : npm install --save-dev xxx-loader (1)通过CLI : 命令行中运行 webpack --module-bind jade  --module-bind 'css=style!css' //jade,style,css后面可省略-loader,他们分别对.jade使用jade-loader,对.css使用style-loader和css-loader (2)通过require :

怎样写一个webpack loader

在上一篇<webpack从入门到上线>介绍了wepack的配置和相关的概念,这一篇介绍怎样写一个webpack loader. 通过写一个js的html模板为例子. 上篇文章已提及,loader加载器就是对各种非正常资源的解析,转化成浏览器可以识别的js/css文件等,甚至可以说loader就是一个小型的编译器.例如sass loader:将sass格式编译成css,在安装sass的过程中你会发现,其实sass用的是C++,sass本身是面向对象的.但是本文不会介绍怎样写一个编译器(我也不知道

[李景山php]每天TP5-20161205|Loader.php-3

    // 注册classmap     public static function addClassMap($class, $map = '')     {// 如果 addClassMap  类文件映射,支持 数组,或者 key value 两种方式         if (is_array($class)) {             self::$map = array_merge(self::$map, $class);         } else {             s

universal image loader在listview/gridview中滚动时重复加载图片的问题及解决方法

在listview/gridview中使用UIL来display每个item的图片,当图片数量较多需要滑动滚动时会出现卡顿,而且加载过的图片再次上翻后依然会重复加载(显示设置好的加载中图片) 最近在使用UIL遇到了这个问题,相信这个问题许多使用UIL的人都碰到过 现在把解决方法贴出来给有同样问题的朋友做参考 先看下UIL的工作流程 在已经允许内存,存储卡缓存的前提下,当一个图片被请求display时,首先要判断图片是否缓存在内存中,如果false则尝试从存储卡读取,如果依然不存在最后才从网络地址

ExtJs6 loader 引入html页面不执行页面内js的解决办法

如题: extjs4的代码 到了ext6不执行了 ext4代码: loader: {                    url: me.url,                    autoLoad: true,                    scripts: true                } 在ext6中作如下修改即可: loader: { renderer : function(loader, response, active) {