Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/iNavFlight/inav-configurator.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorAlberto García Hierro <alberto@garciahierro.com>2019-04-26 20:46:30 +0300
committerPawel Spychalski (DzikuVx) <pspychalski@gmail.com>2019-07-16 20:56:58 +0300
commit9e81e6dbb17550caef29994ed23092129513abd3 (patch)
tree2a7391d679b309039c3f00d4239a160124159461 /js
parentc20fff75b20e9bd1fd1ca1e3d72304afb9a68ec1 (diff)
Make firmware flasher more robust
Check for DFU/serial port regularly during 10 seconds instead of waiting 1s and trying once. Also, make sure that we don't mistake DFU devices with serial ones, since the serial port might appear briefly while the FC is rebooting.
Diffstat (limited to 'js')
-rw-r--r--js/protocols/stm32.js50
1 files changed, 35 insertions, 15 deletions
diff --git a/js/protocols/stm32.js b/js/protocols/stm32.js
index ebe34d22..968d4901 100644
--- a/js/protocols/stm32.js
+++ b/js/protocols/stm32.js
@@ -100,25 +100,45 @@ STM32_protocol.prototype.connect = function (port, baud, hex, options, callback)
serial.send(bufferOut, function () {
serial.disconnect(function (result) {
if (result) {
- // delay to allow board to boot in bootloader mode
- // required to detect if a DFU device appears
- setTimeout(function() {
- // refresh device list
+ var intervalMs = 200;
+ var retries = 0;
+ var maxRetries = 50; // timeout after intervalMs * 50
+ var interval = setInterval(function() {
+ var tryFailed = function() {
+ retries++;
+ if (retries > maxRetries) {
+ clearInterval(interval);
+ GUI.log('<span style="color: red">Failed</span> to flash ' + port);
+ }
+ }
+ // Check for DFU devices
PortHandler.check_usb_devices(function(dfu_available) {
- if(dfu_available) {
+ if (dfu_available) {
+ clearInterval(interval);
STM32DFU.connect(usbDevices.STM32DFU, hex, options);
- } else {
- serial.connect(port, {bitrate: self.baud, parityBit: 'even', stopBits: 'one'}, function (openInfo) {
- if (openInfo) {
- self.initialize();
- } else {
- GUI.connect_lock = false;
- GUI.log('<span style="color: red">Failed</span> to open serial port');
- }
- });
+ return;
}
+ // Check for the serial port
+ serial.getDevices(function(devices) {
+ if (devices && devices.includes(port)) {
+ // Serial port might briefly reappear on DFU devices while
+ // the FC is rebooting, so we don't clear the interval
+ // until we succesfully connect.
+ serial.connect(port, {bitrate: self.baud, parityBit: 'even', stopBits: 'one'}, function (openInfo) {
+ if (openInfo) {
+ clearInterval(interval);
+ self.initialize();
+ } else {
+ GUI.connect_lock = false;
+ tryFailed();
+ }
+ });
+ return;
+ }
+ tryFailed();
+ });
});
- }, 1000);
+ }, intervalMs);
} else {
GUI.connect_lock = false;
}