mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-23 16:25:31 +03:00
utilizing new hex parser
This commit is contained in:
parent
c57d52c3d5
commit
71ee8d5ad1
2 changed files with 50 additions and 28 deletions
64
js/stm32.js
64
js/stm32.js
|
@ -1,5 +1,5 @@
|
||||||
var STM32_protocol = function() {
|
var STM32_protocol = function() {
|
||||||
this.hex_to_flash; // data to flash
|
this.parsed_hex; // hex object
|
||||||
|
|
||||||
this.receive_buffer;
|
this.receive_buffer;
|
||||||
|
|
||||||
|
@ -118,8 +118,8 @@ STM32_protocol.prototype.initialize = function() {
|
||||||
// reset and set some variables before we start
|
// reset and set some variables before we start
|
||||||
self.receive_buffer = [];
|
self.receive_buffer = [];
|
||||||
|
|
||||||
self.flashing_memory_address = 0x08000000;
|
self.flashing_memory_address = self.parsed_hex.extended_linear_address;
|
||||||
self.verify_memory_address = 0x08000000;
|
self.verify_memory_address = self.parsed_hex.extended_linear_address;
|
||||||
|
|
||||||
self.bytes_flashed = 0;
|
self.bytes_flashed = 0;
|
||||||
self.bytes_verified = 0;
|
self.bytes_verified = 0;
|
||||||
|
@ -204,6 +204,7 @@ STM32_protocol.prototype.send = function(Array, bytes_to_read, callback) {
|
||||||
STM32_protocol.prototype.verify_response = function(val, data) {
|
STM32_protocol.prototype.verify_response = function(val, data) {
|
||||||
if (val != data[0]) {
|
if (val != data[0]) {
|
||||||
console.log('STM32 Communication failed, wrong response, expected: ' + val + ' received: ' + data[0]);
|
console.log('STM32 Communication failed, wrong response, expected: ' + val + ' received: ' + data[0]);
|
||||||
|
STM32.GUI_status('STM32 Communication <span style="color: red">failed</span>, wrong response, expected: ' + val + ' received: ' + data[0]);
|
||||||
|
|
||||||
// disconnect
|
// disconnect
|
||||||
this.upload_procedure(99);
|
this.upload_procedure(99);
|
||||||
|
@ -220,7 +221,10 @@ STM32_protocol.prototype.verify_chip_signature = function(signature) {
|
||||||
switch (signature) {
|
switch (signature) {
|
||||||
case 0x412:
|
case 0x412:
|
||||||
// low density
|
// low density
|
||||||
return false;
|
// not tested
|
||||||
|
console.log('Chip recognized as F1 Low-density');
|
||||||
|
|
||||||
|
return true;
|
||||||
break;
|
break;
|
||||||
case 0x410:
|
case 0x410:
|
||||||
// medium density
|
// medium density
|
||||||
|
@ -230,25 +234,41 @@ STM32_protocol.prototype.verify_chip_signature = function(signature) {
|
||||||
break;
|
break;
|
||||||
case 0x414:
|
case 0x414:
|
||||||
// high density
|
// high density
|
||||||
return false
|
// not tested
|
||||||
|
console.log('Chip recognized as F1 High-density');
|
||||||
|
|
||||||
|
return true;
|
||||||
break;
|
break;
|
||||||
case 0x418:
|
case 0x418:
|
||||||
// connectivity line
|
// connectivity line
|
||||||
return false;
|
// not tested
|
||||||
|
console.log('Chip recognized as F1 Connectivity line');
|
||||||
|
|
||||||
|
return true;
|
||||||
break;
|
break;
|
||||||
case 0x420:
|
case 0x420:
|
||||||
// medium density value line
|
// medium density value line
|
||||||
return false;
|
// not tested
|
||||||
|
console.log('Chip recognized as F1 Medium-density value line');
|
||||||
|
|
||||||
|
return true;
|
||||||
break;
|
break;
|
||||||
case 0x428:
|
case 0x428:
|
||||||
// high density value line
|
// high density value line
|
||||||
return false;
|
// not tested
|
||||||
|
console.log('Chip recognized as F1 High-density value line');
|
||||||
|
|
||||||
|
return true;
|
||||||
break;
|
break;
|
||||||
case 0x430:
|
case 0x430:
|
||||||
// XL density
|
// XL density
|
||||||
return false;
|
// not tested
|
||||||
|
console.log('Chip recognized as F1 XL-density value line');
|
||||||
|
|
||||||
|
return true;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
console.log('Chip NOT recognized: ' + signature);
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -311,8 +331,6 @@ STM32_protocol.prototype.upload_procedure = function(step) {
|
||||||
// proceed to next step
|
// proceed to next step
|
||||||
self.upload_procedure(4);
|
self.upload_procedure(4);
|
||||||
} else {
|
} else {
|
||||||
console.log('Chip not supported, sorry :-(');
|
|
||||||
|
|
||||||
// disconnect
|
// disconnect
|
||||||
self.upload_procedure(99);
|
self.upload_procedure(99);
|
||||||
}
|
}
|
||||||
|
@ -342,11 +360,11 @@ STM32_protocol.prototype.upload_procedure = function(step) {
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
// upload
|
// upload
|
||||||
if (self.bytes_flashed < self.hex_to_flash.length) {
|
if (self.bytes_flashed < self.parsed_hex.data.length) {
|
||||||
if ((self.bytes_flashed + 256) <= self.hex_to_flash.length) {
|
if ((self.bytes_flashed + 256) <= self.parsed_hex.data.length) {
|
||||||
var data_length = 256;
|
var data_length = 256;
|
||||||
} else {
|
} else {
|
||||||
var data_length = self.hex_to_flash.length - self.bytes_flashed;
|
var data_length = self.parsed_hex.data.length - self.bytes_flashed;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('STM32 - Writing to: 0x' + self.flashing_memory_address.toString(16) + ', ' + data_length + ' bytes');
|
console.log('STM32 - Writing to: 0x' + self.flashing_memory_address.toString(16) + ', ' + data_length + ' bytes');
|
||||||
|
@ -364,8 +382,8 @@ STM32_protocol.prototype.upload_procedure = function(step) {
|
||||||
|
|
||||||
var checksum = array_out[0];
|
var checksum = array_out[0];
|
||||||
for (var i = 0; i < data_length; i++) {
|
for (var i = 0; i < data_length; i++) {
|
||||||
array_out[i + 1] = self.hex_to_flash[self.bytes_flashed]; // + 1 because of the first byte offset
|
array_out[i + 1] = self.parsed_hex.data[self.bytes_flashed]; // + 1 because of the first byte offset
|
||||||
checksum ^= self.hex_to_flash[self.bytes_flashed];
|
checksum ^= self.parsed_hex.data[self.bytes_flashed];
|
||||||
|
|
||||||
self.bytes_flashed++;
|
self.bytes_flashed++;
|
||||||
self.flashing_memory_address++;
|
self.flashing_memory_address++;
|
||||||
|
@ -395,11 +413,11 @@ STM32_protocol.prototype.upload_procedure = function(step) {
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
// verify
|
// verify
|
||||||
if (self.bytes_verified < self.hex_to_flash.length) {
|
if (self.bytes_verified < self.parsed_hex.data.length) {
|
||||||
if ((self.bytes_verified + 256) <= self.hex_to_flash.length) {
|
if ((self.bytes_verified + 256) <= self.parsed_hex.data.length) {
|
||||||
var data_length = 256;
|
var data_length = 256;
|
||||||
} else {
|
} else {
|
||||||
var data_length = self.hex_to_flash.length - self.bytes_verified;
|
var data_length = self.parsed_hex.data.length - self.bytes_verified;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('STM32 - Reading from: 0x' + self.verify_memory_address.toString(16) + ', ' + data_length + ' bytes');
|
console.log('STM32 - Reading from: 0x' + self.verify_memory_address.toString(16) + ', ' + data_length + ' bytes');
|
||||||
|
@ -433,7 +451,7 @@ STM32_protocol.prototype.upload_procedure = function(step) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
var result = self.verify_flash(self.hex_to_flash, self.verify_hex);
|
var result = self.verify_flash(self.parsed_hex.data, self.verify_hex);
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
console.log('Verifying: done');
|
console.log('Verifying: done');
|
||||||
|
@ -459,7 +477,11 @@ STM32_protocol.prototype.upload_procedure = function(step) {
|
||||||
|
|
||||||
self.send([self.command.go, 0xDE], 1, function(reply) { // 0x21 ^ 0xFF
|
self.send([self.command.go, 0xDE], 1, function(reply) { // 0x21 ^ 0xFF
|
||||||
if (self.verify_response(self.status.ACK, reply)) {
|
if (self.verify_response(self.status.ACK, reply)) {
|
||||||
self.send([0x08, 0x00, 0x00, 0x00, 0x08], 1, function(reply) {
|
var gt_address = self.parsed_hex.extended_linear_address;
|
||||||
|
var address = [(gt_address >> 24), (gt_address >> 16) & 0x00FF, (gt_address >> 8) & 0x00FF, (gt_address & 0x00FF)];
|
||||||
|
var address_checksum = address[0] ^ address[1] ^ address[2] ^ address[3];
|
||||||
|
|
||||||
|
self.send([address[0], address[1], address[2], address[3], address_checksum], 1, function(reply) {
|
||||||
if (self.verify_response(self.status.ACK, reply)) {
|
if (self.verify_response(self.status.ACK, reply)) {
|
||||||
// disconnect
|
// disconnect
|
||||||
self.upload_procedure(99);
|
self.upload_procedure(99);
|
||||||
|
|
|
@ -3,7 +3,7 @@ function tab_initialize_firmware_flasher() {
|
||||||
GUI.active_tab = 'firmware_flasher';
|
GUI.active_tab = 'firmware_flasher';
|
||||||
|
|
||||||
var intel_hex = false; // standard intel hex in string format
|
var intel_hex = false; // standard intel hex in string format
|
||||||
var raw_hex = false; // parsed raw hex in array format
|
var parsed_hex = false; // parsed raw hex in array format
|
||||||
|
|
||||||
$('#content').load("./tabs/firmware_flasher.html", function() {
|
$('#content').load("./tabs/firmware_flasher.html", function() {
|
||||||
// UI Hooks
|
// UI Hooks
|
||||||
|
@ -31,9 +31,9 @@ function tab_initialize_firmware_flasher() {
|
||||||
STM32.GUI_status('<span style="color: green">Firmware loaded, ready for flashing</span>');
|
STM32.GUI_status('<span style="color: green">Firmware loaded, ready for flashing</span>');
|
||||||
|
|
||||||
intel_hex = e.target.result;
|
intel_hex = e.target.result;
|
||||||
raw_hex = read_hex_file(intel_hex);
|
parsed_hex = read_hex_file(intel_hex);
|
||||||
|
|
||||||
$('span.size').html((raw_hex.length / 1000) + ' kB');
|
$('span.size').html((parsed_hex.bytes / 1000) + ' kB');
|
||||||
$('a.flash_firmware').removeClass('locked');
|
$('a.flash_firmware').removeClass('locked');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -52,10 +52,10 @@ function tab_initialize_firmware_flasher() {
|
||||||
|
|
||||||
$.get('https://raw.github.com/multiwii/baseflight/master/obj/baseflight.hex', function(data) {
|
$.get('https://raw.github.com/multiwii/baseflight/master/obj/baseflight.hex', function(data) {
|
||||||
intel_hex = data;
|
intel_hex = data;
|
||||||
raw_hex = read_hex_file(intel_hex);
|
parsed_hex = read_hex_file(intel_hex);
|
||||||
|
|
||||||
$('span.path').html('Using remote Firmware');
|
$('span.path').html('Using remote Firmware');
|
||||||
$('span.size').html((raw_hex.length / 1000) + ' kB');
|
$('span.size').html((parsed_hex.bytes / 1000) + ' kB');
|
||||||
$('a.flash_firmware').removeClass('locked');
|
$('a.flash_firmware').removeClass('locked');
|
||||||
|
|
||||||
STM32.GUI_status('<span style="color: green">Remote Firmware loaded, ready for flashing</span>');
|
STM32.GUI_status('<span style="color: green">Remote Firmware loaded, ready for flashing</span>');
|
||||||
|
@ -68,8 +68,8 @@ function tab_initialize_firmware_flasher() {
|
||||||
$('a.flash_firmware').click(function() {
|
$('a.flash_firmware').click(function() {
|
||||||
if (!$(this).hasClass('locked')) {
|
if (!$(this).hasClass('locked')) {
|
||||||
if (!GUI.connect_lock) { // button disabled while flashing is in progress
|
if (!GUI.connect_lock) { // button disabled while flashing is in progress
|
||||||
if (raw_hex != false) {
|
if (parsed_hex != false) {
|
||||||
STM32.hex_to_flash = raw_hex.slice(0);
|
STM32.parsed_hex = parsed_hex;
|
||||||
|
|
||||||
STM32.connect();
|
STM32.connect();
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue