utility now detects devices connected in their normal operating mode and sends command to make them jump into bootloader mode

This commit is contained in:
2019-08-23 17:35:02 -04:00
parent b934698bff
commit 0a107b0c74
5 changed files with 72 additions and 68 deletions

View File

@@ -69,8 +69,18 @@
#define DEFAULT_VID 0x04D8 #define DEFAULT_VID 0x04D8
#define DEFAULT_PID 0x003C #define DEFAULT_PID 0x003C
// the command to make the device jump into bootloader mode
#define COMMAND_JUMP_BOOTLOADER 0xBB
struct USBDevIds
{
unsigned short vendor_id;
unsigned short product_id;
} NormalModeDevIds[2] =
{
{0x1209, 0x0600}, // from pid.codes
{0x04D8, 0xECEE} // from microchip sublicense
};
//Surely the micro doesn't have a programmable memory region greater than 268 Megabytes... //Surely the micro doesn't have a programmable memory region greater than 268 Megabytes...
@@ -367,6 +377,50 @@ void MainWindow::Connection(void)
emit SetProgressBar(0); emit SetProgressBar(0);
} }
} }
// check if a device is found in normal non-bootloader mode
hid_device_info *hidDevs = hid_enumerate(0, 0);
hid_device_info *d = hidDevs;
while (d)
{
for (unsigned int i=0;i<sizeof(NormalModeDevIds)/sizeof(USBDevIds);i++)
{
USBDevIds ids = NormalModeDevIds[i];
if (d->vendor_id == ids.vendor_id &&
d->product_id == ids.product_id)
{
// a device was found, prompt user that it will need to be reset into bootloader mode
QMessageBox msgbox(QMessageBox::Information,
"Device detected in non-FW update mode",
"A device was detected in normal operating mode. Press OK to reset the device into firmware update mode and proceed.",
QMessageBox::Ok,
this,
Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint | Qt::CustomizeWindowHint | Qt::WindowTitleHint);
msgbox.setWindowModality(Qt::ApplicationModal);
msgbox.exec();
// the user has closed the message box - send the bootloader entry command to the device
hid_device *dev = hid_open_path(d->path);
if (dev == NULL)
{
QMessageBox::critical(this, "Error", "Failed to open the HID device");
break;
}
unsigned char hidOutData[2] = {0, COMMAND_JUMP_BOOTLOADER};
int bytesWritten = hid_write(dev, &hidOutData[0], sizeof(hidOutData));
if (bytesWritten == -1)
{
QString errMsg = QString("Failed to send mode switch command to the device:\n\n%1").arg(hid_error(dev));
QMessageBox::critical(this, "Error", errMsg);
}
hid_close(dev);
}
}
d = d->next;
}
hid_free_enumeration(hidDevs);
} }
void MainWindow::setBootloadEnabled(bool enable) void MainWindow::setBootloadEnabled(bool enable)

View File

@@ -26,7 +26,7 @@
</property> </property>
<property name="windowIcon"> <property name="windowIcon">
<iconset resource="resources.qrc"> <iconset resource="resources.qrc">
<normaloff>:/MainWindow/img/Microchip_logo.Ico</normaloff>:/MainWindow/img/Microchip_logo.Ico</iconset> <normaloff>:/MainWindow/img/amx_logo.ico</normaloff>:/MainWindow/img/amx_logo.ico</iconset>
</property> </property>
<widget class="QWidget" name="centralWidget"> <widget class="QWidget" name="centralWidget">
<layout class="QVBoxLayout" name="_2"> <layout class="QVBoxLayout" name="_2">
@@ -518,58 +518,25 @@ QGroupBox::title {
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QWidget" name="formAdvancedButtons" native="true"> <widget class="QPushButton" name="btnResetDevice">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font"> <property name="font">
<font> <font>
<family>Segoe UI</family> <family>Segoe UI</family>
<pointsize>10</pointsize>
</font> </font>
</property> </property>
<layout class="QHBoxLayout" name="horizontalLayout"> <property name="text">
<item> <string>Reset Device</string>
<widget class="QPushButton" name="btnResetDevice"> </property>
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<family>Segoe UI</family>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>Reset Device</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnResetDeviceFWUpdateMode">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<family>Segoe UI</family>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>Reset Device into FW Update Mode</string>
</property>
</widget>
</item>
</layout>
</widget> </widget>
</item> </item>
<item> <item>

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

View File

@@ -34,30 +34,12 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
hid_device *dev = hid_open(0x1209, 0x0600, NULL);
if (dev == NULL)
{
qCritical("failed to open device");
return 1;
}
unsigned char data[2] = { 0, 0xBB };
int written = hid_write(dev, &data[0], sizeof(data));
qWarning("Wrote %d bytes", written);
qWarning("%s", QString::fromWCharArray(hid_error(dev)).toStdString().c_str());
hid_close(dev);
//hid_exit();
return 0;
/////////////////////////////////////////////////
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication a(argc, argv); QApplication a(argc, argv);
QCoreApplication::setOrganizationName("JOJCorp"); QCoreApplication::setOrganizationName("JOJCorp");
QCoreApplication::setOrganizationDomain("source.jojcorp.com"); QCoreApplication::setOrganizationDomain("source.jojcorp.com");
QCoreApplication::setApplicationName("Dancepad Interface FW Flash Tool"); QCoreApplication::setApplicationName("BIA MicroDDR FW Flash Tool");
MainWindow w; MainWindow w;
w.show(); w.show();

View File

@@ -10,5 +10,6 @@
<file>img/Reset.png</file> <file>img/Reset.png</file>
<file>img/help.png</file> <file>img/help.png</file>
<file>img/Microchip_logo.Ico</file> <file>img/Microchip_logo.Ico</file>
<file>img/amx_logo.ico</file>
</qresource> </qresource>
</RCC> </RCC>