历史上的今天
今天是:2025年01月26日(星期日)
2021年01月26日 | msp430几种不同开发平台的对比
2021-01-26 来源:eefocus
TinyOS (moteiv & mica)
编辑器
没有特定的编辑器,记事本类似的都行,保证所编辑的源文件是“.nc”结尾的nesC程序。
工程管理
一个目录即为一个工程,包括一个makefile檔和一个或多个“components”,组件有两种:
1. 配件(configuration):描述不同组件之间的关系;
2. 模块:(module):描述组件提供的接口中的函数功能的实验过程。
开发环境
在windows下安装cygwin环境,并在cygwin下安装TinyOS的开发工具包,其中包括
avr-binutils, 二进制代码工具
avr-gcc,
avr-insight,
avr-libc,
nesC-1.1.2 nesC编译器
…
编译、运行和下载
TinyOS支持多种硬件平台,每个硬件平台在tos/platform有自己的目录。
在应用程序的目录里/app/Blink下输入:
make tmote //其中tmote代表的是平台种类。如果target为pc,刚生成的main.exe可
//用于GDB的调试。
上面的语句实际上是按照当前目录的makefile文件运行的,makefile檔中包含了编译、连接等。具体的实现如下:
1.ncc编译链接: #ncc –o main.exe –target=tmote Blink.nc //编译生成了main.exe,可以作
//PC机上的模拟之用。
2.转换: #msp430-objcopy –output-target=ihex main.exe main.ihex //生成了main.ihex
下载:运行: #make tmote reinstall,1 //设置网络地址为1
其中运行过程中主要的两个命令如下:
installing tmote bootloader using bsl ####安装启动引导檔,根据开发板的不同而不同。
tos-bsl –telosb –c 7 –r –I –p C:/cygwin/opt/moteiv/tos/lib/Deluge/TOSBoot/build/tmote/main.ihex
installing tmote binary using bsl #####安装二进制程序。ihex与ihex.out-1文件相同
tos-bsl –telosb –c 7 –r –I –p build/tmote/main.ihex.out-1
make过程分析
其中提到的目录说明如下:(具体参照上面的图)
opttinyos-1.xtoslib ----------------------------------------包括了用到的库函数.
opttinyos-1.xtosinterfaces----------------------------------包括接口函数,
opttinyos-1.xtosplatform----------包括了不同硬件平台间的配置文件.(启动引导檔在这里)
opttinyos-1.xtossensorboards ------------------------------包括板载传感器的具体实现
可以看到所有的程序都是调用了同一个make规则,除了工程本身所在目录的makefile文件与本工程相关外,在opttinyos-1.xapps目录下的makerule文件是公用的,其中定义了选用的编译器及硬件平台的选择。
TinyOS操作系统设计思想
1.轻量级线程技术(lightweight thread)
2.主动消息通信技术(active message)
3.事件驱动模块(event driver)
4.组件化编程(component-based programming)
nesC语言把组件化/模块化思想和基于事件驱动的执行模型结合起来。
组件化:其中的组件即“Configuration”(配件)、“Module”。两个东西就像零件一样组合在一起。
模块化:
MSPGCC
编辑器
可以配置一些IDE(集成开发环境),如VIM、UltraEdit、CodeBlocks等,其中VIM是命令行的,用起来很有感觉,CodeBlocks是开源的,UltraEdit为商业软件。但不管怎么样,都是调用的mspgcc安装程序里的make.exe,调试环境是msp430-insight
工程管理
用UltraEdit可以很好的管理工程文件,在工程目录里面应该有一个makefile檔,告诉make如何去生成所要的目录文件和文件之间的依赖关系。同样,用开源的CodeBlocks也可以自己搭建一个很好的IDE,鉴于对CodeBlocks都比较熟悉,即采用之!
开发环境
在windows下安装mspgcc-2007021.exe,注意,这里最好是安装最新版的,在之前我下载的是2003版的,又很多工具都不全,导致一个人摸索了好久。
然后在CodeBlocks里的“settings”项里配置相关的compiler和debugger,最重要的部分是库函数所在的目录位置。
编译、运行和下载
编译和链接部分基本上和相同,只是分别调用的是msp430-gcc.exe、msp430-ld.exe
下载是通过msp430-downloader.exe来下载的。
make过程分析
下面是makefile文件的部分分析:
${NAME}.elf: ${OBJECTS} #######################msp430-gcc进行编译
msp43o-gcc.exe -mmcu=${CPU} -o $@ ${OBJECTS} ####生成了 “*.elf”文件
${NAME}.a43: ${NAME}.elf ##################目标文件进行转换
msp430-objcopy -O ihex $^ $@ ##################将elf文件转换为*.a43文件
${NAME}.lst: ${NAME}.elf ##################反汇编,生成*.lst文件,其中
msp430-objdump -dSt $^ >$@ ##################这个文件包含了c源码,汇 ##################编原码
download-jtag: all
msp430-jtag -e ${NAME}.elf
download-bsl: all #####这里的下载工具也是bsl,和TinyOS的tos-bsl类似
msp430-bsl -e ${NAME}.elf
其中,*.a43为TI-Text格式, *.hex为Intel-hex格式.
IAR_MSP430
编辑器
IAR Embedded Workbench IDE一个瑞士开发的商用软件的,价格好象在6500.00;目前个人感觉相比开源的MSPGCC也没太大的优势。
工程管理
一个“.eww ”即为一个工程,
开发调试环境
编译、运行和下载
编译:调用“icc430.exe”编译器和已经设定好的一些参数,包括指定的动态库文件,输出文件所在的目录,具体的代码好下:
icc430.exe -I D:Program FilesIAR SystemsEmbedded Workbench 4.0430INC
-I D:Program FilesIAR SystemsEmbedded Workbench 4.0430INCDLIB
-o C:Documents and SettingsAdministratorMy DocumentsDebugObj
-z3 --no_cse --no_unroll --no_inline --no_code_motion --no_tbaa --debug -e --double=32
-D_DLIB_CONFIG_FILE=D:ProgramFilesIARSystemsEmbeddedWorkbench4.0430LIBDLIBdl430fn.h
D:Program FilesIAR SystemsEmbedded Workbench 4.0430FET_examplesfet140C-sourcefet140_1.c
运行上面的命令之后,在“..obj”目录下生成了“*.r43”文件。(The Obj directory is the destination directory for the object files from the compiler and the assembler. These files have the extension r43 and will be used as input to the IAR XLINK Linker.)
链接:这里调用的是“xlink.exe”,具体的代码好下:
xlink.exe C:Documents and SettingsAdministratorMy DocumentsDebugObjfet140_1.r43
-o C:Documents and SettingsAdministratorMy DocumentsDebugExeSMC4200.d43 –I D:Program FilesIAR SystemsEmbedded Workbench 4.0430LIB
-f D:Program FilesIAR SystemsEmbedded Workbench 4.0430CONFIGlnk430F149.xcl
-f D:Program FilesIAR SystemsEmbedded Workbench 4.0430configmultiplier.xcl -D_STACK_SIZE=50
-rt D:Program FilesIAR SystemsEmbedded Workbench 4.0430LIBDLIBdl430fn.r43
-e_PrintfLarge=_Printf
-e_ScanfLarge=_Scanf
-D_HEAP_SIZE=50
-s __program_start
##### -o This option creates a UBROF output file, with a DE>d43DE> filename extension, to be used with the IAR C-SPY Debugger. (The Exe directory is the destination directory for the executable file. It has the extension d43 and will be used as input to the IAR C-SPY Debugger. Note that this
directory will be empty until you have linked the object files.) < 下载: 在下载部分,IAR没有给出很详细的, 下面是和IAR、Jennic及TinyOS平台做的对比: 开发工具包 IAR Jennic TinyOS MSPGCC compiler 编译器 C Compiler icc430.exe ba-elf-gcc.exe ncc.exe msp430-gcc.exe msp430-gcc.exe C++ Compiler ba-elf-g++.exe msp430-g++.exe Linker 链接器 动态库的链接器 xlink.exe ba-elf-ld.exe msp430-ld.exe 静态库的链接器 ? ba-elf-ar.exe msp430-ar.exe Debugger ba-elf-gdb.exe msp430-gdb.exe make Make.exe Make.exe Make.exe Download file ? *.bin *.hex.out-1 (tmote) *.elf *.hex *.txt downloader tos-bsl download-bsl IAR ü application and library projects. ü The Obj directory is the destination directory for the object files from the compiler and the assembler. These files have the extension r43 and will be used as input to the IAR XLINK Linker(< 嵌入式开发,C语言不可或缺。优秀的编译器直如倚天屠龙。读书时,用过MSP430,编译器为IAR(盗版),code有2K限制。为此,曾攻读过专门以此器为背景的C语言书(蓝封面,北航社,忘其名)。此器,功能强大,调试方便,硬件寄存器皆有显示。窥430之门径,离Hello World之苦海,伴我几易寒暑,初踏嵌入式之地者,正是此器。总结:
AVRGCC、ARMGCC和MSPGCC
后,一直未曾用430。前些天,某任务要用。我重拾往日之事。IAR终为不完全盗版,破解太烦。懒,不愿做。放狗搜,见mspgcc,版本号:20081230。与gcc一脉传承,想必不错。试用几日,感觉这才是利器!
1. 正版。无限制。
GPL,天下皆知
2. 与gcc系出同源,使用方式极像。
如果用过gcc
查看mspgcc对gcc的扩展
如果没有用过gcc
先了解一下gcc的基本用法,比如
gcc -o hello hell.c
gcc -S hell.c
等
然后,mspgcc
其它
goto error;
3. 针对430扩展C语言,汇编能做的,他几乎都能做。
仅在此列出我认为有趣的几个,详情,查手册。
(1)堆栈
mspgcc对堆栈的设置很灵活。你可以为自己保留一定字节的RAM不被C占用。如下声明
int RESERVE_RAM(10) main()
你保留的10字节RAM。
你也可以自己写启动文件,代替标准的启动文件,自己控制进入C语言时的环境。
(2)头文件
在嵌入式开发中,一般会有针对硬件的头文件。其中为特殊功能寄存器定义等。不同的硬件环境,当然需要不同的定义。在mspgcc的开发环境中只需增加
#include
即可。
不同的硬件如何区别?在Makefile文件中或者在编译时说明是哪种430芯片就可以了。这一点,和winavr相同。
(3)中断
中断是硬件的珍贵资源。标准C中似乎没有中断的定义,所以一般采用扩展。mspgcc提供了interrupt关键字,以及控制进入中断方式的选项。比如,下面的中断程序中没有用到诸如R4,R5等其它寄存器,却仍将其在堆栈中保护。
interrupt (ADC_VECTOR) ADC12ISR(void)
{
ADCresult = ADC12MEM0; // Move results, IFG is cleared
}
属性naked修饰后,裸奔。不做任何事情,甚至reti都不执行,所以,得自己控制返回。
interrupt (ADC_VECTOR) __attribute__ ((naked)) ADC12ISR(void)
{
ADCresult = ADC12MEM0; // Move results, IFG is cleared
asm("reti");
}
mspgcc中扩展了下面这些属性(参考mspgcc手册)。
reserve(x) When applied to main(), this reserves "x" bytes of RAM above the stack. This cannot be used with C++ (if C++ is supported later on).
interrupt(x) Make the function an interrupt service routine for interrupt "x".
signal Make an interrupt service routine allow further nested interrupts.
wakeup When applied to an interrupt service routine, wake the processor from any low power state as the routine exits. When applied to other routines, this attribute is silently ignored.
naked Do not generate a prologue or epilogue for the function.
critical Disable interrupts on entry, and restore the previous interrupt state on exit.
reentrant Disable interrupts on entry, and always enable them on exit.
saveprologue Use a subroutine for the function prologue, to save memory.
noint_hwmul Supress the generation of disable and enable interrupt instructions around hardware multiplier code.
(4)汇编
mapgcc支持行间汇编。只是,gcc的汇编语言似乎与TI的不尽相同。
4. 烧写
有三种方式
(1) gdb
(2) msp430-downloader.exe
(3) msp430-jtag.exe
5. 调试
当前,最新版mspgcc没有insight,只有gdb。个人感觉不如IAR直观
史海拾趣




