Skip to content

Commit

Permalink
Merge pull request #143 from tessel/jon-better-flash
Browse files Browse the repository at this point in the history
Makes the python flashing code more reliable
  • Loading branch information
johnnyman727 committed Feb 16, 2016
2 parents 9c160ba + eab49ec commit 723bdf9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions firmware/firmware.h
Expand Up @@ -98,6 +98,9 @@ void bridge_close_1();
void bridge_close_2();
void bridge_close_3();

void cancel_breathing_animation();
void init_breathing_animation();

// port.c

#define UART_MS_TIMEOUT 10 // send uart data after ms timeout even if buffer is not full
Expand Down
2 changes: 2 additions & 0 deletions firmware/usb.c
Expand Up @@ -429,6 +429,7 @@ bool usb_cb_set_interface(uint16_t interface, uint16_t new_altsetting) {

if (altsetting == ALTSETTING_FLASH) {
flash_disable();
init_breathing_animation();
} else if (altsetting == ALTSETTING_PIPE) {
usbpipe_disable();
}
Expand All @@ -440,6 +441,7 @@ bool usb_cb_set_interface(uint16_t interface, uint16_t new_altsetting) {
}

if (new_altsetting == ALTSETTING_FLASH){
cancel_breathing_animation();
flash_init();
} else if (booted && new_altsetting == ALTSETTING_PIPE) {
usbpipe_init();
Expand Down
13 changes: 13 additions & 0 deletions scripts/flash.py
Expand Up @@ -122,6 +122,16 @@ def write_tessel_flash(self, path, mac1, mac2):
def randbyte():
return random.randint(0, 255)

def reset_openwrt(device):
# Reset the USB interface
device.reset();
# Control transfer to put RST line high
device.ctrl_transfer(0x40, 0x10, 1, 0, '')
# Control transfer to put RST line low
device.ctrl_transfer(0x40, 0x10, 0, 0, '')
# Control transfer to put RST line high
device.ctrl_transfer(0x40, 0x10, 1, 0, '')

if __name__ == '__main__':
dev = usb.core.find(idVendor=0x1209, idProduct=0x7551)
if dev is None:
Expand All @@ -138,3 +148,6 @@ def randbyte():
print("Generated MAC addr ", ':'.join("{:02x}".format(x) for x in mac1))

flash.write_tessel_flash(basepath, mac1, mac2)

print("Rebooting device...")
reset_openwrt(dev)

0 comments on commit 723bdf9

Please sign in to comment.