@ -143,7 +143,7 @@ STM32DFU_protocol.prototype.controlTransfer = function(direction, request, value
if ( result . resultCode ) console . log ( result . resultCode ) ;
var buf = new Uint8Array ( result . data ) ;
callback ( buf );
callback ( buf , result . resultCode );
} ) ;
} else {
// length is ignored
@ -345,38 +345,43 @@ STM32DFU_protocol.prototype.upload_procedure = function(step) {
}
function load _read _address ( ) {
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 ) ;
self . controlTransfer ( 'in' , self . request . GETSTATUS , 0 , 0 , 6 , 0 , function ( data ) {
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 ) {
clear _status ( ) ;
} else {
console . log ( data ) ;
}
} ) ;
} , delay ) ;
} else {
console . log ( data ) ;
}
} ) ;
setTimeout ( function ( ) {
self . controlTransfer ( 'out' , self . request . DNLOAD , 0 , 0 , 0 , [ 0x21 , address , ( address >> 8 ) , ( address >> 16 ) , ( address >> 24 ) ] , function ( result ) { // problem on this call !!
self . controlTransfer ( 'in' , self . request . GETSTATUS , 0 , 0 , 6 , 0 , function ( data ) {
if ( data [ 4 ] == self . state . dfuDNBUSY ) {
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 ) {
clear _status ( ) ;
} else {
console . log ( data ) ;
}
} ) ;
} , delay ) ;
} else if ( data [ 4 ] == self . state . dfuUPLOAD _IDLE ) {
read ( ) ;
} else {
console . log ( data ) ;
}
} ) ;
} ) ;
} , delay ) ;
} ) ;
}
function clear _status ( ) {
self . controlTransfer ( 'out' , self . request . CLRSTATUS , 0 , 0 , 0 , 0 , function ( ) {
self . controlTransfer ( 'out' , self . request . CLRSTATUS , 0 , 0 , 0 , 0 , function ( ) {
self . controlTransfer ( 'in' , self . request . GETSTATUS , 0 , 0 , 6 , 0 , function ( data ) {
if ( data [ 4 ] == self . state . dfuIDLE ) {
read ( ) ;
} else {
// throw some error
console . log ( data ) ;
}
} ) ;
self . controlTransfer ( 'in' , self . request . GETSTATUS , 0 , 0 , 6 , 0 , function ( data ) {
if ( data [ 4 ] == self . state . dfuIDLE ) {
read ( ) ;
} else {
clear _status ( ) ;
}
} ) ;
} ) ;
}
@ -385,7 +390,7 @@ STM32DFU_protocol.prototype.upload_procedure = function(step) {
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 ) ;
self . controlTransfer ( 'in' , self . request . UPLOAD , wBlockNum ++ , 0 , bytes _to _read , 0 , function ( data ) {
self . controlTransfer ( 'in' , self . request . UPLOAD , wBlockNum ++ , 0 , bytes _to _read , 0 , function ( data , code ) {
for ( var i = 0 ; i < data . length ; i ++ ) {
self . verify _hex [ reading _block ] . push ( data [ i ] ) ;
}
@ -407,7 +412,7 @@ STM32DFU_protocol.prototype.upload_procedure = function(step) {
address = self . hex . data [ reading _block ] . address ;
bytes _verified = 0 ;
wBlockNum = 2 ;
//wBlockNum = 2;
load _read _address ( ) ;
} else {