Merge from 2.3

This commit is contained in:
Bertrand Songis
2019-12-05 09:29:11 +01:00
161 changed files with 3682 additions and 10305 deletions
+9 -7
View File
@@ -27,7 +27,7 @@ bool isBootloader(const char * filename)
uint8_t buffer[1024];
UINT count;
if (f_read(&file, buffer, 1024, &count) != FR_OK || count != 1024) {
if (f_read(&file, buffer, sizeof(buffer), &count) != FR_OK || count != sizeof(buffer)) {
return false;
}
@@ -47,18 +47,18 @@ void bootloaderFlash(const char * filename)
unlockFlash();
}
for (int i=0; i<BOOTLOADER_SIZE; i+=1024) {
watchdogSuspend(100/*1s*/);
if (f_read(&file, buffer, 1024, &count) != FR_OK || count != 1024) {
for (int i = 0; i < BOOTLOADER_SIZE; i += 1024) {
watchdogSuspend(1000/*10s*/);
if (f_read(&file, buffer, sizeof(buffer), &count) != FR_OK || count != sizeof(buffer)) {
POPUP_WARNING(STR_SDCARD_ERROR);
break;
}
if (i==0 && !isBootloaderStart(buffer)) {
if (i == 0 && !isBootloaderStart(buffer)) {
POPUP_WARNING(STR_INCOMPATIBLE);
break;
}
for (int j=0; j<1024; j+=FLASH_PAGESIZE) {
flashWrite(CONVERT_UINT_PTR(FIRMWARE_ADDRESS+i+j), (uint32_t *)(buffer+j));
for (int j = 0; j < 1024; j += FLASH_PAGESIZE) {
flashWrite(CONVERT_UINT_PTR(FIRMWARE_ADDRESS + i + j), CONVERT_UINT_PTR(buffer + j));
}
#if !defined(COLORLCD)
drawProgressScreen("Bootloader", STR_WRITING, i, BOOTLOADER_SIZE);
@@ -70,6 +70,8 @@ void bootloaderFlash(const char * filename)
#endif
}
watchdogSuspend(0);
if (unlocked) {
lockFlash();
unlocked = 0;
+18 -14
View File
@@ -102,7 +102,7 @@ bool FrskyDeviceFirmwareUpdate::readBuffer(uint8_t * buffer, uint8_t count, uint
{
watchdogSuspend(timeout);
switch(module) {
switch (module) {
case INTERNAL_MODULE:
{
uint32_t elapsed = 0;
@@ -177,8 +177,8 @@ const uint8_t * FrskyDeviceFirmwareUpdate::readFrame(uint32_t timeout)
{
RTOS_WAIT_MS(1);
switch(module) {
#if defined(INTMODULE_USART) && !(defined(PCBXLITE) && !defined(PCBXLITES))
switch (module) {
#if defined(INTERNAL_MODULE_PXX2)
case INTERNAL_MODULE:
return readFullDuplexFrame(intmoduleFifo, timeout);
#endif
@@ -236,8 +236,8 @@ void FrskyDeviceFirmwareUpdate::sendFrame()
}
}
switch(module) {
#if defined(INTMODULE_USART) && !(defined(PCBXLITE) && !defined(PCBXLITES))
switch (module) {
#if defined(INTERNAL_MODULE_PXX2)
case INTERNAL_MODULE:
return intmoduleSendBuffer(outputTelemetryBuffer.data, ptr - outputTelemetryBuffer.data);
#endif
@@ -332,10 +332,7 @@ const char * FrskyDeviceFirmwareUpdate::doFlashFirmware(const char * filename, P
#endif
switch (module) {
#if defined(INTMODULE_USART) && !(defined(PCBXLITE) && !defined(PCBXLITES))
// on XLite we don't use TX + RX but the S.PORT line
// this ifdef can be removed if we use .frsk instead of .frk
// theorically it should be possible to use an ISRM module in an XLite
#if defined(INTERNAL_MODULE_PXX2)
case INTERNAL_MODULE:
intmoduleSerialStart(57600, true, USART_Parity_No, USART_StopBits_1, USART_WordLength_8b);
break;
@@ -496,7 +493,7 @@ const char * FrskyDeviceFirmwareUpdate::flashFirmware(const char * filename, Pro
progressHandler(getBasename(filename), STR_DEVICE_RESET, 0, 0);
/* wait 2s off */
watchdogSuspend(2000);
watchdogSuspend(1000 /*10s*/);
RTOS_WAIT_MS(2000);
const char * result = doFlashFirmware(filename, progressHandler);
@@ -512,12 +509,14 @@ const char * FrskyDeviceFirmwareUpdate::flashFirmware(const char * filename, Pro
POPUP_INFORMATION(STR_FIRMWARE_UPDATE_SUCCESS);
}
#if defined(HARDWARE_INTERNAL_MODULE)
INTERNAL_MODULE_OFF();
#endif
EXTERNAL_MODULE_OFF();
SPORT_UPDATE_POWER_OFF();
/* wait 2s off */
watchdogSuspend(2000);
watchdogSuspend(500 /*5s*/);
RTOS_WAIT_MS(2000);
telemetryClearFifo();
@@ -550,7 +549,7 @@ const char * FrskyChipFirmwareUpdate::waitAnswer(uint8_t & status)
uint8_t buffer[12];
for (uint8_t i = 0; i < sizeof(buffer); i++) {
uint32_t retry = 0;
while(1) {
while (true) {
if (telemetryGetByte(&buffer[i])) {
if ((i == 0 && buffer[0] != 0x7F) ||
(i == 1 && buffer[1] != 0xFE) ||
@@ -573,6 +572,10 @@ const char * FrskyChipFirmwareUpdate::waitAnswer(uint8_t & status)
const char * FrskyChipFirmwareUpdate::startBootloader()
{
sportSendByte(0x03);
RTOS_WAIT_MS(20);
sportSendByte(0x02);
RTOS_WAIT_MS(20);
sportSendByte(0x01);
for (uint8_t i = 0; i < 30; i++)
@@ -583,6 +586,7 @@ const char * FrskyChipFirmwareUpdate::startBootloader()
sportSendByte(0x7F);
}
RTOS_WAIT_MS(20);
sportSendByte(0xFA);
/*for (uint8_t i=0; i < 30; i++)
@@ -753,7 +757,7 @@ const char * FrskyChipFirmwareUpdate::flashFirmware(const char * filename, Progr
if (wait) {
/* wait 2s off */
watchdogSuspend(2000);
watchdogSuspend(1000 /*10s*/);
RTOS_WAIT_MS(2000);
}
@@ -773,7 +777,7 @@ const char * FrskyChipFirmwareUpdate::flashFirmware(const char * filename, Progr
}
/* wait 2s off */
watchdogSuspend(2000);
watchdogSuspend(1000 /*10s*/);
RTOS_WAIT_MS(2000);
#if defined(HARDWARE_INTERNAL_MODULE)
+1 -1
View File
@@ -28,7 +28,7 @@ class ModuleFifo : public Fifo<uint8_t, PXX2_FRAME_MAXLENGTH> {
public:
bool getFrame(uint8_t * frame)
{
while (1) {
while (true) {
if (isEmpty()) {
return false;
}
+60 -30
View File
@@ -33,20 +33,21 @@ class MultiFirmwareUpdateDriver
const char* flashFirmware(FIL* file, const char* label) const;
protected:
virtual void init() const = 0;
virtual void moduleOn() const = 0;
virtual void init(bool inverted) const = 0;
virtual bool getByte(uint8_t& byte) const = 0;
virtual void sendByte(uint8_t byte) const = 0;
virtual void clear() const = 0;
virtual void deinit() const {}
virtual void deinit(bool inverted) const {}
private:
bool getRxByte(uint8_t& byte) const;
bool checkRxByte(uint8_t byte) const;
const char * waitForInitialSync() const;
const char * waitForInitialSync(bool& inverted) const;
const char * getDeviceSignature(uint8_t* signature) const;
const char * loadAddress(uint32_t offset) const;
const char * progPage(uint8_t* buffer, uint16_t size) const;
void leaveProgMode() const;
void leaveProgMode(bool inverted) const;
};
#if defined(INTERNAL_MODULE_MULTI)
@@ -57,9 +58,13 @@ class MultiInternalUpdateDriver: public MultiFirmwareUpdateDriver
MultiInternalUpdateDriver() {}
protected:
void init() const override
void moduleOn() const override
{
INTERNAL_MODULE_ON();
}
void init(bool inverted) const override
{
intmoduleSerialStart(57600, true, USART_Parity_No, USART_StopBits_1, USART_WordLength_8b);
}
@@ -78,7 +83,7 @@ class MultiInternalUpdateDriver: public MultiFirmwareUpdateDriver
intmoduleFifo.clear();
}
void deinit() const override
void deinit(bool inverted) const override
{
clear();
}
@@ -88,13 +93,18 @@ static const MultiInternalUpdateDriver multiInternalUpdateDriver;
#endif
class MultiExternalSoftSerialUpdateDriver: public MultiFirmwareUpdateDriver
class MultiExternalUpdateDriver: public MultiFirmwareUpdateDriver
{
public:
MultiExternalSoftSerialUpdateDriver() {}
MultiExternalUpdateDriver() {}
protected:
void init() const override
void moduleOn() const override
{
EXTERNAL_MODULE_ON();
}
void init(bool inverted) const override
{
#if !defined(EXTMODULE_USART)
GPIO_InitTypeDef GPIO_InitStructure;
@@ -106,8 +116,10 @@ class MultiExternalSoftSerialUpdateDriver: public MultiFirmwareUpdateDriver
GPIO_Init(EXTMODULE_TX_GPIO, &GPIO_InitStructure);
#endif
EXTERNAL_MODULE_ON();
telemetryPortInvertedInit(57600);
if (inverted)
telemetryPortInvertedInit(57600);
else
telemetryPortInit(57600, TELEMETRY_SERIAL_DEFAULT);
}
bool getByte(uint8_t& byte) const override
@@ -125,14 +137,18 @@ class MultiExternalSoftSerialUpdateDriver: public MultiFirmwareUpdateDriver
telemetryClearFifo();
}
void deinit() const override
void deinit(bool inverted) const override
{
telemetryPortInvertedInit(0);
if (inverted)
telemetryPortInvertedInit(0);
else
telemetryPortInit(0, 0);
clear();
}
};
static const MultiExternalSoftSerialUpdateDriver multiExternalSoftSerialUpdateDriver;
static const MultiExternalUpdateDriver multiExternalUpdateDriver;
bool MultiFirmwareUpdateDriver::getRxByte(uint8_t& byte) const
{
@@ -159,19 +175,27 @@ bool MultiFirmwareUpdateDriver::checkRxByte(uint8_t byte) const
return getRxByte(rxchar) ? rxchar == byte : false;
}
const char * MultiFirmwareUpdateDriver::waitForInitialSync() const
const char * MultiFirmwareUpdateDriver::waitForInitialSync(bool& inverted) const
{
uint8_t byte;
int retries = 1000;
int retries = 200;
clear();
do {
// Invert at half-time
if (retries == 100) {
deinit(inverted);
inverted = !inverted;
init(inverted);
}
// Send sync request
sendByte(STK_GET_SYNC);
sendByte(CRC_EOP);
getRxByte(byte);
wdt_reset();
WDG_RESET();
} while((byte != STK_INSYNC) && --retries);
@@ -195,6 +219,7 @@ const char * MultiFirmwareUpdateDriver::getDeviceSignature(uint8_t* signature) c
// Read signature
sendByte(STK_READ_SIGN);
sendByte(CRC_EOP);
clear();
if (!checkRxByte(STK_INSYNC))
return "NoSync";
@@ -245,7 +270,7 @@ const char * MultiFirmwareUpdateDriver::progPage(uint8_t* buffer, uint16_t size)
uint8_t retries = 4;
do {
getRxByte(byte);
wdt_reset();
WDG_RESET();
} while(!byte && --retries);
if (!retries || (byte != STK_OK))
@@ -254,35 +279,38 @@ const char * MultiFirmwareUpdateDriver::progPage(uint8_t* buffer, uint16_t size)
return nullptr;
}
void MultiFirmwareUpdateDriver::leaveProgMode() const
void MultiFirmwareUpdateDriver::leaveProgMode(bool inverted) const
{
sendByte(STK_LEAVE_PROGMODE);
sendByte(CRC_EOP);
// eat last sync byte
checkRxByte(STK_INSYNC);
deinit();
deinit(inverted);
}
const char * MultiFirmwareUpdateDriver::flashFirmware(FIL* file, const char* label) const
{
const char* result = nullptr;
init();
moduleOn();
bool inverted = true; //false; // true
init(inverted);
/* wait 500ms for power on */
watchdogSuspend(500);
watchdogSuspend(500 /*5s*/);
RTOS_WAIT_MS(500);
result = waitForInitialSync();
result = waitForInitialSync(inverted);
if (result) {
leaveProgMode();
leaveProgMode(inverted);
return result;
}
unsigned char signature[4]; // 3 bytes signature + STK_OK
result = getDeviceSignature(signature);
if (result) {
leaveProgMode();
leaveProgMode(inverted);
return result;
}
@@ -291,7 +319,7 @@ const char * MultiFirmwareUpdateDriver::flashFirmware(FIL* file, const char* lab
uint32_t writeOffset = 0;
if (signature[0] != 0x1E) {
leaveProgMode();
leaveProgMode(inverted);
return "Wrong signature";
}
@@ -341,7 +369,7 @@ const char * MultiFirmwareUpdateDriver::flashFirmware(FIL* file, const char* lab
#endif
}
leaveProgMode();
leaveProgMode(inverted);
return result;
}
@@ -492,7 +520,7 @@ bool multiFlashFirmware(uint8_t moduleIdx, const char * filename)
}
}
const MultiFirmwareUpdateDriver* driver = &multiExternalSoftSerialUpdateDriver;
const MultiFirmwareUpdateDriver* driver = &multiExternalUpdateDriver;
#if defined(INTERNAL_MODULE_MULTI)
if (moduleIdx == INTERNAL_MODULE)
driver = &multiInternalUpdateDriver;
@@ -517,7 +545,7 @@ bool multiFlashFirmware(uint8_t moduleIdx, const char * filename)
#endif
/* wait 2s off */
watchdogSuspend(2000);
watchdogSuspend(500 /*5s*/);
RTOS_WAIT_MS(2000);
const char * result = driver->flashFirmware(&file, getBasename(filename));
@@ -534,12 +562,14 @@ bool multiFlashFirmware(uint8_t moduleIdx, const char * filename)
POPUP_INFORMATION(STR_FIRMWARE_UPDATE_SUCCESS);
}
#if defined(HARDWARE_INTERNAL_MODULE)
INTERNAL_MODULE_OFF();
#endif
EXTERNAL_MODULE_OFF();
SPORT_UPDATE_POWER_OFF();
/* wait 2s off */
watchdogSuspend(2000);
watchdogSuspend(500 /*5s*/);
RTOS_WAIT_MS(2000);
// reset telemetry protocol
+10 -6
View File
@@ -76,22 +76,26 @@ class MultiFirmwareInformation {
bool isMultiExternalFirmware() const
{
return (boardType == FIRMWARE_MULTI_STM && telemetryInversion == true && optibootSupport == true && bootloaderCheck == true && telemetryType == FIRMWARE_MULTI_TELEM_MULTI_TELEMETRY);
return (telemetryInversion == true && optibootSupport == true && bootloaderCheck == true && telemetryType == FIRMWARE_MULTI_TELEM_MULTI_TELEMETRY);
}
const char * readMultiFirmwareInformation(const char * filename);
const char * readMultiFirmwareInformation(FIL * file);
private:
uint8_t boardType;
uint8_t optibootSupport;
uint8_t bootloaderCheck;
uint8_t telemetryType;
uint8_t telemetryInversion;
bool optibootSupport:1;
bool telemetryInversion:1;
bool bootloaderCheck:1;
uint8_t boardType:2;
uint8_t telemetryType:2;
bool spare:1;
/* For future use
uint8_t firmwareVersionMajor;
uint8_t firmwareVersionMinor;
uint8_t firmwareVersionRevision;
uint8_t firmwareVersionSubRevision;
*/
const char * readV1Signature(const char * buffer);
const char * readV2Signature(const char * buffer);