From c01514186967d9acee469cdd74ac1b8930351c6e Mon Sep 17 00:00:00 2001 From: Travis Goodspeed Date: Sun, 11 Nov 2018 12:24:20 -0500 Subject: [PATCH] Codeplug is now stored in regular flash, rather than info flash. Fixes tuner in SBW-flashed devices. --- bin/goodwatch-txt2cpstr.py | 83 ++++++++++++++++++++++++++++++++++++++ firmware/.gitignore | 2 + firmware/Makefile | 7 +++- firmware/codeplug.c | 5 ++- 4 files changed, 94 insertions(+), 3 deletions(-) create mode 100755 bin/goodwatch-txt2cpstr.py diff --git a/bin/goodwatch-txt2cpstr.py b/bin/goodwatch-txt2cpstr.py new file mode 100755 index 0000000..9e4edc3 --- /dev/null +++ b/bin/goodwatch-txt2cpstr.py @@ -0,0 +1,83 @@ +#!/usr/bin/python2 + +## This quick and dirty tool converts a textfile of frequencies and +## names into a GoodWatch codeplug, for storage in the firmware image. +## Previously, we converted it to an Intel Hex image that loaded at +## 0x1800, but this caused problems with mspdebug's tilib driver, +## which can't seem to unlock info flash. + +import sys, argparse; + + +def freqbytes(freq): + """Converts a frequency to three FREQ bytes. Assumes 26MHz xtal.""" + freqMult = (0x10000 / 1000000.0) / 26.0; + num=int(freq*1e6*freqMult); + FREQ2=(num>>16) & 0xFF; + FREQ1=(num>> 8) & 0xFF; + FREQ0= num & 0xFF + return FREQ2, FREQ1, FREQ0; + +codeplugadr=0x1800; +def handleline(line): + """Handles one line of the file.""" + global codeplugadr; + if len(line)==0: #Empty line. + return; + elif line[0]=='#': #Comment + return; + else: + # This is a real line. First word ought to be the frequency, + # and the second word ought to be the name (8 characters or + # less). Further words would be flags, but we ignore them for + # now. + LEN=12; + words=line.split(); + freq=float(words[0]); + name=words[1]; + namehex=name.encode('hex'); + assert(len(name)<=8); + while len(namehex)<16: + namehex='20'+namehex; + FLAGS=0; + (FREQ2, FREQ1, FREQ0) = freqbytes(freq); + + hexline="\"\\x%02x\\x%02x\\x%02x\\x%02x\" \"%s\"" % ( + FLAGS, FREQ2,FREQ1,FREQ0, namehex.decode("hex") + ); + + line="%s //%s \n" %( + hexline, name + ); + + codeplugadr=codeplugadr+12; + return line; + +def convertcodeplug(infile, outfile): + """Converts a codeplug textfile into an intel hex file for flashing.""" + i=open(infile,'r'); + o=open(outfile,'w'); + + o.write("/* Auto-generated codeplug string by goodwatch-txt2cpstr.py. */\n\n"); + o.write("const char codeplugstr[]=\n"); + + for line in i: + ihl=handleline(line.strip()); + if(ihl!=None): + o.write(ihl); + + o.write(";\n"); + + i.close(); + o.close(); + + +if __name__=='__main__': + parser = argparse.ArgumentParser(description='GoodWatch Codeplug Compiler') + parser.add_argument('-i','--input', help='Input Textfile'); + parser.add_argument('-o','--output', help='Output Intel Hex File'); + + args=parser.parse_args(); + + if args.input!=None and args.output!=None: + convertcodeplug(args.input, args.output); diff --git a/firmware/.gitignore b/firmware/.gitignore index 66230e3..efaa5f7 100644 --- a/firmware/.gitignore +++ b/firmware/.gitignore @@ -1,3 +1,5 @@ config.h buildtime.h libs/assembler +codeplugstr.c +dmesg.bin diff --git a/firmware/Makefile b/firmware/Makefile index a537ca9..e8a75b6 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -78,7 +78,8 @@ CC = msp430-gcc -mmcu=cc430f6137 -Wall -I. -Os $(addprefix -D, $(APPS_DEFINES)) BSL = ../bin/cc430-bsl.py -r 38400 -p $(PORT) -modules=rtcasm.o main.o lcd.o lcdtext.o rtc.o keypad.o bcd.o apps.o applist.o adc.o ref.o \ +modules=rtcasm.o main.o lcd.o lcdtext.o rtc.o keypad.o bcd.o apps.o\ + applist.o adc.o ref.o codeplugstr.o \ sidebutton.o power.o uart.o monitor.o ucs.o buzz.o \ radio.o packet.o dmesg.o codeplug.o rng.o descriptor.o \ optim.o libs/assembler.o libs/morse.o @@ -102,7 +103,7 @@ goodwatch.hex: goodwatch.elf msp430-objcopy -O ihex goodwatch.elf goodwatch.hex clean: - rm -rf *~ */*~ *.hex *.elf *.o */*.o goodwatch githash.h buildtime.h html latex goodwatch.elf energytrace.png energytrace.txt + rm -rf *~ */*~ *.hex *.elf *.o */*.o goodwatch githash.h buildtime.h html latex goodwatch.elf energytrace.png energytrace.txt codeplugstr.c dmesg.bin erase: $(BSL) -e sbwflash: goodwatch.hex codeplug.hex @@ -123,6 +124,8 @@ run: codeplug.hex: codeplug.txt ../bin/goodwatch-txt2cp.py -i codeplug.txt -o codeplug.hex +codeplugstr.c: codeplug.txt + ../bin/goodwatch-txt2cpstr.py -i codeplug.txt -o codeplugstr.c flashcp: codeplug.hex $(BSL) -Ef codeplug.hex diff --git a/firmware/codeplug.c b/firmware/codeplug.c index 90f66dd..7bfa2ed 100644 --- a/firmware/codeplug.c +++ b/firmware/codeplug.c @@ -11,8 +11,11 @@ #include "codeplug.h" #include "radio.h" +extern const char codeplugstr[]; + //! Array of codeplug entries in info flash. -struct codeplugentry *codeplug = (struct codeplugentry*) 0x1800; +struct codeplugentry *codeplug = + (struct codeplugentry*) codeplugstr; //formerly 0x1800 static struct codeplugentry *selectedentry;