From b6f8e810c3687b22f565493a1676b1f7cf6d32e5 Mon Sep 17 00:00:00 2001 From: Dan White Date: Fri, 7 Sep 2012 23:39:02 -0500 Subject: [PATCH] WIP give up for the day, alignment issues?? --- msp4th/Makefile | 16 ++++- msp4th/ldscript_ns430 | 8 +-- msp4th/main.c | 39 ++++++++--- msp4th/msp4th.c | 151 +++++++++++++++++++++++++----------------- msp4th/ns430-uart.c | 4 +- msp4th/x.c | 1 - python-lib/flash.py | 36 +++++----- rename_regs.sh | 9 ++- 8 files changed, 164 insertions(+), 100 deletions(-) diff --git a/msp4th/Makefile b/msp4th/Makefile index c4722b0..d309c21 100644 --- a/msp4th/Makefile +++ b/msp4th/Makefile @@ -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: diff --git a/msp4th/ldscript_ns430 b/msp4th/ldscript_ns430 index fdee3f9..a0f26e5 100644 --- a/msp4th/ldscript_ns430 +++ b/msp4th/ldscript_ns430 @@ -3,9 +3,9 @@ OUTPUT_FORMAT("elf32-msp430","elf32-msp430","elf32-msp430") OUTPUT_ARCH(msp:20) MEMORY { - text (rx) : ORIGIN = 0x4000, LENGTH = 0x3FDF - data (rwx) : ORIGIN = 0x4000, LENGTH = 0x3FDF - vectors (rw) : ORIGIN = 0xFFDE, LENGTH = 32 + text (rx) : ORIGIN = 0x4000, LENGTH = 0x3FE0 + data (rwx) : ORIGIN = 0x4000, LENGTH = 0x3FE0 + vectors (rw) : ORIGIN = 0xFFE0, LENGTH = 64 bootloader(rx) : ORIGIN = 0x0800, LENGTH = 2048 infomem(rx) : ORIGIN = 0x0000, LENGTH = 256 infomemnobits(rx) : ORIGIN = 0x0100, LENGTH = 256 @@ -196,7 +196,7 @@ SECTIONS .debug_str 0 : { *(.debug_str) } .debug_loc 0 : { *(.debug_loc) } .debug_macinfo 0 : { *(.debug_macinfo) } - PROVIDE (__stack = 0xC000) ; + PROVIDE (__stack = ORIGIN(data) + LENGTH(data) - 1) ; PROVIDE (__data_start_rom = _etext) ; PROVIDE (__data_end_rom = _etext + SIZEOF (.data)) ; PROVIDE (__noinit_start_rom = _etext + SIZEOF (.data)) ; diff --git a/msp4th/main.c b/msp4th/main.c index 1820574..700df9f 100644 --- a/msp4th/main.c +++ b/msp4th/main.c @@ -10,26 +10,40 @@ #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; } + + diff --git a/msp4th/msp4th.c b/msp4th/msp4th.c index 685d394..3cb915b 100644 --- a/msp4th/msp4th.c +++ b/msp4th/msp4th.c @@ -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 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 diff --git a/msp4th/ns430-uart.c b/msp4th/ns430-uart.c index b1b6cf5..5e35d78 100644 --- a/msp4th/ns430-uart.c +++ b/msp4th/ns430-uart.c @@ -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; } diff --git a/msp4th/x.c b/msp4th/x.c index 63ad6c6..99ffcab 100644 --- a/msp4th/x.c +++ b/msp4th/x.c @@ -1394,7 +1394,6 @@ NAKED(_unexpected_){ INTERRUPT_VECTORS = { - main, // RST just jump to next main, // NMI restart at main main, // External IRQ diff --git a/python-lib/flash.py b/python-lib/flash.py index 7d923c7..6f090bd 100755 --- a/python-lib/flash.py +++ b/python-lib/flash.py @@ -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]) diff --git a/rename_regs.sh b/rename_regs.sh index 58da61d..b5d23e1 100755 --- a/rename_regs.sh +++ b/rename_regs.sh @@ -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' -- 2.25.1