Skip to content

Commit 0389657

Browse files
committed
give the IP stack more time to handle the data
may help with esp8266#1157
1 parent 9a096f8 commit 0389657

File tree

1 file changed

+30
-22
lines changed

1 file changed

+30
-22
lines changed

cores/esp8266/Updater.cpp

+30-22
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,14 @@ bool UpdaterClass::end(bool evenIfRemaining){
168168
}
169169

170170
bool UpdaterClass::_writeBuffer(){
171+
172+
yield();
173+
bool result = ESP.flashEraseSector(_currentAddress/FLASH_SECTOR_SIZE);
174+
yield();
175+
if (result) {
176+
result = ESP.flashWrite(_currentAddress, (uint32_t*) _buffer, _bufferLen);
177+
}
171178
yield();
172-
bool result = ESP.flashEraseSector(_currentAddress/FLASH_SECTOR_SIZE) &&
173-
ESP.flashWrite(_currentAddress, (uint32_t*) _buffer, _bufferLen);
174179

175180
if (!result) {
176181
_error = UPDATE_ERROR_WRITE;
@@ -217,29 +222,32 @@ size_t UpdaterClass::write(uint8_t *data, size_t len) {
217222
}
218223

219224
size_t UpdaterClass::writeStream(Stream &data) {
220-
size_t written = 0;
221-
size_t toRead = 0;
222-
if(hasError() || !isRunning())
223-
return 0;
224-
225-
while(remaining()) {
226-
toRead = FLASH_SECTOR_SIZE - _bufferLen;
227-
toRead = data.readBytes(_buffer + _bufferLen, toRead);
228-
if(toRead == 0){ //Timeout
229-
_error = UPDATE_ERROR_STREAM;
230-
_currentAddress = (_startAddress + _size);
225+
size_t written = 0;
226+
size_t toRead = 0;
227+
if(hasError() || !isRunning())
228+
return 0;
229+
230+
while(remaining()) {
231+
toRead = data.readBytes(_buffer + _bufferLen, (FLASH_SECTOR_SIZE - _bufferLen));
232+
if(toRead == 0) { //Timeout
233+
delay(100);
234+
toRead = data.readBytes(_buffer + _bufferLen, (FLASH_SECTOR_SIZE - _bufferLen));
235+
if(toRead == 0) { //Timeout
236+
_error = UPDATE_ERROR_STREAM;
237+
_currentAddress = (_startAddress + _size);
231238
#ifdef DEBUG_UPDATER
232-
printError(DEBUG_UPDATER);
239+
printError(DEBUG_UPDATER);
233240
#endif
234-
return written;
241+
}
242+
return written;
243+
}
244+
_bufferLen += toRead;
245+
if((_bufferLen == remaining() || _bufferLen == FLASH_SECTOR_SIZE) && !_writeBuffer())
246+
return written;
247+
written += toRead;
248+
yield();
235249
}
236-
_bufferLen += toRead;
237-
if((_bufferLen == remaining() || _bufferLen == FLASH_SECTOR_SIZE) && !_writeBuffer())
238-
return written;
239-
written += toRead;
240-
yield();
241-
}
242-
return written;
250+
return written;
243251
}
244252

245253
void UpdaterClass::printError(Stream &out){

0 commit comments

Comments
 (0)