Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/iNavFlight/inav-configurator.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorKonstantin Sharlaimov <konstantin.sharlaimov@gmail.com>2020-08-11 11:34:46 +0300
committerGitHub <noreply@github.com>2020-08-11 11:34:46 +0300
commit948ca25e5bffc2eaea04cc1a2c8df034b6a115b8 (patch)
treec88236a055fe63f376dbadfb01a67915a76d92ee /js
parentefb0e7590c539805b4a4e88be1959f9291ea5a58 (diff)
parent4eea6b7fe0718efc3f15c53c305cd7acba206efc (diff)
Merge pull request #1048 from iNavFlight/de_variable_transfer_size_support
[DFU] Allow variable transfer size (required for H7 flashing)
Diffstat (limited to 'js')
-rw-r--r--js/protocols/stm32usbdfu.js49
1 files changed, 43 insertions, 6 deletions
diff --git a/js/protocols/stm32usbdfu.js b/js/protocols/stm32usbdfu.js
index a60b3e43..3e0f0d22 100644
--- a/js/protocols/stm32usbdfu.js
+++ b/js/protocols/stm32usbdfu.js
@@ -64,6 +64,7 @@ var STM32DFU_protocol = function () {
this.chipInfo = null; // information about chip's memory
this.flash_layout = { 'start_address': 0, 'total_size': 0, 'sectors': []};
+ this.transferSize = 2048; // Default USB DFU transfer size for F3,F4 and F7
};
STM32DFU_protocol.prototype.connect = function (device, hex, options, callback) {
@@ -287,6 +288,38 @@ STM32DFU_protocol.prototype.getInterfaceDescriptor = function (_interface, callb
});
}
+STM32DFU_protocol.prototype.getFunctionalDescriptor = function (_interface, callback) {
+ var self = this;
+ chrome.usb.controlTransfer(this.handle, {
+ 'direction': 'in',
+ 'recipient': 'interface',
+ 'requestType': 'standard',
+ 'request': 6,
+ 'value': 0x2100,
+ 'index': 0,
+ 'length': 255
+ }, function (result) {
+ if(self.checkChromeError()) {
+ console.log('USB getFunctionalDescriptor failed! ' + result.resultCode);
+ callback({}, result.resultCode);
+ return;
+ }
+
+ var buf = new Uint8Array(result.data);
+
+ var descriptor = {
+ 'bLength': buf[0],
+ 'bDescriptorType': buf[1],
+ 'bmAttributes': buf[2],
+ 'wDetachTimeOut': (buf[4] << 8)|buf[3],
+ 'wTransferSize': (buf[6] << 8)|buf[5],
+ 'bcdDFUVersion': buf[7]
+ };
+
+ callback(descriptor, result.resultCode);
+ });
+}
+
STM32DFU_protocol.prototype.getChipInfo = function (_interface, callback) {
var self = this;
@@ -511,9 +544,9 @@ STM32DFU_protocol.prototype.upload_procedure = function (step) {
if (typeof chipInfo.internal_flash === "undefined") {
console.log('Failed to detect internal flash');
self.upload_procedure(99);
- }
+ }
- self.chipInfo = chipInfo;
+ self.chipInfo = chipInfo;
self.flash_layout = chipInfo.internal_flash;
self.available_flash_size = self.flash_layout.total_size - (self.hex.start_linear_address - self.flash_layout.start_address);
@@ -526,8 +559,12 @@ STM32DFU_protocol.prototype.upload_procedure = function (step) {
(self.available_flash_size / 1024.0).toFixed(1)]));
self.upload_procedure(99);
} else {
- self.clearStatus(function () {
- self.upload_procedure(1);
+ self.getFunctionalDescriptor(0, function (descriptor, resultCode) {
+ self.transferSize = resultCode ? 2048 : descriptor.wTransferSize;
+ console.log('Using transfer size: ' + self.transferSize);
+ self.clearStatus(function () {
+ self.upload_procedure(1);
+ });
});
}
}
@@ -763,7 +800,7 @@ STM32DFU_protocol.prototype.upload_procedure = function (step) {
var write = function () {
if (bytes_flashed < self.hex.data[flashing_block].bytes) {
- var bytes_to_write = ((bytes_flashed + 2048) <= self.hex.data[flashing_block].bytes) ? 2048 : (self.hex.data[flashing_block].bytes - bytes_flashed);
+ var bytes_to_write = ((bytes_flashed + self.transferSize) <= self.hex.data[flashing_block].bytes) ? self.transferSize : (self.hex.data[flashing_block].bytes - bytes_flashed);
var data_to_flash = self.hex.data[flashing_block].data.slice(bytes_flashed, bytes_flashed + bytes_to_write);
@@ -847,7 +884,7 @@ STM32DFU_protocol.prototype.upload_procedure = function (step) {
var read = function () {
if (bytes_verified < self.hex.data[reading_block].bytes) {
- var bytes_to_read = ((bytes_verified + 2048) <= self.hex.data[reading_block].bytes) ? 2048 : (self.hex.data[reading_block].bytes - bytes_verified);
+ var bytes_to_read = ((bytes_verified + self.transferSize) <= self.hex.data[reading_block].bytes) ? self.transferSize : (self.hex.data[reading_block].bytes - bytes_verified);
self.controlTransfer('in', self.request.UPLOAD, wBlockNum++, 0, bytes_to_read, 0, function (data, code) {
for (var i = 0; i < data.length; i++) {