split write into load address and write routines

pull/3/head
cTn 10 years ago
parent 700ca41957
commit 4425dfb5c3

@ -233,61 +233,60 @@ STM32DFU_protocol.prototype.upload_procedure = function(step) {
var bytes_flashed_total = 0; // used for progress bar var bytes_flashed_total = 0; // used for progress bar
var wBlockNum = 2; // required by DFU var wBlockNum = 2; // required by DFU
// this is unoptimized version of write, where address is set before every transmission, this should be reworked to only transmit addres at the beginning and at block change function load_address() {
// such approach should give a nice speed boost (if needed) self.controlTransfer('out', self.request.DNLOAD, 0, 0, 0, [0x21, address, (address >> 8), (address >> 16), (address >> 24)], function() {
self.controlTransfer('in', self.request.GETSTATUS, 0, 0, 6, 0, function(data) {
if (data[4] == self.state.dfuDNBUSY) { // completely normal
var delay = data[1] | (data[2] << 8) | (data[3] << 16);
setTimeout(function() {
self.controlTransfer('in', self.request.GETSTATUS, 0, 0, 6, 0, function(data) {
if (data[4] == self.state.dfuDNLOAD_IDLE) {
write();
} else {
console.log(data);
}
});
}, delay);
} else {
console.log(data);
}
});
});
}
function write() { function write() {
if (bytes_flashed < self.hex.data[flashing_block].bytes) { 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 + 2048) <= self.hex.data[flashing_block].bytes) ? 2048 : (self.hex.data[flashing_block].bytes - bytes_flashed);
self.controlTransfer('out', self.request.DNLOAD, 0, 0, 0, [0x21, address, (address >> 8), (address >> 16), (address >> 24)], function() { var data = [];
self.controlTransfer('in', self.request.GETSTATUS, 0, 0, 6, 0, function(data) { for (var i = 0; i < bytes_to_write; i++) {
if (data[4] == self.state.dfuDNBUSY) { // completely normal data.push(self.hex.data[flashing_block].data[bytes_flashed++]);
var delay = data[1] | (data[2] << 8) | (data[3] << 16); }
setTimeout(function() { address += bytes_to_write;
self.controlTransfer('in', self.request.GETSTATUS, 0, 0, 6, 0, function(data) { bytes_flashed_total += bytes_to_write;
if (data[4] == self.state.dfuDNLOAD_IDLE) {
// address loaded in this stage self.controlTransfer('out', self.request.DNLOAD, wBlockNum++, 0, 0, data, function() {
var data = []; self.controlTransfer('in', self.request.GETSTATUS, 0, 0, 6, 0, function(data) {
for (var i = 0; i < bytes_to_write; i++) { var delay = data[1] | (data[2] << 8) | (data[3] << 16);
data.push(self.hex.data[flashing_block].data[bytes_flashed++]);
} setTimeout(function() {
self.controlTransfer('in', self.request.GETSTATUS, 0, 0, 6, 0, function(data) {
address += bytes_to_write; if (data[4] == self.state.dfuDNLOAD_IDLE) {
bytes_flashed_total += bytes_to_write; // update progress bar
self.progress_bar_e.val(bytes_flashed_total / (self.hex.bytes_total * 2) * 100);
self.controlTransfer('out', self.request.DNLOAD, 2, 0, 0, data, function() {
self.controlTransfer('in', self.request.GETSTATUS, 0, 0, 6, 0, function(data) { // flash another page
var delay = data[1] | (data[2] << 8) | (data[3] << 16); write();
} else {
setTimeout(function() { // throw some error
self.controlTransfer('in', self.request.GETSTATUS, 0, 0, 6, 0, function(data) { console.log(data);
if (data[4] == self.state.dfuDNLOAD_IDLE) { }
// update progress bar });
self.progress_bar_e.val(bytes_flashed_total / (self.hex.bytes_total * 2) * 100); }, delay);
// flash another page
write();
} else {
// throw some error
console.log(data);
}
});
}, delay);
});
})
} else {
// throw some error
console.log(data);
}
});
}, delay);
} else {
// throw some error
console.log(data);
}
}); });
}); })
} else { } else {
// move to another block // move to another block
if (flashing_block < blocks) { if (flashing_block < blocks) {
@ -295,20 +294,21 @@ STM32DFU_protocol.prototype.upload_procedure = function(step) {
address = self.hex.data[flashing_block].address; address = self.hex.data[flashing_block].address;
bytes_flashed = 0; bytes_flashed = 0;
wBlockNum = 2;
write(); load_address();
} else { } else {
// all blocks flashed // all blocks flashed
console.log('Writing: done'); console.log('Writing: done');
// proceed to next step // proceed to next step
self.upload_procedure(5); self.upload_procedure(6);
} }
} }
} }
// start writing // start
write(); load_address();
break; break;
case 5: case 5:
// verify // verify
@ -321,6 +321,7 @@ STM32DFU_protocol.prototype.upload_procedure = function(step) {
var bytes_verified = 0; var bytes_verified = 0;
var bytes_verified_total = 0; // used for progress bar var bytes_verified_total = 0; // used for progress bar
var wBlockNum = 2; // required by DFU
// initialize arrays // initialize arrays
for (var i = 0; i <= blocks; i++) { for (var i = 0; i <= blocks; i++) {

Loading…
Cancel
Save