Tuesday, October 25, 2011

Uploading an executable program to MSB430 mote

 Even though most of the times I write programs for sensor motes with Contiki operating system, there are situations where we have to write applications that can run independently on motes without an operating system.

When working with Contiki OS, we don't have to worry about uploading our program to mote. As an example if we have a Contiki program named my_app.c we can compile it and upload to a MSB430 mote by issuing the following commnad.

make TARGET=msb430 my_app.u

It will compile our program with the Contiki OS and burn it to the flash memory of the MSB430 mote. But if we write applications without Contiki, we have to take care of compiling and burning it to mote separately. As an example take a look at the following program saved as blink.c which can blink the LEDs of MSB430 motes. It doesn't rely on any operating system routines.

1:  #include <msp430x16x.h>  
2:  int main () {  
3:  int i,j=0;  
4:  P5SEL = 0x00;  
5:  P5DIR = 0xff;  
6:  while (1) {  
7:       for (i=0 ; i<2000 ; i++){  
8:            P5OUT = 0x00;  
9:       }  
10:       for (j=0 ; j<2000 ; j++){  
11:            P5OUT = 0xff;  
12:       }  
13:  }  
14:  return 1;  
15:  }  




We can compile this program by issuing the following command.

msp430-gcc -mmcu=msp430x1612 blink.c

The parameter -mmcu is used to specify the architecture type of the microcontroller that our executable code is intended to run. Here we have given the type of MCU that resides in the MSB430 mote. This command will create an executable file as a.out which can run on MSB430 motes. So it's time to upload it to mote.   

For this, I use a little trick. Contiki source code contains a tool named as PyJTAG which will be used to write a compiled Contiki application to motes flash memory. We can use the same tool to upload our program to mote. You can find that tool in the following location in the Contiki source code.

contiki-2.x/platform/msb430/buildscripts/jtag/pyjtag

Copy that whole pyjtag directory to some other place like your desktop. Now copy the executable program that we got (a.out) to the inside of that new pyjtag
directory. Now open a terminal and goto this pyjtag directory from it.



Connect the MSB430 mote to the parallel port of the PC and give permissions to access it by issuing the commnd,

sudo chmod 777 /dev/parport0

Issue the following command to erase the current content of flash memory of MSB430 mote.

python jtag.py -l /dev/parport0 -m

Then issue the following command to burn our a.out program to mote.

python jtag.py -l /dev/parport0 -D -D -S -R 2048 -p a.out

 After this command completed you will notice that LED of the mote is blinking. If so, you have successfully burnt an independent program to a MSB430 mote without an operating system.
 

No comments:

Post a Comment