WIP give up for the day, alignment issues??
authorDan White <dan@whiteaudio.com>
Sat, 8 Sep 2012 04:39:02 +0000 (23:39 -0500)
committerDan White <dan@whiteaudio.com>
Sat, 8 Sep 2012 04:39:02 +0000 (23:39 -0500)
msp4th/Makefile
msp4th/ldscript_ns430
msp4th/main.c
msp4th/msp4th.c
msp4th/ns430-uart.c
msp4th/x.c
python-lib/flash.py
rename_regs.sh

index c4722b0583ffbe0449db0f04dd763586406ba1de..d309c2106fb154c9d10d3c6d3673b9e0bc00719a 100644 (file)
@@ -21,9 +21,10 @@ SOURCES = main.c ns430-uart.c msp4th.c
 INCLUDES = -I.
 # Add or subtract whatever MSPGCC flags you want. There are plenty more
 #######################################################################################
-CFLAGS   = -mmcu=$(MCU) -g -Os -Wall -Wunused $(INCLUDES)   
+#CFLAGS   = -mmcu=$(MCU) -g -Os -Wall -Wunused $(INCLUDES)   
+CFLAGS   = -mmcu=$(MCU) -O1 -Wall -Wunused -mendup-at=main $(INCLUDES)   
 #ASFLAGS  = -mmcu=$(MCU) -x assembler-with-cpp -Wa,-gstabs
-ASFLAGS  = -mmcu=$(MCU) -Os -Wall -Wunused
+ASFLAGS  = -mmcu=$(MCU) -O1 -Wall -Wunused
 LDFLAGS  = -mmcu=$(MCU) -Wl,-Map=$(TARGET).map -T ldscript_ns430
 ########################################################################################
 CC       = msp430-gcc
@@ -52,7 +53,7 @@ OBJECTS = $(SOURCES:.c=.o)
 ASSEMBLYS = $(SOURCES:.c=.lst)
 
 #all: $(TARGET).elf $(TARGET).hex $(TARGET).txt 
-all: $(TARGET).elf $(TARGET).hex $(ASSEMBLYS)
+all: $(TARGET).elf $(TARGET).hex $(TARGET).xout $(ASSEMBLYS)
 
 $(TARGET).elf: $(OBJECTS)
        @echo "Linking $@"
@@ -65,6 +66,11 @@ $(TARGET).elf: $(OBJECTS)
 %.hex: %.elf
        $(OBJCOPY) -O ihex $< $@
 
+%.xout: %.elf
+       msp430-objdump --disassemble-all $< \
+           | ../inc2syms.py ../ns430-atoi.inc \
+           | ../rename_regs.sh > $@
+
 %.txt: %.hex
        $(MAKETXT) -O $@ -TITXT $< -I
        unix2dos $(TARGET).txt
@@ -91,6 +97,10 @@ endif
        @echo "Generating dependencies $@ from $<"
        $(CC) -M ${CFLAGS} $< >$@
 
+.PHONY:        flash
+flash: $(TARGET).hex
+       ./flash.py -e $(TARGET).hex
+
 #.SILENT:
 .PHONY:       clean
 clean:
index fdee3f9b3f75033f7fc32a050651fc3c051ccc7e..a0f26e5473afeec516aeb5b97cc286f068725cfd 100644 (file)
@@ -3,9 +3,9 @@ OUTPUT_FORMAT("elf32-msp430","elf32-msp430","elf32-msp430")
 OUTPUT_ARCH(msp:20)\r
 MEMORY\r
 {\r
-  text   (rx)          : ORIGIN = 0x4000, LENGTH = 0x3FDF\r
-  data   (rwx)         : ORIGIN = 0x4000, LENGTH = 0x3FDF\r
-  vectors (rw)         : ORIGIN = 0xFFDE, LENGTH = 32\r
+  text   (rx)          : ORIGIN = 0x4000, LENGTH = 0x3FE0\r
+  data   (rwx)         : ORIGIN = 0x4000, LENGTH = 0x3FE0\r
+  vectors (rw)         : ORIGIN = 0xFFE0, LENGTH = 64\r
   bootloader(rx)       : ORIGIN = 0x0800, LENGTH = 2048\r
   infomem(rx)          : ORIGIN = 0x0000, LENGTH = 256\r
   infomemnobits(rx)    : ORIGIN = 0x0100, LENGTH = 256\r
@@ -196,7 +196,7 @@ SECTIONS
   .debug_str      0 : { *(.debug_str) }\r
   .debug_loc      0 : { *(.debug_loc) }\r
   .debug_macinfo  0 : { *(.debug_macinfo) }\r
-  PROVIDE (__stack = 0xC000) ;\r
+  PROVIDE (__stack = ORIGIN(data) + LENGTH(data) - 1) ;\r
   PROVIDE (__data_start_rom = _etext) ;\r
   PROVIDE (__data_end_rom   = _etext + SIZEOF (.data)) ;\r
   PROVIDE (__noinit_start_rom = _etext + SIZEOF (.data)) ;\r
index 18205746166b3970e53f5ef42114b427dbec87bd..700df9fff7d64a5b75e6947e14a0672b35256a5e 100644 (file)
 #include "msp4th.h"
 
 
+#define DEVBOARD_CLOCK 25000000L
+#define BAUDRATE 4800L
+
+
+NAKED(_reset_vector__){
+  __asm__ __volatile__("br #main"::);
+}
+
+
+static void __inline__ delay(register unsigned int n){
+  __asm__ __volatile__ (
+      "1: \n"
+      " dec     %[n] \n"
+      " jne     1b \n"
+      : [n] "+r"(n));
+}
+
+
 int main(void){
 
+    uint16_t tmp;
+
+    dint();
+
     PAPER = 0x0030;
     PAOUT = 0x0000;
     PAOEN = 0x0010;  // set data direction registers
 
-    init_msp4th();
+    UART0_BCR = BCR(DEVBOARD_CLOCK, BAUDRATE);
+    UART0_CR = UARTEn;
 
-    /*TMR0_CNT = 0x0000;*/
-    /*TMR0_SR = 0;*/
-    /*TMR0_RC = 1059;*/
-    /*TMR0_CR = 0x003C;*/
+    tmp = UART0_SR;
 
-    /* 8e6 / (16*19200) - 1 = 25.0416 */
-    /* 8e6 / (16*2400) - 1 = 207.33 */
-    /* 25e6 / (16*2400) - 1 = 207.33 */
-    UART0_BCR = BCR(25000000L, 2400L);
-    UART0_CR = UARTEn;
 
-    dint();
     putchar('!');   
 
     char c;
@@ -49,7 +63,10 @@ int main(void){
     putchar('g');
     puts("This is a test of the UART serial printing\r\nit really does work ...\r\n");
 
+    init_msp4th();
     processLoop();
 
     return 0;
 }
+
+
index 685d3949f1a0b18774aff4a56ae3f977e90f4494..3cb915bd0ce200e64b8bf4803da409cb020417bc 100644 (file)
@@ -16,6 +16,9 @@
 #define PROG_SPACE 256
 #define USR_OPCODE_SIZE 32
 
+#define LINE_SIZE 128
+#define WORD_SIZE 32
+
 #define BI_PROG_SHIFT 10000
 
 /*
@@ -32,7 +35,7 @@ void pushAddrStack(int16_t n);
 int16_t lookupToken(char *x, char *l);
 void luFunc(void);
 void numFunc(void);
-void ifFunc(uint8_t x);
+void ifFunc(int16_t x);
 void pushnFunc(void);
 void overFunc(void);
 void dfnFunc(void);
@@ -296,12 +299,12 @@ const int16_t progBi[] = { // address actually start at 10000
          
 int16_t progCounter;
 
-char lineBuffer[128];      /* input line buffer */
+char lineBuffer[LINE_SIZE];      /* input line buffer */
 
 uint16_t lineBufferPtr;                 /* input line buffer pointer */
 // uint8_t xit;                    /* set to 1 to kill program */
 
-char wordBuffer[32];           // just get a word
+char wordBuffer[WORD_SIZE];            // just get a word
 
 
 uint8_t getKeyB(){
@@ -388,8 +391,7 @@ void inline listFunction(){
 }
   
 int16_t popMathStack(){
-  int16_t i,j;
-
+  volatile int16_t i,j;
   j = mathStack[0];
   for(i=1;i<MATH_STACK_SIZE;i++){
     mathStack[i-1] = mathStack[i];
@@ -399,7 +401,7 @@ int16_t popMathStack(){
 }
 
 void pushMathStack(int16_t n){
-  uint16_t i;
+  volatile uint16_t i;
   for(i=MATH_STACK_SIZE - 2;i > 0;i--){
     mathStack[i] = mathStack[i-1];
   }
@@ -407,14 +409,14 @@ void pushMathStack(int16_t n){
 }
 
 int16_t popAddrStack(){
-  int16_t j;
+  volatile int16_t j;
   j = addrStack[addrStackPtr];
-  addrStackPtr++;
+  addrStackPtr = addrStackPtr + 1;
   return(j);
 }
 
 void pushAddrStack(int16_t n){
-  addrStackPtr--;
+  addrStackPtr = addrStackPtr - 1;
   addrStack[addrStackPtr] = n;
 }
 
@@ -492,73 +494,92 @@ void luFunc(){
 } 
 
 void numFunc(){  // the word to test is in wordBuffer
-  int16_t i,j,n;
-  puts("in numFunc()\r\n");
-  puts(wordBuffer);
+  volatile int16_t i;
+  volatile int16_t j;
+  volatile int16_t n;
+
+  puts("in numFunc()\r");
+  /*puts(wordBuffer);*/
   // first check for neg sign
+  puts("here\r");
   i = 0;
-  if(wordBuffer[0] == '-'){
-    i++;
+  if(wordBuffer[i] == '-'){
+    i = i + 1;
   }
+  puts("there\r");
   if((wordBuffer[i] >= '0') && (wordBuffer[i] <= '9')){
+    puts("num\r");
     // it is a number 
     j = 1;
     // check if hex
     if(wordBuffer[0] == '0' && wordBuffer[1] == 'x'){
+      puts("hex\r");
       // base 16 number ... just assume all characters are good
       i=2;
       n = 0;
       while(wordBuffer[i]){
         n = n << 4;
-        n += wordBuffer[i] - '0';
+        n = n + wordBuffer[i] - '0';
         if(wordBuffer[i] > '9'){
-          n += -7;
+          n = n - 7;
         }
-        i++;
+        i = i + 1;
       }
     } else {
+      puts("dec\r");
       // base 10 number
       n = 0;
       while(wordBuffer[i]){
-        n *= 10;
-        n += wordBuffer[i] - '0';
-        i++;
+        n = n * 10;
+        n = n + wordBuffer[i] - '0';
+        i = i + 1;
       }
       if(wordBuffer[0] == '-'){
         n = -n;
       }
     }
   } else {
+    puts("not number\r");
     n = 0;
     j = 0;
   }
   /*printNumber(n);*/
   /*printNumber(j);*/
   /*puts("\r\n");*/
+  putchar('.');
   pushMathStack(n);
   pushMathStack(j);
+  putchar('.');
 }
 
-void ifFunc(uint8_t x){     // used as goto if x == 1
-  int16_t addr;
-  int16_t i;
-  if(progCounter > 9999){
-    addr = progBi[progCounter - 10000];
-  } else {
-    addr = prog[progCounter];
-  }
-  progCounter++;
+void ifFunc(int16_t x){     // used as goto if x == 1
+    volatile int16_t addr;
+    volatile uint16_t tmp;
+    volatile int16_t i;
 
-  if(x == 1){
-    // this is a goto
-    progCounter = addr;
-  } else {
-    // this is the "if" processing
-    i = popMathStack();
-    if(!i){
-      progCounter = addr;
+    puts("in ifFunc\r");
+    puts("here\r");
+
+    if(progCounter > 9999){
+        tmp = progCounter - 10000;
+        addr = progBi[tmp];
+    } else {
+        addr = prog[progCounter];
     }
-  }
+    progCounter = progCounter + 1;
+
+    putchar('.');
+    if(x == 1){
+        // this is a goto
+        progCounter = addr;
+    } else {
+        // this is the "if" processing
+        i = popMathStack();
+        if(!i){
+            progCounter = addr;
+        }
+    }
+    putchar('.');
 }
 
 void pushnFunc(){
@@ -568,7 +589,7 @@ void pushnFunc(){
   } else {
     i = prog[progCounter];
   }
-  progCounter++;
+  progCounter = progCounter + 1;
   pushMathStack(i);
 }
 
@@ -583,10 +604,12 @@ void dfnFunc(){
   // this function adds a new def to the list and creats a new opcode
   i = 0;
   while(wordBuffer[i]){
-    cmdList[cmdListPtr++] = wordBuffer[i];
-    i++;
+    cmdList[cmdListPtr] = wordBuffer[i];
+    cmdListPtr = cmdListPtr + 1;
+    i = i + 1;
   }
-  cmdList[cmdListPtr++] = ' ';
+  cmdList[cmdListPtr] = ' ';
+  cmdListPtr = cmdListPtr + 1;
   cmdList[cmdListPtr] = 0;
   i = lookupToken(wordBuffer,cmdList);
   progOps[i] = progPtr;
@@ -594,8 +617,9 @@ void dfnFunc(){
 
 
 void printNumber(int16_t n){
-  int16_t k,x[7];
-  int16_t i,j;
+  volatile int16_t k,x[7];
+  volatile uint16_t i,j;
+  putchar('.');
   k = n;
   if(k < 0){
     k = -k;
@@ -605,17 +629,19 @@ void printNumber(int16_t n){
   do{
     j = k % 10;
     k = k / 10;
-
-    x[i++] = j + '0';
+    x[i] = j + '0';
+    i = i + 1;
   }while(k);
-  i--;
+  i = i - 1;
   
   if(n < 0){
     putchar('-');
   }
   do{
-    putchar(x[i--]);
+    putchar(x[i]);
+    i = i - 1;
   }while(i >= 0);
+  putchar('.');
   putchar(' ');
 }
 
@@ -667,8 +693,8 @@ void execN(int16_t n){
   int16_t i,j,k,m;
   int32_t x,y,z;
   puts("execN: ");
-  printNumber(n);
-  puts("\r\n");
+  printHexWord(n);
+  puts("\r");
   switch(n){
     case 1:
   //    xit = 1;
@@ -759,9 +785,10 @@ void execN(int16_t n){
      break;
 
     case 17: // allot
-      prog[progPtr++] = popMathStack();
+      prog[progPtr] = popMathStack();
+      progPtr = progPtr + 1;
       if(progPtr >= PROG_SPACE){
-        puts("prog mem");
+        puts("prog mem\r");
       }
       break;
 
@@ -823,7 +850,7 @@ void execN(int16_t n){
 
 
     case 30:  // num
-      puts("in case 30\r\n");
+      puts("in case 30\r");
       numFunc();
       break;
 
@@ -900,7 +927,7 @@ void execN(int16_t n){
       j = popAddrStack();  // loop address
       k = popAddrStack();  // count
       m = popAddrStack();  // limit
-      k++;                // up the count
+      k = k + 1;           // up the count
       if(k >= m){
         // we are done
       } else {
@@ -1043,14 +1070,14 @@ void execN(int16_t n){
       break;
 
     default:
-      puts("opcode ");      
+      puts("opcode \r");      
       break;
   }
 }
 
 
 void init_msp4th(void) {
-    uint16_t i;
+    volatile uint16_t i;
 
 //  xit = 0;
     addrStackPtr = ADDR_STACK_SIZE;    // this is one past the end !!!! as it should be
@@ -1064,11 +1091,11 @@ void init_msp4th(void) {
     dirMemory = (void *) 0;   // its an array starting at zero
 
     lineBufferPtr = 0;
-    for (i=0; i < 128; i++) {
+    for (i=0; i < LINE_SIZE; i++) {
         lineBuffer[i] = 0;
     }
 
-    for (i=0; i < 32; i++) {
+    for (i=0; i < WORD_SIZE; i++) {
         wordBuffer[i] = 0;
     }
 
@@ -1078,16 +1105,18 @@ void init_msp4th(void) {
 
 void processLoop(){            // this processes the forth opcodes.
   int16_t opcode;
+  int16_t tmp;
 
   while(1){
-      puts("processLoop()\r\n");
+      puts("processLoop()\r");
     if(progCounter > 9999){
-      opcode = progBi[progCounter - 10000];
+      tmp = progCounter - 10000;
+      opcode = progBi[tmp];
     } else {
       opcode = prog[progCounter];
     }
 
-    progCounter++;
+    progCounter = progCounter + 1;
 
     if(opcode > 19999){
       // this is a built in opcode
index b1b6cf519ed3c6a8f1a3ff9f62efe0c2ecc85220..5e35d7867aa88649d4af185fe9d510c5061568ae 100644 (file)
@@ -14,7 +14,7 @@ int putchar(int c)
         // wait for register to clear
         i++;
     }
-    UART0_TDR = c;
+    UART0_TDR = (c & 0xff);
     return 0;
 }
 
@@ -24,7 +24,7 @@ int getchar(void){
   while ((UART0_SR & RDRF) == 0) {
       // wait for char
   }
-  c = UART0_RDR & 0x00ff;
+  c = (UART0_RDR & 0x00ff);
   return c;
 } 
 
index 63ad6c6242fb01957fc232f1010ec209a2442ab1..99ffcab8ffde3efdcb7f4b4c7270f8e1c8cf37c2 100644 (file)
@@ -1394,7 +1394,6 @@ NAKED(_unexpected_){
 
 
 INTERRUPT_VECTORS = { 
-
    main,     // RST          just jump to next
    main,     // NMI          restart at main
    main,               // External IRQ
index 7d923c75a8d0d29519f7470404866cd1e2da391a..6f090bd97223640be45700829424758ba4eaebc1 100755 (executable)
@@ -181,11 +181,14 @@ class M25PExx(object):
             e = min(s+256, len(data))
             a = addr + s
             while not self.isReady():
-                print hex(self.status())
-            print 'writing page: %06x %s' % (a, str2hex(data[s:e]))
+                pass
+                #print hex(self.status())
+            d = data[s:e]
+            print len(d),
+            print 'writing page: %06x %s' % (a, str2hex(d))
             self.writeEnable(True)
-            self.writePage(a, data[s:e])
-            print hex(self.status())
+            self.writePage(a, d)
+            #print hex(self.status())
 
     def program(self, addr, data):
         if addr & 0xff != 0:
@@ -212,17 +215,18 @@ spi0 = AtoiSPI0(1000e3) #port A
 #flash = M25PExx(spi0, 'flash')
 flash = M25PExx(spi0)
 flash.power(True)
-print flash.status()
+#print flash.status()
 print 'id:', str2hex(flash.id())
-print flash.status()
-print 'data:', str2hex(flash.read(0x4000, 16))
+#print flash.status()
+#print 'data:', str2hex(flash.read(0x4000, 16))
 
 flash.writeEnable(True)
 if opt.erase:
     flash.eraseAll()
     print 'erasing',
     while not flash.isReady():
-        print '.',
+        pass
+        #print '.',
     print
 
 #h = IntelHex('../msp4th/hello-world.hex')
@@ -246,7 +250,8 @@ if 1:
 # the flash uses 256-byte pages, include code from 0xff00 - 0xffcf
 # as it was excluded above
     vectors = ''.join([chr(h[i]) for i in range(0xff00, 0x10000-2)])
-    vectors += '\x00\x40'
+    #vectors += '\x00\x40'
+    vectors = ''.join([chr(h[i]) for i in range(0xff00, 0x10000)])
     flash.write(0xff00, vectors)
 
 while not flash.isReady():
@@ -259,16 +264,17 @@ if 1:
         nr = min(256, len(code)-nread)
         c = flash.read(0x4000 + nread, nr)
         c2 += c
-        print 'read: %06x %s' % (0x4000+nread, str2hex(c))
+        #print 'read: %06x %s' % (0x4000+nread, str2hex(c))
         nread += nr
 
     print len(code), len(c2)
     if 0:
         for i in range(len(code)):
             print i, code[i] == c2[i]
-    print len(code), len(c2)
-    print str2hex(code[-4:]), str2hex(c2[-4:])
-    print all([code[i] == c2[i] for i in range(len(code))])
+    print 'code written/read:', len(code), len(c2)
+    #print str2hex(code[-4:]), str2hex(c2[-4:])
+    print 'verified:', all([code[i] == c2[i] for i in range(len(code))])
+
+#print str2hex(code[:4])
+#print str2hex(c2[:4])
 
-print str2hex(code[:4])
-print str2hex(c2[:4])
index 58da61d4d565829c1fddfe6efc4e743c8d1a8b55..b5d23e10cf406ec7c3398d9c5ba27fde8bc19d0e 100755 (executable)
@@ -1,6 +1,9 @@
 #!/bin/bash
 
-sed -r -e 's/[^;]r0([ \t,\)])/pc\1/g' \
-    -e 's/[^;]r1([ \t,\)])/sp\1/g' \
-    -e 's/[^;]r2([ \t,\)])/sr\1/g'
+#sed -r -e 's/[^;]r0([ \t,\)])/pc\1/g' \
+       #-e 's/[^;]r1([ \t,\)])/sp\1/g' \
+       #-e 's/[^;]r2([ \t,\)])/sr\1/g'
+sed -r -e 's/([, \t])r0([ \t,\)])/\1pc\2/g' \
+       -e 's/([, \t])r1([ \t,\)])/\1sp\2/g' \
+       -e 's/([, \t])r2([ \t,\)])/\1sr\2/g'