mirror of
https://github.com/betaflight/betaflight-configurator.git
synced 2025-07-16 04:45:20 +03:00
Added button to exit DFU.
This commit is contained in:
parent
4475586e59
commit
d293d6b1e7
8 changed files with 261 additions and 191 deletions
|
@ -73,10 +73,13 @@ STM32DFU_protocol.prototype.connect = function (device, hex, options, callback)
|
|||
self.callback = callback;
|
||||
|
||||
self.options = {
|
||||
erase_chip: false
|
||||
erase_chip: false,
|
||||
exitDfu: false,
|
||||
};
|
||||
|
||||
if (options.erase_chip) {
|
||||
if (options.exitDfu) {
|
||||
self.options.exitDfu = true;
|
||||
} else if (options.erase_chip) {
|
||||
self.options.erase_chip = true;
|
||||
}
|
||||
|
||||
|
@ -85,9 +88,7 @@ STM32DFU_protocol.prototype.connect = function (device, hex, options, callback)
|
|||
self.verify_hex = [];
|
||||
|
||||
// reset progress bar to initial state
|
||||
TABS.firmware_flasher.flashingMessage(null, TABS.firmware_flasher.FLASH_MESSAGE_TYPES.NEUTRAL)
|
||||
.flashProgress(0);
|
||||
|
||||
TABS.firmware_flasher.flashingMessage(null, TABS.firmware_flasher.FLASH_MESSAGE_TYPES.NEUTRAL).flashProgress(0);
|
||||
|
||||
chrome.usb.getDevices(device, function (result) {
|
||||
if (result.length) {
|
||||
|
@ -157,12 +158,16 @@ STM32DFU_protocol.prototype.claimInterface = function (interfaceNumber) {
|
|||
chrome.usb.claimInterface(this.handle, interfaceNumber, function claimed() {
|
||||
if(self.checkChromeError()) {
|
||||
console.log('Failed to claim USB device!');
|
||||
self.upload_procedure(99);
|
||||
self.cleanup();
|
||||
}
|
||||
|
||||
console.log('Claimed interface: ' + interfaceNumber);
|
||||
|
||||
self.upload_procedure(0);
|
||||
if (self.options.exitDfu) {
|
||||
self.leave();
|
||||
} else {
|
||||
self.upload_procedure(0);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -523,7 +528,7 @@ STM32DFU_protocol.prototype.loadAddress = function (address, callback, abort) {
|
|||
} else {
|
||||
console.log('Failed to execute address load');
|
||||
if(typeof abort === "undefined" || abort) {
|
||||
self.upload_procedure(99);
|
||||
self.cleanup();
|
||||
} else {
|
||||
callback(data);
|
||||
}
|
||||
|
@ -532,7 +537,7 @@ STM32DFU_protocol.prototype.loadAddress = function (address, callback, abort) {
|
|||
}, delay);
|
||||
} else {
|
||||
console.log('Failed to request address load');
|
||||
self.upload_procedure(99);
|
||||
self.cleanup();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -562,7 +567,7 @@ STM32DFU_protocol.prototype.upload_procedure = function (step) {
|
|||
self.getChipInfo(0, function (chipInfo, resultCode) {
|
||||
if (resultCode != 0 || typeof chipInfo === "undefined") {
|
||||
console.log('Failed to detect chip info, resultCode: ' + resultCode);
|
||||
self.upload_procedure(99);
|
||||
self.cleanup();
|
||||
} else {
|
||||
if (typeof chipInfo.internal_flash !== "undefined") {
|
||||
// internal flash
|
||||
|
@ -577,7 +582,7 @@ STM32DFU_protocol.prototype.upload_procedure = function (step) {
|
|||
GUI.log(i18n.getMessage('dfu_error_image_size',
|
||||
[(self.hex.bytes_total / 1024.0).toFixed(1),
|
||||
(self.available_flash_size / 1024.0).toFixed(1)]));
|
||||
self.upload_procedure(99);
|
||||
self.cleanup();
|
||||
} else {
|
||||
self.getFunctionalDescriptor(0, function (descriptor, resultCode) {
|
||||
self.transferSize = resultCode ? 2048 : descriptor.wTransferSize;
|
||||
|
@ -604,7 +609,7 @@ STM32DFU_protocol.prototype.upload_procedure = function (step) {
|
|||
GUI.log(i18n.getMessage('dfu_error_image_size',
|
||||
[(self.hex.bytes_total / 1024.0).toFixed(1),
|
||||
(self.available_flash_size / 1024.0).toFixed(1)]));
|
||||
self.upload_procedure(99);
|
||||
self.cleanup();
|
||||
} else {
|
||||
self.getFunctionalDescriptor(0, function (descriptor, resultCode) {
|
||||
self.transferSize = resultCode ? 2048 : descriptor.wTransferSize;
|
||||
|
@ -616,7 +621,7 @@ STM32DFU_protocol.prototype.upload_procedure = function (step) {
|
|||
}
|
||||
} else {
|
||||
console.log('Failed to detect internal or external flash');
|
||||
self.upload_procedure(99);
|
||||
self.cleanup();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -624,7 +629,7 @@ STM32DFU_protocol.prototype.upload_procedure = function (step) {
|
|||
case 1:
|
||||
if (typeof self.chipInfo.option_bytes === "undefined") {
|
||||
console.log('Failed to detect option bytes');
|
||||
self.upload_procedure(99);
|
||||
self.cleanup();
|
||||
}
|
||||
|
||||
var unprotect = function() {
|
||||
|
@ -666,7 +671,7 @@ STM32DFU_protocol.prototype.upload_procedure = function (step) {
|
|||
GUI.log(i18n.getMessage('stm32UnprotectFailed'));
|
||||
TABS.firmware_flasher.flashingMessage(i18n.getMessage('stm32UnprotectFailed'), TABS.firmware_flasher.FLASH_MESSAGE_TYPES.INVALID);
|
||||
console.log(data);
|
||||
self.upload_procedure(99);
|
||||
self.cleanup();
|
||||
}
|
||||
}, 2000); // this should stall/disconnect anyways. so we only wait 2 sec max.
|
||||
}, incr);
|
||||
|
@ -675,7 +680,7 @@ STM32DFU_protocol.prototype.upload_procedure = function (step) {
|
|||
let messageUnprotectInitFailed = i18n.getMessage('stm32UnprotectInitFailed')
|
||||
GUI.log(messageUnprotectInitFailed);
|
||||
TABS.firmware_flasher.flashingMessage(messageUnprotectInitFailed, TABS.firmware_flasher.FLASH_MESSAGE_TYPES.INVALID)
|
||||
self.upload_procedure(99);
|
||||
self.cleanup();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -686,7 +691,7 @@ STM32DFU_protocol.prototype.upload_procedure = function (step) {
|
|||
self.controlTransfer('in', self.request.UPLOAD, 2, 0, self.chipInfo.option_bytes.total_size, 0, function (ob_data, errcode) {
|
||||
if(errcode) {
|
||||
console.log('USB transfer error while reading option bytes: ' + errcode1);
|
||||
self.upload_procedure(99);
|
||||
self.cleanup();
|
||||
return;
|
||||
}
|
||||
self.controlTransfer('in', self.request.GETSTATUS, 0, 0, 6, 0, function (data) {
|
||||
|
@ -710,16 +715,16 @@ STM32DFU_protocol.prototype.upload_procedure = function (step) {
|
|||
self.controlTransfer('in', self.request.GETSTATUS, 0, 0, 6, 0, function (data) {
|
||||
if (data[4] == self.state.dfuDNLOAD_IDLE) {
|
||||
console.log('Failed to write ob');
|
||||
self.upload_procedure(99);
|
||||
self.cleanup();
|
||||
} else {
|
||||
console.log('Success writing ob');
|
||||
self.upload_procedure(99);
|
||||
self.cleanup();
|
||||
}
|
||||
});
|
||||
}, delay);
|
||||
} else {
|
||||
console.log('Failed to initiate write ob');
|
||||
self.upload_procedure(99);
|
||||
self.cleanup();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -750,7 +755,7 @@ STM32DFU_protocol.prototype.upload_procedure = function (step) {
|
|||
self.clearStatus(tryReadOB);
|
||||
} else {
|
||||
GUI.log(i18n.getMessage('stm32AddressLoadUnknown'));
|
||||
self.upload_procedure(99);
|
||||
self.cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -792,7 +797,7 @@ STM32DFU_protocol.prototype.upload_procedure = function (step) {
|
|||
if (erase_pages.length === 0) {
|
||||
console.log('Aborting, No flash pages to erase');
|
||||
TABS.firmware_flasher.flashingMessage(i18n.getMessage('stm32InvalidHex'), TABS.firmware_flasher.FLASH_MESSAGE_TYPES.INVALID);
|
||||
self.upload_procedure(99);
|
||||
self.cleanup();
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -851,7 +856,7 @@ STM32DFU_protocol.prototype.upload_procedure = function (step) {
|
|||
erase_page_next();
|
||||
} else {
|
||||
console.log('Failed to erase page 0x' + page_addr.toString(16) + ' (did not reach dfuIDLE after clearing');
|
||||
self.upload_procedure(99);
|
||||
self.cleanup();
|
||||
}
|
||||
})
|
||||
});
|
||||
|
@ -859,13 +864,13 @@ STM32DFU_protocol.prototype.upload_procedure = function (step) {
|
|||
erase_page_next();
|
||||
} else {
|
||||
console.log('Failed to erase page 0x' + page_addr.toString(16));
|
||||
self.upload_procedure(99);
|
||||
self.cleanup();
|
||||
}
|
||||
});
|
||||
}, delay);
|
||||
} else {
|
||||
console.log('Failed to initiate page erase, page 0x' + page_addr.toString(16));
|
||||
self.upload_procedure(99);
|
||||
self.cleanup();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -914,13 +919,13 @@ STM32DFU_protocol.prototype.upload_procedure = function (step) {
|
|||
write();
|
||||
} else {
|
||||
console.log('Failed to write ' + bytes_to_write + 'bytes to 0x' + address.toString(16));
|
||||
self.upload_procedure(99);
|
||||
self.cleanup();
|
||||
}
|
||||
});
|
||||
}, delay);
|
||||
} else {
|
||||
console.log('Failed to initiate write ' + bytes_to_write + 'bytes to 0x' + address.toString(16));
|
||||
self.upload_procedure(99);
|
||||
self.cleanup();
|
||||
}
|
||||
});
|
||||
})
|
||||
|
@ -1022,48 +1027,60 @@ STM32DFU_protocol.prototype.upload_procedure = function (step) {
|
|||
TABS.firmware_flasher.flashingMessage(i18n.getMessage('stm32ProgrammingSuccessful'), TABS.firmware_flasher.FLASH_MESSAGE_TYPES.VALID);
|
||||
|
||||
// proceed to next step
|
||||
self.upload_procedure(6);
|
||||
self.leave();
|
||||
} else {
|
||||
console.log('Programming: FAILED');
|
||||
// update progress bar
|
||||
TABS.firmware_flasher.flashingMessage(i18n.getMessage('stm32ProgrammingFailed'), TABS.firmware_flasher.FLASH_MESSAGE_TYPES.INVALID);
|
||||
|
||||
// disconnect
|
||||
self.upload_procedure(99);
|
||||
self.cleanup();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 6:
|
||||
// jump to application code
|
||||
var address = self.hex.data[0].address;
|
||||
}
|
||||
};
|
||||
|
||||
self.clearStatus(function () {
|
||||
self.loadAddress(address, leave);
|
||||
});
|
||||
STM32DFU_protocol.prototype.leave = function () {
|
||||
// leave DFU
|
||||
|
||||
var leave = function () {
|
||||
self.controlTransfer('out', self.request.DNLOAD, 0, 0, 0, 0, function () {
|
||||
self.controlTransfer('in', self.request.GETSTATUS, 0, 0, 6, 0, function (data) {
|
||||
self.upload_procedure(99);
|
||||
});
|
||||
const self = this;
|
||||
|
||||
let address;
|
||||
if (self.hex) {
|
||||
address = self.hex.data[0].address;
|
||||
} else {
|
||||
// Assuming we're running off internal flash
|
||||
address = 0x08000000;
|
||||
}
|
||||
|
||||
self.clearStatus(function () {
|
||||
self.loadAddress(address, function () {
|
||||
// 'downloading' 0 bytes to the program start address followed by a GETSTATUS is used to trigger DFU exit on STM32
|
||||
self.controlTransfer('out', self.request.DNLOAD, 0, 0, 0, 0, function () {
|
||||
self.controlTransfer('in', self.request.GETSTATUS, 0, 0, 6, 0, function (data) {
|
||||
self.cleanup();
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
break;
|
||||
case 99:
|
||||
// cleanup
|
||||
self.releaseInterface(0);
|
||||
STM32DFU_protocol.prototype.cleanup = function () {
|
||||
const self = this;
|
||||
|
||||
GUI.connect_lock = false;
|
||||
self.releaseInterface(0);
|
||||
|
||||
var timeSpent = new Date().getTime() - self.upload_time_start;
|
||||
GUI.connect_lock = false;
|
||||
|
||||
console.log('Script finished after: ' + (timeSpent / 1000) + ' seconds');
|
||||
var timeSpent = new Date().getTime() - self.upload_time_start;
|
||||
|
||||
if (self.callback) self.callback();
|
||||
break;
|
||||
console.log('Script finished after: ' + (timeSpent / 1000) + ' seconds');
|
||||
|
||||
if (self.callback) {
|
||||
self.callback();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue