1
0
Fork 0
mirror of https://github.com/iNavFlight/inav-configurator.git synced 2025-07-13 11:29:53 +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:
Dominic Clifton 2015-05-22 00:27:09 +01:00
parent ef682cdca9
commit 90cc08c86b

View file

@ -46,6 +46,7 @@ var STM32_protocol = function () {
this.available_flash_size = 0;
this.page_size = 0;
this.useExtendedErase = false;
};
// 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)
// result = true/false
STM32_protocol.prototype.verify_response = function (val, data) {
var self = this;
if (val != data[0]) {
console.error('STM32 Communication failed, wrong response, expected: ' + val + ' received: ' + data[0]);
$('span.progressLabel').text('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) + ')';
console.error(message);
$('span.progressLabel').text(message);
self.progress_bar_e.addClass('invalid');
// disconnect
@ -302,7 +306,7 @@ STM32_protocol.prototype.verify_chip_signature = function (signature) {
case 0x432: // not tested
console.log('Chip recognized as F3 STM32F37xxx, STM32F38xxx');
break;
case 0x422: // not tested
case 0x422:
console.log('Chip recognized as F3 STM32F30xxx, STM32F31xxx');
this.available_flash_size = 0x40000;
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) {
var self = this;
var extendedErase=false;
switch (step) {
case 1:
// 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]
console.log('STM32 - Bootloader version: ' + (parseInt(data[0].toString(16)) / 10).toFixed(1)); // convert dec to hex, hex to dec and add floating point
extendedErase=data[7]==0x44;
self.useExtendedErase = (data[7] == 0x44);
// proceed to next step
self.upload_procedure(3);
@ -423,30 +424,29 @@ STM32_protocol.prototype.upload_procedure = function (step) {
break;
case 4:
// 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)
{
console.log('Executing global chip extended erase');
self.send([0x44, 0xBB], 1, function (reply) {
if (self.verify_response(self.status.ACK, reply)) {
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);
}
});
}
});
}else{
self.send([0x44, 0xBB], 1, function (reply) {
if (self.verify_response(self.status.ACK, reply)) {
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;
}
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
if (self.verify_response(self.status.ACK, reply)) {
@ -460,7 +460,9 @@ STM32_protocol.prototype.upload_procedure = function (step) {
}
});
} 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
if (self.verify_response(self.status.ACK, reply)) {
@ -489,7 +491,6 @@ STM32_protocol.prototype.upload_procedure = function (step) {
}
});
}
}
break;
case 5:
// upload