def __init__(self, *args, **kargs):
self.data=[0];
def timeout(self):
- print "timout\n";
+ print "timeout\n";
def serInit(self, port=None):
"""Open the serial port"""
self.serialport = serial.Serial(
port,
+ #300,
+ #2400,
+ #4800,
#9600,
+ #19200,
+ #38400,
+ #57600,
115200,
parity = serial.PARITY_NONE
)
#time.sleep(1);
self.readcmd(); #Read the first command.
if(self.verb!=0x7F):
- print "Verb is wrong. Incorrect firmware?";
-
+ print "Verb %02x is wrong. Incorrect firmware?" % self.verb;
+ print "Connected."
def writecmd(self, app, verb, count, data):
"""Write a command and some data to the GoodFET."""
self.serialport.write(chr(app));
"""Determine how many bytes of RAM are unused by looking for 0xBEEF.."""
self.writecmd(0,0x91,0,self.data);
return ord(self.data[0])+(ord(self.data[1])<<8);
+
+ #Baud rates.
+ baudrates=[115200,
+ 9600,
+ 19200,
+ 38400,
+ 57600,
+ 115200];
def setBaud(self,baud):
- rates=[9600, 9600, 19200, 38400];
+ """Change the baud rate. TODO fix this."""
+ rates=self.baudrates;
self.data=[baud];
print "Changing FET baud."
self.serialport.write(chr(0x00));
print "Baud is now %i." % rates[baud];
return;
+ def readbyte(self):
+ return ord(self.serialport.read(1));
+ def findbaud(self):
+ for r in self.baudrates:
+ print "\nTrying %i" % r;
+ self.serialport.setBaudrate(r);
+ #time.sleep(1);
+ self.serialport.flushInput()
+ self.serialport.flushOutput()
+
+ for i in range(1,10):
+ self.readbyte();
+
+ print "Read %02x %02x %02x %02x" % (
+ self.readbyte(),self.readbyte(),self.readbyte(),self.readbyte());
def monitortest(self):
"""Self-test several functions through the monitor."""
print "Performing monitor self-test.";
print "0x%04x RAM bytes free." % client.monitor_ram_depth();
if(sys.argv[1]=="test"):
client.monitortest();
+if(sys.argv[1]=="findbaud"):
+ client.findbaud();
if(sys.argv[1]=="dump"):
f = sys.argv[2];
start=0x0200;
PORT=/dev/ttyUSB0
-BSL=msp430-bsl --invert-reset --invert-test -c $(PORT) --speed=38400
+BSL=../../contrib/tos-bsl --invert-reset --invert-test -c $(PORT) --speed=38400
#mcu=msp430x2618
mcu=msp430x1612
msp430_init_dco();\r
msp430_init_uart();\r
\r
+ \r
+ \r
+ \r
//Enable Interrupts.\r
//eint();\r
}\r
\r
//Ready\r
//txdata(MONITOR,OK,0);\r
+ //while (1){\r
+ // txdata(0xFF,0xff,0x0);\r
+ // delay(1000);\r
+ //}\r
+ //delay(0xffff);\r
+ //while(*((int*)0x1001));\r
+ //while(1)\r
+ // txdata(0xFF,0xFF,0);\r
txstring(MONITOR,OK,"http://goodfet.sf.net/");\r
\r
//Command loop. There's no end!\r
//! Receive a byte.
unsigned char serial1_rx(){
//TODO
+ return 00;
}
-
//! Transmit a byte.
void serial_tx(unsigned char x){
- while ((IFG2 & UCA0TXIFG) == 0); //loop unti lbuffer is free
+ while ((IFG2 & UCA0TXIFG) == 0); //loop until buffer is free
+ UCA0TXBUF = x; /* send the character */
+ while(!(IFG2 & UCA0TXIFG));
+}
+//! Transmit a byte.
+void serial_tx_old(unsigned char x){
+ while ((IFG2 & UCA0TXIFG) == 0); //loop until buffer is free
UCA0TXBUF = x; /* send the character */
while(!(IFG2 & UCA0TXIFG));
}
//! Transmit a byte on the second UART.
void serial1_tx(unsigned char x){
+
}
//! Set the baud rate.
}
-//host.h says 0x2B for DCO=4.9MHZ
-//Divide by four for accuracy.
//19200
-#define BAUD0EN 0x41
-#define BAUD1EN 0x03
+#define BAUD0EN 0x1b
+#define BAUD1EN 0x00
void msp430_init_uart(){
- // Serial on P3.4, P3.5
+
+ // Serial on P3.4, P3.5
P3SEL |= BIT4 + BIT5;
P3DIR |= BIT4;
-
- //UCA0CTL1 |= UCSWRST; /* disable UART */
+
+ //UCA0CTL1 |= UCSWRST; /* disable UART */
UCA0CTL0 = 0x00;
- //UCA0CTL0 |= UCMSB ;
- UCA0CTL1 |= UCSSEL_2; // SMCLK
- UCA0BR0 = BAUD0EN; // 115200
+ //UCA0CTL0 |= UCMSB ;
+ UCA0CTL1 |= UCSSEL_2; // SMCLK
+ UCA0BR0 = BAUD0EN; // 115200
UCA0BR1 = BAUD1EN;
- UCA0MCTL = 0; // Modulation UCBRSx = 5
- UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
-
-}
+ UCA0MCTL = 0; // Modulation UCBRSx = 5
+ UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
+
+ //Leave this commented!
+ //Interrupt is handled by target code, not by bootloader.
+ //IE2 |= UCA0RXIE;
+}
+
+//external resistor
+#define DCOR 1
void msp430_init_dco() {
BCSCTL1 = CALBC1_16MHZ;
- DCOCTL = CALDCO_16MHZ;
-
+ DCOCTL = CALDCO_16MHZ;
return;
}
BSL=tos-bsl --invert-reset --invert-test -c $(PORT)
#mcu=msp430x1611
-mcu=msp430x1612
+mcu=msp430x2618
-GCCINC=-T ../../ldscripts/161x.x
+#GCCINC=-T ../../ldscripts/161x.x
CC=msp430-gcc -g -mmcu=$(mcu) -DGCC $(GCCINC) -I ../../include
BSL=tos-bsl --invert-reset --invert-test -c $(PORT)
#mcu=msp430x1611
-mcu=msp430x1612
+mcu=msp430x2618
#ldscript is wonky
-GCCINC=-T ../../ldscripts/161x.x
+#GCCINC=-T ../../ldscripts/161x.x
CC=msp430-gcc -g -mmcu=$(mcu) -DGCC $(GCCINC) -I ../../include
-libs=../../lib/msp430f1612.c
+libs=../../lib/msp430x2618.c
app=echo
install: $(app)
PLEDOUT^=PLEDPIN; // Blink\r
\r
//while(1) serial_tx(serial_rx());\r
- while(1) serial_tx(serial_rx());\r
+ while(1) serial_tx('G');\r
\r
while(1){\r
i = 10000;\r