@ -233,12 +233,7 @@ 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)
function write ( ) {
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 ) ;
self . controlTransfer ( 'out' , self . request . DNLOAD , 0 , 0 , 0 , [ 0x21 , address , ( address >> 8 ) , ( address >> 16 ) , ( address >> 24 ) ] , function ( ) {
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 ) {
self . controlTransfer ( 'in' , self . request . GETSTATUS , 0 , 0 , 6 , 0 , function ( data ) {
if ( data [ 4 ] == self . state . dfuDNBUSY ) { // completely normal
if ( data [ 4 ] == self . state . dfuDNBUSY ) { // completely normal
@ -247,7 +242,23 @@ STM32DFU_protocol.prototype.upload_procedure = function(step) {
setTimeout ( function ( ) {
setTimeout ( function ( ) {
self . controlTransfer ( 'in' , self . request . GETSTATUS , 0 , 0 , 6 , 0 , function ( data ) {
self . controlTransfer ( 'in' , self . request . GETSTATUS , 0 , 0 , 6 , 0 , function ( data ) {
if ( data [ 4 ] == self . state . dfuDNLOAD _IDLE ) {
if ( data [ 4 ] == self . state . dfuDNLOAD _IDLE ) {
// address loaded in this stage
write ( ) ;
} else {
console . log ( data ) ;
}
} ) ;
} , delay ) ;
} else {
console . log ( data ) ;
}
} ) ;
} ) ;
}
function write ( ) {
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 data = [ ] ;
var data = [ ] ;
for ( var i = 0 ; i < bytes _to _write ; i ++ ) {
for ( var i = 0 ; i < bytes _to _write ; i ++ ) {
data . push ( self . hex . data [ flashing _block ] . data [ bytes _flashed ++ ] ) ;
data . push ( self . hex . data [ flashing _block ] . data [ bytes _flashed ++ ] ) ;
@ -256,7 +267,7 @@ STM32DFU_protocol.prototype.upload_procedure = function(step) {
address += bytes _to _write ;
address += bytes _to _write ;
bytes _flashed _total += bytes _to _write ;
bytes _flashed _total += bytes _to _write ;
self . controlTransfer ( 'out' , self . request . DNLOAD , 2 , 0 , 0 , data , function ( ) {
self . controlTransfer ( 'out' , self . request . DNLOAD , wBlockNum ++ , 0 , 0 , data , function ( ) {
self . controlTransfer ( 'in' , self . request . GETSTATUS , 0 , 0 , 6 , 0 , function ( data ) {
self . controlTransfer ( 'in' , self . request . GETSTATUS , 0 , 0 , 6 , 0 , function ( data ) {
var delay = data [ 1 ] | ( data [ 2 ] << 8 ) | ( data [ 3 ] << 16 ) ;
var delay = data [ 1 ] | ( data [ 2 ] << 8 ) | ( data [ 3 ] << 16 ) ;
@ -276,18 +287,6 @@ STM32DFU_protocol.prototype.upload_procedure = function(step) {
} , delay ) ;
} , 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 ++ ) {