上回讲到已经成功编译了源代码,生成了可执行文件,接下来就是要连接仿真器,下载可执行文件了。mspgcc中连接仿真其用的是mspdebug(功能上类似与openocd),连接成功之后它也能够充当gdbserver的角色,开启守护进程之后我们就可以使用msp430-gdb进行调试以及下载程序了。
mspdebug之前已经从Ubuntu的源中安装过了,接下来首先插上仿真器,我用的是SEED-FET430USB,外壳被合众达包了一下而已,芯片还是TI的FET430UIF,插上电脑之后,就能识别出来,在终端中输入:
lsusb
输出下面内容:
。。。。。
Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 003: ID 090c:c371 Silicon Motion, Inc. - Taiwan (formerly Feiya Technology Corp.)
Bus 005 Device 004: ID 093a:2510 Pixart Imaging, Inc. Optical Mouse
Bus 006 Device 014: ID 2047:0010 Texas Instruments
。。。
然后会在/dev目录下模拟出一个ttyxxx的终端,并且不同版本的固件模拟出的终端名称还不一样,我查了一下资料,有这么一段说法:
The V3 firmware image provides a CDC-ACM class interface, whereas the V2 image appears as a generic TI3410 serial adapter. In the following instructions, it's assumed that devices running V2 firmware appear as /dev/ttyUSB0 and devices running V3 firmware appear as /dev/ttyACM0. You may have to adjust these names to suit your system.
如果出现/dev/ttyUSB0的话,则是V2的固件版本。如果是出现/dev/ttyACM0的话则是V3的固件版本。
大家可以试一试,如果是V2的固件版本,即出现/dev/ttyUSB0的情况下是否能够连接上,至少我是连接不成功的,命令如下:
sudo mspdebug uif -d /dev/ttyUSB0
如果连接不成功的话就需要考虑将V2版本库升级到V3版本库了。官方的链接如下:
总结一下有下面几个步骤:
- The libmsp430.so binary, built as explained above.
- Uifv3Updater-1_00_00_00.zip -- a package from TI containing upgrade/downgrade program images.
- The latest git version of mspdebug (at least commit 82ec966d5e377a66d7d904067cc227d65dccdd01).
首先需要编译出libmsp430.so的共享库,然后下载固件升级/降级的程序,然后使用mspdebug进行固件升级。下面详细介绍步骤:
1. 编译libmsp430.so
首先下载共享库的源码,链接送上:http://www-s.ti.com/sc/techzip/slac460.zip,然后安装编译需要的一些开发包:
sudo apt-get install quilt libboost-dev libboost1.46-devsudo apt-get install libboost-thread-dev libboost-filesystem-devsudo apt-get install libboost-date-time-dev libboost-system-dev
接下进行源码的编译安装:
unzip slac460e.zip
cd MSP430.DLLv3_OS_Package
make
编译过程中会遇到如下Error:
DLL430_v3/src/TI/DLL430/MessageData.cpp:113:33: error: 'memcpy' was not declared
参考了这篇链接:
http://e2e.ti.com/support/embedded/linux/f/354/t/212816.aspx
这里需要稍微修改一下源代码:
在MSP430.DLLv3_OS_Package/DLL430_v3/src/TI/DLL430/MessageData.cpp中添加#include <cstring>
在MSP430.DLLv3_OS_Package/DLL430_v3/src/TI/DLL430/EM/Sequencer/Sequencer430.h中添加#include <cstring>
再次make之后就能编译通过,然后将源代码顶层目录下生成的libmsp430.so拷贝到系统库目录中,同时刷新共享库cache:
2. 下载固件升级/降级程序
sudo cp libmsp430.so /usr/local/lib
sudo ldconfig
链接如下:Uifv3Updater-1_00_00_00.zip,解压即可3. 重新编译mspdebug
编译之前我们需要将ubuntu中已经安装的mspdebug包卸载,并且安装编译所需要的一些开发包。
sudo apt-get remove mspdebug
sudo apt-get install libreadline-dev
下载教新版本的mspdebug,我下载的是0.21,链接如下:http://sourceforge.net/projects/mspdebug/,接下来就是一系列的操作:
4. 升级固件
tar xvf mspdebug-0.21.tar.gz
cd mspdebug-0.21
make
sudo make install
首先最好做一个当前仿真器固件的备份:
sudo mspdebug uif-bsl -d /dev/ttyUSB0 "hexout 0x2500 0xdb00 old-v2-firmware.hex"
MSPDebug version 0.18 - debugging tool for MSP430 MCUsCopyright (C) 2009-2011 Daniel Beer <dlbeer@gmail.com>This is free software; see the source for copying conditions. There is NOwarranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.Device ID: 0xf16cBSL version is 1.61Reading 4096 bytes from 0x2500...Reading 4096 bytes from 0x3500...Reading 4096 bytes from 0x4500...Reading 4096 bytes from 0x5500...Reading 4096 bytes from 0x6500...Reading 4096 bytes from 0x7500...Reading 4096 bytes from 0x8500...Reading 4096 bytes from 0x9500...Reading 4096 bytes from 0xa500...Reading 4096 bytes from 0xb500...Reading 4096 bytes from 0xc500...Reading 4096 bytes from 0xd500...Reading 4096 bytes from 0xe500...Reading 2816 bytes from 0xf500...接下来加载V3版本的固件升级程序,注意首先将终端切换到固件升级包解压之后的目录。mspdebug/mspdebug uif-bsl -d /dev/ttyUSB0 "prog Uifv3Updater.txt"
MSPDebug version 0.18 - debugging tool for MSP430 MCUsCopyright (C) 2009-2011 Daniel Beer <dlbeer@gmail.com>This is free software; see the source for copying conditions. There is NOwarranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.Device ID: 0xf16cBSL version is 1.61Erasing...Programming...Writing 4096 bytes to 2500...Writing 4096 bytes to 3500...Writing 4096 bytes to 4500...Writing 3374 bytes to 5500...Writing 2 bytes to f7f0...Writing 2 bytes to f7fe...bsl: failed on command 0x3b (addr = 0x0000, len = 0x0000)最后的是正常的,这个时候FET仿真器会自动重启并且在linux下会模拟出/dev/ttyACM0的设备,现在可以写入最新的匹配固件库了:sudo mspdebug tilib -d /dev/ttyACM0 --allow-fw-update
MSPDebug version 0.21 - debugging tool for MSP430 MCUsCopyright (C) 2009-2012 Daniel Beer <dlbeer@gmail.com>This is free software; see the source for copying conditions. There is NOwarranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.MSP430_Initialize: /dev/ttyACM0Firmware version is 30205004MSP430_VCC: 3000 mVMSP430_OpenDeviceMSP430_GetFoundDeviceDevice: MSP430F169 (id = 0x006a)8 breakpoints availableMSP430_EEM_InitChip ID data: f1 69Available commands:= erase isearch opt run setwatch_walias exit load power save_raw simiobreak fill load_raw prog set stepcgraph gdb locka read setbreak symdelbreak help md regs setwatch verifydis hexout mw reset setwatch_r verify_rawAvailable options:color gdb_loop iradixfet_block_size gdbc_xfer_size quietType "help <topic>" for more information.Press Ctrl+D to quit.(mspdebug)到这里升级就成功了。这里请注意,我升级固件库升级了三次才成功,所以如果第一次失败请多尝试几次。下次要连接仿真器只需要输入:sudo mspdebug tilib -d /dev/ttyACM0
如果要开启gdb守护进程,即作为一个gdbserver来工作的话,输入:
sudo mspdebug tilib -d /dev/ttyACM0 "gdb"MSPDebug version 0.21 - debugging tool for MSP430 MCUsCopyright (C) 2009-2012 Daniel Beer <dlbeer@gmail.com>This is free software; see the source for copying conditions. There is NOwarranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.MSP430_Initialize: /dev/ttyACM0Firmware version is 30205004MSP430_VCC: 3000 mVMSP430_OpenDeviceMSP430_GetFoundDeviceDevice: MSP430F169 (id = 0x006a)8 breakpoints availableMSP430_EEM_InitChip ID data: f1 69Bound to port 2000. Now waiting for connection...此时启动msp430-gdb之后进行远程连接目标,即可进行gdb调试:msp430-gdb
GNU gdb (Linaro GDB) 7.3Copyright (C) 2011 Free Software Foundation, Inc.License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>This is free software: you are free to change and redistribute it.There is NO WARRANTY, to the extent permitted by law. Type "show copying"and "show warranty" for details.This GDB was configured as "--host=i686-linux-gnu --target=msp430".For bug reporting instructions, please see:<http://bugs.launchpad.net/gdb-linaro/>.(gdb) target remote localhost:2000Remote debugging using localhost:2000段错误 (核心已转储)这里出现了一个段错误,后来谷歌了一下,发现launchpad上有人已经报告了这个bug,并且已经提供了patch补丁:Bug #891970 “msp430-gdb segmentation fault with target remote” : Bugs : “gdb-msp430” package : Ubuntu
鉴于时间精力有限,这里就不再折腾了,不过到这里已经离成功很接近了。参考链接:

