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
- #!/usr/bin/tclsh
- 2 #------------------------------------------------------------------------------
- 3 # File Name: openmsp430-loader.tcl
- 4 #------------------------------------------------------------------------------
- global omsp_conf
- global omsp_info
- 9 ###############################################################################
- 10 # SOURCE LIBRARIES #
- 11 ###############################################################################
- 13 # Get library path
- set current_file [info script]
- if {[file type $current_file]=="link"} {
- set current_file [file readlink $current_file]
- }
- set lib_path [file dirname $current_file]/../lib/tcl-lib
- 20 # Source library
- source $lib_path/dbg_functions.tcl
- source $lib_path/dbg_utils.tcl
- 25 ###############################################################################
- 26 # PARAMETER CHECK #
- 27 ###############################################################################
- 28 #proc GetAllowedSpeeds
- proc help {} {
- puts ""
- puts "USAGE : openmsp430-loader.tcl \[-device <communication port>\]"
- puts " \[-adaptor <adaptor type>\]"
- puts " \[-speed <communication speed>\]"
- puts " \[-i2c_addr <cpu address>\] <elf/ihex-file>"
- puts ""
- puts "DEFAULT : <communication port> = /dev/ttyUSB0"
- puts " <adaptor type> = uart_generic"
- puts " <communication speed> = 115200 (for UART) / I2C_S_100KHZ (for I2C)"
- puts " <core address> = 42"
- puts ""
- puts "EXAMPLES: openmsp430-loader.tcl -device /dev/ttyUSB0 -adaptor uart_generic -speed 9600 leds.elf"
- puts " openmsp430-loader.tcl -device COM2: -adaptor i2c_usb-iss -speed I2C_S_100KHZ -i2c_addr 75 ta_uart.ihex"
- puts ""
- }
- 47 # Default values
- set omsp_conf(interface) uart_generic
- set omsp_conf(device) /dev/ttyUSB0
- set omsp_conf(baudrate) [lindex [GetAllowedSpeeds] ]
- set omsp_conf(,cpuaddr)
- set elf_file -
- set bin_file "[clock clicks].bin"
- 55 # Parse arguments
- for {set i } {$i < $argc} {incr i} {
- switch -exact -- [lindex $argv $i] {
- -device {set omsp_conf(device) [lindex $argv [expr $i+]]; incr i}
- -adaptor {set omsp_conf(interface) [lindex $argv [expr $i+]]; incr i}
- -speed {set omsp_conf(baudrate) [lindex $argv [expr $i+]]; incr i}
- -i2c_addr {set omsp_conf(,cpuaddr) [lindex $argv [expr $i+]]; incr i}
- default {set elf_file [lindex $argv $i]}
- }
- }
- 66 # Make sure arugments were specified
- if {[string eq $elf_file -]} {
- puts "\nERROR: ELF/IHEX file isn't specified"
- help
- exit
- }
- 73 # Make sure the elf file exists
- if {![file exists $elf_file]} {
- puts "\nERROR: Specified ELF/IHEX file doesn't exist"
- help
- exit
- }
- 80 # Make sure the selected adptor is valid
- if {![string eq $omsp_conf(interface) "uart_generic"] &
- ![string eq $omsp_conf(interface) "i2c_usb-iss"]} {
- puts "\nERROR: Specified adaptor is not valid (should be \"uart_generic\" or \"i2c_usb-iss\")"
- help
- exit
- }
- 88 # Make sure the I2C address is an integer
- if {![string is integer $omsp_conf(,cpuaddr)]} {
- puts "\nERROR: Specified I2C address is not an integer"
- help
- exit
- }
- 95 # Make sure the I2C address is valid
- if {($omsp_conf(,cpuaddr)<) | ($omsp_conf(,cpuaddr)>)} {
- puts "\nERROR: Specified I2C address should lay between 7 and 120"
- help
- exit
- }
- 102 # If the selected interface is a UART, make sure the selected speed is an integer
- if {[string eq $omsp_conf(interface) "uart_generic"]} {
- if {![string is integer $omsp_conf(baudrate)]} {
- puts "\nERROR: Specified UART communication speed is not an integer"
- help
- exit
- }
- } elseif {[string eq $omsp_conf(interface) "i2c_usb-iss"]} {
- if {[lsearch [lindex [GetAllowedSpeeds] ] $omsp_conf(baudrate)]==-} {
- puts "\nERROR: Specified I2C communication speed is not valid."
- puts " Allowed values are:"
- foreach allowedVal [lindex [GetAllowedSpeeds] ] {
- puts " - $allowedVal"
- }
- puts ""
- exit
- }
- }
- 122 ###############################################################################
- 123 # CREATE AND READ BINARY EXECUTABLE FILE #
- 124 ###############################################################################
- 126 # Detect the file format depending on the fil extention
- set fileType [file extension $elf_file]
- set fileType [string tolower $fileType]
- regsub {\.} $fileType {} fileType
- if {![string eq $fileType "ihex"] & ![string eq $fileType "hex"] & ![string eq $fileType "elf"]} {
- puts "\nERROR: [string toupper $fileType] file format not supported"
- return
- }
- if {[string eq $fileType "hex"]} {
- set fileType "ihex"
- }
- if {[string eq $fileType "elf"]} {
- set fileType "elf32-msp430"
- }
- 141 # Generate binary file
- if {[catch {exec msp430-objcopy -I $fileType -O binary $elf_file $bin_file} errMsg]} {
- puts $errMsg
- exit
- }
- 147 # Wait until bin file is present on the filesystem
- set timeout
- for {set i } {$i <= $timeout} {incr i} {
- after
- if {[file exists $bin_file]} {
- break
- }
- }
- if {$i>=$timeout} {
- puts "\nTimeout: ELF to BIN file conversion problem with \"msp430-objcopy\" executable"
- puts "$errMsg"
- exit
- }
- 161 # Read file
- set fp [open $bin_file r]
- fconfigure $fp -translation binary
- binary scan [read $fp] H* hex_data yop
- close $fp
- 167 # Cleanup
- file delete $bin_file
- 170 # Get program size
- set hex_size [string length $hex_data]
- set byte_size [expr $hex_size/]
- set word_size [expr $byte_size/]
- 175 # Format data
- for {set i } {$i < $hex_size} {set i [expr $i+]} {
- set hex_msb "[string index $hex_data [expr $i+2]][string index $hex_data [expr $i+3]]"
- set hex_lsb "[string index $hex_data [expr $i+0]][string index $hex_data [expr $i+1]]"
- lappend DataArray "0x$hex_msb$hex_lsb"
- }
- 183 ###############################################################################
- 184 # LOAD PROGRAM TO OPENMSP430 TARGET #
- 185 ###############################################################################
- 187 # Connect to target and stop CPU
- puts ""
- puts -nonewline "Connecting with the openMSP430 ($omsp_conf(device), $omsp_conf(baudrate)\ bps)... "
- flush stdout
- if {![GetDevice ]} {
- puts "failed"
- puts "Could not open $omsp_conf(device)"
- puts "Available serial ports are:"
- foreach port [utils::uart_port_list] {
- puts " - $port"
- }
- if {[string eq $omsp_conf(interface) "i2c_usb-iss"]} {
- puts "\nMake sure the specified I2C device address is correct: $omsp_conf(0,cpuaddr)\n"
- }
- exit
- }
- ExecutePOR_Halt
- puts "done"
- set sizes [GetCPU_ID_SIZE ]
- if {$omsp_info(,alias)!=""} {
- puts "Connected: target device identified as $omsp_info(0,alias)."
- }
- puts "Connected: target device has [lindex $sizes 0]B Program Memory and [lindex $sizes 1]B Data Memory"
- puts ""
- 213 # Make sure ELF program size is the same as the available program memory
- if {[lindex $sizes ] != [expr $hex_size/]} {
- puts "ERROR: ELF program size ($byte_size B) is different than the available program memory ([lindex $sizes 0] B)"
- exit
- }
- 219 # Load Program Memory
- set StartAddr [format "0x%04x" [expr 0x10000-$byte_size]]
- puts -nonewline "Load Program Memory... "
- flush stdout
- WriteMemQuick $StartAddr $DataArray
- after
- puts "done"
- 227 # Check Data
- puts -nonewline "Verify Program Memory... "
- flush stdout
- if {[VerifyMem $StartAddr $DataArray ]} {
- puts "done"
- } else {
- puts "ERROR"
- exit
- }
- 237 # Release device
- ReleaseDevice 0xfffe
openMSP430之openmsp430-loader的更多相关文章
- openMSP430之io_test
openMSP430: IO functionality test with interupt #include "omsp_system.h" volatile char shi ...
- 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 ...
- Verilog之openMSP430(1)
openMSP430_IO interrupt Verilog file: omsp_gpio.v //================================================ ...
- webpack入门教程之初识loader(二)
上一节我们学习了webpack的安装和编译,这一节我们来一起学习webpack的加载器和配置文件. 要想让网页看起来绚丽多彩,那么css就是必不可少的一份子.如果想要在应用中增加一个css文件,那么w ...
- 简单实用的进度条加载组件loader.js
本文提供一个简单的方法实现一个流程的进度条加载效果,以便在页面中可以通过它来更好地反馈耗时任务的完成进度.要实现这个功能,首先要考虑怎样实现一个静态的进度条效果,类似下面这样的: 这个倒是比较简单,两 ...
- 怎样写一个webpack loader
div{display:table-cell;vertical-align:middle}#crayon-theme-info .content *{float:left}#crayon-theme- ...
- 异常:java.lang.LinkageError: loader constraint violation: when resolving interface method
异常:java.lang.LinkageError: loader constraint violation: when resolving interface method "javax. ...
- ClassNotFoundException: org.apache.catalina.loader.DevLoader 自己摸索,丰衣足食
使用tomcat插件时遇到的问题: ClassNotFoundException: org.apache.catalina.loader.DevLoader 解决方案: 参考了许多文章,对我自己的目录 ...
- xcode8打包ipa文件, application loader上传成功,但是iTunes Connect不显示构建版本
最近更新的Xcode8.今天提交新项目时.按照以往的流程走 Xcode 编译ipa文件.applicaiton loader提交成功 但是.iTunes connect构建版本不显示.非常疑惑.平时等 ...
随机推荐
- 3 Java的基本程序设计结构
本章主要内容: 一个简单的Java应用程序 注释 数据类型 变量 运算符 字符串 输入输出 控制流 大数值 数组 本章主要介绍程序设计的基本概念(如数据类型.分支以及循环)在Jav ...
- linux学习9-进程管理知识
Linux 进程管理 实验环境: 用户名:shiyanlou 密码:AJW3tui5 Linux进程之管理控制 实验介绍 通过本实验我们将掌握一些 Linux 所提供的工具来进行进程的查看与控制,掌握 ...
- [bzoj4025]二分图_LCT
二分图 bzoj-4025 题目大意:给定一个n个节点的图,m条边,每条边有一个产生时间和一个删除时间,询问所有时间点是否是连通图. 注释:$1\le n\le 10^5$,$1\le m\le 2\ ...
- 洛谷——P2676 超级书架
https://www.luogu.org/problem/show?pid=2676#sub 题目描述 Farmer John最近为奶牛们的图书馆添置了一个巨大的书架,尽管它是如此的大,但它还是几乎 ...
- Kotlin和Java名称的由来
Kotlin和Java名称的由来 学习了:http://blog.jobbole.com/111249/ JetBrains由战斗民族开发: Java来源于印尼群岛中的Java岛: Kotlin来源于 ...
- hdu 1874 畅通project续
最短路问题,尽管a!=b,可是同一条路測评数据会给你非常多个.因此在读入的时候要去最短的那条路存起来.........见了鬼了.坑爹 #include<iostream> #include ...
- 从vs中删除自带的Microsoft Git Provider
https://researchaholic.com/2015/02/02/remove-the-microsoft-gitprovider-from-visual-studio-2013/ vs自带 ...
- DCloud-MUI:下拉刷新、上拉加载
ylbtech-DCloud-MUI:下拉刷新.上拉加载 1. 下拉刷新返回顶部 0. http://dev.dcloud.net.cn/mui/pulldown/ 1. 概述 为实现下拉刷新功能,大 ...
- Appium + python - 监控appium server start
import osimport time as t def start_appium(port = 4723,udid="4871660c"): a = os.popen(&quo ...
- Django day08 多表操作 (二) 添加表记录
一: 一对多 1. 一对多新增 两种方式: publish = 对象 publish_id = id 1. publish_id 和 publish 的区别就是: 1)publish_id 可 ...