Monday, August 31, 2009

msploader

It was quite difficult (for me) to come up with the right google searches, but I finally found not one but two efforts to loading the msp430 from linux, specifically the boards designed for the ez430 using the usb stick that comes with the ez430. The problem is the usb interface is done with a separate processor which has its own protocol on the usb serial side and from that creates the spy-bi-wire on the target msp430 side. TI did not publish this protocol but instead hid it in a windows dll. So the linux solution thus far has been to use some tricks to ride on top of that windows dll. One was called msp430fet by Travis Goodspeed (if not every then every other google search you do will hit his blog). He stopped working on it when fetproxy came out which is an attempt to replace msp430-gdbproxy on linux without the windows dll.

My goals are much much simpler. I want a program to load a binary from a file into the msp430. Finding the libraries and building and using gdb with fetproxy is more than I am willing to tolerate.

I was already working on a disassembler for the msp430. Not for public consumption really but I feel the best way to learn an instruction set is to write a disassembler for it. Elf files are somewhat trivial to read, esp for finding a single chunk of binary data, so naturally I started there. The disassembler is still in the package below, no guarantees that it is accurate, for accurate or at least supported disassembly use binutils objdump.

The current release of msploader is here:
http://www.dwelch.com/msp430stuff/msploader-r001_36d6295d5849.tar.gz

Prior releases:
http://www.dwelch.com/msp430stuff/msploader-r000_923b533b2beb.tar.gz

It happens to be a full hg repo with change info. Although the initial release, rev000 has only the one commit of the initial source.

This is a somewhat brute force program. For now the serial port is hardcoded, you will need to go into ser.c and change it. I will probably fix that before long and make it a command line option. Also, it is assuming a single binary with a single entry point, basically no interrupt support or any other events in the interrupt vector table at this time. The code is simple enough though that adding support for multiple blocks is not hard. At this time I do not have support for intel hex files, only elf files as I use binutils to generate my binaries and leave them in the native elf format without the extra objcopy to intel hex. For this tool to be useful to other compilers and toolchains I should add support for intel hex files.

One thing I learned fairly quickly was not to perform an erase all. The problem is that it erases all of the flash. The program space and ivt are fine, but it also clears the configuration space with the factory calibrated clock initializaition values. msploader erases flash pages as needed to load the program and leaves the rest unchanged. The ivt does have to be cleared in order to program the entry point.

At the time of this writing there are some Linux problems with the ez430 usb stick. Running on ubuntu 9.10 beta (9.10 wont be out for a month or two) and 9.04 you have the problem that you can only open the serial port one time per reboot of the computer. I think I saw a website with a solution but have not persued it. My choice was instead to downgrade to 8.10. 8.10 has its own problems but with little effort you can be in a situation where you can load the msp more than once without having to reboot the computer.

When you plug the usb stick in you will see something like this:

[85098.925011] ti_usb_3410_5052: TI USB 3410/5052 Serial Driver v0.9
[85099.064020] usb 4-3: new full speed USB device using ohci_hcd and address 5
[85099.280621] usb 4-3: configuration #1 chosen from 2 choices
[85099.283545] ti_usb_3410_5052 4-3:1.0: TI USB 3410 1 port adapter converter detected
[85099.283684] ti_usb_3410_5052: probe of 4-3:1.0 failed with error -5


Notice how usb 4-3 is mentioned in the above output, your output will vary, but with 8.04 or 8.10 should end in the error -5.

Using the usb information from dmesg perform this step:

echo 2 > /sys/bus/usb/devices/4-3/bConfigurationValue

This results in a new dmesg output:

[85295.502696] ti_usb_3410_5052 4-3:2.0: TI USB 3410 1 port adapter converter detected
[85295.502963] usb 4-3: TI USB 3410 1 port adapter converter now attached to ttyUSB2


The specific usb port will also vary so for now you need to examine the output of dmesg and change ser.c to match (and re-compile) before using msploader.

So long as you do not remove the usb stick you can load the msp430 as many times as you like.

This msploader release also includes an openmsp430 directory. This will be described in a separate post. Basically using an open source msp430 core in verilog and icarus verilog to create a simulation you can execute your msp430 programs with visibility inside the pins. I dont expect this to be a 100% accurate at the signal level core, but you can certainly watch the rom, ram and registers, something you cannot do staring at the chip on a board.

No comments:

Post a Comment