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

openMSP430之openmsp430-loader的更多相关文章

  1. openMSP430之io_test

    openMSP430: IO functionality test with interupt #include "omsp_system.h" volatile char shi ...

  2. openMSP430之Custom linker script

    The use of the -mmcu switch is of course NOT mandatory. It is simply a convenient way to use the pre ...

  3. Verilog之openMSP430(1)

    openMSP430_IO interrupt Verilog file: omsp_gpio.v //================================================ ...

  4. webpack入门教程之初识loader(二)

    上一节我们学习了webpack的安装和编译,这一节我们来一起学习webpack的加载器和配置文件. 要想让网页看起来绚丽多彩,那么css就是必不可少的一份子.如果想要在应用中增加一个css文件,那么w ...

  5. 简单实用的进度条加载组件loader.js

    本文提供一个简单的方法实现一个流程的进度条加载效果,以便在页面中可以通过它来更好地反馈耗时任务的完成进度.要实现这个功能,首先要考虑怎样实现一个静态的进度条效果,类似下面这样的: 这个倒是比较简单,两 ...

  6. 怎样写一个webpack loader

    div{display:table-cell;vertical-align:middle}#crayon-theme-info .content *{float:left}#crayon-theme- ...

  7. 异常:java.lang.LinkageError: loader constraint violation: when resolving interface method

    异常:java.lang.LinkageError: loader constraint violation: when resolving interface method "javax. ...

  8. ClassNotFoundException: org.apache.catalina.loader.DevLoader 自己摸索,丰衣足食

    使用tomcat插件时遇到的问题: ClassNotFoundException: org.apache.catalina.loader.DevLoader 解决方案: 参考了许多文章,对我自己的目录 ...

  9. xcode8打包ipa文件, application loader上传成功,但是iTunes Connect不显示构建版本

    最近更新的Xcode8.今天提交新项目时.按照以往的流程走 Xcode 编译ipa文件.applicaiton loader提交成功 但是.iTunes connect构建版本不显示.非常疑惑.平时等 ...

随机推荐

  1. 3 Java的基本程序设计结构

        本章主要内容: 一个简单的Java应用程序 注释 数据类型 变量 运算符 字符串 输入输出 控制流 大数值 数组       本章主要介绍程序设计的基本概念(如数据类型.分支以及循环)在Jav ...

  2. linux学习9-进程管理知识

    Linux 进程管理 实验环境: 用户名:shiyanlou 密码:AJW3tui5 Linux进程之管理控制 实验介绍 通过本实验我们将掌握一些 Linux 所提供的工具来进行进程的查看与控制,掌握 ...

  3. [bzoj4025]二分图_LCT

    二分图 bzoj-4025 题目大意:给定一个n个节点的图,m条边,每条边有一个产生时间和一个删除时间,询问所有时间点是否是连通图. 注释:$1\le n\le 10^5$,$1\le m\le 2\ ...

  4. 洛谷——P2676 超级书架

    https://www.luogu.org/problem/show?pid=2676#sub 题目描述 Farmer John最近为奶牛们的图书馆添置了一个巨大的书架,尽管它是如此的大,但它还是几乎 ...

  5. Kotlin和Java名称的由来

    Kotlin和Java名称的由来 学习了:http://blog.jobbole.com/111249/ JetBrains由战斗民族开发: Java来源于印尼群岛中的Java岛: Kotlin来源于 ...

  6. hdu 1874 畅通project续

    最短路问题,尽管a!=b,可是同一条路測评数据会给你非常多个.因此在读入的时候要去最短的那条路存起来.........见了鬼了.坑爹 #include<iostream> #include ...

  7. 从vs中删除自带的Microsoft Git Provider

    https://researchaholic.com/2015/02/02/remove-the-microsoft-gitprovider-from-visual-studio-2013/ vs自带 ...

  8. DCloud-MUI:下拉刷新、上拉加载

    ylbtech-DCloud-MUI:下拉刷新.上拉加载 1. 下拉刷新返回顶部 0. http://dev.dcloud.net.cn/mui/pulldown/ 1. 概述 为实现下拉刷新功能,大 ...

  9. Appium + python - 监控appium server start

    import osimport time as t def start_appium(port = 4723,udid="4871660c"): a = os.popen(&quo ...

  10. Django day08 多表操作 (二) 添加表记录

    一: 一对多 1. 一对多新增 两种方式:  publish = 对象    publish_id = id 1. publish_id 和 publish 的区别就是: 1)publish_id 可 ...