Skip to content

Commit 79bec47

Browse files
committed
Merge remote-tracking branch 'remotes/esp8266/esp8266' into esp8266
Conflicts: hardware/esp8266com/esp8266/cores/esp8266/Updater.cpp hardware/esp8266com/esp8266/libraries/ESP8266WiFi/src/include/ClientContext.h
2 parents 8e50cdb + 1d0222c commit 79bec47

34 files changed

+974
-344
lines changed

boards.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ nodemcu.name=NodeMCU 0.9 (ESP-12 Module)
181181

182182
nodemcu.upload.tool=esptool
183183
nodemcu.upload.speed=115200
184-
nodemcu.upload.resetmethod=ck
184+
nodemcu.upload.resetmethod=nodemcu
185185
nodemcu.upload.maximum_size=1044464
186186
nodemcu.upload.maximum_data_size=81920
187187
nodemcu.upload.wait_for_upload_port=true

cores/esp8266/Esp.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,3 +400,26 @@ bool EspClass::updateSketch(Stream& in, uint32_t size, bool restartOnFail, bool
400400
if(restartOnSuccess) ESP.restart();
401401
return true;
402402
}
403+
404+
static const int FLASH_INT_MASK = ((B10 << 8) | B00111010);
405+
406+
bool EspClass::flashEraseSector(uint32_t sector) {
407+
ets_isr_mask(FLASH_INT_MASK);
408+
int rc = spi_flash_erase_sector(sector);
409+
ets_isr_unmask(FLASH_INT_MASK);
410+
return rc == 0;
411+
}
412+
413+
bool EspClass::flashWrite(uint32_t offset, uint32_t *data, size_t size) {
414+
ets_isr_mask(FLASH_INT_MASK);
415+
int rc = spi_flash_write(offset, (uint32_t*) data, size);
416+
ets_isr_unmask(FLASH_INT_MASK);
417+
return rc == 0;
418+
}
419+
420+
bool EspClass::flashRead(uint32_t offset, uint32_t *data, size_t size) {
421+
ets_isr_mask(FLASH_INT_MASK);
422+
int rc = spi_flash_read(offset, (uint32_t*) data, size);
423+
ets_isr_unmask(FLASH_INT_MASK);
424+
return rc == 0;
425+
}

cores/esp8266/Esp.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ class EspClass {
117117
FlashMode_t getFlashChipMode();
118118
uint32_t getFlashChipSizeByChipId();
119119

120+
bool flashEraseSector(uint32_t sector);
121+
bool flashWrite(uint32_t offset, uint32_t *data, size_t size);
122+
bool flashRead(uint32_t offset, uint32_t *data, size_t size);
123+
120124
uint32_t getSketchSize();
121125
uint32_t getFreeSketchSpace();
122126
bool updateSketch(Stream& in, uint32_t size, bool restartOnFail = false, bool restartOnSuccess = true);

cores/esp8266/FS.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,14 @@ String Dir::fileName() {
144144
return _impl->fileName();
145145
}
146146

147+
size_t Dir::fileSize() {
148+
if (!_impl) {
149+
return 0;
150+
}
151+
152+
return _impl->fileSize();
153+
}
154+
147155
bool Dir::next() {
148156
if (!_impl) {
149157
return false;

cores/esp8266/FS.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ class Dir {
7878

7979
File openFile(const char* mode);
8080
String fileName();
81+
size_t fileSize();
8182
bool next();
8283

8384
protected:

cores/esp8266/FSImpl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class DirImpl {
5656
virtual ~DirImpl() { }
5757
virtual FileImplPtr openFile(OpenMode openMode, AccessMode accessMode) = 0;
5858
virtual const char* fileName() = 0;
59+
virtual size_t fileSize() = 0;
5960
virtual bool next() = 0;
6061
};
6162

cores/esp8266/Updater.cpp

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55

66
//#define DEBUG_UPDATER Serial
77

8+
extern "C" {
9+
#include "c_types.h"
10+
#include "spi_flash.h"
11+
}
12+
813
extern "C" uint32_t _SPIFFS_start;
914

1015
UpdaterClass::UpdaterClass()
@@ -112,28 +117,14 @@ bool UpdaterClass::end(bool evenIfRemaining){
112117
return true;
113118
}
114119

115-
bool UpdaterClass::_writeBuffer() {
116-
int rc = 0;
117-
delay(2); // give the rtos some time to handle TCP
118-
{
119-
AutoInterruptLock(15);
120-
rc = SPIEraseSector(_currentAddress / FLASH_SECTOR_SIZE);
121-
}
122-
123-
delay(2); // give the rtos some time to handle TCP
124-
125-
if(!rc) {
126-
{
127-
AutoInterruptLock(15);
128-
rc = SPIWrite(_currentAddress, _buffer, _bufferLen);
129-
}
130-
}
131-
132-
delay(2); // give the rtos some time to handle TCP
120+
bool UpdaterClass::_writeBuffer(){
121+
yield();
122+
bool result = ESP.flashEraseSector(_currentAddress/FLASH_SECTOR_SIZE) &&
123+
ESP.flashWrite(_currentAddress, (uint32_t*) _buffer, _bufferLen);
133124

134-
if(rc) {
135-
_error = UPDATE_ERROR_WRITE;
136-
_currentAddress = (_startAddress + _size);
125+
if (!result) {
126+
_error = UPDATE_ERROR_WRITE;
127+
_currentAddress = (_startAddress + _size);
137128
#ifdef DEBUG_UPDATER
138129
printError(DEBUG_UPDATER);
139130
#endif

cores/esp8266/core_esp8266_noniso.c

Lines changed: 49 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ char* ultoa(unsigned long value, char* result, int base) {
148148
}
149149

150150
char * dtostrf(double number, signed char width, unsigned char prec, char *s) {
151-
151+
bool negative = false;
152+
152153
if (isnan(number)) {
153154
strcpy(s, "nan");
154155
return s;
@@ -158,50 +159,65 @@ char * dtostrf(double number, signed char width, unsigned char prec, char *s) {
158159
return s;
159160
}
160161

161-
if (number > 4294967040.0 || number < -4294967040.0) {
162-
strcpy(s, "ovf");
163-
return s;
164-
}
165-
166162
char* out = s;
167-
int signInt_Part = 1;
168-
163+
164+
int fillme = width; // how many cells to fill for the integer part
165+
if (prec > 0) {
166+
fillme -= (prec+1);
167+
}
168+
169169
// Handle negative numbers
170170
if (number < 0.0) {
171-
signInt_Part = -1;
171+
negative = true;
172+
fillme--;
172173
number = -number;
173174
}
174175

175-
// calc left over digits
176-
if (prec > 0)
177-
{
178-
width -= (prec + 1);
179-
}
180-
181176
// Round correctly so that print(1.999, 2) prints as "2.00"
182-
double rounding = 0.5;
177+
// I optimized out most of the divisions
178+
double rounding = 2.0;
183179
for (uint8_t i = 0; i < prec; ++i)
184-
rounding /= 10.0;
180+
rounding *= 10.0;
181+
rounding = 1.0 / rounding;
185182

186183
number += rounding;
187-
188-
// Extract the integer part of the number and print it
189-
unsigned long int_part = (unsigned long)number;
190-
double remainder = number - (double)int_part;
191-
out += sprintf(out, "%*ld", width, int_part * signInt_Part);
192-
193-
// Print the decimal point, but only if there are digits beyond
194-
if (prec > 0) {
195-
*out = '.';
196-
++out;
197-
198-
199-
for (unsigned char decShift = prec; decShift > 0; decShift--) {
200-
remainder *= 10.0;
201-
}
202-
sprintf(out, "%0*d", prec, (int)remainder);
184+
185+
// Figure out how big our number really is
186+
double tenpow = 1.0;
187+
int digitcount = 1;
188+
while (number >= 10.0 * tenpow) {
189+
tenpow *= 10.0;
190+
digitcount++;
191+
}
192+
193+
number /= tenpow;
194+
fillme -= digitcount;
195+
196+
// Pad unused cells with spaces
197+
while (fillme-- > 0) {
198+
*out++ = ' ';
199+
}
200+
201+
// Handle negative sign
202+
if (negative) *out++ = '-';
203+
204+
// Print the digits, and if necessary, the decimal point
205+
digitcount += prec;
206+
int8_t digit = 0;
207+
while (digitcount-- > 0) {
208+
digit = (int8_t)number;
209+
if (digit > 9) digit = 9; // insurance
210+
*out++ = (char)('0' | digit);
211+
if ((digitcount == prec) && (prec > 0)) {
212+
*out++ = '.';
213+
}
214+
number -= digit;
215+
number *= 10.0;
203216
}
204217

218+
// make sure the string is terminated
219+
*out = 0;
205220
return s;
206221
}
207222

223+

cores/esp8266/spiffs/README

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
SPIFFS (SPI Flash File System)
2-
V0.3.0
2+
V0.3.2
33

44
Copyright (c) 2013-2015 Peter Andersson (pelleplutt1976<at>gmail.com)
55

@@ -58,6 +58,30 @@ For testing and contributions, see the docs/IMPLEMENTING file.
5858

5959
* HISTORY
6060

61+
0.3.2
62+
Limit cache size if too much cache is given (thanks pgeiem)
63+
New feature - Controlled erase. #23
64+
SPIFFS_rename leaks file descriptors #28 (thanks benpicco)
65+
moved dbg print defines in test framework to params_test.h
66+
lseek should return the resulting offset (thanks hefloryd)
67+
fixed type on dbg ifdefs
68+
silence warning about signed/unsigned comparison when spiffs_obj_id is 32 bit (thanks benpicco)
69+
Possible error in test_spiffs.c #21 (thanks yihcdaso-yeskela)
70+
Cache might writethrough too often #16
71+
even moar testrunner updates
72+
Test framework update and some added tests
73+
Some thoughts for next gen
74+
Test sigsevs when having too many sectors #13 (thanks alonewolfx2)
75+
GC might be suboptimal #11
76+
Fix eternal readdir when objheader at last block, last entry
77+
78+
New API functions:
79+
SPIFFS_gc_quick - call a nonintrusive gc
80+
SPIFFS_gc - call a full-scale intrusive gc
81+
82+
0.3.1
83+
Removed two return warnings, was too triggerhappy on release
84+
6185
0.3.0
6286
Added existing namecheck when creating files
6387
Lots of static analysis bugs #6

0 commit comments

Comments
 (0)