diff options
author | David Crocker <dcrocker@eschertech.com> | 2017-12-23 20:44:33 +0300 |
---|---|---|
committer | David Crocker <dcrocker@eschertech.com> | 2017-12-23 20:44:33 +0300 |
commit | 01055ad6390f6b81eb71480d01ee38dc336055e0 (patch) | |
tree | c6099a76ee9d22f82e13fc04f539689d81348d4d | |
parent | 51b64dfeac44ce1e11299df66672eae1bb83d4a0 (diff) |
Version 1.20v1.20
Fixed sending of motor currents to DWC
Immediate LCD messages are now sent in a more timely manner
Clear system paramerters area when uploading new wifi firmware
Baud rates for wifi firmware upload now start at 230400 and end at 9600
-rw-r--r-- | src/Network2/ESP8266/WifiFirmwareUploader.cpp | 62 | ||||
-rw-r--r-- | src/Network2/ESP8266/WifiFirmwareUploader.h | 14 | ||||
-rw-r--r-- | src/Platform.cpp | 16 | ||||
-rw-r--r-- | src/Platform.h | 1 | ||||
-rw-r--r-- | src/RepRap.cpp | 2 | ||||
-rw-r--r-- | src/SAME70_TEST/WifiFirmwareUploader.cpp | 58 | ||||
-rw-r--r-- | src/SAME70_TEST/WifiFirmwareUploader.h | 6 | ||||
-rw-r--r-- | src/Version.h | 4 |
8 files changed, 110 insertions, 53 deletions
diff --git a/src/Network2/ESP8266/WifiFirmwareUploader.cpp b/src/Network2/ESP8266/WifiFirmwareUploader.cpp index 0e8c1800..40861f2c 100644 --- a/src/Network2/ESP8266/WifiFirmwareUploader.cpp +++ b/src/Network2/ESP8266/WifiFirmwareUploader.cpp @@ -64,7 +64,7 @@ const char * const resultMessages[] = // Probably our UART ISR cannot receive bytes fast enough, perhaps because of the latency of the system tick ISR. // 460800b doesn't always manage to connect, but if it does then uploading appears to be reliable. // 230400b always manages to connect. -static const uint32_t uploadBaudRates[] = { 460800, 230400, 115200, 74880 }; +static const uint32_t uploadBaudRates[] = { 230400, 115200, 74880, 9600 }; WifiFirmwareUploader::WifiFirmwareUploader(UARTClass& port) : uploadPort(port), uploadFile(nullptr), state(UploadState::idle) @@ -470,8 +470,7 @@ WifiFirmwareUploader::EspUploadResult WifiFirmwareUploader::Sync(uint16_t timeou WifiFirmwareUploader::EspUploadResult WifiFirmwareUploader::flashBegin(uint32_t addr, uint32_t size) { // determine the number of blocks represented by the size - uint32_t blkCnt; - blkCnt = (size + EspFlashBlockSize - 1) / EspFlashBlockSize; + const uint32_t blkCnt = (size + EspFlashBlockSize - 1) / EspFlashBlockSize; // ensure that the address is on a block boundary addr &= ~(EspFlashBlockSize - 1); @@ -562,6 +561,26 @@ WifiFirmwareUploader::EspUploadResult WifiFirmwareUploader::flashWriteBlock(uint return stat; } +WifiFirmwareUploader::EspUploadResult WifiFirmwareUploader::DoErase(uint32_t address, uint32_t size) +{ + const uint32_t sectorsPerBlock = 16; + const uint32_t sectorSize = 4096; + const uint32_t numSectors = (size + sectorSize - 1)/sectorSize; + const uint32_t startSector = address/sectorSize; + uint32_t headSectors = sectorsPerBlock - (startSector % sectorsPerBlock); + + if (numSectors < headSectors) + { + headSectors = numSectors; + } + const uint32_t eraseSize = (numSectors < 2 * headSectors) + ? (numSectors + 1) / 2 * sectorSize + : (numSectors - headSectors) * sectorSize; + + MessageF("Erasing %u bytes...\n", eraseSize); + return flashBegin(uploadAddress, eraseSize); +} + void WifiFirmwareUploader::Spin() { switch (state) @@ -602,7 +621,7 @@ void WifiFirmwareUploader::Spin() // Successful connection // MessageF(" success on attempt %d\n", (connectAttemptNumber % retriesPerBaudRate) + 1); MessageF(" success\n"); - state = UploadState::erasing; + state = UploadState::erasing1; } else { @@ -620,25 +639,26 @@ void WifiFirmwareUploader::Spin() } break; - case UploadState::erasing: + case UploadState::erasing1: if (millis() - lastAttemptTime >= blockWriteInterval) { - const uint32_t sectorsPerBlock = 16; - const uint32_t sectorSize = 4096; - const uint32_t numSectors = (fileSize + sectorSize - 1)/sectorSize; - const uint32_t startSector = uploadAddress/sectorSize; - uint32_t headSectors = sectorsPerBlock - (startSector % sectorsPerBlock); - - if (numSectors < headSectors) + uploadResult = DoErase(systemParametersAddress, systemParametersSize); + if (uploadResult == EspUploadResult::success) { - headSectors = numSectors; + state = UploadState::erasing2; } - const uint32_t eraseSize = (numSectors < 2 * headSectors) - ? (numSectors + 1) / 2 * sectorSize - : (numSectors - headSectors) * sectorSize; + else + { + MessageF("Erase failed\n"); + state = UploadState::done; + } + } + break; - MessageF("Erasing %u bytes...\n", fileSize); - uploadResult = flashBegin(uploadAddress, eraseSize); + case UploadState::erasing2: + if (millis() - lastAttemptTime >= blockWriteInterval) + { + uploadResult = DoErase(uploadAddress, fileSize); if (uploadResult == EspUploadResult::success) { MessageF("Uploading file...\n"); @@ -701,7 +721,7 @@ void WifiFirmwareUploader::Spin() } else { - reprap.GetPlatform().MessageF(FirmwareUpdateMessage, "Error: Installation failed due to %s error\n", resultMessages[(size_t)uploadResult]); + MessageF("Error: Installation failed due to %s error\n", resultMessages[(size_t)uploadResult]); // Not safe to restart the network reprap.GetNetwork().ResetWiFi(); } @@ -720,7 +740,7 @@ void WifiFirmwareUploader::SendUpdateFile(const char *file, const char *dir, uin uploadFile = platform.OpenFile(dir, file, OpenMode::read); if (uploadFile == nullptr) { - platform.MessageF(FirmwareUpdateMessage, "Failed to open file %s\n", file); + MessageF("Failed to open file %s\n", file); return; } @@ -728,7 +748,7 @@ void WifiFirmwareUploader::SendUpdateFile(const char *file, const char *dir, uin if (fileSize == 0) { uploadFile->Close(); - platform.MessageF(FirmwareUpdateMessage, "Upload file is empty %s\n", file); + MessageF("Upload file is empty %s\n", file); return; } diff --git a/src/Network2/ESP8266/WifiFirmwareUploader.h b/src/Network2/ESP8266/WifiFirmwareUploader.h index dc7a0a3d..1fd4195b 100644 --- a/src/Network2/ESP8266/WifiFirmwareUploader.h +++ b/src/Network2/ESP8266/WifiFirmwareUploader.h @@ -22,16 +22,18 @@ public: static const uint32_t WebFilesAddress = 0x00100000; private: - static const uint32_t defaultTimeout = 500; // default timeout in milliseconds + static const uint32_t defaultTimeout = 500; // default timeout in milliseconds static const uint32_t syncTimeout = 1000; static const unsigned int retriesPerBaudRate = 9; static const unsigned int retriesPerReset = 3; static const uint32_t connectAttemptInterval = 50; static const uint32_t resetDelay = 500; - static const uint32_t blockWriteInterval = 15; // 15ms is long enough, 10ms is mostly too short + static const uint32_t blockWriteInterval = 15; // 15ms is long enough, 10ms is mostly too short static const uint32_t blockWriteTimeout = 200; - static const uint32_t eraseTimeout = 15000; // increased from 12 to 15 seconds because Roland's board was timing out - static const unsigned int percentToReportIncrement = 5; // how often we report % complete + static const uint32_t eraseTimeout = 15000; // increased from 12 to 15 seconds because Roland's board was timing out + static const unsigned int percentToReportIncrement = 5; // how often we report % complete + static const uint32_t systemParametersAddress = 0x3FE000; // the address of the system + user parameter area that needs to be cleared when changing SDK version + static const uint32_t systemParametersSize = 0x2000; // the size of the system + user parameter area // Return codes - this list must be kept in step with the corresponding messages enum class EspUploadResult @@ -53,7 +55,8 @@ private: idle, resetting, connecting, - erasing, + erasing1, + erasing2, uploading, done }; @@ -77,6 +80,7 @@ private: EspUploadResult flashFinish(bool reboot); static uint16_t checksum(const uint8_t *data, uint16_t dataLen, uint16_t cksum); EspUploadResult flashWriteBlock(uint16_t flashParmVal, uint16_t flashParmMask); + EspUploadResult DoErase(uint32_t address, uint32_t size); UARTClass& uploadPort; FileStore *uploadFile; diff --git a/src/Platform.cpp b/src/Platform.cpp index 86f820bb..4c54bc67 100644 --- a/src/Platform.cpp +++ b/src/Platform.cpp @@ -1231,7 +1231,8 @@ void Platform::SendAuxMessage(const char* msg) buf->copy("{\"message\":"); buf->EncodeString(msg, strlen(msg), false, true); buf->cat("}\n"); - Message(LcdMessage, buf); + auxOutput->Push(buf); + FlushAuxMessages(); } } @@ -1310,7 +1311,7 @@ void Platform::SetNetMask(byte nm[]) } // Flush messages to USB and aux, returning true if there is more to send -bool Platform::FlushMessages() +bool Platform::FlushAuxMessages() { // Write non-blocking data to the AUX line OutputBuffer *auxOutputBuffer = auxOutput->GetFirstItem(); @@ -1328,6 +1329,13 @@ bool Platform::FlushMessages() auxOutput->SetFirstItem(auxOutputBuffer); } } + return auxOutput->GetFirstItem() != nullptr; +} + +// Flush messages to USB and aux, returning true if there is more to send +bool Platform::FlushMessages() +{ + const bool auxHasMore = FlushAuxMessages(); #ifdef SERIAL_AUX2_DEVICE // Write non-blocking data to the second AUX line @@ -1375,7 +1383,7 @@ bool Platform::FlushMessages() } } - return auxOutput->GetFirstItem() != nullptr + return auxHasMore #ifdef SERIAL_AUX2_DEVICE || aux2Output->GetFirstItem() != nullptr #endif @@ -3459,7 +3467,7 @@ void Platform::RawMessage(MessageType type, const char *message) logger->LogMessage(realTime, message); } - // Send the nessage to the destinations + // Send the message to the destinations if ((type & ImmediateLcdMessage) != 0) { SendAuxMessage(message); diff --git a/src/Platform.h b/src/Platform.h index 9f7dc46c..21fa55aa 100644 --- a/src/Platform.h +++ b/src/Platform.h @@ -387,6 +387,7 @@ public: void Message(MessageType type, OutputBuffer *buffer); void MessageF(MessageType type, const char *fmt, ...) __attribute__ ((format (printf, 3, 4))); void MessageF(MessageType type, const char *fmt, va_list vargs); + bool FlushAuxMessages(); bool FlushMessages(); // Flush messages to USB and aux, returning true if there is more to send void SendAlert(MessageType mt, const char *message, const char *title, int sParam, float tParam, AxesBitmap controls); void StopLogging(); diff --git a/src/RepRap.cpp b/src/RepRap.cpp index 60da2d49..78eb9ac8 100644 --- a/src/RepRap.cpp +++ b/src/RepRap.cpp @@ -1186,7 +1186,7 @@ OutputBuffer *RepRap::GetConfigResponse() ch = '['; for (size_t drive = 0; drive < DRIVES; drive++) { - response->catf("%c%.2f", ch, (double)(platform->GetMotorCurrent(drive, false))); + response->catf("%c%.2f", ch, (double)(platform->GetMotorCurrent(drive, 906))); ch = ','; } diff --git a/src/SAME70_TEST/WifiFirmwareUploader.cpp b/src/SAME70_TEST/WifiFirmwareUploader.cpp index 9d77f18d..d4e41838 100644 --- a/src/SAME70_TEST/WifiFirmwareUploader.cpp +++ b/src/SAME70_TEST/WifiFirmwareUploader.cpp @@ -44,7 +44,7 @@ const uint32_t ESP_FLASH_ADDR = 0x40200000; // address of start of Flash const uint32_t ESP_FLASH_READ_STUB_BEGIN = IRAM_ADDR + 0x18; // Messages corresponding to result codes, should make sense when followed by " error" -const char *resultMessages[] = +const char * const resultMessages[] = { "no", "timeout", @@ -65,7 +65,7 @@ const char *resultMessages[] = // Probably our UART ISR cannot receive bytes fast enough, perhaps because of the latency of the system tick ISR. // 460800b doesn't always manage to connect, but if it does then uploading appears to be reliable. // 230400b always manages to connect. -static const uint32_t uploadBaudRates[] = { 460800, 230400, 115200, 74880 }; +static const uint32_t uploadBaudRates[] = { 230400, 115200, 74880, 9600 }; WifiFirmwareUploader::WifiFirmwareUploader(UARTClass& port, WiFiInterface& iface) : uploadPort(port), interface(iface), uploadFile(nullptr), state(UploadState::idle) @@ -471,8 +471,7 @@ WifiFirmwareUploader::EspUploadResult WifiFirmwareUploader::Sync(uint16_t timeou WifiFirmwareUploader::EspUploadResult WifiFirmwareUploader::flashBegin(uint32_t addr, uint32_t size) { // determine the number of blocks represented by the size - uint32_t blkCnt; - blkCnt = (size + EspFlashBlockSize - 1) / EspFlashBlockSize; + const uint32_t blkCnt = (size + EspFlashBlockSize - 1) / EspFlashBlockSize; // ensure that the address is on a block boundary addr &= ~(EspFlashBlockSize - 1); @@ -563,6 +562,26 @@ WifiFirmwareUploader::EspUploadResult WifiFirmwareUploader::flashWriteBlock(uint return stat; } +WifiFirmwareUploader::EspUploadResult WifiFirmwareUploader::DoErase(uint32_t address, uint32_t size) +{ + const uint32_t sectorsPerBlock = 16; + const uint32_t sectorSize = 4096; + const uint32_t numSectors = (size + sectorSize - 1)/sectorSize; + const uint32_t startSector = address/sectorSize; + uint32_t headSectors = sectorsPerBlock - (startSector % sectorsPerBlock); + + if (numSectors < headSectors) + { + headSectors = numSectors; + } + const uint32_t eraseSize = (numSectors < 2 * headSectors) + ? (numSectors + 1) / 2 * sectorSize + : (numSectors - headSectors) * sectorSize; + + MessageF("Erasing %u bytes...\n", eraseSize); + return flashBegin(uploadAddress, eraseSize); +} + void WifiFirmwareUploader::Spin() { switch (state) @@ -603,7 +622,7 @@ void WifiFirmwareUploader::Spin() // Successful connection // MessageF(" success on attempt %d\n", (connectAttemptNumber % retriesPerBaudRate) + 1); MessageF(" success\n"); - state = UploadState::erasing; + state = UploadState::erasing1; } else { @@ -621,25 +640,26 @@ void WifiFirmwareUploader::Spin() } break; - case UploadState::erasing: + case UploadState::erasing1: if (millis() - lastAttemptTime >= blockWriteInterval) { - const uint32_t sectorsPerBlock = 16; - const uint32_t sectorSize = 4096; - const uint32_t numSectors = (fileSize + sectorSize - 1)/sectorSize; - const uint32_t startSector = uploadAddress/sectorSize; - uint32_t headSectors = sectorsPerBlock - (startSector % sectorsPerBlock); - - if (numSectors < headSectors) + uploadResult = DoErase(systemParametersAddress, systemParametersSize); + if (uploadResult == EspUploadResult::success) { - headSectors = numSectors; + state = UploadState::erasing2; } - const uint32_t eraseSize = (numSectors < 2 * headSectors) - ? (numSectors + 1) / 2 * sectorSize - : (numSectors - headSectors) * sectorSize; + else + { + MessageF("Erase failed\n"); + state = UploadState::done; + } + } + break; - MessageF("Erasing %u bytes...\n", fileSize); - uploadResult = flashBegin(uploadAddress, eraseSize); + case UploadState::erasing2: + if (millis() - lastAttemptTime >= blockWriteInterval) + { + uploadResult = DoErase(uploadAddress, fileSize); if (uploadResult == EspUploadResult::success) { MessageF("Uploading file...\n"); diff --git a/src/SAME70_TEST/WifiFirmwareUploader.h b/src/SAME70_TEST/WifiFirmwareUploader.h index bb7ea506..ef815f87 100644 --- a/src/SAME70_TEST/WifiFirmwareUploader.h +++ b/src/SAME70_TEST/WifiFirmwareUploader.h @@ -34,6 +34,8 @@ private: static const uint32_t blockWriteTimeout = 200; static const uint32_t eraseTimeout = 15000; // increased from 12 to 15 seconds because Roland's board was timing out static const unsigned int percentToReportIncrement = 5; // how often we report % complete + static const uint32_t systemParametersAddress = 0x3FE000; // the address of the system + user parameter area that needs to be cleared when changing SDK version + static const uint32_t systemParametersSize = 0x2000; // the size of the system + user parameter area // Return codes - this list must be kept in step with the corresponding messages enum class EspUploadResult @@ -55,7 +57,8 @@ private: idle, resetting, connecting, - erasing, + erasing1, + erasing2, uploading, done }; @@ -79,6 +82,7 @@ private: EspUploadResult flashFinish(bool reboot); static uint16_t checksum(const uint8_t *data, uint16_t dataLen, uint16_t cksum); EspUploadResult flashWriteBlock(uint16_t flashParmVal, uint16_t flashParmMask); + EspUploadResult DoErase(uint32_t address, uint32_t size); UARTClass& uploadPort; WiFiInterface& interface; diff --git a/src/Version.h b/src/Version.h index 5e164720..ad59f43f 100644 --- a/src/Version.h +++ b/src/Version.h @@ -9,11 +9,11 @@ #define SRC_VERSION_H_ #ifndef VERSION -# define VERSION "1.20RC4" +# define VERSION "1.20" #endif #ifndef DATE -# define DATE "2017-12-20" +# define DATE "2017-12-23" #endif #define AUTHORS "reprappro, dc42, chrishamm, t3p3, dnewman" |