mirror of
https://github.com/iNavFlight/inav-configurator.git
synced 2025-07-16 04:45:18 +03:00
Test and cleanup STM32 extended erase bootloader command support.
Note: entire chip only for now - 'Full Chip Erase' checkbox is ignored.
This commit is contained in:
parent
ef682cdca9
commit
90cc08c86b
1 changed files with 30 additions and 29 deletions
|
@ -46,6 +46,7 @@ var STM32_protocol = function () {
|
||||||
|
|
||||||
this.available_flash_size = 0;
|
this.available_flash_size = 0;
|
||||||
this.page_size = 0;
|
this.page_size = 0;
|
||||||
|
this.useExtendedErase = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
// no input parameters
|
// no input parameters
|
||||||
|
@ -234,9 +235,12 @@ STM32_protocol.prototype.send = function (Array, bytes_to_read, callback) {
|
||||||
// data = response of n bytes from mcu (array)
|
// data = response of n bytes from mcu (array)
|
||||||
// result = true/false
|
// result = true/false
|
||||||
STM32_protocol.prototype.verify_response = function (val, data) {
|
STM32_protocol.prototype.verify_response = function (val, data) {
|
||||||
|
var self = this;
|
||||||
|
|
||||||
if (val != data[0]) {
|
if (val != data[0]) {
|
||||||
console.error('STM32 Communication failed, wrong response, expected: ' + val + ' received: ' + data[0]);
|
var message = 'STM32 Communication failed, wrong response, expected: ' + val + ' (0x' + val.toString(16) + ') received: ' + data[0] + ' (0x' + data[0].toString(16) + ')';
|
||||||
$('span.progressLabel').text('STM32 Communication failed, wrong response, expected: ' + val + ' received: ' + data[0]);
|
console.error(message);
|
||||||
|
$('span.progressLabel').text(message);
|
||||||
self.progress_bar_e.addClass('invalid');
|
self.progress_bar_e.addClass('invalid');
|
||||||
|
|
||||||
// disconnect
|
// disconnect
|
||||||
|
@ -302,7 +306,7 @@ STM32_protocol.prototype.verify_chip_signature = function (signature) {
|
||||||
case 0x432: // not tested
|
case 0x432: // not tested
|
||||||
console.log('Chip recognized as F3 STM32F37xxx, STM32F38xxx');
|
console.log('Chip recognized as F3 STM32F37xxx, STM32F38xxx');
|
||||||
break;
|
break;
|
||||||
case 0x422: // not tested
|
case 0x422:
|
||||||
console.log('Chip recognized as F3 STM32F30xxx, STM32F31xxx');
|
console.log('Chip recognized as F3 STM32F30xxx, STM32F31xxx');
|
||||||
this.available_flash_size = 0x40000;
|
this.available_flash_size = 0x40000;
|
||||||
this.page_size = 2048;
|
this.page_size = 2048;
|
||||||
|
@ -344,8 +348,6 @@ STM32_protocol.prototype.verify_flash = function (first_array, second_array) {
|
||||||
STM32_protocol.prototype.upload_procedure = function (step) {
|
STM32_protocol.prototype.upload_procedure = function (step) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
var extendedErase=false;
|
|
||||||
|
|
||||||
switch (step) {
|
switch (step) {
|
||||||
case 1:
|
case 1:
|
||||||
// initialize serial interface on the MCU side, auto baud rate settings
|
// initialize serial interface on the MCU side, auto baud rate settings
|
||||||
|
@ -393,8 +395,7 @@ STM32_protocol.prototype.upload_procedure = function (step) {
|
||||||
self.retrieve(data[1] + 1 + 1, function (data) { // data[1] = number of bytes that will follow [– 1 except current and ACKs]
|
self.retrieve(data[1] + 1 + 1, function (data) { // data[1] = number of bytes that will follow [– 1 except current and ACKs]
|
||||||
console.log('STM32 - Bootloader version: ' + (parseInt(data[0].toString(16)) / 10).toFixed(1)); // convert dec to hex, hex to dec and add floating point
|
console.log('STM32 - Bootloader version: ' + (parseInt(data[0].toString(16)) / 10).toFixed(1)); // convert dec to hex, hex to dec and add floating point
|
||||||
|
|
||||||
|
self.useExtendedErase = (data[7] == 0x44);
|
||||||
extendedErase=data[7]==0x44;
|
|
||||||
|
|
||||||
// proceed to next step
|
// proceed to next step
|
||||||
self.upload_procedure(3);
|
self.upload_procedure(3);
|
||||||
|
@ -423,30 +424,29 @@ STM32_protocol.prototype.upload_procedure = function (step) {
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
// erase memory
|
// erase memory
|
||||||
$('span.progressLabel').text('Erasing ...');
|
|
||||||
|
|
||||||
|
if (self.useExtendedErase) {
|
||||||
|
var message = 'Executing global chip (via extended erase)';
|
||||||
|
console.log(message);
|
||||||
|
$('span.progressLabel').text(message + ' ...');
|
||||||
|
|
||||||
if(extendedErase)
|
self.send([0x44, 0xBB], 1, function (reply) {
|
||||||
{
|
if (self.verify_response(self.status.ACK, reply)) {
|
||||||
console.log('Executing global chip extended erase');
|
self.send( [0xFF, 0xFF, 0x00], 1, function (reply) {
|
||||||
|
if (self.verify_response(self.status.ACK, reply)) {
|
||||||
self.send([0x44, 0xBB], 1, function (reply) {
|
console.log('Executing global chip extended erase: done');
|
||||||
if (self.verify_response(self.status.ACK, reply)) {
|
self.upload_procedure(5);
|
||||||
self.send( [0xFF, 0xFF, 0x00], 1, function (reply){
|
}
|
||||||
if (self.verify_response(self.status.ACK, reply)){
|
});
|
||||||
console.log('Executing global chip extended erase - done');
|
}
|
||||||
self.upload_procedure(5);
|
});
|
||||||
}
|
break;
|
||||||
});
|
}
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}else{
|
|
||||||
|
|
||||||
if (self.options.erase_chip) {
|
if (self.options.erase_chip) {
|
||||||
console.log('Executing global chip erase');
|
var message = 'Executing global chip erase' ;
|
||||||
|
console.log(message);
|
||||||
|
$('span.progressLabel').text(message + ' ...');
|
||||||
|
|
||||||
self.send([self.command.erase, 0xBC], 1, function (reply) { // 0x43 ^ 0xFF
|
self.send([self.command.erase, 0xBC], 1, function (reply) { // 0x43 ^ 0xFF
|
||||||
if (self.verify_response(self.status.ACK, reply)) {
|
if (self.verify_response(self.status.ACK, reply)) {
|
||||||
|
@ -460,7 +460,9 @@ STM32_protocol.prototype.upload_procedure = function (step) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
console.log('Executing local erase (only needed pages)');
|
var message = 'Executing local erase (only needed pages)';
|
||||||
|
console.log(message);
|
||||||
|
$('span.progressLabel').text(message + ' ...');
|
||||||
|
|
||||||
self.send([self.command.erase, 0xBC], 1, function (reply) { // 0x43 ^ 0xFF
|
self.send([self.command.erase, 0xBC], 1, function (reply) { // 0x43 ^ 0xFF
|
||||||
if (self.verify_response(self.status.ACK, reply)) {
|
if (self.verify_response(self.status.ACK, reply)) {
|
||||||
|
@ -489,7 +491,6 @@ STM32_protocol.prototype.upload_procedure = function (step) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
// upload
|
// upload
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue