Python作为一个无所不能的工具, 当然可以给MSP430下载Firmware.
根据官方的wiki页面http://processors.wiki.ti.com/index.php/BSL_(MSP430),有一个叫做MSP430 Tools (Python scripts and library)的包.
于是我就去试用了一把, 但从主页上下载的装不上去, 从库里面checkout出来的在program时报错.
-_-
为了让伟大的python可以BSL, 研究一下代码吧, 都commit 400多次了还用不了?
---------------------------------------------------------------------------
因为对python不是很熟, 于是先从表现上分析. bus hound(试用版) 分析后发现

0x80 SYNC, 0x90 ACK , 0xA0 NACK
根据TI的文档 slau319 ,它先做了Mass erase,然后是Rx password, 然后TX BSL version,然后TX data block.
我的调用指令是
1
python -m msp430.bsl.target -e -p COM2
只是mass erase啊(-e),为啥要读version? 而且还读错了? mcu回0xA0.
然后在msp430\bsl\target\__init__.py里面发现
1
2
3
# check for extended features (e.g. >64kB support)
self.logger.debug('Checking if device has extended features')
self.check_extended()
在check_extended时出错,先注释掉.继续bus hound(正式版)

发完密码就sync不了了?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# override reset method: use control line
defreset(self):
"""Reset the device."""
self.logger.info('Reset device')
# dual reset:
# 1) use the control line
# 2) while the control line is used to set the device in reset, also
# use a write to the WDTCTL register.
# This has the advantage that the control line is used when connected
# but when the control line is not available, a reset is still likely
# to be successful with the WDTCTL.
self.set_RST(False)
SerialBSL.reset(self)
time.sleep(0.1)
self.set_RST(True)
time.sleep(0.1)
竟然在rst的时候调SerialBSL.reset(self)...
注释掉后可以program,但verify 依旧不行....在搞了一天以后我决定再找找.
----------------------------------------------------------------------
TinyOS 项目的Pybsl
https://github.com/tinyos/tinyos-main/tree/master/tools/platforms/msp430/pybsl
里面的exe文件振奋人心啊,可以用.
但py不行(tos-bsl.in文件).
这个结构比较简单,功能都实现在tos-bsl文件中.于是学着用了下pdb.
发现在bsl.invertRST这个竟然是1, 于是在1551行发现
1
2
bsl.invertRST=1
bsl.invertTEST=itest
竟然初始化成了1,后边又没改....作者用的硬件是inverted的吗?
改为0后一切正常啦~
比如我用的MSP430G2955的调用方法是
1
python tos-bsl.py-c1-epv--invert-test firmware_to_downloaded.txt
C1: 在我的机器上是Com2
epv: 擦除,编程,校验.
--invert-test: 2955需要这个...参考slau319.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
D:\src\Python\pybsl>python tos-bsl.py -c1 -epv --invert-test xxxxx.txt
MSP430 Bootstrap Loader Version: 1.39-goodfet-8
Mass Erase...
Transmit default password ...
Invoking BSL...
Transmit default password ...
Autodetect failed! Unkown ID: 2955. Trying to continue anyway.
Current bootstrap loader version: 2.2 (Device ID: 2955)
Program ...
22771 bytes programmed.
Verify ...
D:\src\Python\pybsl>pause
Press any key to continue . . .