initial commit with unmodified qt5-based bootloader flash utility source from the MLA
71
qt5_src/Bootloader/Bootloader.pro
Normal file
@@ -0,0 +1,71 @@
|
||||
TARGET = "HIDBootloader"
|
||||
TEMPLATE = app
|
||||
QT += sql
|
||||
QT += widgets
|
||||
QMAKE_CXXFLAGS_RELEASE = -Os
|
||||
INCLUDEPATH += ../
|
||||
SOURCES += \
|
||||
Settings.cpp \
|
||||
MainWindow.cpp \
|
||||
main.cpp \
|
||||
DeviceData.cpp \
|
||||
Device.cpp \
|
||||
Comm.cpp \
|
||||
ImportExportHex.cpp
|
||||
HEADERS += \
|
||||
Settings.h \
|
||||
MainWindow.h \
|
||||
DeviceData.h \
|
||||
Device.h \
|
||||
Comm.h \
|
||||
ImportExportHex.h
|
||||
|
||||
|
||||
FORMS += MainWindow.ui \
|
||||
Settings.ui
|
||||
RESOURCES += resources.qrc
|
||||
OTHER_FILES += windows.rc
|
||||
|
||||
#-------------------------------------------------
|
||||
# Add the correct HIDAPI library according to what
|
||||
# OS is being used
|
||||
#-------------------------------------------------
|
||||
win32: LIBS += -L../HIDAPI/windows
|
||||
macx: LIBS += -L../HIDAPI/mac
|
||||
unix: !macx: LIBS += -L../HIDAPI/linux
|
||||
LIBS += -lHIDAPI
|
||||
|
||||
#-------------------------------------------------
|
||||
# Make sure to add the required libraries or
|
||||
# frameoworks for the hidapi to work depending on
|
||||
# what OS is being used
|
||||
#-------------------------------------------------
|
||||
macx: LIBS += -framework CoreFoundation -framework IOkit
|
||||
win32: LIBS += -lSetupAPI
|
||||
unix: !macx: LIBS += -lusb-1.0
|
||||
|
||||
#-------------------------------------------------
|
||||
# Make sure output directory for object file and
|
||||
# executable is in the correct subdirectory
|
||||
#-------------------------------------------------
|
||||
macx {
|
||||
DESTDIR = mac
|
||||
OBJECTS_DIR = mac
|
||||
MOC_DIR = mac
|
||||
UI_DIR = mac
|
||||
RCC_DIR = mac
|
||||
}
|
||||
unix: !macx {
|
||||
DESTDIR = linux
|
||||
OBJECTS_DIR = linux
|
||||
MOC_DIR = linux
|
||||
UI_DIR = linux
|
||||
RCC_DIR = linux
|
||||
}
|
||||
win32 {
|
||||
DESTDIR = windows
|
||||
OBJECTS_DIR = windows
|
||||
MOC_DIR = windows
|
||||
UI_DIR = windows
|
||||
RCC_DIR = windows
|
||||
}
|
||||
1021
qt5_src/Bootloader/Comm.cpp
Normal file
197
qt5_src/Bootloader/Comm.h
Normal file
@@ -0,0 +1,197 @@
|
||||
/************************************************************************
|
||||
* Copyright (c) 2009-2010, Microchip Technology Inc.
|
||||
*
|
||||
* Microchip licenses this software to you solely for use with Microchip
|
||||
* products. The software is owned by Microchip and its licensors, and
|
||||
* is protected under applicable copyright laws. All rights reserved.
|
||||
*
|
||||
* SOFTWARE IS PROVIDED "AS IS." MICROCHIP EXPRESSLY DISCLAIMS ANY
|
||||
* WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL
|
||||
* MICROCHIP BE LIABLE FOR ANY INCIDENTAL, SPECIAL, INDIRECT OR
|
||||
* CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, HARM TO YOUR
|
||||
* EQUIPMENT, COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY
|
||||
* OR SERVICES, ANY CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT LIMITED
|
||||
* TO ANY DEFENSE THEREOF), ANY CLAIMS FOR INDEMNITY OR CONTRIBUTION,
|
||||
* OR OTHER SIMILAR COSTS.
|
||||
*
|
||||
* To the fullest extent allowed by law, Microchip and its licensors
|
||||
* liability shall not exceed the amount of fees, if any, that you
|
||||
* have paid directly to Microchip to use this software.
|
||||
*
|
||||
* MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE
|
||||
* OF THESE TERMS.
|
||||
*
|
||||
* Author Date Comment
|
||||
*************************************************************************
|
||||
* T. Lawrence 2011/01/24 Initial code ported from AN1310.
|
||||
************************************************************************/
|
||||
|
||||
#ifndef COMM_H
|
||||
#define COMM_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <QThread>
|
||||
#include <QTimer>
|
||||
|
||||
#include "../HIDAPI/hidapi.h"
|
||||
#include "Device.h"
|
||||
|
||||
|
||||
|
||||
|
||||
#define USB_PACKET_SIZE 64
|
||||
#define USB_PACKET_SIZE_WITH_REPORT_ID (USB_PACKET_SIZE + 1)
|
||||
|
||||
|
||||
// Packet commands
|
||||
#define QUERY_DEVICE 0x02
|
||||
#define UNLOCK_CONFIG 0x03
|
||||
#define ERASE_DEVICE 0x04
|
||||
#define PROGRAM_DEVICE 0x05
|
||||
#define PROGRAM_COMPLETE 0x06
|
||||
#define GET_DATA 0x07
|
||||
#define RESET_DEVICE 0x08
|
||||
#define SIGN_FLASH 0x09 //The host PC application should send this command after the verify operation has completed successfully. If checksums are used instead of a true verify (due to ALLOW_GET_DATA_COMMAND being commented), then the host PC application should send SIGN_FLASH command after is has verified the checksums are as exected. The firmware will then program the SIGNATURE_WORD into flash at the SIGNATURE_ADDRESS.
|
||||
#define QUERY_EXTENDED_INFO 0x0C //Used by host PC app to get additional info about the device, beyond the basic NVM layout provided by the query device command
|
||||
|
||||
// Maximum number of memory regions that can be bootloaded
|
||||
#define MAX_DATA_REGIONS 0x06
|
||||
|
||||
|
||||
#define MAX_ERASE_BLOCK_SIZE 8196 //Increase this in the future if any microcontrollers with bigger than 8196 byte erase block is implemented
|
||||
|
||||
|
||||
/*!
|
||||
* Provides low level HID bootloader communication.
|
||||
*/
|
||||
class Comm : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
signals:
|
||||
void SetProgressBar(int newValue);
|
||||
|
||||
|
||||
protected:
|
||||
hid_device *boot_device;
|
||||
bool connected;
|
||||
|
||||
public:
|
||||
|
||||
explicit Comm();
|
||||
~Comm();
|
||||
|
||||
static const int SyncWaitTime;
|
||||
|
||||
enum ErrorCode
|
||||
{
|
||||
Success = 0, NotConnected, Fail, IncorrectCommand, Timeout, Other = 0xFF
|
||||
};
|
||||
|
||||
QString ErrorString(ErrorCode errorCode) const;
|
||||
|
||||
#pragma pack(1)
|
||||
struct MemoryRegion
|
||||
{
|
||||
unsigned char type;
|
||||
uint32_t address;
|
||||
uint32_t size;
|
||||
};
|
||||
|
||||
struct BootInfo
|
||||
{
|
||||
unsigned char command;
|
||||
unsigned char bytesPerPacket;
|
||||
unsigned char deviceFamily;
|
||||
MemoryRegion memoryRegions[MAX_DATA_REGIONS];
|
||||
unsigned char versionFlag;
|
||||
unsigned char pad[7];
|
||||
};
|
||||
|
||||
//Structure for the response to the QUERY_EXTENDED_INFO command
|
||||
union ExtendedQueryInfo
|
||||
{
|
||||
unsigned char command;
|
||||
struct
|
||||
{
|
||||
unsigned char command;
|
||||
uint16_t bootloaderVersion;
|
||||
uint16_t applicationVersion;
|
||||
uint32_t signatureAddress;
|
||||
uint16_t signatureValue;
|
||||
uint32_t erasePageSize;
|
||||
unsigned char config1LMask;
|
||||
unsigned char config1HMask;
|
||||
unsigned char config2LMask;
|
||||
unsigned char config2HMask;
|
||||
unsigned char config3LMask;
|
||||
unsigned char config3HMask;
|
||||
unsigned char config4LMask;
|
||||
unsigned char config4HMask;
|
||||
unsigned char config5LMask;
|
||||
unsigned char config5HMask;
|
||||
unsigned char config6LMask;
|
||||
unsigned char config6HMask;
|
||||
unsigned char config7LMask;
|
||||
unsigned char config7HMask;
|
||||
unsigned char pad[USB_PACKET_SIZE_WITH_REPORT_ID - 29];
|
||||
}PIC18;
|
||||
struct
|
||||
{
|
||||
unsigned char command;
|
||||
uint16_t bootloaderVersion;
|
||||
uint16_t applicationVersion;
|
||||
uint32_t signatureAddress;
|
||||
uint16_t signatureValue;
|
||||
uint32_t erasePageSize;
|
||||
#warning Replace with real stuff when implemented.
|
||||
//uint16_t configxxMask...
|
||||
//unsigned char pad[USB_PACKET_SIZE_WITH_REPORT_ID - XX];
|
||||
}PIC24;
|
||||
};
|
||||
|
||||
|
||||
|
||||
struct WritePacket
|
||||
{
|
||||
unsigned char report;
|
||||
unsigned char command;
|
||||
union {
|
||||
uint32_t address;
|
||||
unsigned char LockedValue;
|
||||
};
|
||||
unsigned char bytesPerPacket;
|
||||
unsigned char data[58];
|
||||
};
|
||||
struct ReadPacket
|
||||
{
|
||||
unsigned char command;
|
||||
uint32_t address;
|
||||
unsigned char bytesPerPacket;
|
||||
unsigned char data[59];
|
||||
};
|
||||
#pragma pack()
|
||||
|
||||
void PollUSB(uint16_t deviceVIDtoPoll, uint16_t devicePIDtoPoll);
|
||||
ErrorCode open(uint16_t deviceVIDtoOpen, uint16_t devicePIDtoOpen);
|
||||
void close(void);
|
||||
bool isConnected(void);
|
||||
void Reset(void);
|
||||
|
||||
ErrorCode GetData(uint32_t address, unsigned char bytesPerPacket, unsigned char bytesPerAddress,
|
||||
unsigned char bytesPerWord, uint32_t endAddress, unsigned char *data);
|
||||
ErrorCode Program(uint32_t address, unsigned char bytesPerPacket, unsigned char bytesPerAddress,
|
||||
unsigned char bytesPerWord, unsigned char deviceFamily, uint32_t endAddress, unsigned char *data);
|
||||
ErrorCode Erase(void);
|
||||
ErrorCode LockUnlockConfig(bool lock);
|
||||
ErrorCode ReadBootloaderInfo(BootInfo* bootInfo);
|
||||
ErrorCode ReadExtendedQueryInfo(ExtendedQueryInfo* extendedBootInfo);
|
||||
ErrorCode SignFlash(void);
|
||||
ErrorCode SendPacket(unsigned char *data, int size);
|
||||
ErrorCode ReceivePacket(unsigned char *data, int size);
|
||||
};
|
||||
|
||||
#endif // COMM_H
|
||||
204
qt5_src/Bootloader/Device.cpp
Normal file
@@ -0,0 +1,204 @@
|
||||
/************************************************************************
|
||||
* Copyright (c) 2009-2011, Microchip Technology Inc.
|
||||
*
|
||||
* Microchip licenses this software to you solely for use with Microchip
|
||||
* products. The software is owned by Microchip and its licensors, and
|
||||
* is protected under applicable copyright laws. All rights reserved.
|
||||
*
|
||||
* SOFTWARE IS PROVIDED "AS IS." MICROCHIP EXPRESSLY DISCLAIMS ANY
|
||||
* WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL
|
||||
* MICROCHIP BE LIABLE FOR ANY INCIDENTAL, SPECIAL, INDIRECT OR
|
||||
* CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, HARM TO YOUR
|
||||
* EQUIPMENT, COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY
|
||||
* OR SERVICES, ANY CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT LIMITED
|
||||
* TO ANY DEFENSE THEREOF), ANY CLAIMS FOR INDEMNITY OR CONTRIBUTION,
|
||||
* OR OTHER SIMILAR COSTS.
|
||||
*
|
||||
* To the fullest extent allowed by law, Microchip and its licensors
|
||||
* liability shall not exceed the amount of fees, if any, that you
|
||||
* have paid directly to Microchip to use this software.
|
||||
*
|
||||
* MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE
|
||||
* OF THESE TERMS.
|
||||
*
|
||||
* Author Date Comment
|
||||
*************************************************************************
|
||||
* E. Schlunder 2010/02/01 Loading config bit fields/settings added.
|
||||
* E. Schlunder 2009/04/14 Initial code ported from VB app.
|
||||
* F. Schlunder 2011/06/13 Minor changes for USB HID Bootloader use.
|
||||
************************************************************************/
|
||||
|
||||
#include "Device.h"
|
||||
|
||||
Device::Device(DeviceData *data)
|
||||
{
|
||||
deviceData = data;
|
||||
|
||||
setUnknown();
|
||||
}
|
||||
|
||||
void Device::setUnknown(void)
|
||||
{
|
||||
family = Unknown;
|
||||
|
||||
bytesPerAddressFLASH = 1;
|
||||
bytesPerAddressEEPROM = 1;
|
||||
bytesPerAddressConfig = 1;
|
||||
|
||||
bytesPerWordEEPROM = 1;
|
||||
bytesPerWordConfig = 2;
|
||||
bytesPerWordFLASH = 2;
|
||||
}
|
||||
|
||||
bool Device::hasEeprom(void)
|
||||
{
|
||||
DeviceData::MemoryRange range;
|
||||
foreach(range, deviceData->ranges)
|
||||
{
|
||||
if(range.type == EEPROM_MEMORY)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Device::hasConfig(void)
|
||||
{
|
||||
DeviceData::MemoryRange range;
|
||||
foreach(range, deviceData->ranges)
|
||||
{
|
||||
if(range.type == CONFIG_MEMORY)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//This method is useful for hex file parsing. This function checks if the address indicated in the hex
|
||||
//file line is contained in one of the programmable regions (ex: flash, eeprom, config words, etc.), as
|
||||
//specified by the USB device, (from the query response that we received earlier). If the address
|
||||
//from the hex file is contained in the programmable device address range, this function returns
|
||||
//bool includedInProgrammableRange = true, with the type set to the programmable region type
|
||||
//(which can be determined based on the address and the query response). This function also returns
|
||||
//the new effective device address (not from the .hex file, which is a raw linear byte address, but the
|
||||
//effective address the device should load into its self programming address registers, in order to
|
||||
//program the contents [PIC24 uses a 16-bit word addressed flash array, so the hex file addresses
|
||||
//don't match the microcontroller addresses]).
|
||||
//This function also returns bool addressWasEndofRange = true, if the input hexAddress corresponded
|
||||
//to the very last byte of the last address of the programmable memory region that the hexAddress
|
||||
//corresponded to. Otherwise this value returns false. This provides an easy check later to
|
||||
//know when an end of a region has been completed during hex file parsing.
|
||||
unsigned int Device::GetDeviceAddressFromHexAddress(unsigned int hexAddress, DeviceData* pData, unsigned char& type, bool& includedInProgrammableRange, bool& addressWasEndofRange, unsigned int& bytesPerAddressAndType, unsigned int& endDeviceAddressofRegion, unsigned char*& pPCRAMBuffer)
|
||||
{
|
||||
DeviceData::MemoryRange range;
|
||||
unsigned int flashAddress = hexAddress / bytesPerAddressFLASH;
|
||||
unsigned int eepromAddress = hexAddress / bytesPerAddressEEPROM;
|
||||
unsigned int configAddress = hexAddress / bytesPerAddressConfig;
|
||||
unsigned char* pRAMDataBuffer;
|
||||
unsigned int byteOffset;
|
||||
|
||||
|
||||
//Loop for each of the previously identified programmable regions, based on the results of the
|
||||
//previous Query device response packet.
|
||||
foreach(range, pData->ranges)
|
||||
{
|
||||
//Find what address range the hex address seems to contained within (if any, could be none, in
|
||||
//the case the .hex file contains info that is not part of the bootloader re-programmable region of flash).
|
||||
if((range.type == PROGRAM_MEMORY) && (flashAddress >= range.start) && (flashAddress < range.end))
|
||||
{
|
||||
includedInProgrammableRange = true;
|
||||
if(range.start != 0)
|
||||
{
|
||||
byteOffset = ((flashAddress - range.start) * bytesPerAddressFLASH) + (hexAddress % bytesPerAddressFLASH);
|
||||
pRAMDataBuffer = range.pDataBuffer + byteOffset;
|
||||
pPCRAMBuffer = pRAMDataBuffer;
|
||||
}
|
||||
else
|
||||
{
|
||||
pPCRAMBuffer = 0;
|
||||
}
|
||||
|
||||
type = PROGRAM_MEMORY;
|
||||
bytesPerAddressAndType = bytesPerAddressFLASH;
|
||||
endDeviceAddressofRegion = range.end;
|
||||
//Check if this was the very last byte of the very last address of the region.
|
||||
//We can determine this, using the below check.
|
||||
if((flashAddress == (range.end - 1)) && ((hexAddress % bytesPerAddressFLASH) == (bytesPerAddressFLASH - 1)))
|
||||
{
|
||||
addressWasEndofRange = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
addressWasEndofRange = false;
|
||||
}
|
||||
return flashAddress;
|
||||
}
|
||||
|
||||
if((range.type == EEPROM_MEMORY) && (eepromAddress >= range.start) && (eepromAddress < range.end))
|
||||
{
|
||||
includedInProgrammableRange = true;
|
||||
if(range.start != 0)
|
||||
{
|
||||
byteOffset = ((eepromAddress - range.start) * bytesPerAddressEEPROM) + (hexAddress % bytesPerAddressEEPROM);
|
||||
pRAMDataBuffer = range.pDataBuffer + byteOffset;
|
||||
pPCRAMBuffer = pRAMDataBuffer;
|
||||
}
|
||||
else
|
||||
{
|
||||
pPCRAMBuffer = 0;
|
||||
}
|
||||
type = EEPROM_MEMORY;
|
||||
bytesPerAddressAndType = bytesPerAddressEEPROM;
|
||||
endDeviceAddressofRegion = range.end;
|
||||
//Check if this was the very last byte of the very last address of the region.
|
||||
//We can determine this, using the below check.
|
||||
if((eepromAddress == (range.end - 1)) && ((eepromAddress % bytesPerAddressEEPROM) == (bytesPerAddressEEPROM - 1)))
|
||||
{
|
||||
addressWasEndofRange = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
addressWasEndofRange = false;
|
||||
}
|
||||
return eepromAddress;
|
||||
}
|
||||
|
||||
if((range.type == CONFIG_MEMORY) && (configAddress >= range.start) && (configAddress < range.end))
|
||||
{
|
||||
includedInProgrammableRange = true;
|
||||
if(range.start != 0)
|
||||
{
|
||||
byteOffset = ((configAddress - range.start) * bytesPerAddressConfig) + (hexAddress % bytesPerAddressConfig);
|
||||
pRAMDataBuffer = range.pDataBuffer + byteOffset;
|
||||
pPCRAMBuffer = pRAMDataBuffer;
|
||||
}
|
||||
else
|
||||
{
|
||||
pPCRAMBuffer = 0;
|
||||
}
|
||||
type = CONFIG_MEMORY;
|
||||
bytesPerAddressAndType = bytesPerAddressConfig;
|
||||
endDeviceAddressofRegion = range.end;
|
||||
//Check if this was the very last byte of the very last address of the region.
|
||||
//We can determine this, using the below check.
|
||||
if((configAddress == (range.end - 1)) && ((configAddress % bytesPerAddressConfig) == (bytesPerAddressConfig - 1)))
|
||||
{
|
||||
addressWasEndofRange = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
addressWasEndofRange = false;
|
||||
}
|
||||
return configAddress;
|
||||
}
|
||||
}
|
||||
|
||||
//If we get to here, that means the hex file address that was passed in was not included in any of the
|
||||
//device's reported programmable memory regions.
|
||||
includedInProgrammableRange = false;
|
||||
addressWasEndofRange = false;
|
||||
pPCRAMBuffer = 0;
|
||||
return 0;
|
||||
}
|
||||
80
qt5_src/Bootloader/Device.h
Normal file
@@ -0,0 +1,80 @@
|
||||
/************************************************************************
|
||||
* Copyright (c) 2009-2010, Microchip Technology Inc.
|
||||
*
|
||||
* Microchip licenses this software to you solely for use with Microchip
|
||||
* products. The software is owned by Microchip and its licensors, and
|
||||
* is protected under applicable copyright laws. All rights reserved.
|
||||
*
|
||||
* SOFTWARE IS PROVIDED "AS IS." MICROCHIP EXPRESSLY DISCLAIMS ANY
|
||||
* WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL
|
||||
* MICROCHIP BE LIABLE FOR ANY INCIDENTAL, SPECIAL, INDIRECT OR
|
||||
* CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, HARM TO YOUR
|
||||
* EQUIPMENT, COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY
|
||||
* OR SERVICES, ANY CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT LIMITED
|
||||
* TO ANY DEFENSE THEREOF), ANY CLAIMS FOR INDEMNITY OR CONTRIBUTION,
|
||||
* OR OTHER SIMILAR COSTS.
|
||||
*
|
||||
* To the fullest extent allowed by law, Microchip and its licensors
|
||||
* liability shall not exceed the amount of fees, if any, that you
|
||||
* have paid directly to Microchip to use this software.
|
||||
*
|
||||
* MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE
|
||||
* OF THESE TERMS.
|
||||
*/
|
||||
|
||||
#ifndef DEVICE_H
|
||||
#define DEVICE_H
|
||||
|
||||
#include <QString>
|
||||
#include <QVariant>
|
||||
#include <QLinkedList>
|
||||
#include <QList>
|
||||
|
||||
#include "DeviceData.h"
|
||||
|
||||
/*!
|
||||
* Provides microcontroller device specific parameters, address calculations, and
|
||||
* assembly code tools.
|
||||
*/
|
||||
class Device
|
||||
{
|
||||
public:
|
||||
enum Families
|
||||
{
|
||||
Unknown = 0,
|
||||
PIC18 = 0x01,
|
||||
PIC24 = 0x02,
|
||||
PIC32 = 0x03,
|
||||
PIC16 = 0x04
|
||||
};
|
||||
|
||||
Device(DeviceData* data);
|
||||
|
||||
void setUnknown(void);
|
||||
|
||||
Families family;
|
||||
|
||||
unsigned int bytesPerPacket;
|
||||
unsigned int bytesPerWordFLASH;
|
||||
unsigned int bytesPerWordEEPROM;
|
||||
unsigned int bytesPerWordConfig;
|
||||
|
||||
unsigned int bytesPerAddressFLASH;
|
||||
unsigned int bytesPerAddressEEPROM;
|
||||
unsigned int bytesPerAddressConfig;
|
||||
|
||||
bool hasEeprom(void);
|
||||
bool hasConfig(void);
|
||||
|
||||
bool hasConfigAsFlash(void);
|
||||
bool hasConfigAsFuses(void);
|
||||
|
||||
unsigned int GetDeviceAddressFromHexAddress(unsigned int hexAddress, DeviceData* pData, unsigned char& type, bool& includedInProgrammableRange, bool& addressWasEndofRange, unsigned int& bytesPerAddressAndType, unsigned int& endDeviceAddressofRegion, unsigned char*& pPCRAMBuffer);
|
||||
|
||||
protected:
|
||||
DeviceData *deviceData;
|
||||
};
|
||||
|
||||
#endif // DEVICE_H
|
||||
40
qt5_src/Bootloader/DeviceData.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
/************************************************************************
|
||||
* Copyright (c) 2009-2011, Microchip Technology Inc.
|
||||
*
|
||||
* Microchip licenses this software to you solely for use with Microchip
|
||||
* products. The software is owned by Microchip and its licensors, and
|
||||
* is protected under applicable copyright laws. All rights reserved.
|
||||
*
|
||||
* SOFTWARE IS PROVIDED "AS IS." MICROCHIP EXPRESSLY DISCLAIMS ANY
|
||||
* WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL
|
||||
* MICROCHIP BE LIABLE FOR ANY INCIDENTAL, SPECIAL, INDIRECT OR
|
||||
* CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, HARM TO YOUR
|
||||
* EQUIPMENT, COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY
|
||||
* OR SERVICES, ANY CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT LIMITED
|
||||
* TO ANY DEFENSE THEREOF), ANY CLAIMS FOR INDEMNITY OR CONTRIBUTION,
|
||||
* OR OTHER SIMILAR COSTS.
|
||||
*
|
||||
* To the fullest extent allowed by law, Microchip and its licensors
|
||||
* liability shall not exceed the amount of fees, if any, that you
|
||||
* have paid directly to Microchip to use this software.
|
||||
*
|
||||
* MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE
|
||||
* OF THESE TERMS.
|
||||
*
|
||||
* Author Date Comment
|
||||
*************************************************************************
|
||||
* E. Schlunder 2009/05/07 Added code for CRC calculation.
|
||||
* E. Schlunder 2009/04/29 Code ported from PicKit2 pk2cmd source code.
|
||||
*************************************************************************/
|
||||
|
||||
#include "DeviceData.h"
|
||||
|
||||
DeviceData::DeviceData()
|
||||
{
|
||||
}
|
||||
|
||||
DeviceData::~DeviceData()
|
||||
{
|
||||
}
|
||||
62
qt5_src/Bootloader/DeviceData.h
Normal file
@@ -0,0 +1,62 @@
|
||||
/************************************************************************
|
||||
* Copyright (c) 2009-2011, Microchip Technology Inc.
|
||||
*
|
||||
* Microchip licenses this software to you solely for use with Microchip
|
||||
* products. The software is owned by Microchip and its licensors, and
|
||||
* is protected under applicable copyright laws. All rights reserved.
|
||||
*
|
||||
* SOFTWARE IS PROVIDED "AS IS." MICROCHIP EXPRESSLY DISCLAIMS ANY
|
||||
* WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL
|
||||
* MICROCHIP BE LIABLE FOR ANY INCIDENTAL, SPECIAL, INDIRECT OR
|
||||
* CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, HARM TO YOUR
|
||||
* EQUIPMENT, COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY
|
||||
* OR SERVICES, ANY CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT LIMITED
|
||||
* TO ANY DEFENSE THEREOF), ANY CLAIMS FOR INDEMNITY OR CONTRIBUTION,
|
||||
* OR OTHER SIMILAR COSTS.
|
||||
*
|
||||
* To the fullest extent allowed by law, Microchip and its licensors
|
||||
* liability shall not exceed the amount of fees, if any, that you
|
||||
* have paid directly to Microchip to use this software.
|
||||
*
|
||||
* MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE
|
||||
* OF THESE TERMS.
|
||||
*/
|
||||
#ifndef DEVICEDATA_H
|
||||
#define DEVICEDATA_H
|
||||
|
||||
// Types of memory regions
|
||||
#define PROGRAM_MEMORY 0x01
|
||||
#define EEPROM_MEMORY 0x02
|
||||
#define CONFIG_MEMORY 0x03
|
||||
#define USERID_MEMORY 0x04
|
||||
#define END_OF_TYPES_LIST 0xFF
|
||||
#define BOOTLOADER_V1_01_OR_NEWER_FLAG 0xA5 //Tacked on in region Type6 byte, to indicate when using newer version of bootloader with extended query info available
|
||||
|
||||
|
||||
#include <QVector>
|
||||
|
||||
|
||||
/*!
|
||||
* Provides in-memory, PC representation of microcontroller device memory contents.
|
||||
*/
|
||||
class DeviceData
|
||||
{
|
||||
public:
|
||||
DeviceData();
|
||||
~DeviceData();
|
||||
|
||||
struct MemoryRange
|
||||
{
|
||||
unsigned char type;
|
||||
unsigned int start;
|
||||
unsigned int end;
|
||||
unsigned int dataBufferLength;
|
||||
unsigned char* pDataBuffer;
|
||||
};
|
||||
|
||||
QList<DeviceData::MemoryRange> ranges;
|
||||
};
|
||||
|
||||
#endif // DEVICEDATA_H
|
||||
287
qt5_src/Bootloader/ImportExportHex.cpp
Normal file
@@ -0,0 +1,287 @@
|
||||
/************************************************************************
|
||||
* Copyright (c) 2005-2010, Microchip Technology Inc.
|
||||
*
|
||||
* Microchip licenses this software to you solely for use with Microchip
|
||||
* products. The software is owned by Microchip and its licensors, and
|
||||
* is protected under applicable copyright laws. All rights reserved.
|
||||
*
|
||||
* SOFTWARE IS PROVIDED "AS IS." MICROCHIP EXPRESSLY DISCLAIMS ANY
|
||||
* WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL
|
||||
* MICROCHIP BE LIABLE FOR ANY INCIDENTAL, SPECIAL, INDIRECT OR
|
||||
* CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, HARM TO YOUR
|
||||
* EQUIPMENT, COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY
|
||||
* OR SERVICES, ANY CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT LIMITED
|
||||
* TO ANY DEFENSE THEREOF), ANY CLAIMS FOR INDEMNITY OR CONTRIBUTION,
|
||||
* OR OTHER SIMILAR COSTS.
|
||||
*
|
||||
* To the fullest extent allowed by law, Microchip and its licensors
|
||||
* liability shall not exceed the amount of fees, if any, that you
|
||||
* have paid directly to Microchip to use this software.
|
||||
*
|
||||
* MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE
|
||||
* OF THESE TERMS.
|
||||
*
|
||||
* Author Date Ver Comment
|
||||
*************************************************************************
|
||||
* E. Schlunder 2009/04/29 0.01 Code ported from PicKit2 pk2cmd source code.
|
||||
* F. Schlunder 2011/06/13 2.90 Some changes for USB HID Bootloader use.
|
||||
* F. Schlunder 2011/07/06 2.90a Updated ImportHexFile() function so it can
|
||||
* support importing of hex files with
|
||||
* "non-monotonic" line address ordering.
|
||||
*************************************************************************/
|
||||
|
||||
#include <QFile>
|
||||
#include "ImportExportHex.h"
|
||||
#include "Device.h"
|
||||
|
||||
|
||||
HexImporter::HexImporter(void)
|
||||
{
|
||||
}
|
||||
|
||||
HexImporter::~HexImporter(void)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
PIC16Fxx parts use only one address for each FLASH program word. Address 0 has 14 bits of data, Address 1 has
|
||||
14 bits of data, etc. However, the PIC16Fxx HEX file addresses each byte of data with a unique address number.
|
||||
As a result, you basically have to take the HEX file address and divide by 2 to figure out the actual
|
||||
PIC16Fxx FLASH memory address that the byte belongs to.
|
||||
|
||||
Example: PIC16F886 has 8K program words, word addressed as 0 to 0x2000.
|
||||
A full HEX file for this part would have 16Kbytes of FLASH data. The HEX file bytes would
|
||||
be addressed from 0 to 0x4000.
|
||||
|
||||
This presents a predicament for EEPROM data. Instead of starting from HEX file address 0x2100 as
|
||||
the EDC device database might indicate, the HEX file has to start EEPROM data at 0x2000 + 0x2100 = 0x4100,
|
||||
to avoid overlapping with the HEX file's FLASH addresses.
|
||||
*/
|
||||
|
||||
//This function reads in Intel 32-bit .hex file formatted firmware image files and stores the
|
||||
//parsed data into buffers in the PC system RAM, so that it is in a format more suitable for directly
|
||||
//programming into the target microcontroller.
|
||||
HexImporter::ErrorCode HexImporter::ImportHexFile(QString fileName, DeviceData* pData, Device* device)
|
||||
{
|
||||
QFile hexfile(fileName);
|
||||
|
||||
hasEndOfFileRecord = false;
|
||||
fileExceedsFlash = false;
|
||||
|
||||
//Open the user specified .hex file.
|
||||
if (!hexfile.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||
{
|
||||
return CouldNotOpenFile;
|
||||
}
|
||||
|
||||
bool ok;
|
||||
bool includedInProgrammableRange;
|
||||
bool addressWasEndofRange;
|
||||
unsigned int segmentAddress = 0;
|
||||
unsigned int byteCount;
|
||||
unsigned int lineAddress;
|
||||
unsigned int deviceAddress;
|
||||
unsigned int i;
|
||||
unsigned int endDeviceAddressofRegion;
|
||||
unsigned int bytesPerAddressAndType;
|
||||
|
||||
unsigned char* pPCRAMBuffer = 0;
|
||||
bool importedAtLeastOneByte = false;
|
||||
|
||||
unsigned char type;
|
||||
|
||||
HEX32_RECORD recordType;
|
||||
|
||||
QString hexByte;
|
||||
unsigned int wordByte;
|
||||
hasConfigBits = false;
|
||||
|
||||
|
||||
//Parse the entire hex file, line by line.
|
||||
while (!hexfile.atEnd())
|
||||
{
|
||||
//Fetch a line of ASCII text from the .hex file.
|
||||
QByteArray line = hexfile.readLine();
|
||||
|
||||
//Do some error checking on the .hex file contents, to make sure the file is
|
||||
//formatted like a legitimate Intel 32-bit formatted .hex file.
|
||||
if ((line[0] != ':') || (line.size() < 11))
|
||||
{
|
||||
//Something is wrong if hex line entry, is not minimum length or does not have leading colon (ex: ":BBAAAATTCC")
|
||||
//If an error is detected in the hex file formatting, the safest approach is to
|
||||
//abort the operation and force the user to supply a properly formatted hex file.
|
||||
if(hexfile.isOpen())
|
||||
hexfile.close();
|
||||
return ErrorInHexFile;
|
||||
}
|
||||
|
||||
//Extract the info prefix fields from the hex file line data.
|
||||
//Example Intel 32-bit hex file line format is as follows (Note: spaces added to separate fields, actual line does not have spaces in it):
|
||||
//: 10 0100 00 214601360121470136007EFE09D21901 40
|
||||
//Leading ":" is always present on each line from the .hex file.
|
||||
//Next two chars (10) are the byte count of the data payload on this hex file line. (ex: 10 = 0x10 = 16 bytes)
|
||||
//Next four chars (0100) are the 16 bit address (needs to be combined with the extended linear address to generate a 32-bit address).
|
||||
//Next two chars (00) are the "record type". "00" means it is a "data" record, which means it contains programmable payload data bytes.
|
||||
//Next 2n characters are the data payload bytes (where n is the number of bytes specified in the first two numbers (10 in this example))
|
||||
//Last two characters on the line are the two complement of the byte checksum computed on the other bytes in the line.
|
||||
//For more details on Intel 32-bit hex file formatting see: http://en.wikipedia.org/wiki/Intel_HEX
|
||||
byteCount = line.mid(1, 2).toInt(&ok, 16); //Convert the two ASCII chars corresponding to the byte count into a binary encoded byte
|
||||
lineAddress = segmentAddress + line.mid(3, 4).toInt(&ok, 16); //Convert the four ASCII chars that correspond to the line address into a 16-bit binary encoded word
|
||||
recordType = (HEX32_RECORD)line.mid(7, 2).toInt(&ok, 16); //Convert the two ASCII chars corresponding to the record type into a binary encoded byte
|
||||
|
||||
//Error check: Verify checksum byte at the end of the .hex file line is valid. Note,
|
||||
//this is not the same checksum as MPLAB(R) IDE uses/computes for the entire hex file.
|
||||
//This is only the mini-checksum at the end of each line in the .hex file.
|
||||
unsigned int hexLineChecksum = 0;
|
||||
for(i = 0; i < (byteCount+4); i++) //+4 correction is for byte count, 16-bit address, and record type bytes
|
||||
{
|
||||
hexByte = line.mid(1 + (2 * i), 2); //Fetch two adjacent ASCII bytes from the .hex file
|
||||
wordByte = hexByte.toInt(&ok, 16); //Re-format the above two ASCII bytes into a single binary encoded byte (0x00-0xFF)
|
||||
//Add the newly fetched byte to the running checksum
|
||||
hexLineChecksum += (unsigned char)wordByte;
|
||||
}
|
||||
//Now get the two's complement of the hexLineChecksum.
|
||||
hexLineChecksum = 0 - hexLineChecksum;
|
||||
hexLineChecksum &= 0xFF; //Truncate to a single byte. We now have our computed checksum. This should match the .hex file.
|
||||
//Fetch checksum byte from the .hex file
|
||||
hexByte = line.mid(1 + (2 * i), 2); //Fetch the two ASCII bytes that correspond to the checksum byte
|
||||
wordByte = hexByte.toInt(&ok, 16); //Re-format the above two ASCII bytes into a single binary encoded byte (0x00-0xFF)
|
||||
wordByte &= 0xFF;
|
||||
//Now check if the checksum we computed matches the one at the end of the line in the hex file.
|
||||
if(hexLineChecksum != wordByte)
|
||||
{
|
||||
//Checksum in the hex file doesn't match the line contents. This implies a corrupted hex file.
|
||||
//If an error is detected in the hex file formatting, the safest approach is to
|
||||
//abort the operation and force the user to supply a properly formatted hex file.
|
||||
if(hexfile.isOpen())
|
||||
hexfile.close();
|
||||
return ErrorInHexFile;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//Check the record type of the hex line, to determine how to continue parsing the data.
|
||||
if (recordType == END_OF_FILE) // end of file record
|
||||
{
|
||||
hasEndOfFileRecord = true;
|
||||
break;
|
||||
}
|
||||
else if ((recordType == EXTENDED_SEGMENT_ADDR) || (recordType == EXTENDED_LINEAR_ADDR)) // Segment address
|
||||
{
|
||||
//Error check: Make sure the line contains the correct number of bytes for the specified record type
|
||||
if((unsigned int)line.size() >= (11 + (2 * byteCount)))
|
||||
{
|
||||
//Fetch the payload, which is the upper 4 or 16-bits of the 20-bit or 32-bit hex file address
|
||||
segmentAddress = line.mid(9, 4).toInt(&ok, 16);
|
||||
|
||||
//Load the upper bits of the address
|
||||
if (recordType == EXTENDED_SEGMENT_ADDR)
|
||||
{
|
||||
segmentAddress <<= 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
segmentAddress <<= 16;
|
||||
}
|
||||
|
||||
//Update the line address, now that we know the upper bits are something new.
|
||||
lineAddress = segmentAddress + line.mid(3, 4).toInt(&ok, 16);
|
||||
}
|
||||
else
|
||||
{
|
||||
//Length appears to be wrong in hex line entry.
|
||||
//If an error is detected in the hex file formatting, the safest approach is to
|
||||
//abort the operation and force the user to supply a properly formatted hex file.
|
||||
if(hexfile.isOpen())
|
||||
hexfile.close();
|
||||
return ErrorInHexFile;
|
||||
}
|
||||
|
||||
} // end if ((recordType == EXTENDED_SEGMENT_ADDR) || (recordType == EXTENDED_LINEAR_ADDR)) // Segment address
|
||||
else if (recordType == DATA) // Data Record
|
||||
{
|
||||
//Error check to make sure line is long enough to be consistent with the specified record type
|
||||
if ((unsigned int)line.size() < (11 + (2 * byteCount)))
|
||||
{
|
||||
//If an error is detected in the hex file formatting, the safest approach is to
|
||||
//abort the operation and force the user to supply a proper hex file.
|
||||
if(hexfile.isOpen())
|
||||
hexfile.close();
|
||||
return ErrorInHexFile;
|
||||
}
|
||||
|
||||
|
||||
//For each data payload byte we find in the hex file line, check if it is contained within
|
||||
//a progammable region inside the microcontroller. If so save it. If not, discard it.
|
||||
for(i = 0; i < byteCount; i++)
|
||||
{
|
||||
//Use the hex file linear byte address, to compute other imformation about the
|
||||
//byte/location. The GetDeviceAddressFromHexAddress() function gives us a pointer to
|
||||
//the PC RAM buffer byte that will get programmed into the microcontroller, which corresponds
|
||||
//to the specified .hex file extended address.
|
||||
//The function also returns a boolean letting us know if the address is part of a programmable memory region on the device.
|
||||
deviceAddress = device->GetDeviceAddressFromHexAddress(lineAddress + i, pData, type, includedInProgrammableRange, addressWasEndofRange, bytesPerAddressAndType, endDeviceAddressofRegion, pPCRAMBuffer);
|
||||
//Check if the just parsed hex byte was included in one of the microcontroller reported programmable memory regions.
|
||||
//If so, save the byte into the proper location in the PC RAM buffer, so it can be programmed later.
|
||||
if((includedInProgrammableRange == true) && (pPCRAMBuffer != 0)) //Make sure pPCRAMBuffer pointer is valid before using it.
|
||||
{
|
||||
//Print debug output text to debug window
|
||||
if(i == 0)
|
||||
{
|
||||
qDebug(QString("Importing .hex file line with device address: 0x" + QString::number(deviceAddress, 16)).toLatin1());
|
||||
}
|
||||
|
||||
//Fetch ASCII encoded payload byte from .hex file and save the byte to our temporary RAM buffer.
|
||||
hexByte = line.mid(9 + (2 * i), 2); //Fetch two ASCII data payload bytes from the .hex file
|
||||
wordByte = hexByte.toInt(&ok, 16); //Re-format the above two ASCII bytes into a single binary encoded byte (0x00-0xFF)
|
||||
|
||||
*pPCRAMBuffer = (unsigned char)wordByte; //Save the .hex file data byte into the PC RAM buffer that holds the data to be programmed
|
||||
importedAtLeastOneByte = true; //Set flag so we know we imported something successfully.
|
||||
|
||||
//Check if we just parsed a config bit byte. If so, set flag so the user is no longer locked out
|
||||
//of programming the config bits section.
|
||||
if(type == CONFIG_MEMORY)
|
||||
{
|
||||
hasConfigBits = true;
|
||||
}
|
||||
}
|
||||
else if((includedInProgrammableRange == true) && (pPCRAMBuffer == 0))
|
||||
{
|
||||
//Previous memory allocation must have failed, or otherwise pPCRAMBuffer would not be = 0.
|
||||
//Since the memory allocation failed, we should bug out and let the user know.
|
||||
if(hexfile.isOpen())
|
||||
hexfile.close();
|
||||
return InsufficientMemory;
|
||||
}
|
||||
}//for(i = 0; i < byteCount; i++)
|
||||
} // end else if (recordType == DATA)
|
||||
}//while (!hexfile.atEnd())
|
||||
|
||||
//If we get to here, that means we reached the end of the hex file, or we found a END_OF_FILE record in the .hex file.
|
||||
if(hexfile.isOpen())
|
||||
{
|
||||
hexfile.close();
|
||||
}
|
||||
|
||||
//Check if we imported any data from the .hex file.
|
||||
if(importedAtLeastOneByte == true)
|
||||
{
|
||||
qDebug(QString("Hex File imported successfully.").toLatin1());
|
||||
return Success;
|
||||
}
|
||||
else
|
||||
{
|
||||
//If we get to here, we didn't import anything. The hex file must have been empty or otherwise didn't
|
||||
//contain any data that overlaps a device programmable region. We should let the user know they should
|
||||
//supply a better hex file designed for their device.
|
||||
return NoneInRange;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
78
qt5_src/Bootloader/ImportExportHex.h
Normal file
@@ -0,0 +1,78 @@
|
||||
/************************************************************************
|
||||
* Copyright (c) 2005-2009, Microchip Technology Inc.
|
||||
*
|
||||
* Microchip licenses this software to you solely for use with Microchip
|
||||
* products. The software is owned by Microchip and its licensors, and
|
||||
* is protected under applicable copyright laws. All rights reserved.
|
||||
*
|
||||
* SOFTWARE IS PROVIDED "AS IS." MICROCHIP EXPRESSLY DISCLAIMS ANY
|
||||
* WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL
|
||||
* MICROCHIP BE LIABLE FOR ANY INCIDENTAL, SPECIAL, INDIRECT OR
|
||||
* CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, HARM TO YOUR
|
||||
* EQUIPMENT, COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY
|
||||
* OR SERVICES, ANY CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT LIMITED
|
||||
* TO ANY DEFENSE THEREOF), ANY CLAIMS FOR INDEMNITY OR CONTRIBUTION,
|
||||
* OR OTHER SIMILAR COSTS.
|
||||
*
|
||||
* To the fullest extent allowed by law, Microchip and its licensors
|
||||
* liability shall not exceed the amount of fees, if any, that you
|
||||
* have paid directly to Microchip to use this software.
|
||||
*
|
||||
* MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE
|
||||
* OF THESE TERMS.
|
||||
*/
|
||||
#ifndef IMPORTEXPORTHEX_H
|
||||
#define IMPORTEXPORTHEX_H
|
||||
|
||||
#include <QString>
|
||||
#include "DeviceData.h"
|
||||
#include "Device.h"
|
||||
|
||||
/*!
|
||||
* Reads HEX files into an in-memory DeviceData object.
|
||||
*/
|
||||
class HexImporter
|
||||
{
|
||||
public:
|
||||
enum ErrorCode { Success = 0, CouldNotOpenFile, NoneInRange, ErrorInHexFile, InsufficientMemory };
|
||||
//Definitions for the record type bytes in Intel 32-bit .HEX file formatted firmware images
|
||||
enum HEX32_RECORD
|
||||
{
|
||||
DATA = 0x00,
|
||||
END_OF_FILE = 0x01,
|
||||
EXTENDED_SEGMENT_ADDR = 0x02,
|
||||
EXTENDED_LINEAR_ADDR = 0x04,
|
||||
};
|
||||
|
||||
//Definitions for the program memory "word write" size for different microcontroller families
|
||||
enum PROG_WORD_WRITE_SIZE
|
||||
{
|
||||
PIC18_PROG_WORD_WRITE_SIZE = 0x02, //Word writes perform two byte writes on these devices.
|
||||
PIC24_PROG_WORD_WRITE_SIZE = 0x04, //3 useful bytes per "word write", but the empty phantom byte makes 4 bytes total
|
||||
PIC32_PROG_WORD_WRITE_SIZE = 0x04,
|
||||
};
|
||||
|
||||
|
||||
|
||||
HexImporter(void);
|
||||
~HexImporter(void);
|
||||
|
||||
ErrorCode ImportHexFile(QString fileName, DeviceData* data, Device* device);
|
||||
|
||||
bool hasEndOfFileRecord; // hex file does have an end of file record
|
||||
bool hasConfigBits; // hex file has config bit settings
|
||||
bool fileExceedsFlash; // hex file records exceed device memory constraints
|
||||
|
||||
QList<DeviceData::MemoryRange> rawimport;
|
||||
|
||||
|
||||
protected:
|
||||
//int ParseHex(char* characters, int length);
|
||||
//unsigned char computeChecksum(char* fileLine);
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // IMPORTEXPORTHEX_H
|
||||
1538
qt5_src/Bootloader/MainWindow.cpp
Normal file
130
qt5_src/Bootloader/MainWindow.h
Normal file
@@ -0,0 +1,130 @@
|
||||
/************************************************************************
|
||||
* Copyright (c) 2009-2010, Microchip Technology Inc.
|
||||
*
|
||||
* Microchip licenses this software to you solely for use with Microchip
|
||||
* products. The software is owned by Microchip and its licensors, and
|
||||
* is protected under applicable copyright laws. All rights reserved.
|
||||
*
|
||||
* SOFTWARE IS PROVIDED "AS IS." MICROCHIP EXPRESSLY DISCLAIMS ANY
|
||||
* WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL
|
||||
* MICROCHIP BE LIABLE FOR ANY INCIDENTAL, SPECIAL, INDIRECT OR
|
||||
* CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, HARM TO YOUR
|
||||
* EQUIPMENT, COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY
|
||||
* OR SERVICES, ANY CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT LIMITED
|
||||
* TO ANY DEFENSE THEREOF), ANY CLAIMS FOR INDEMNITY OR CONTRIBUTION,
|
||||
* OR OTHER SIMILAR COSTS.
|
||||
*
|
||||
* To the fullest extent allowed by law, Microchip and its licensors
|
||||
* liability shall not exceed the amount of fees, if any, that you
|
||||
* have paid directly to Microchip to use this software.
|
||||
*
|
||||
* MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE
|
||||
* OF THESE TERMS.
|
||||
*/
|
||||
|
||||
#ifndef MAINWINDOW_H
|
||||
#define MAINWINDOW_H
|
||||
|
||||
#include <QtWidgets/QMainWindow>
|
||||
#include <QtWidgets/QLabel>
|
||||
#include <QFileInfo>
|
||||
#include <QFileSystemWatcher>
|
||||
#include <QtCore/QProcess>
|
||||
#include <QtWidgets/QMenu>
|
||||
#include <QFuture>
|
||||
|
||||
#include "Comm.h"
|
||||
#include "DeviceData.h"
|
||||
#include "Device.h"
|
||||
#include "ImportExportHex.h"
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class MainWindowClass;
|
||||
}
|
||||
|
||||
#define MAX_RECENT_FILES 3
|
||||
|
||||
/*!
|
||||
* The main Serial Bootloader GUI window.
|
||||
*/
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MainWindow(QWidget *parent = 0);
|
||||
~MainWindow();
|
||||
|
||||
void GetQuery(void);
|
||||
void LoadFile(QString fileName);
|
||||
|
||||
void EraseDevice(void);
|
||||
void BlankCheckDevice(void);
|
||||
void WriteDevice(void);
|
||||
void VerifyDevice(void);
|
||||
|
||||
void setBootloadBusy(bool busy);
|
||||
|
||||
signals:
|
||||
void IoWithDeviceCompleted(QString msg, Comm::ErrorCode, double time);
|
||||
void IoWithDeviceStarted(QString msg);
|
||||
void AppendString(QString msg);
|
||||
void SetProgressBar(int newValue);
|
||||
|
||||
public slots:
|
||||
void Connection(void);
|
||||
void openRecentFile(void);
|
||||
void IoWithDeviceComplete(QString msg, Comm::ErrorCode, double time);
|
||||
void IoWithDeviceStart(QString msg);
|
||||
void AppendStringToTextbox(QString msg);
|
||||
void UpdateProgressBar(int newValue);
|
||||
|
||||
protected:
|
||||
Comm* comm;
|
||||
DeviceData* deviceData;
|
||||
DeviceData* hexData;
|
||||
Device* device;
|
||||
|
||||
QFuture<void> future;
|
||||
|
||||
QString fileName, watchFileName;
|
||||
QFileSystemWatcher* fileWatcher;
|
||||
QTimer *timer;
|
||||
|
||||
bool writeFlash;
|
||||
bool writeEeprom;
|
||||
bool writeConfig;
|
||||
bool eraseDuringWrite;
|
||||
bool hexOpen;
|
||||
|
||||
void setBootloadEnabled(bool enable);
|
||||
|
||||
void UpdateRecentFileList(void);
|
||||
|
||||
Comm::ErrorCode RemapInterruptVectors(Device* device, DeviceData* deviceData);
|
||||
|
||||
private:
|
||||
Ui::MainWindowClass *ui;
|
||||
QLabel deviceLabel;
|
||||
|
||||
int failed;
|
||||
QAction *recentFiles[MAX_RECENT_FILES];
|
||||
|
||||
bool wasBootloaderMode;
|
||||
|
||||
private slots:
|
||||
void on_actionBlank_Check_triggered();
|
||||
void on_actionReset_Device_triggered();
|
||||
void on_action_Settings_triggered();
|
||||
void on_action_Verify_Device_triggered();
|
||||
void on_action_About_triggered();
|
||||
void on_actionWrite_Device_triggered();
|
||||
void on_actionOpen_triggered();
|
||||
void on_actionErase_Device_triggered();
|
||||
void on_actionExit_triggered();
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
243
qt5_src/Bootloader/MainWindow.ui
Normal file
@@ -0,0 +1,243 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>MainWindowClass</class>
|
||||
<widget class="QMainWindow" name="MainWindowClass">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>439</width>
|
||||
<height>403</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string notr="true">USB HID Bootloader</string>
|
||||
</property>
|
||||
<property name="windowIcon">
|
||||
<iconset resource="resources.qrc">
|
||||
<normaloff>:/MainWindow/img/Microchip_logo.Ico</normaloff>:/MainWindow/img/Microchip_logo.Ico</iconset>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralWidget">
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QProgressBar" name="progressBar">
|
||||
<property name="value">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="textVisible">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="Line" name="line">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QPlainTextEdit" name="plainTextEdit">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>350</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QMenuBar" name="menuBar">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>439</width>
|
||||
<height>19</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QMenu" name="menuFile">
|
||||
<property name="title">
|
||||
<string>&File</string>
|
||||
</property>
|
||||
<addaction name="actionOpen"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionExit"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuProgrammer">
|
||||
<property name="title">
|
||||
<string>&Program</string>
|
||||
</property>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionWrite_Device"/>
|
||||
<addaction name="action_Verify_Device"/>
|
||||
<addaction name="actionErase_Device"/>
|
||||
<addaction name="actionBlank_Check"/>
|
||||
<addaction name="actionReset_Device"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="action_Settings"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menu_Help">
|
||||
<property name="title">
|
||||
<string>&Help</string>
|
||||
</property>
|
||||
<addaction name="action_About"/>
|
||||
</widget>
|
||||
<addaction name="menuFile"/>
|
||||
<addaction name="menuProgrammer"/>
|
||||
<addaction name="menu_Help"/>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusBar"/>
|
||||
<widget class="QToolBar" name="mainToolBar">
|
||||
<property name="windowTitle">
|
||||
<string>Display Toolbar</string>
|
||||
</property>
|
||||
<property name="movable">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="floatable">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<attribute name="toolBarArea">
|
||||
<enum>TopToolBarArea</enum>
|
||||
</attribute>
|
||||
<attribute name="toolBarBreak">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<addaction name="actionOpen"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionWrite_Device"/>
|
||||
<addaction name="action_Verify_Device"/>
|
||||
<addaction name="actionErase_Device"/>
|
||||
<addaction name="actionBlank_Check"/>
|
||||
<addaction name="actionReset_Device"/>
|
||||
</widget>
|
||||
<action name="actionOpen">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="resources.qrc">
|
||||
<normaloff>:/MainWindow/img/open.png</normaloff>:/MainWindow/img/open.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>&Import Firmware Image</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Import Firmware Image</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+O</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionExit">
|
||||
<property name="text">
|
||||
<string>E&xit</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+Q</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionWrite_Device">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="resources.qrc">
|
||||
<normaloff>:/MainWindow/img/writetqfp.png</normaloff>:/MainWindow/img/writetqfp.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Erase/Program/Verify Device</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionErase_Device">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="resources.qrc">
|
||||
<normaloff>:/MainWindow/img/erasetqfp.png</normaloff>:/MainWindow/img/erasetqfp.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Erase Device</string>
|
||||
</property>
|
||||
<property name="visible">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</action>
|
||||
<action name="action_About">
|
||||
<property name="icon">
|
||||
<iconset resource="resources.qrc">
|
||||
<normaloff>:/MainWindow/img/help.png</normaloff>:/MainWindow/img/help.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>&About</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="action_Verify_Device">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="resources.qrc">
|
||||
<normaloff>:/MainWindow/img/verify.png</normaloff>:/MainWindow/img/verify.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>&Verify Device</string>
|
||||
</property>
|
||||
<property name="visible">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</action>
|
||||
<action name="action_Settings">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>&Settings...</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionReset_Device">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="resources.qrc">
|
||||
<normaloff>:/MainWindow/img/Reset.png</normaloff>:/MainWindow/img/Reset.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Reset Device</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionBlank_Check">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="resources.qrc">
|
||||
<normaloff>:/MainWindow/img/BlankCheck.png</normaloff>:/MainWindow/img/BlankCheck.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Blank Check</string>
|
||||
</property>
|
||||
<property name="visible">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<resources>
|
||||
<include location="resources.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
120
qt5_src/Bootloader/Settings.cpp
Normal file
@@ -0,0 +1,120 @@
|
||||
/************************************************************************
|
||||
* Copyright (c) 2009, Microchip Technology Inc.
|
||||
*
|
||||
* Microchip licenses this software to you solely for use with Microchip
|
||||
* products. The software is owned by Microchip and its licensors, and
|
||||
* is protected under applicable copyright laws. All rights reserved.
|
||||
*
|
||||
* SOFTWARE IS PROVIDED "AS IS." MICROCHIP EXPRESSLY DISCLAIMS ANY
|
||||
* WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL
|
||||
* MICROCHIP BE LIABLE FOR ANY INCIDENTAL, SPECIAL, INDIRECT OR
|
||||
* CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, HARM TO YOUR
|
||||
* EQUIPMENT, COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY
|
||||
* OR SERVICES, ANY CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT LIMITED
|
||||
* TO ANY DEFENSE THEREOF), ANY CLAIMS FOR INDEMNITY OR CONTRIBUTION,
|
||||
* OR OTHER SIMILAR COSTS.
|
||||
*
|
||||
* To the fullest extent allowed by law, Microchip and its licensors
|
||||
* liability shall not exceed the amount of fees, if any, that you
|
||||
* have paid directly to Microchip to use this software.
|
||||
*
|
||||
* MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE
|
||||
* OF THESE TERMS.
|
||||
*
|
||||
* Author Date Comment
|
||||
*************************************************************************
|
||||
* E. Schlunder 2009/04/29 Initial code.
|
||||
************************************************************************/
|
||||
|
||||
#include "Settings.h"
|
||||
#include "ui_Settings.h"
|
||||
|
||||
#include <QtWidgets/QMessageBox>
|
||||
|
||||
Settings::Settings(QWidget *parent) : QDialog(parent), m_ui(new Ui::Settings)
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
|
||||
alreadyWarnedConfigBitWrite = false;
|
||||
}
|
||||
|
||||
Settings::~Settings()
|
||||
{
|
||||
delete m_ui;
|
||||
}
|
||||
|
||||
void Settings::enableEepromBox(bool Eeprom)
|
||||
{
|
||||
m_ui->EepromCheckBox->setEnabled(Eeprom);
|
||||
hasEeprom = Eeprom;
|
||||
}
|
||||
|
||||
void Settings::setWriteFlash(bool value)
|
||||
{
|
||||
writeFlash = value;
|
||||
m_ui->FlashProgramMemorycheckBox->setChecked(value);
|
||||
}
|
||||
|
||||
void Settings::setWriteEeprom(bool value)
|
||||
{
|
||||
writeEeprom = value && hasEeprom;
|
||||
m_ui->EepromCheckBox->setChecked(value && hasEeprom);
|
||||
}
|
||||
|
||||
void Settings::setWriteConfig(bool value)
|
||||
{
|
||||
writeConfig = value && hasConfig;
|
||||
bool warnedFlag = alreadyWarnedConfigBitWrite;
|
||||
alreadyWarnedConfigBitWrite = true;
|
||||
m_ui->ConfigBitsCheckBox->setChecked(value && hasConfig);
|
||||
alreadyWarnedConfigBitWrite = warnedFlag;
|
||||
}
|
||||
|
||||
void Settings::changeEvent(QEvent *e)
|
||||
{
|
||||
switch (e->type())
|
||||
{
|
||||
case QEvent::LanguageChange:
|
||||
m_ui->retranslateUi(this);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Settings::on_buttonBox_accepted()
|
||||
{
|
||||
writeFlash = m_ui->FlashProgramMemorycheckBox->isChecked();
|
||||
writeConfig = m_ui->ConfigBitsCheckBox->isChecked();
|
||||
writeEeprom = m_ui->EepromCheckBox->isChecked();
|
||||
}
|
||||
|
||||
void Settings::on_ConfigBitsCheckBox_toggled(bool checked)
|
||||
{
|
||||
if((alreadyWarnedConfigBitWrite == false) && checked)
|
||||
{
|
||||
QMessageBox msgBox(this);
|
||||
msgBox.setWindowTitle("Warning!");
|
||||
|
||||
msgBox.setText("Writing Config Bits is not a safe bootloader operation.\n" \
|
||||
"\n" \
|
||||
"The device and bootloader may stop functioning if the new config bit settings are\nnot compatible with USB operation.\n" \
|
||||
"When the bootloader becomes inoperable, restoring the device will not be possible\n" \
|
||||
"without dedicated external chip programming tools.\n" \
|
||||
"\n" \
|
||||
"Are you sure you wish to enable the \"Write Config Bits\" option?");
|
||||
|
||||
msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
|
||||
msgBox.setDefaultButton(QMessageBox::Cancel);
|
||||
int result = msgBox.exec();
|
||||
if(result != QMessageBox::Ok)
|
||||
{
|
||||
m_ui->ConfigBitsCheckBox->setChecked(false);
|
||||
return;
|
||||
}
|
||||
|
||||
alreadyWarnedConfigBitWrite = true;
|
||||
}
|
||||
}
|
||||
77
qt5_src/Bootloader/Settings.h
Normal file
@@ -0,0 +1,77 @@
|
||||
/************************************************************************
|
||||
* Copyright (c) 2009, Microchip Technology Inc.
|
||||
*
|
||||
* Microchip licenses this software to you solely for use with Microchip
|
||||
* products. The software is owned by Microchip and its licensors, and
|
||||
* is protected under applicable copyright laws. All rights reserved.
|
||||
*
|
||||
* SOFTWARE IS PROVIDED "AS IS." MICROCHIP EXPRESSLY DISCLAIMS ANY
|
||||
* WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL
|
||||
* MICROCHIP BE LIABLE FOR ANY INCIDENTAL, SPECIAL, INDIRECT OR
|
||||
* CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, HARM TO YOUR
|
||||
* EQUIPMENT, COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY
|
||||
* OR SERVICES, ANY CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT LIMITED
|
||||
* TO ANY DEFENSE THEREOF), ANY CLAIMS FOR INDEMNITY OR CONTRIBUTION,
|
||||
* OR OTHER SIMILAR COSTS.
|
||||
*
|
||||
* To the fullest extent allowed by law, Microchip and its licensors
|
||||
* liability shall not exceed the amount of fees, if any, that you
|
||||
* have paid directly to Microchip to use this software.
|
||||
*
|
||||
* MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE
|
||||
* OF THESE TERMS.
|
||||
*
|
||||
* Author Date Comment
|
||||
*************************************************************************
|
||||
* E. Schlunder 2009/04/29 Initial code.
|
||||
************************************************************************/
|
||||
|
||||
#ifndef SETTINGS_H
|
||||
#define SETTINGS_H
|
||||
|
||||
#include <QtWidgets/QDialog>
|
||||
//#include <hidapi.h>
|
||||
#include <QtWidgets/QComboBox>
|
||||
|
||||
namespace Ui {
|
||||
class Settings;
|
||||
}
|
||||
|
||||
/*!
|
||||
* The Settings GUI dialog box for configuring flash, EEPROM, and config bit write regions.
|
||||
*/
|
||||
class Settings : public QDialog {
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(Settings)
|
||||
public:
|
||||
explicit Settings(QWidget *parent = 0);
|
||||
virtual ~Settings();
|
||||
|
||||
void enableEepromBox(bool Eeprom);
|
||||
void setWriteFlash(bool value);
|
||||
void setWriteEeprom(bool value);
|
||||
void setWriteConfig(bool value);
|
||||
|
||||
bool writeFlash;
|
||||
bool writeEeprom;
|
||||
bool writeConfig;
|
||||
|
||||
bool hasEeprom;
|
||||
bool hasConfig;
|
||||
|
||||
protected:
|
||||
virtual void changeEvent(QEvent *e);
|
||||
void populateBaudRates(QComboBox* comboBox);
|
||||
|
||||
private:
|
||||
Ui::Settings *m_ui;
|
||||
bool alreadyWarnedConfigBitWrite;
|
||||
|
||||
private slots:
|
||||
void on_ConfigBitsCheckBox_toggled(bool checked);
|
||||
void on_buttonBox_accepted();
|
||||
};
|
||||
|
||||
#endif // SETTINGS_H
|
||||
124
qt5_src/Bootloader/Settings.ui
Normal file
@@ -0,0 +1,124 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Settings</class>
|
||||
<widget class="QDialog" name="Settings">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>402</width>
|
||||
<height>190</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Settings</string>
|
||||
</property>
|
||||
<property name="windowIcon">
|
||||
<iconset>
|
||||
<normaloff>:/MainWindow/img/microchip.png</normaloff>:/MainWindow/img/microchip.png</iconset>
|
||||
</property>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>30</x>
|
||||
<y>150</y>
|
||||
<width>341</width>
|
||||
<height>32</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QGroupBox" name="WriteOptionsGroupBox">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>20</x>
|
||||
<y>10</y>
|
||||
<width>361</width>
|
||||
<height>131</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>Write Options</string>
|
||||
</property>
|
||||
<widget class="QCheckBox" name="FlashProgramMemorycheckBox">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>17</x>
|
||||
<y>30</y>
|
||||
<width>201</width>
|
||||
<height>19</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>FLASH Program Memory</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QCheckBox" name="ConfigBitsCheckBox">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>17</x>
|
||||
<y>60</y>
|
||||
<width>201</width>
|
||||
<height>19</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Config Bits</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QCheckBox" name="EepromCheckBox">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>16</x>
|
||||
<y>90</y>
|
||||
<width>201</width>
|
||||
<height>19</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>EEPROM</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>Settings</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>Settings</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
||||
BIN
qt5_src/Bootloader/img/BlankCheck.png
Normal file
|
After Width: | Height: | Size: 252 B |
BIN
qt5_src/Bootloader/img/Microchip_logo.Ico
Normal file
|
After Width: | Height: | Size: 3.2 KiB |
BIN
qt5_src/Bootloader/img/Reset.png
Normal file
|
After Width: | Height: | Size: 227 B |
BIN
qt5_src/Bootloader/img/abort.png
Normal file
|
After Width: | Height: | Size: 421 B |
BIN
qt5_src/Bootloader/img/clear.png
Normal file
|
After Width: | Height: | Size: 235 B |
BIN
qt5_src/Bootloader/img/erasetqfp.png
Normal file
|
After Width: | Height: | Size: 250 B |
BIN
qt5_src/Bootloader/img/help.png
Normal file
|
After Width: | Height: | Size: 622 B |
BIN
qt5_src/Bootloader/img/open.png
Normal file
|
After Width: | Height: | Size: 259 B |
BIN
qt5_src/Bootloader/img/readtqfp.png
Normal file
|
After Width: | Height: | Size: 244 B |
BIN
qt5_src/Bootloader/img/stop.png
Normal file
|
After Width: | Height: | Size: 303 B |
BIN
qt5_src/Bootloader/img/verify.png
Normal file
|
After Width: | Height: | Size: 249 B |
BIN
qt5_src/Bootloader/img/writetqfp.png
Normal file
|
After Width: | Height: | Size: 245 B |
44
qt5_src/Bootloader/main.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
/************************************************************************
|
||||
* Copyright (c) 2009-2010, Microchip Technology Inc.
|
||||
*
|
||||
* Microchip licenses this software to you solely for use with Microchip
|
||||
* products. The software is owned by Microchip and its licensors, and
|
||||
* is protected under applicable copyright laws. All rights reserved.
|
||||
*
|
||||
* SOFTWARE IS PROVIDED "AS IS." MICROCHIP EXPRESSLY DISCLAIMS ANY
|
||||
* WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL
|
||||
* MICROCHIP BE LIABLE FOR ANY INCIDENTAL, SPECIAL, INDIRECT OR
|
||||
* CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, HARM TO YOUR
|
||||
* EQUIPMENT, COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY
|
||||
* OR SERVICES, ANY CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT LIMITED
|
||||
* TO ANY DEFENSE THEREOF), ANY CLAIMS FOR INDEMNITY OR CONTRIBUTION,
|
||||
* OR OTHER SIMILAR COSTS.
|
||||
*
|
||||
* To the fullest extent allowed by law, Microchip and its licensors
|
||||
* liability shall not exceed the amount of fees, if any, that you
|
||||
* have paid directly to Microchip to use this software.
|
||||
*
|
||||
* MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE
|
||||
* OF THESE TERMS.
|
||||
*
|
||||
* Author Date Comment
|
||||
*************************************************************************
|
||||
* E. Schlunder 2009/04/14 Initial code ported from VB app.
|
||||
************************************************************************/
|
||||
|
||||
#include <QtWidgets/QApplication>
|
||||
#include "MainWindow.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
QCoreApplication::setOrganizationName("Microchip");
|
||||
QCoreApplication::setOrganizationDomain("microchip.com");
|
||||
QCoreApplication::setApplicationName("USB HID Bootloader");
|
||||
|
||||
MainWindow w;
|
||||
w.show();
|
||||
return a.exec();
|
||||
}
|
||||
14
qt5_src/Bootloader/resources.qrc
Normal file
@@ -0,0 +1,14 @@
|
||||
<RCC>
|
||||
<qresource prefix="/MainWindow">
|
||||
<file>img/abort.png</file>
|
||||
<file>img/open.png</file>
|
||||
<file>img/writetqfp.png</file>
|
||||
<file>img/erasetqfp.png</file>
|
||||
<file>img/verify.png</file>
|
||||
<file>img/stop.png</file>
|
||||
<file>img/BlankCheck.png</file>
|
||||
<file>img/Reset.png</file>
|
||||
<file>img/help.png</file>
|
||||
<file>img/Microchip_logo.Ico</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
1
qt5_src/Bootloader/windows.rc
Normal file
@@ -0,0 +1 @@
|
||||
IDI_ICON1 ICON DISCARDABLE "img/icon.ico"
|
||||