|
|
@ -110,23 +110,16 @@ const char *resultMessages[] = { |
|
|
|
// 230400b always manages to connect.
|
|
|
|
static const uint32_t uploadBaudRates[] = { 460800, 230400, 115200, 74880 }; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
signed char IsReady() { |
|
|
|
return esp_upload.state == upload_idle; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void uploadPort_write(const uint8_t *buf, size_t len) { |
|
|
|
#if 0 |
|
|
|
int i; |
|
|
|
|
|
|
|
for (i = 0; i < len; i++) { |
|
|
|
while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET); |
|
|
|
|
|
|
|
while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET) { /* nada */ } |
|
|
|
USART_SendData(USART1, *(buf + i)); |
|
|
|
} |
|
|
|
#endif |
|
|
@ -138,28 +131,22 @@ char uploadPort_read() { |
|
|
|
return retChar; |
|
|
|
else |
|
|
|
return 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
int uploadPort_available() { |
|
|
|
return usartFifoAvailable(&WifiRxFifo); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void uploadPort_begin() { |
|
|
|
esp_port_begin(1); |
|
|
|
} |
|
|
|
|
|
|
|
void uploadPort_close() { |
|
|
|
|
|
|
|
//WIFI_COM.end();
|
|
|
|
//WIFI_COM.begin(115200, true);
|
|
|
|
|
|
|
|
esp_port_begin(0); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void flushInput() { |
|
|
|
while (uploadPort_available() != 0) { |
|
|
|
(void)uploadPort_read(); |
|
|
@ -304,7 +291,6 @@ EspUploadResult readPacket(uint8_t op, uint32_t *valp, size_t *bodyLen, uint32_t |
|
|
|
|
|
|
|
*bodyLen = 0; |
|
|
|
|
|
|
|
|
|
|
|
while (state != done) { |
|
|
|
uint8_t c; |
|
|
|
EspUploadResult stat; |
|
|
@ -397,7 +383,7 @@ EspUploadResult readPacket(uint8_t op, uint32_t *valp, size_t *bodyLen, uint32_t |
|
|
|
opRet = (uint8_t)getData(1, hdr, 1); |
|
|
|
// Sync packets often provoke a response with a zero opcode instead of ESP_SYNC
|
|
|
|
if (resp != 0x01 || opRet != op) { |
|
|
|
//debug//printf("resp %02x %02x\n", resp, opRet);
|
|
|
|
//printf("resp %02x %02x\n", resp, opRet); //debug
|
|
|
|
return respHeader; |
|
|
|
} |
|
|
|
|
|
|
@ -432,7 +418,6 @@ void _writePacket(const uint8_t *data, size_t len) { |
|
|
|
// 0xC0 and 0xDB replaced by the two-byte sequences {0xDB, 0xDC} and {0xDB, 0xDD} respectively.
|
|
|
|
|
|
|
|
void writePacket(const uint8_t *hdr, size_t hdrLen, const uint8_t *data, size_t dataLen) { |
|
|
|
|
|
|
|
WriteByteRaw(0xC0); // send the packet start character
|
|
|
|
_writePacket(hdr, hdrLen); // send the header
|
|
|
|
_writePacket(data, dataLen); // send the data block
|
|
|
@ -460,13 +445,11 @@ void sendCommand(uint8_t op, uint32_t checkVal, const uint8_t *data, size_t data |
|
|
|
|
|
|
|
// send the packet
|
|
|
|
//flushInput();
|
|
|
|
if (op == ESP_SYNC) { |
|
|
|
if (op == ESP_SYNC) |
|
|
|
writePacketRaw(hdr, sizeof(hdr), data, dataLen); |
|
|
|
} |
|
|
|
else { |
|
|
|
else |
|
|
|
writePacket(hdr, sizeof(hdr), data, dataLen); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// Send a command to the attached device together with the supplied data, if any, and get the response
|
|
|
|
EspUploadResult doCommand(uint8_t op, const uint8_t *data, size_t dataLen, uint32_t checkVal, uint32_t *valp, uint32_t msTimeout) { |
|
|
@ -476,9 +459,8 @@ EspUploadResult doCommand(uint8_t op, const uint8_t *data, size_t dataLen, uint3 |
|
|
|
sendCommand(op, checkVal, data, dataLen); |
|
|
|
|
|
|
|
stat = readPacket(op, valp, &bodyLen, msTimeout); |
|
|
|
if (stat == success && bodyLen != 2) { |
|
|
|
if (stat == success && bodyLen != 2) |
|
|
|
stat = badReply; |
|
|
|
} |
|
|
|
|
|
|
|
return stat; |
|
|
|
} |
|
|
@ -611,6 +593,8 @@ EspUploadResult flashWriteBlock(uint16_t flashParmVal, uint16_t flashParmMask) { |
|
|
|
//printf("Upload %d\%\n", ftell(&esp_upload.uploadFile) * 100 / esp_upload.fileSize);
|
|
|
|
|
|
|
|
return stat; |
|
|
|
#else |
|
|
|
return success; |
|
|
|
#endif |
|
|
|
} |
|
|
|
|
|
|
@ -634,7 +618,6 @@ void upload_spin() { |
|
|
|
//uploadPort.begin(baud);
|
|
|
|
//uploadPort_close();
|
|
|
|
|
|
|
|
|
|
|
|
uploadPort_begin(); |
|
|
|
|
|
|
|
wifi_delay(2000); |
|
|
@ -654,7 +637,7 @@ void upload_spin() { |
|
|
|
esp_upload.lastAttemptTime = getWifiTick(); |
|
|
|
if (res == success) { |
|
|
|
// Successful connection
|
|
|
|
// //MessageF(" success on attempt %d\n", (connectAttemptNumber % retriesPerBaudRate) + 1);
|
|
|
|
//MessageF(" success on attempt %d\n", (connectAttemptNumber % retriesPerBaudRate) + 1);
|
|
|
|
//printf("connect success\n");
|
|
|
|
esp_upload.state = erasing; |
|
|
|
} |
|
|
@ -675,11 +658,10 @@ void upload_spin() { |
|
|
|
const uint32_t sectorSize = 4096; |
|
|
|
const uint32_t numSectors = (esp_upload.fileSize + sectorSize - 1)/sectorSize; |
|
|
|
const uint32_t startSector = esp_upload.uploadAddress/sectorSize; |
|
|
|
|
|
|
|
uint32_t headSectors = sectorsPerBlock - (startSector % sectorsPerBlock); |
|
|
|
NOMORE(headSectors, numSectors); |
|
|
|
|
|
|
|
if (numSectors < headSectors) { |
|
|
|
headSectors = numSectors; |
|
|
|
} |
|
|
|
eraseSize = (numSectors < 2 * headSectors) |
|
|
|
? (numSectors + 1) / 2 * sectorSize |
|
|
|
: (numSectors - headSectors) * sectorSize; |
|
|
|