From 3b32cb30990180a2c3737280d29620c3314bb323 Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Tue, 1 Dec 2015 13:39:19 -0800 Subject: [PATCH] More reliable radio flash Verify is still failing though --- src/QGCLoggingCategory.cc | 3 +- src/QGCLoggingCategory.h | 1 + src/VehicleSetup/Bootloader.cc | 6 ++-- src/VehicleSetup/FirmwareImage.cc | 4 +-- src/VehicleSetup/PX4FirmwareUpgradeThread.cc | 38 +++++++++++--------- 5 files changed, 29 insertions(+), 23 deletions(-) diff --git a/src/QGCLoggingCategory.cc b/src/QGCLoggingCategory.cc index bd102e438..509c2e44e 100644 --- a/src/QGCLoggingCategory.cc +++ b/src/QGCLoggingCategory.cc @@ -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; diff --git a/src/QGCLoggingCategory.h b/src/QGCLoggingCategory.h index b31de010b..947be2610 100644 --- a/src/QGCLoggingCategory.h +++ b/src/QGCLoggingCategory.h @@ -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 diff --git a/src/VehicleSetup/Bootloader.cc b/src/VehicleSetup/Bootloader.cc index ec2d01745..7cb464ca8 100644 --- a/src/VehicleSetup/Bootloader.cc +++ b/src/VehicleSetup/Bootloader.cc @@ -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 diff --git a/src/VehicleSetup/FirmwareImage.cc b/src/VehicleSetup/FirmwareImage.cc index b2ec91b5f..146d81b48 100644 --- a/src/VehicleSetup/FirmwareImage.cc +++ b/src/VehicleSetup/FirmwareImage.cc @@ -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; diff --git a/src/VehicleSetup/PX4FirmwareUpgradeThread.cc b/src/VehicleSetup/PX4FirmwareUpgradeThread.cc index fe6c88780..0c8c85313 100644 --- a/src/VehicleSetup/PX4FirmwareUpgradeThread.cc +++ b/src/VehicleSetup/PX4FirmwareUpgradeThread.cc @@ -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())) { -- 2.22.0