Fixed some issues in Windows DFU uploader.
This commit is contained in:
parent
a43cbf65c9
commit
87c14c294b
|
@ -33,7 +33,7 @@
|
||||||
#define STATE_DFU_IDLE 0x02
|
#define STATE_DFU_IDLE 0x02
|
||||||
#define STATE_DFU_DOWNLOAD_SYNC 0x03
|
#define STATE_DFU_DOWNLOAD_SYNC 0x03
|
||||||
#define STATE_DFU_DOWNLOAD_BUSY 0x04
|
#define STATE_DFU_DOWNLOAD_BUSY 0x04
|
||||||
define STATE_DFU_DOWNLOAD_IDLE 0x05
|
#define STATE_DFU_DOWNLOAD_IDLE 0x05
|
||||||
#define STATE_DFU_MANIFEST_SYNC 0x06
|
#define STATE_DFU_MANIFEST_SYNC 0x06
|
||||||
#define STATE_DFU_MANIFEST 0x07
|
#define STATE_DFU_MANIFEST 0x07
|
||||||
#define STATE_DFU_MANIFEST_WAIT_RESET 0x08
|
#define STATE_DFU_MANIFEST_WAIT_RESET 0x08
|
||||||
|
|
|
@ -21,6 +21,8 @@
|
||||||
#include <usb.h>
|
#include <usb.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
#include "dfu.h"
|
#include "dfu.h"
|
||||||
#include "stm32mem.h"
|
#include "stm32mem.h"
|
||||||
#include "bindata.h"
|
#include "bindata.h"
|
||||||
|
@ -66,7 +68,7 @@ struct usb_device * find_dev(void)
|
||||||
|
|
||||||
if((dev->descriptor.idProduct == 0x5740) &&
|
if((dev->descriptor.idProduct == 0x5740) &&
|
||||||
!strcmp(man, "Black Sphere Technologies") &&
|
!strcmp(man, "Black Sphere Technologies") &&
|
||||||
!strcmp(prod, "Black Magic Probe"))
|
!strcmp(prod, "Black Magic Firmware Upgrade"))
|
||||||
return dev;
|
return dev;
|
||||||
|
|
||||||
if((dev->descriptor.idProduct == 0xDF11) &&
|
if((dev->descriptor.idProduct == 0xDF11) &&
|
||||||
|
@ -98,7 +100,8 @@ usb_dev_handle * get_dfu_interface(struct usb_device *dev, uint16_t *interface)
|
||||||
//usb_set_configuration(handle, i);
|
//usb_set_configuration(handle, i);
|
||||||
usb_claim_interface(handle, j);
|
usb_claim_interface(handle, j);
|
||||||
//usb_set_altinterface(handle, k);
|
//usb_set_altinterface(handle, k);
|
||||||
*interface = j;
|
//*interface = j;
|
||||||
|
*interface = iface->bInterfaceNumber;
|
||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -122,6 +125,9 @@ int main(void)
|
||||||
retry:
|
retry:
|
||||||
if(!(dev = find_dev()) || !(handle = get_dfu_interface(dev, &iface))) {
|
if(!(dev = find_dev()) || !(handle = get_dfu_interface(dev, &iface))) {
|
||||||
puts("FATAL: No compatible device found!\n");
|
puts("FATAL: No compatible device found!\n");
|
||||||
|
#ifdef WIN32
|
||||||
|
system("pause");
|
||||||
|
#endif
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,9 +138,9 @@ retry:
|
||||||
usb_release_interface(handle, iface);
|
usb_release_interface(handle, iface);
|
||||||
usb_close(handle);
|
usb_close(handle);
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
Sleep(3000);
|
Sleep(5000);
|
||||||
#else
|
#else
|
||||||
sleep(1);
|
sleep(5);
|
||||||
#endif
|
#endif
|
||||||
goto retry;
|
goto retry;
|
||||||
}
|
}
|
||||||
|
@ -145,7 +151,7 @@ retry:
|
||||||
for(offset = 0; offset < bindatalen; offset += 1024) {
|
for(offset = 0; offset < bindatalen; offset += 1024) {
|
||||||
printf("Progress: %d%%\r", (offset*100)/bindatalen);
|
printf("Progress: %d%%\r", (offset*100)/bindatalen);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
stm32_mem_erase(handle, iface, LOAD_ADDRESS + offset);
|
assert(stm32_mem_erase(handle, iface, LOAD_ADDRESS + offset) == 0);
|
||||||
stm32_mem_write(handle, iface, (void*)&bindata[offset], 1024);
|
stm32_mem_write(handle, iface, (void*)&bindata[offset], 1024);
|
||||||
}
|
}
|
||||||
stm32_mem_manifest(handle, iface);
|
stm32_mem_manifest(handle, iface);
|
||||||
|
@ -155,6 +161,10 @@ retry:
|
||||||
|
|
||||||
puts("All operations complete!\n");
|
puts("All operations complete!\n");
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
system("pause");
|
||||||
|
#endif
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,16 +43,16 @@ static int stm32_download(usb_dev_handle *dev, uint16_t iface,
|
||||||
while(1) {
|
while(1) {
|
||||||
if((i = dfu_getstatus(dev, iface, &status)) < 0) return i;
|
if((i = dfu_getstatus(dev, iface, &status)) < 0) return i;
|
||||||
switch(status.bState) {
|
switch(status.bState) {
|
||||||
case STATE_DFU_DOWNLOAD_BUSY:
|
case STATE_DFU_DOWNLOAD_BUSY:
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
Sleep(status.bwPollTimeout);
|
Sleep(status.bwPollTimeout);
|
||||||
#else
|
#else
|
||||||
usleep(status.bwPollTimeout * 1000);
|
usleep(status.bwPollTimeout * 1000);
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
case STATE_DFU_DOWNLOAD_IDLE:
|
case STATE_DFU_DOWNLOAD_IDLE:
|
||||||
return 0;
|
return 0;
|
||||||
default:
|
default:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -87,9 +87,9 @@ int stm32_mem_manifest(usb_dev_handle *dev, uint16_t iface)
|
||||||
usleep(status.bwPollTimeout * 1000);
|
usleep(status.bwPollTimeout * 1000);
|
||||||
#endif
|
#endif
|
||||||
switch(status.bState) {
|
switch(status.bState) {
|
||||||
case STATE_DFU_MANIFEST:
|
case STATE_DFU_MANIFEST:
|
||||||
return 0;
|
return 0;
|
||||||
default:
|
default:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue