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
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 $@"
%.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
@echo "Generating dependencies $@ from $<"
$(CC) -M ${CFLAGS} $< >$@
+.PHONY: flash
+flash: $(TARGET).hex
+ ./flash.py -e $(TARGET).hex
+
#.SILENT:
.PHONY: clean
clean:
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
.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
#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;
putchar('g');
puts("This is a test of the UART serial printing\r\nit really does work ...\r\n");
+ init_msp4th();
processLoop();
return 0;
}
+
+
#define PROG_SPACE 256
#define USR_OPCODE_SIZE 32
+#define LINE_SIZE 128
+#define WORD_SIZE 32
+
#define BI_PROG_SHIFT 10000
/*
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);
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(){
}
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];
}
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];
}
}
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;
}
}
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(){
} else {
i = prog[progCounter];
}
- progCounter++;
+ progCounter = progCounter + 1;
pushMathStack(i);
}
// 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;
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;
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(' ');
}
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;
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;
case 30: // num
- puts("in case 30\r\n");
+ puts("in case 30\r");
numFunc();
break;
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 {
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
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;
}
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
// wait for register to clear
i++;
}
- UART0_TDR = c;
+ UART0_TDR = (c & 0xff);
return 0;
}
while ((UART0_SR & RDRF) == 0) {
// wait for char
}
- c = UART0_RDR & 0x00ff;
+ c = (UART0_RDR & 0x00ff);
return c;
}
INTERRUPT_VECTORS = {
-
main, // RST just jump to next
main, // NMI restart at main
main, // External IRQ
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:
#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')
# 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():
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])
#!/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'