1
0
Fork 0
mirror of https://github.com/betaflight/betaflight-configurator.git synced 2025-07-16 04:45:20 +03:00

Detect board in firmware_flasher patch

This commit is contained in:
Mark Haslinghuis 2021-07-01 01:11:33 +02:00
parent b1481ad2d9
commit c0cda1f735
No known key found for this signature in database
GPG key ID: 198B0F616296A584
7 changed files with 107 additions and 29 deletions

View file

@ -2986,7 +2986,7 @@
"message": "Select build type to see available boards."
},
"firmwareFlasherOnlineSelectBoardDescription": {
"message": "Select your board to see available online firmware releases - Select the correct firmware appropriate for your board."
"message": "Select or auto-detect your board to see available online firmware releases - Select the correct firmware appropriate for your board."
},
"firmwareFlasherOnlineSelectBoardHint": {
"message": "Starting with Betaflight 4.1, Betaflight is introducing support for <strong>Unified Targets</strong>. The concept of Unified Targets means that the same firmware .hex file can be used for all boards using the same MCU (F4, F7). To make the different boards work with the same firmware, a specific configuration file is deployed alongside the firmware when a Unified Target is flashed.<br>This version of Betaflight configurator supports flashing of Unified Targets with the respective board specific configurations in one step. The different firmware types that are available for each board are shown in the drop-down as follows:<br /><br /><strong>&lt;board name&gt;</strong> or<br><strong>&lt;board name&gt; (Legacy)</strong>:<br>non-unified target, or pre-4.1 versions of the firmware for Unified Targets.<br /><br /><strong>&lt;board name&gt; (&lt;manufacturer id&gt;)</strong>:<br>(4 character manufacturer id)<br>Unified Target.<br /><br /><strong>Please use Unified Targets where available.</strong> If you encounter problems using a Unified Target, please open an <a href=\"https://github.com/betaflight/betaflight/issues\" target=\"_blank\" rel=\"noopener noreferrer\">issue</a> and then use the non-unified target until the issue has been resolved."
@ -3171,6 +3171,15 @@
"firmwareFlasherButtonContinue": {
"message": "Continue"
},
"firmwareFlasherDetectBoardButton": {
"message": "Auto-detect"
},
"firmwareFlasherDetectBoardDescriptionHint": {
"message": "Auto-detect only works when not in DFU mode and when MSP communication is working. Sometimes you have to retry a few times or even reconnect USB. Try connecting as normal first as you could have forgotten to apply custom defaults. Please reboot after flashing - replug your USB."
},
"firmwareFlasherDetectBoardQuery": {
"message": "Query board information to preselect right firmware"
},
"unstableFirmwareAcknoledgementDialog": {
"message": "You are about to flash a <strong>development build of the firmware</strong>. These builds are a work in progress, and any of the following can be the case:<strong><ul><li>the firmware does not work at all;</li><li>the firmware is not flyable;</li><li>there are safety issues with the firmware, for example flyaways</li><li>the firmware can cause the flight controller to become unresponsive, or damaged</li></ul></strong>If you proceed with flashing this firmware, <strong>you are assuming full responsibility for the risk of any of the above happening</strong>. Furthermore you acknowledge that it is necessary to perform <strong>thorough bench tests with props off</strong> before any attempts to fly this firmware."
},

View file

@ -78,8 +78,12 @@
text-align: left;
}
.tab-firmware_flasher td {
text-align: left;
.tab-firmware_flasher td.board-description {
padding: 1px 0 3px 0;
}
.tab-firmware_flasher .helpicon {
margin-top: 3px;
}
.tab-firmware_flasher .options label input {
@ -202,6 +206,16 @@
opacity: 0.5;
}
.tab-firmware_flasher .default_btn {
margin: 1px 7px 0 0;
width: fit-content;
}
.tab-firmware_flasher .default_btn a {
padding: 0 4px 2px 4px;
font-size: 11px;
}
#dialogUnstableFirmwareAcknoledgement .content {
margin-top: 10px;
}

View file

@ -12,6 +12,7 @@ const PortHandler = new function () {
this.port_detected_callbacks = [];
this.port_removed_callbacks = [];
this.dfu_available = false;
this.port_available = false;
};
PortHandler.initialize = function () {
@ -118,6 +119,7 @@ PortHandler.removePort = function(currentPorts) {
if (removePorts.length) {
console.log(`PortHandler - Removed: ${JSON.stringify(removePorts)}`);
self.port_available = false;
// disconnect "UI" - routine can't fire during atmega32u4 reboot procedure !!!
if (GUI.connected_to) {
for (let i = 0; i < removePorts.length; i++) {
@ -170,6 +172,7 @@ PortHandler.detectPort = function(currentPorts) {
}
});
self.port_available = true;
// Signal board verification
if (GUI.active_tab === 'firmware_flasher') {
TABS.firmware_flasher.boardNeedsVerification = true;
@ -266,6 +269,7 @@ PortHandler.selectPort = function(ports) {
const legacyDeviceRecognized = portName.includes('usb');
if (isWindows && deviceRecognized || isTty && (deviceRecognized || legacyDeviceRecognized)) {
this.portPickerElement.val(pathSelect);
this.port_available = true;
console.log(`Porthandler detected device ${portName} on port: ${pathSelect}`);
}
}

View file

@ -89,7 +89,12 @@ STM32_protocol.prototype.connect = function (port, baud, hex, options, callback)
});
} else {
var startFlashing = function() {
let rebootMode = 0; // FIRMWARE
const startFlashing = () => {
if (rebootMode === 0) {
return;
}
// refresh device list
PortHandler.check_usb_devices(function(dfu_available) {
if (dfu_available) {
@ -144,7 +149,6 @@ STM32_protocol.prototype.connect = function (port, baud, hex, options, callback)
GUI.log(i18n.getMessage('apiVersionReceived', [FC.CONFIG.apiVersion]));
if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_42)) {
self.msp_connector.disconnect(function (disconnectionResult) {
// need some time for the port to be closed, serial port does not open if tried immediately
@ -154,7 +158,6 @@ STM32_protocol.prototype.connect = function (port, baud, hex, options, callback)
console.log('Looking for capabilities via MSP');
MSP.send_message(MSPCodes.MSP_BOARD_INFO, false, false, () => {
var rebootMode = 0; // FIRMWARE
if (bit_check(FC.CONFIG.targetCapabilities, FC.TARGET_CAPABILITIES_FLAGS.HAS_FLASH_BOOTLOADER)) {
// Board has flash bootloader
GUI.log(i18n.getMessage('deviceRebooting_flashBootloader'));
@ -166,7 +169,7 @@ STM32_protocol.prototype.connect = function (port, baud, hex, options, callback)
rebootMode = 1; // MSP_REBOOT_BOOTLOADER_ROM;
}
const selectedBoard = TABS.firmware_flasher.selectedBoard;
const selectedBoard = TABS.firmware_flasher.selectedBoard !== '0' ? TABS.firmware_flasher.selectedBoard : 'NONE';
const connectedBoard = FC.CONFIG.boardName ? FC.CONFIG.boardName : 'UNKNOWN';
function reboot() {
@ -179,7 +182,6 @@ STM32_protocol.prototype.connect = function (port, baud, hex, options, callback)
self.msp_connector.disconnect(disconnectionResult => onDisconnect(disconnectionResult));
}, () => console.log('Reboot request received by device'));
}
function onAbort() {
@ -190,12 +192,11 @@ STM32_protocol.prototype.connect = function (port, baud, hex, options, callback)
TABS.firmware_flasher.refresh();
}
if (selectedBoard !== connectedBoard) {
if (selectedBoard !== connectedBoard && !TABS.firmware_flasher.localFirmwareLoaded) {
TABS.firmware_flasher.showDialogVerifyBoard(selectedBoard, connectedBoard, onAbort, reboot);
} else {
reboot();
}
});
}
};
@ -209,6 +210,7 @@ STM32_protocol.prototype.connect = function (port, baud, hex, options, callback)
var onFailureHandler = function() {
GUI.connect_lock = false;
TABS.firmware_flasher.refresh();
};
GUI.connect_lock = true;
@ -323,7 +325,6 @@ STM32_protocol.prototype.send = function (bytes_to_send, 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]) {
var message = 'STM32 Communication failed, wrong response, expected: ' + val + ' (0x' + val.toString(16) + ') received: ' + data[0] + ' (0x' + data[0].toString(16) + ')';

View file

@ -18,10 +18,7 @@ const serial = {
connect: function (path, options, callback) {
const self = this;
const testUrl = path.match(/^tcp:\/\/([A-Za-z0-9\.-]+)(?:\:(\d+))?$/);
if (self.connectionId || self.connected) {
console.warn('We already connected. Aborting', self.connectionId, self.connected);
return;
}
if (testUrl) {
self.connectTcp(testUrl[1], testUrl[2], options, callback);
} else if (path === 'virtual') {

View file

@ -317,8 +317,6 @@ firmware_flasher.initialize = function (callback) {
$('select[name="board"]').val(boardReleases ? result.selected_board : 0).trigger('change');
}
});
verifyBoard();
}
const buildTypes = [
@ -344,8 +342,8 @@ firmware_flasher.initialize = function (callback) {
loader: () => self.jenkinsLoader.loadBuilds(job.name, loadUnifiedBuilds)
};
});
let buildTypesToShow;
let buildTypesToShow;
const buildType_e = $('select[name="build_type"]');
function buildBuildTypeOptionsList() {
buildType_e.empty();
@ -536,9 +534,15 @@ firmware_flasher.initialize = function (callback) {
$('select[name="board"]').change(function() {
$("a.load_remote_file").addClass('disabled');
const target = $(this).val();
let target = $(this).val();
if (!GUI.connect_lock && target) {
// exception for board flashed with local custom firmware
if (target === null) {
target = '0';
$(this).val(target).trigger('change');
}
if (!GUI.connect_lock) {
if (TABS.firmware_flasher.selectedBoard !== target) {
// We're sure the board actually changed
if (self.isConfigLocal) {
@ -547,7 +551,11 @@ firmware_flasher.initialize = function (callback) {
self.unifiedTarget = {};
}
}
ConfigStorage.set({'selected_board': target});
if (target !== '0') {
ConfigStorage.set({'selected_board': target});
}
TABS.firmware_flasher.selectedBoard = target;
TABS.firmware_flasher.bareBoard = undefined;
console.log('board changed to', target);
@ -563,7 +571,7 @@ firmware_flasher.initialize = function (callback) {
}
const versions_e = $('select[name="firmware_version"]');
if (target === 0) {
if (target === '0') {
// target is 0 is the "Choose a Board" option. Throw out anything loaded
clearBufferedFirmware();
@ -774,7 +782,6 @@ firmware_flasher.initialize = function (callback) {
function onFinishClose() {
MSP.clearListeners();
GUI.connect_lock = false;
}
function onClose() {
@ -795,18 +802,28 @@ firmware_flasher.initialize = function (callback) {
function getBoard() {
console.log(`Requesting board information`);
MSP.send_message(MSPCodes.MSP_API_VERSION, false, false, () => MSP.send_message(MSPCodes.MSP_BOARD_INFO, false, false, onFinish));
MSP.send_message(MSPCodes.MSP_API_VERSION, false, false, () => {
if (!FC.CONFIG.apiVersion || FC.CONFIG.apiVersion === 'null.null.0') {
FC.CONFIG.apiVersion = '0.0.0';
}
console.log(FC.CONFIG.apiVersion);
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_39)) {
MSP.send_message(MSPCodes.MSP_BOARD_INFO, false, false, onFinish);
} else {
console.log('Firmware version not supported for reading board information');
onClose();
}
});
}
function onConnect(openInfo) {
if (openInfo) {
GUI.connect_lock = true;
serial.onReceive.addListener(data => MSP.read(data));
const mspHelper = new MspHelper();
MSP.listen(mspHelper.process_data.bind(mspHelper));
getBoard();
} else {
console.dir('Failed to open connection:', openInfo);
GUI.log(i18n.getMessage('serialPortOpenFail'));
}
}
@ -817,7 +834,7 @@ firmware_flasher.initialize = function (callback) {
if ($('input.flash_manual_baud').is(':checked')) {
baud = parseInt($('#flash_manual_baud_rate').val());
}
console.log('Query board information to preselect right firmware');
GUI.log(i18n.getMessage('firmwareFlasherDetectBoardQuery'));
if (!(serial.connected || serial.connectionId)) {
serial.connect(port, {bitrate: baud}, onConnect);
} else {
@ -825,12 +842,40 @@ firmware_flasher.initialize = function (callback) {
serial.disconnect();
}
} else {
console.log('Please select valid serial port');
GUI.log(i18n.getMessage('firmwareFlasherNoValidPort'));
}
}
}
const detectBoardElement = $('a.detect-board');
let isClickable = true;
detectBoardElement.on('click', () => {
detectBoardElement.addClass('disabled');
if (isClickable) {
isClickable = false;
verifyBoard();
setTimeout(() => isClickable = true, 1000);
}
});
function updateDetectBoardButton() {
const board = $('select[name="board"] option:selected').val();
const firmwareVersion = $('select[name="firmware_version"] option:selected').val();
const isDfu = portPickerElement.val().includes('DFU');
const isBusy = GUI.connect_lock;
const isLoaded = board !== '0' && firmwareVersion !== '0';
const isAvailable = PortHandler.port_available || false;
const isButtonDisabled = isDfu || isBusy || !isLoaded || !isAvailable;
detectBoardElement.toggleClass('disabled', isButtonDisabled);
}
document.querySelector('select[name="build_type"]').addEventListener('change', updateDetectBoardButton);
document.querySelector('select[name="board"]').addEventListener('change', updateDetectBoardButton);
document.querySelector('select[name="firmware_version"]').addEventListener('change', updateDetectBoardButton);
ConfigStorage.get('erase_chip', function (result) {
if (result.erase_chip) {
$('input.erase_chip').prop('checked', true);
@ -1092,6 +1137,7 @@ firmware_flasher.initialize = function (callback) {
exitDfuElement.addClass('disabled');
}
}
updateDetectBoardButton();
}).change();
$('a.flash_firmware').click(function () {

View file

@ -26,7 +26,14 @@
<td class="board-select"><select name="board">
<option value="0" i18n="firmwareFlasherOptionLoading">Loading ...</option>
</select></td>
<td><span class="description" i18n="firmwareFlasherOnlineSelectBoardDescription"></span><div class="helpicon cf_tip_wide" i18n_title="firmwareFlasherOnlineSelectBoardHint"></div></td>
<td class="board-description">
<div class="btn default_btn">
<a class="detect-board disabled" href="#" i18n="firmwareFlasherDetectBoardButton"></a>
</div>
<span class="description" i18n="firmwareFlasherOnlineSelectBoardDescription"></span>
<div class="helpicon cf_tip_wide" i18n_title="firmwareFlasherOnlineSelectBoardHint"></div>
<div class="helpicon cf_tip_wide" i18n_title="firmwareFlasherDetectBoardDescriptionHint"></div>
</td>
</tr>
<tr>
<td><select name="firmware_version">