From 568359df2c8ad4293dfc14b57db9b01fb2f1adab Mon Sep 17 00:00:00 2001 From: cpldcpu Date: Sun, 5 Jan 2014 19:35:47 +0100 Subject: commandline: Support for new v2 transmission protocol The block transfer is now done in the address and indexfield of a setup-packet to save a lot of memory in the firmware: This requires twice the number of transmissions, but is effectively faster due to less bus congestion and resends. --- commandline/library/micronucleus_lib.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'commandline') diff --git a/commandline/library/micronucleus_lib.c b/commandline/library/micronucleus_lib.c index 51b42e7..dd10d25 100644 --- a/commandline/library/micronucleus_lib.c +++ b/commandline/library/micronucleus_lib.c @@ -176,6 +176,33 @@ int micronucleus_writeFlash(micronucleus* deviceHandle, unsigned int program_siz // ask microcontroller to write this page's data if (pagecontainsdata) { + + if (deviceHandle->version.major == 1) { + // Firmware rev.1 transfers a page as a single block + // ask microcontroller to write this page's data + res = usb_control_msg(deviceHandle->device, + USB_ENDPOINT_OUT| USB_TYPE_VENDOR | USB_RECIP_DEVICE, + 1, + page_length, address, + page_buffer, page_length, + MICRONUCLEUS_USB_TIMEOUT); + } else if (deviceHandle->version.major >= 2) { + // Firmware rev.2 uses individual set up packets to transfer data + res = usb_control_msg(deviceHandle->device, USB_ENDPOINT_OUT| USB_TYPE_VENDOR | USB_RECIP_DEVICE, 1, page_length, address, NULL, 0, MICRONUCLEUS_USB_TIMEOUT); + if (res) return -1; + int i; + + for (i=0; i< page_length; i+=4) + { + int w1,w2; + w1=(page_buffer[i+1]<<8)+(page_buffer[i+0]<<0); + w2=(page_buffer[i+3]<<8)+(page_buffer[i+2]<<0); + + res = usb_control_msg(deviceHandle->device, USB_ENDPOINT_OUT| USB_TYPE_VENDOR | USB_RECIP_DEVICE, 3, w1, w2, NULL, 0, MICRONUCLEUS_USB_TIMEOUT); + if (res) return -1; + } + } + /* res = usb_control_msg(deviceHandle->device, USB_ENDPOINT_OUT| USB_TYPE_VENDOR | USB_RECIP_DEVICE, 1, @@ -184,7 +211,7 @@ int micronucleus_writeFlash(micronucleus* deviceHandle, unsigned int program_siz MICRONUCLEUS_USB_TIMEOUT); if (res != page_length) return -1; - + */ // give microcontroller enough time to write this page and come back online delay(deviceHandle->write_sleep); } -- cgit v1.2.3