Skip to content

RfCat version plus some fixes and extra functionality #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ ASM_REL = $(ASM_SRC:.asm=.rel)
ASM_RST = $(ASM_SRC:.asm=.rst)
ASM_SYM = $(ASM_SRC:.asm=.sym)

PROGS = CCBootloader.hex
PROGS = CCBootloader.hex CCBootloader-rfcat-chronosdongle.hex CCBootloader-rfcat-donsdongle.hex CCBootloader-rfcat-ys1.hex
PCDB = $(PROGS:.hex=.cdb)
PLNK = $(PROGS:.hex=.lnk)
PMAP = $(PROGS:.hex=.map)
Expand All @@ -63,8 +63,40 @@ all: $(PROGS)
CCBootloader.hex: $(REL) $(ASM_REL) Makefile
$(CC) $(LDFLAGS_FLASH) $(CFLAGS) -o CCBootloader.hex $(ASM_REL) $(REL)

CCBootloader-rfcat-chronosdongle.hex: CFLAGS += -DRFCAT -DRFCAT_CHRONOS
CCBootloader-rfcat-chronosdongle.hex: $(REL) $(ASM_REL) Makefile
$(CC) $(LDFLAGS_FLASH) $(CFLAGS) -o CCBootloader-rfcat-chronosdongle.hex $(ASM_REL) $(REL)

CCBootloader-rfcat-donsdongle.hex: CFLAGS += -DRFCAT -DRFCAT_DONSDONGLE
CCBootloader-rfcat-donsdongle.hex: $(REL) $(ASM_REL) Makefile
$(CC) $(LDFLAGS_FLASH) $(CFLAGS) -o CCBootloader-rfcat-donsdongle.hex $(ASM_REL) $(REL)

CCBootloader-rfcat-ys1.hex: CFLAGS += -DRFCAT -DRFCAT_YARDSTICKONE
CCBootloader-rfcat-ys1.hex: $(REL) $(ASM_REL) Makefile
$(CC) $(LDFLAGS_FLASH) $(CFLAGS) -o CCBootloader-rfcat-ys1.hex $(ASM_REL) $(REL)

clean:
rm -f $(ADB) $(ASM) $(LNK) $(LST) $(REL) $(RST) $(SYM)
rm -f $(ASM_ADB) $(ASM_LNK) $(ASM_LST) $(ASM_REL) $(ASM_RST) $(ASM_SYM)
rm -f $(PROGS) $(PCDB) $(PLNK) $(PMAP) $(PMEM) $(PAOM)

install: CCBootloader.hex
goodfet.cc erase
goodfet.cc flash CCBootloader.hex
goodfet.cc verify CCBootloader.hex

installchronosdongle: CCBootloader-rfcat-chronosdongle.hex
goodfet.cc erase
goodfet.cc flash CCBootloader-rfcat-chronosdongle.hex
goodfet.cc verify CCBootloader-rfcat-chronosdongle.hex

installdonsdongle: CCBootloader-rfcat-donsdongle.hex
goodfet.cc erase
goodfet.cc flash CCBootloader-rfcat-donsdongle.hex
goodfet.cc verify CCBootloader-rfcat-donsdongle.hex

installys1dongle: CCBootloader-rfcat-ys1.hex
goodfet.cc erase
goodfet.cc flash CCBootloader-rfcat-ys1.hex
goodfet.cc verify CCBootloader-rfcat-ys1.hex

103 changes: 90 additions & 13 deletions bootload.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,52 @@ def download_code(ihx_file, serial_port):
print "Skipping non data record: '%s'" % line[:-1]
return True

def verify_code(ihx_file, serial_port):
can_read_any= None
for line in ihx_file.readlines():
record_type = int(line[7:9], 16)
if (record_type == 0x00):
length = int(line[1:3], 16)
start_addr = int(line[3:7], 16)
data = line[9:9+(length*2)]
# first time around, check if we can only read 16 byte chunks
if can_read_any == None:
can_read_any = False
do_flash_read(serial_port, start_addr, 1)
for read_data in serial_port:
read_data = read_data.strip()
if not read_data:
continue
if not read_data == ":00000001FF":
can_read_any = True
else:
break
if not can_read_any:
print "*** warning! this version of CC-Bootloader can only read 16 byte blocks!"
print "*** upgrade recommended!"
if can_read_any:
block_length= length
else:
block_length= ((length / 16) + 1) * 16
print "\rVerifying %04d bytes at address: %04X" % (length, start_addr),
do_flash_read(serial_port, start_addr, block_length)
verify_data= ''
for read_data in serial_port:
read_data= read_data.strip()
if (not data or read_data == ":00000001FF"):
break
# strip header and checksum
verify_data += read_data[9:-2]
if (data == verify_data[:length*2]):
print '(OK)',
else:
print 'Failed! Expected:', data, 'Got:', verify_data[:length*2]
exit(1)
sys.stdout.flush()
else:
print "Skipping non data record: '%s'" % line[:-1]
return True

def run_user_code(serial_port):
# User code is entered on intel HEX EOF record
serial_port.write(":00000001FF\n")
Expand Down Expand Up @@ -75,18 +121,26 @@ def erase_user_page(serial_port, page):
return False
return True

def flash_read(serial_port, start_addr, length):
def do_flash_read(serial_port, start_addr, length):
chksum = (0xD9 +
(0x100 - (start_addr & 0xFF)) +
(0x100 - ((start_addr>>8) & 0xFF)) +
(0x100 - (length & 0xFF)) +
(0x100 - ((length>>8) & 0xFF))
) & 0xFF
serial_port.write(":02%04X25%04X%02X\n" % (start_addr, length, chksum))


def flash_read(ihx_file, serial_port, start_addr, length):
do_flash_read(serial_port, start_addr, length)
for line in serial_port:
print line,
if (line == ":00000001FF\n"):
break
if not line == "\n":
if(ihx_file):
ihx_file.write(line)
else:
print line,
if (line == ":00000001FF\n"):
break

def print_usage():
import sys
Expand All @@ -96,13 +150,17 @@ def print_usage():
Usage: ./bootload.py serial_port command

Commands:
download hex_file

download <hex_file>

Download hex_file to the device.

run

Run the user code.

reset

The bootloader will not erase pages that have previously been written to
before writing new data to that page. This allows for random access writes
but prevents you from overwriting downloaded code unless the device is
Expand All @@ -111,18 +169,26 @@ def print_usage():
cycling.

erase_all

Erases the entire user flash area.

erage n
erage <n>

Erases page n of the flash memory (organised into 1024 byte pages). The
bootloader occupies the first few pages and the rest are reserved for user
code. Attempting to erase a bootloader page will have no effect. To
determine which page the user code starts on please check the
USER_CODE_BASE setting in main.h.

read start_addr len
Reads len bytes from flash memory starting from start_addr. start_addr and
len should be specified in hexadecimal (e.g. 0x1234).
read <start_addr> <len> [hex_file]

Reads len bytes from flash memory starting from start_addr and optionally
write to hex_file. start_addr and len should be specified in hexadecimal
(e.g. 0x1234).

verify <hex_file>

Verify hex_file matches device flash memory.
"""

if __name__ == '__main__':
Expand All @@ -137,13 +203,16 @@ def print_usage():
serial_port = serial.Serial(serial_port_name, timeout=1)

try:
if (command == 'download'):
if (command == 'download' or command == 'verify'):
if (len(options) < 1):
print_usage()
else:
ihx_filename = options[0]
ihx_file = open(ihx_filename, 'r')
download_code(ihx_file, serial_port)
if (command == 'download'):
download_code(ihx_file, serial_port)
else:
verify_code(ihx_file, serial_port)

elif (command == 'run'):
run_user_code(serial_port)
Expand All @@ -164,8 +233,16 @@ def print_usage():
if (len(options) < 2):
print_usage()
else:
flash_read(serial_port, int(options[0], 16), int(options[1], 16))

ihx_file = None
if(len(options) == 3):
try:
ihx_filename = options[2]
ihx_file = open(ihx_filename, 'w')
print 'reading to:', ihx_filename
except:
print "couldn't open output file:", ihx_filename
exit(2)
flash_read(ihx_file, serial_port, int(options[0], 16), int(options[1], 16))

else:
print_usage()
Expand Down
56 changes: 48 additions & 8 deletions src/hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,69 @@
*/

#include "cc1111.h"
#include "hal.h"

void setup_led() {
// Setup LED and turn it off
P1DIR |= 2;
P1_1 = 0;
P1DIR |= LED_MASK;
led_off();
}

void setup_button() {
#ifdef RFCAT_DONSDONGLE
P1DIR &= ~4;
#endif
#ifdef RFCAT_CHRONOS
P2DIR &= ~4;
#endif
#ifdef RFCAT_YARDSTICKONE
P2DIR &= ~4;
#endif
}

// any other gpio pins
void setup_gpio() {
#ifdef RFCAT_YARDSTICKONE
// amplifer configuration pins
//P0_0 input with pull-up (antenna port power off)
P0DIR &= ~1; // Set direction to IN (clear bit for P0_0)
P0INP &= ~P0INP_MDP0_0_TRISTATE; // Set as pull up/down (rather than tristate)
P2INP &= ~P2INP_PDUP0_PULL_DOWN; // clear pull down bit (i.e. pull up)
P2DIR |= 0x19;
TX_AMP_EN = 0;
RX_AMP_EN = 0;
AMP_BYPASS_EN = 1;
#endif
}

void led_on() {
P1_1 = 1;
#ifdef RFCAT_YARDSTICKONE
LED1 = 1;
LED2 = 1;
LED3 = 1;
#else
LED = 1;
#endif
}

void led_off() {
P1_1 = 0;
#ifdef RFCAT_YARDSTICKONE
LED1 = 0;
LED2 = 0;
LED3 = 0;
#else
LED = 0;
#endif
}

void usb_up() {
// Bring up the USB link
P1DIR |= 1;
P1_0 = 1;
P1DIR |= USB_MASK;
USB_ENABLE = 1;
}

void usb_down() {
// Bring down the USB link
P1_0 = 0;
P1DIR &= ~1;
USB_ENABLE = 0;
P1DIR &= ~USB_MASK;
}
33 changes: 33 additions & 0 deletions src/hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,44 @@
#ifndef _HAL_H_
#define _HAL_H_

#ifdef RFCAT_CHRONOS
#define LED P1_0
#define LED_MASK 0x01
#define USB_ENABLE P1_1
#define USB_MASK 0x02
#define CC1111CHRONOS_PIN_DC P2_2
#endif

#ifdef RFCAT_DONSDONGLE
#define LED P1_1
#define LED_MASK 0x02
#define USB_ENABLE P1_0
#define USB_MASK 0x01
#define CC1111EM_BUTTON P1_2
#endif

#ifdef RFCAT_YARDSTICKONE
#define LED1 P1_1
#define LED2 P1_2
#define LED3 P1_3
#define LED_MASK 0x0E
#define USB_ENABLE P1_0
#define USB_MASK 0x01
#define CC1111YSONE_PIN_DC P2_2
#define TX_AMP_EN P2_0
#define RX_AMP_EN P2_4
#define AMP_BYPASS_EN P2_3
#endif

void setup_led();
void led_on();
void led_off();
void setup_button();
void setup_gpio();

void usb_up();
void usb_down();

#define BUTTON_PRESSED 0
#define GROUNDED 0
#endif // _HAL_H_
Loading