Try to contact MPM with inverted and non-inverted RX. (#7092)
This commit is contained in:
committed by
Bertrand Songis
parent
70a9e5312a
commit
6ba214725c
@@ -33,20 +33,21 @@ class MultiFirmwareUpdateDriver
|
|||||||
const char* flashFirmware(FIL* file, const char* label) const;
|
const char* flashFirmware(FIL* file, const char* label) const;
|
||||||
|
|
||||||
protected:
|
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 bool getByte(uint8_t& byte) const = 0;
|
||||||
virtual void sendByte(uint8_t byte) const = 0;
|
virtual void sendByte(uint8_t byte) const = 0;
|
||||||
virtual void clear() const = 0;
|
virtual void clear() const = 0;
|
||||||
virtual void deinit() const {}
|
virtual void deinit(bool inverted) const {}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool getRxByte(uint8_t& byte) const;
|
bool getRxByte(uint8_t& byte) const;
|
||||||
bool checkRxByte(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 * getDeviceSignature(uint8_t* signature) const;
|
||||||
const char * loadAddress(uint32_t offset) const;
|
const char * loadAddress(uint32_t offset) const;
|
||||||
const char * progPage(uint8_t* buffer, uint16_t size) const;
|
const char * progPage(uint8_t* buffer, uint16_t size) const;
|
||||||
void leaveProgMode() const;
|
void leaveProgMode(bool inverted) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#if defined(INTERNAL_MODULE_MULTI)
|
#if defined(INTERNAL_MODULE_MULTI)
|
||||||
@@ -57,9 +58,13 @@ class MultiInternalUpdateDriver: public MultiFirmwareUpdateDriver
|
|||||||
MultiInternalUpdateDriver() {}
|
MultiInternalUpdateDriver() {}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void init() const override
|
void moduleOn() const override
|
||||||
{
|
{
|
||||||
INTERNAL_MODULE_ON();
|
INTERNAL_MODULE_ON();
|
||||||
|
}
|
||||||
|
|
||||||
|
void init(bool inverted) const override
|
||||||
|
{
|
||||||
intmoduleSerialStart(57600, true, USART_Parity_No, USART_StopBits_1, USART_WordLength_8b);
|
intmoduleSerialStart(57600, true, USART_Parity_No, USART_StopBits_1, USART_WordLength_8b);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,7 +83,7 @@ class MultiInternalUpdateDriver: public MultiFirmwareUpdateDriver
|
|||||||
intmoduleFifo.clear();
|
intmoduleFifo.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void deinit() const override
|
void deinit(bool inverted) const override
|
||||||
{
|
{
|
||||||
clear();
|
clear();
|
||||||
}
|
}
|
||||||
@@ -88,13 +93,18 @@ static const MultiInternalUpdateDriver multiInternalUpdateDriver;
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class MultiExternalSoftSerialUpdateDriver: public MultiFirmwareUpdateDriver
|
class MultiExternalUpdateDriver: public MultiFirmwareUpdateDriver
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MultiExternalSoftSerialUpdateDriver() {}
|
MultiExternalUpdateDriver() {}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void init() const override
|
void moduleOn() const override
|
||||||
|
{
|
||||||
|
EXTERNAL_MODULE_ON();
|
||||||
|
}
|
||||||
|
|
||||||
|
void init(bool inverted) const override
|
||||||
{
|
{
|
||||||
#if !defined(EXTMODULE_USART)
|
#if !defined(EXTMODULE_USART)
|
||||||
GPIO_InitTypeDef GPIO_InitStructure;
|
GPIO_InitTypeDef GPIO_InitStructure;
|
||||||
@@ -106,8 +116,10 @@ class MultiExternalSoftSerialUpdateDriver: public MultiFirmwareUpdateDriver
|
|||||||
GPIO_Init(EXTMODULE_TX_GPIO, &GPIO_InitStructure);
|
GPIO_Init(EXTMODULE_TX_GPIO, &GPIO_InitStructure);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
EXTERNAL_MODULE_ON();
|
if (inverted)
|
||||||
telemetryPortInvertedInit(57600);
|
telemetryPortInvertedInit(57600);
|
||||||
|
else
|
||||||
|
telemetryPortInit(57600, TELEMETRY_SERIAL_DEFAULT);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool getByte(uint8_t& byte) const override
|
bool getByte(uint8_t& byte) const override
|
||||||
@@ -125,14 +137,18 @@ class MultiExternalSoftSerialUpdateDriver: public MultiFirmwareUpdateDriver
|
|||||||
telemetryClearFifo();
|
telemetryClearFifo();
|
||||||
}
|
}
|
||||||
|
|
||||||
void deinit() const override
|
void deinit(bool inverted) const override
|
||||||
{
|
{
|
||||||
telemetryPortInvertedInit(0);
|
if (inverted)
|
||||||
|
telemetryPortInvertedInit(0);
|
||||||
|
else
|
||||||
|
telemetryPortInit(0, 0);
|
||||||
|
|
||||||
clear();
|
clear();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
static const MultiExternalSoftSerialUpdateDriver multiExternalSoftSerialUpdateDriver;
|
static const MultiExternalUpdateDriver multiExternalUpdateDriver;
|
||||||
|
|
||||||
bool MultiFirmwareUpdateDriver::getRxByte(uint8_t& byte) const
|
bool MultiFirmwareUpdateDriver::getRxByte(uint8_t& byte) const
|
||||||
{
|
{
|
||||||
@@ -159,13 +175,21 @@ bool MultiFirmwareUpdateDriver::checkRxByte(uint8_t byte) const
|
|||||||
return getRxByte(rxchar) ? rxchar == byte : false;
|
return getRxByte(rxchar) ? rxchar == byte : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char * MultiFirmwareUpdateDriver::waitForInitialSync() const
|
const char * MultiFirmwareUpdateDriver::waitForInitialSync(bool& inverted) const
|
||||||
{
|
{
|
||||||
uint8_t byte;
|
uint8_t byte;
|
||||||
int retries = 1000;
|
int retries = 200;
|
||||||
|
|
||||||
clear();
|
clear();
|
||||||
do {
|
do {
|
||||||
|
|
||||||
|
// Invert at half-time
|
||||||
|
if (retries == 100) {
|
||||||
|
deinit(inverted);
|
||||||
|
inverted = !inverted;
|
||||||
|
init(inverted);
|
||||||
|
}
|
||||||
|
|
||||||
// Send sync request
|
// Send sync request
|
||||||
sendByte(STK_GET_SYNC);
|
sendByte(STK_GET_SYNC);
|
||||||
sendByte(CRC_EOP);
|
sendByte(CRC_EOP);
|
||||||
@@ -195,6 +219,7 @@ const char * MultiFirmwareUpdateDriver::getDeviceSignature(uint8_t* signature) c
|
|||||||
// Read signature
|
// Read signature
|
||||||
sendByte(STK_READ_SIGN);
|
sendByte(STK_READ_SIGN);
|
||||||
sendByte(CRC_EOP);
|
sendByte(CRC_EOP);
|
||||||
|
clear();
|
||||||
|
|
||||||
if (!checkRxByte(STK_INSYNC))
|
if (!checkRxByte(STK_INSYNC))
|
||||||
return "NoSync";
|
return "NoSync";
|
||||||
@@ -254,35 +279,38 @@ const char * MultiFirmwareUpdateDriver::progPage(uint8_t* buffer, uint16_t size)
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MultiFirmwareUpdateDriver::leaveProgMode() const
|
void MultiFirmwareUpdateDriver::leaveProgMode(bool inverted) const
|
||||||
{
|
{
|
||||||
sendByte(STK_LEAVE_PROGMODE);
|
sendByte(STK_LEAVE_PROGMODE);
|
||||||
sendByte(CRC_EOP);
|
sendByte(CRC_EOP);
|
||||||
|
|
||||||
// eat last sync byte
|
// eat last sync byte
|
||||||
checkRxByte(STK_INSYNC);
|
checkRxByte(STK_INSYNC);
|
||||||
deinit();
|
deinit(inverted);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char * MultiFirmwareUpdateDriver::flashFirmware(FIL* file, const char* label) const
|
const char * MultiFirmwareUpdateDriver::flashFirmware(FIL* file, const char* label) const
|
||||||
{
|
{
|
||||||
const char* result = nullptr;
|
const char* result = nullptr;
|
||||||
init();
|
moduleOn();
|
||||||
|
|
||||||
|
bool inverted = true; //false; // true
|
||||||
|
init(inverted);
|
||||||
|
|
||||||
/* wait 500ms for power on */
|
/* wait 500ms for power on */
|
||||||
watchdogSuspend(500);
|
watchdogSuspend(500);
|
||||||
RTOS_WAIT_MS(500);
|
RTOS_WAIT_MS(500);
|
||||||
|
|
||||||
result = waitForInitialSync();
|
result = waitForInitialSync(inverted);
|
||||||
if (result) {
|
if (result) {
|
||||||
leaveProgMode();
|
leaveProgMode(inverted);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char signature[4]; // 3 bytes signature + STK_OK
|
unsigned char signature[4]; // 3 bytes signature + STK_OK
|
||||||
result = getDeviceSignature(signature);
|
result = getDeviceSignature(signature);
|
||||||
if (result) {
|
if (result) {
|
||||||
leaveProgMode();
|
leaveProgMode(inverted);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -291,7 +319,7 @@ const char * MultiFirmwareUpdateDriver::flashFirmware(FIL* file, const char* lab
|
|||||||
uint32_t writeOffset = 0;
|
uint32_t writeOffset = 0;
|
||||||
|
|
||||||
if (signature[0] != 0x1E) {
|
if (signature[0] != 0x1E) {
|
||||||
leaveProgMode();
|
leaveProgMode(inverted);
|
||||||
return "Wrong signature";
|
return "Wrong signature";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -333,7 +361,7 @@ const char * MultiFirmwareUpdateDriver::flashFirmware(FIL* file, const char* lab
|
|||||||
drawProgressScreen(label, STR_WRITING, file->fptr, file->obj.objsize);
|
drawProgressScreen(label, STR_WRITING, file->fptr, file->obj.objsize);
|
||||||
}
|
}
|
||||||
|
|
||||||
leaveProgMode();
|
leaveProgMode(inverted);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -484,7 +512,7 @@ bool multiFlashFirmware(uint8_t moduleIdx, const char * filename)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const MultiFirmwareUpdateDriver* driver = &multiExternalSoftSerialUpdateDriver;
|
const MultiFirmwareUpdateDriver* driver = &multiExternalUpdateDriver;
|
||||||
#if defined(INTERNAL_MODULE_MULTI)
|
#if defined(INTERNAL_MODULE_MULTI)
|
||||||
if (moduleIdx == INTERNAL_MODULE)
|
if (moduleIdx == INTERNAL_MODULE)
|
||||||
driver = &multiInternalUpdateDriver;
|
driver = &multiInternalUpdateDriver;
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ class MultiFirmwareInformation {
|
|||||||
|
|
||||||
bool isMultiExternalFirmware() const
|
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(const char * filename);
|
||||||
|
|||||||
Reference in New Issue
Block a user