Commit e6f5eb34 authored by Don Gagne's avatar Don Gagne

Merge pull request #2325 from DonLakeFlyer/RadioFlash

More reliable radio flash
parents 7b229e54 3b32cb30
......@@ -27,7 +27,8 @@
#include "QGCLoggingCategory.h"
// Add Global logging categories (not class specific) here using QGC_LOGGING_CATEGORY
QGC_LOGGING_CATEGORY(FirmwareUpgradeLog, "FirmwareUpgradeLog")
QGC_LOGGING_CATEGORY(FirmwareUpgradeLog, "FirmwareUpgradeLog")
QGC_LOGGING_CATEGORY(FirmwareUpgradeVerboseLog, "FirmwareUpgradeVerboseLog")
QGCLoggingCategoryRegister* _instance = NULL;
......
......@@ -32,6 +32,7 @@
// Add Global logging categories (not class specific) here using Q_DECLARE_LOGGING_CATEGORY
Q_DECLARE_LOGGING_CATEGORY(FirmwareUpgradeLog)
Q_DECLARE_LOGGING_CATEGORY(FirmwareUpgradeVerboseLog)
/// @def QGC_LOGGING_CATEGORY
/// This is a QGC specific replacement for Q_LOGGING_CATEGORY. It will register the category name into a
......
......@@ -273,7 +273,7 @@ bool Bootloader::_ihxProgram(QextSerialPort* port, const FirmwareImage* image)
return false;
}
qCDebug(FirmwareUpgradeLog) << QString("Bootloader::_ihxProgram - address:%1 size:%2 block:%3").arg(flashAddress).arg(bytes.count()).arg(index);
qCDebug(FirmwareUpgradeVerboseLog) << QString("Bootloader::_ihxProgram - address:%1 size:%2 block:%3").arg(flashAddress).arg(bytes.count()).arg(index);
// Set flash address
......@@ -348,7 +348,7 @@ bool Bootloader::verify(QextSerialPort* port, const FirmwareImage* image)
return ret;
}
/// @brief Verify the flash on bootloader eading it back and comparing it against the original image->
/// @brief Verify the flash on bootloader reading it back and comparing it against the original image
bool Bootloader::_verifyBytes(QextSerialPort* port, const FirmwareImage* image)
{
if (image->imageIsBinFormat()) {
......@@ -445,7 +445,7 @@ bool Bootloader::_ihxVerifyBytes(QextSerialPort* port, const FirmwareImage* imag
return false;
}
qCDebug(FirmwareUpgradeLog) << QString("Bootloader::_ihxVerifyBytes - address:%1 size:%2 block:%3").arg(readAddress).arg(imageBytes.count()).arg(index);
qCDebug(FirmwareUpgradeLog) << QString("Bootloader::_ihxVerifyBytes - address:0x%1 size:%2 block:%3").arg(readAddress, 8, 16, QLatin1Char('0')).arg(imageBytes.count()).arg(index);
// Set read address
......
......@@ -165,7 +165,7 @@ bool FirmwareImage::_ihxLoad(const QString& ihxFilename)
if (appendToLastBlock) {
_ihxBlocks[_ihxBlocks.count() - 1].bytes += bytes;
qCDebug(FirmwareUpgradeLog) << QString("_ihxLoad - append - address:%1 size:%2 block:%3").arg(address).arg(blockByteCount).arg(ihxBlockCount());
qCDebug(FirmwareUpgradeVerboseLog) << QString("_ihxLoad - append - address:%1 size:%2 block:%3").arg(address).arg(blockByteCount).arg(ihxBlockCount());
} else {
IntelHexBlock_t block;
......@@ -173,7 +173,7 @@ bool FirmwareImage::_ihxLoad(const QString& ihxFilename)
block.bytes = bytes;
_ihxBlocks += block;
qCDebug(FirmwareUpgradeLog) << QString("_ihxLoad - new block - address:%1 size:%2 block:%3").arg(address).arg(blockByteCount).arg(ihxBlockCount());
qCDebug(FirmwareUpgradeVerboseLog) << QString("_ihxLoad - new block - address:%1 size:%2 block:%3").arg(address).arg(blockByteCount).arg(ihxBlockCount());
}
_imageSize += blockByteCount;
......
......@@ -132,13 +132,13 @@ void PX4FirmwareUpgradeThreadWorker::_findBoardOnce(void)
bool PX4FirmwareUpgradeThreadWorker::_findBoardFromPorts(QGCSerialPortInfo& portInfo, QGCSerialPortInfo::BoardType_t& boardType)
{
foreach (QGCSerialPortInfo info, QGCSerialPortInfo::availablePorts()) {
qCDebug(FirmwareUpgradeLog) << "Serial Port --------------";
qCDebug(FirmwareUpgradeLog) << "\tboard type" << info.boardType();
qCDebug(FirmwareUpgradeLog) << "\tport name:" << info.portName();
qCDebug(FirmwareUpgradeLog) << "\tdescription:" << info.description();
qCDebug(FirmwareUpgradeLog) << "\tsystem location:" << info.systemLocation();
qCDebug(FirmwareUpgradeLog) << "\tvendor ID:" << info.vendorIdentifier();
qCDebug(FirmwareUpgradeLog) << "\tproduct ID:" << info.productIdentifier();
qCDebug(FirmwareUpgradeVerboseLog) << "Serial Port --------------";
qCDebug(FirmwareUpgradeVerboseLog) << "\tboard type" << info.boardType();
qCDebug(FirmwareUpgradeVerboseLog) << "\tport name:" << info.portName();
qCDebug(FirmwareUpgradeVerboseLog) << "\tdescription:" << info.description();
qCDebug(FirmwareUpgradeVerboseLog) << "\tsystem location:" << info.systemLocation();
qCDebug(FirmwareUpgradeVerboseLog) << "\tvendor ID:" << info.vendorIdentifier();
qCDebug(FirmwareUpgradeVerboseLog) << "\tproduct ID:" << info.productIdentifier();
boardType = info.boardType();
if (boardType != QGCSerialPortInfo::BoardTypeUnknown) {
......@@ -167,13 +167,8 @@ void PX4FirmwareUpgradeThreadWorker::_3drRadioForceBootloader(const QGCSerialPor
emit status("Putting radio into command mode");
// Wait a little while for the USB port to initialize. 3DR Radio boot is really slow.
for (int i=0; i<12; i++) {
if (port.open(QIODevice::ReadWrite)) {
break;
} else {
QGC::SLEEP::msleep(250);
}
}
QGC::SLEEP::msleep(2000);
port.open(QIODevice::ReadWrite);
if (!port.isOpen()) {
emit error(QString("Unable to open port: %1 error: %2").arg(portInfo.systemLocation()).arg(port.errorString()));
......@@ -181,6 +176,7 @@ void PX4FirmwareUpgradeThreadWorker::_3drRadioForceBootloader(const QGCSerialPor
}
// Put radio into command mode
QGC::SLEEP::msleep(2000);
port.write("+++", 3);
if (!port.waitForReadyRead(1500)) {
emit error("Unable to put radio into command mode");
......@@ -188,6 +184,7 @@ void PX4FirmwareUpgradeThreadWorker::_3drRadioForceBootloader(const QGCSerialPor
}
QByteArray bytes = port.readAll();
if (!bytes.contains("OK")) {
qCDebug(FirmwareUpgradeLog) << bytes;
emit error("Unable to put radio into command mode");
return;
}
......@@ -196,10 +193,14 @@ void PX4FirmwareUpgradeThreadWorker::_3drRadioForceBootloader(const QGCSerialPor
port.write("AT&UPDATE\r\n");
if (!port.waitForBytesWritten(1500)) {
emit error("Unable to reboot radio");
emit error("Unable to reboot radio (bytes written)");
return;
}
QGC::SLEEP::msleep(2000);
if (!port.waitForReadyRead(1500)) {
emit error("Unable to reboot radio (ready read)");
return;
}
QGC::SLEEP::msleep(700);
port.close();
// The bootloader should be waiting for us now
......@@ -218,7 +219,10 @@ bool PX4FirmwareUpgradeThreadWorker::_findBootloader(const QGCSerialPortInfo& po
_bootloaderPort = new QextSerialPort(QextSerialPort::Polling);
Q_CHECK_PTR(_bootloaderPort);
if (radioMode) {
_bootloaderPort->setBaudRate(BAUD115200);
}
// Wait a little while for the USB port to initialize.
for (int i=0; i<10; i++) {
if (_bootloader->open(_bootloaderPort, portInfo.systemLocation())) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment