感谢支持
我们一直在努力

Ubuntu下搭建MSP430开发环境(MSPGCC)

最近无意间看到网友说MSP430也有了GCC编译器,即MSPGCC,欣喜之余我也开始想到,那在Linux下开发MSP430也不远了。谷歌了一端时间,找到MSPGCC的Wiki:http://sourceforge.net/apps/mediawiki/mspgcc/index.php?title=MSPGCC_Wiki,并且在Ubuntu下已经有编译好的安装包,说到这里,其实本人并不是太喜欢从Ubuntu的源中安装这些工具链,我更倾向于MSPGCC官方发布的工具链,不过官方的工具链找了好久都没有找到,因此现在就暂时先用Ubuntu的安装包吧,上面的链接中找到Ubuntu的链接,https://launchpad.net/ubuntu/oneiric/+search?text=msp430,lp上有6个包,分别是

msp430-libc:

Standard C library for TI MSP430 development
430的C标准库

mspdebug:

debugging tool for MSP430 microcontrollers
430的调试工具,用来连接仿真器

msp430mcu:

Spec files, headers and linker scripts for TI’s MSP430 targets
430的头文件以及链接脚本

binutils-msp430:

Binary utilities supporting TI’s MSP430 targets
430的二进制工具包

gcc-msp430:

The GNU C compiler (cross compiler for MSP430)
430的GCC编译器

gdb-msp430:

The GNU debugger for MSP430
430的GDB调试器

关于这些包的作用以及它们与GCC的关系可以参考下面这篇帖子,个人觉得讲的非常好。
http://cms.mcuapps.com/techinfo/toolchains/gcc/
我们一并装上!在终端中输入:

 

sudo aptget install msp430libc mspdebug msp430mcu binutilsmsp430 gccmsp430 gdbmsp430

不过装的过程中出现了一些小插曲,会出现如下错误:

dpkg:处理 /var/cache/apt/archives/gdb-msp430_7.2~mspgcc-7.2-20110612-1ubuntu1_i386.deb (–unpack)时出错:
正试图覆盖 /usr/share/gdb/python/gdb/__init__.py,它同时被包含于软件包 gdb 7.4-2012.04-0ubuntu2.1
正在处理用于 man-db 的触发器…
在处理时有错误发生:
/var/cache/apt/archives/gdb-msp430_7.2~mspgcc-7.2-20110612-1ubuntu1_i386.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

这里的意思应该是gdb-msp430包中的安装文件会覆盖掉gdb包中的文件,这里参考了这篇博客:

Cross-Compiling for TI MSP430 Launchpad


上面说是直接覆盖就可以了,因为两个东西本质上是一样的,在终端输入:

 

sudo aptgeto Dpkg::Options::=“–force-overwrite” install gdbmsp430

接下来会看到如下信息:

dpkg:警告:由于开启了 –force 选项,以下问题被忽略:
正试图覆盖 /usr/share/gdb/python/gdb/__init__.py,它同时被包含于软件包 gdb 7.4-2012.04-0ubuntu2.1
dpkg:警告:由于开启了 –force 选项,以下问题被忽略:
正试图覆盖 /usr/share/gdb/python/gdb/types.py,它同时被包含于软件包 gdb 7.4-2012.04-0ubuntu2.1
dpkg:警告:由于开启了 –force 选项,以下问题被忽略:
正试图覆盖 /usr/share/gdb/python/gdb/printing.py,它同时被包含于软件包 gdb 7.4-2012.04-0ubuntu2.1
dpkg:警告:由于开启了 –force 选项,以下问题被忽略:
正试图覆盖 /usr/share/gdb/python/gdb/command/__init__.py,它同时被包含于软件包 gdb 7.4-2012.04-0ubuntu2.1
dpkg:警告:由于开启了 –force 选项,以下问题被忽略:
正试图覆盖 /usr/share/gdb/python/gdb/command/pretty_printers.py,它同时被包含于软件包 gdb 7.4-2012.04-0ubuntu2.1
正在处理用于 man-db 的触发器…
正在设置 msp430mcu (20110613-3) …
正在设置 binutils-msp430 (2.22~msp20110716p5-1) …
正在设置 gcc-msp430 (4.5.3~mspgcc-20110716-4) …
正在设置 msp430-libc (20110612-2) …
正在设置 mspdebug (0.18-1) …
正在设置 gdb-msp430 (7.2~mspgcc-7.2-20110612-1ubuntu1) …

到这里表示安装成功。
接下来新建一个文件编译,内容如下:

 

/* Blink LED example */
 
#include<msp430g2553.h>
 
/** Delay function. **/
delay(unsignedint d){
int i;
for(i =0; i<d; i++){
nop();
}
}
 
int main(void){
WDTCTL = WDTPW | WDTHOLD;
P1DIR =0xFF;
P1OUT =0x01;
 
for(;;){
P1OUT =~P1OUT;
delay(0x4fff);
}
}

终端中输入:

 

msp430gcc Osmmcu=msp430g2553 o led.elf led.c

编译成功!关于在线调试以及eclipse+msp430-gdb的调试敬请期待。

上回讲到已经成功编译了源代码,生成了可执行文件,接下来就是要连接仿真器,下载可执行文件了。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版本库了。官方的链接如下:
http://mspdebug.sourceforge.net/tilib.html#fet_firmware
总结一下有下面几个步骤:

  • 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 aptget install quilt libboostdev libboost1.46dev
sudo aptget install libboostthreaddev libboostfilesystemdev
sudo aptget install libboostdatetimedev libboostsystemdev

接下进行源码的编译安装:

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:

 

sudo cp libmsp430.so /usr/local/lib
sudo ldconfig

 

2. 下载固件升级/降级程序

链接如下:Uifv3Updater-1_00_00_00.zip,解压即可

3. 重新编译mspdebug

编译之前我们需要将ubuntu中已经安装的mspdebug包卸载,并且安装编译所需要的一些开发包。

sudo aptget remove mspdebug
sudo aptget install libreadlinedev

下载教新版本的mspdebug,我下载的是0.21,链接如下:http://sourceforge.net/projects/mspdebug/,接下来就是一系列的操作:

 

tar xvf mspdebug-0.21.tar.gz
cd mspdebug-0.21
make
sudo make install

 

4. 升级固件

首先最好做一个当前仿真器固件的备份:

sudo mspdebug uifbsl d /dev/ttyUSB0 “hexout 0x2500 0xdb00 old-v2-firmware.hex”

MSPDebug version 0.18 – debugging tool for MSP430 MCUs
Copyright (C) 2009-2011 Daniel Beer <dlbeer@gmail.com>
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
Device ID: 0xf16c
BSL version is 1.61
Reading 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 uifbsl d /dev/ttyUSB0 “prog Uifv3Updater.txt”

MSPDebug version 0.18 – debugging tool for MSP430 MCUs
Copyright (C) 2009-2011 Daniel Beer <dlbeer@gmail.com>
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
Device ID: 0xf16c
BSL version is 1.61
Erasing…
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 allowfwupdate

MSPDebug version 0.21 – debugging tool for MSP430 MCUs
Copyright (C) 2009-2012 Daniel Beer <dlbeer@gmail.com>
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
MSP430_Initialize: /dev/ttyACM0
Firmware version is 30205004
MSP430_VCC: 3000 mV
MSP430_OpenDevice
MSP430_GetFoundDevice
Device: MSP430F169 (id = 0x006a)
8 breakpoints available
MSP430_EEM_Init
Chip ID data: f1 69
 
Available commands:
= erase isearch opt run setwatch_w
alias exit load power save_raw simio
break fill load_raw prog set step
cgraph gdb locka read setbreak sym
delbreak help md regs setwatch verify
dis hexout mw reset setwatch_r verify_raw
 
Available options:
color gdb_loop iradix
fet_block_size gdbc_xfer_size quiet
 
Type “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 MCUs
Copyright (C) 2009-2012 Daniel Beer <dlbeer@gmail.com>
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
MSP430_Initialize: /dev/ttyACM0
Firmware version is 30205004
MSP430_VCC: 3000 mV
MSP430_OpenDevice
MSP430_GetFoundDevice
Device: MSP430F169 (id = 0x006a)
8 breakpoints available
MSP430_EEM_Init
Chip ID data: f1 69
Bound to port 2000. Now waiting for connection…

此时启动msp430-gdb之后进行远程连接目标,即可进行gdb调试:

msp430gdb

GNU gdb (Linaro GDB) 7.3
Copyright (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:2000
Remote debugging using localhost:2000
段错误 (核心已转储)

这里出现了一个段错误,后来谷歌了一下,发现launchpad上有人已经报告了这个bug,并且已经提供了patch补丁:
Bug #891970 “msp430-gdb segmentation fault with target remote” : Bugs : “gdb-msp430” package : Ubuntu

鉴于时间精力有限,这里就不再折腾了,不过到这里已经离成功很接近了。

参考链接:
GNU 編譯器組合 – MCUApps
A Step by Step Guide To MSP430 Programming under Linux | Four-Three-Oh!
Cross-Compiling for TI MSP430 Launchpad | MitchTech
MSPDebug – MSP430/V3 firmware
Compile and debug using MSPGCC, MSPDEBUG from the command line, avoiding to use an ide like CCSv5v2.1, typing mspdebug -d tilib /dev/ttyACM0. – Linux forum – Linux – TI E2E Community

赞(0) 打赏
转载请注明出处:服务器评测 » Ubuntu下搭建MSP430开发环境(MSPGCC)
分享到: 更多 (0)

听说打赏我的人,都进福布斯排行榜啦!

支付宝扫一扫打赏

微信扫一扫打赏