Skip to content

Commit a00a474

Browse files
authored
Update EEPROM.cpp (esp8266#6599)
use InterruptLock class for scoped interrupts instead of blindly disabling/enabling interrupts, which doesn't support nesting nor restore previous state. Add forgotten include Remove locks, simplify code Fix typo Drop needless include
1 parent 08a0414 commit a00a474

File tree

1 file changed

+7
-18
lines changed

1 file changed

+7
-18
lines changed

libraries/EEPROM/EEPROM.cpp

+7-18
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,8 @@ void EEPROMClass::begin(size_t size) {
7171

7272
_size = size;
7373

74-
noInterrupts();
75-
auto ret = spi_flash_read(_sector * SPI_FLASH_SEC_SIZE, reinterpret_cast<uint32_t*>(_data), _size);
76-
interrupts();
77-
if (ret != SPI_FLASH_RESULT_OK) {
78-
DEBUGV("EEPROMClass::begin spi_flash_read failed, %d\n", (int)ret);
74+
if (!ESP.flashRead(_sector * SPI_FLASH_SEC_SIZE, reinterpret_cast<uint32_t*>(_data), _size)) {
75+
DEBUGV("EEPROMClass::begin flash read failed\n");
7976
}
8077

8178
_dirty = false; //make sure dirty is cleared in case begin() is called 2nd+ time
@@ -128,30 +125,22 @@ void EEPROMClass::write(int const address, uint8_t const value) {
128125
}
129126

130127
bool EEPROMClass::commit() {
131-
bool ret = false;
132128
if (!_size)
133129
return false;
134130
if(!_dirty)
135131
return true;
136132
if(!_data)
137133
return false;
138134

139-
noInterrupts();
140-
auto flashret = spi_flash_erase_sector(_sector);
141-
if (flashret == SPI_FLASH_RESULT_OK) {
142-
flashret = spi_flash_write(_sector * SPI_FLASH_SEC_SIZE, reinterpret_cast<uint32_t*>(_data), _size);
143-
if (flashret == SPI_FLASH_RESULT_OK) {
135+
if (ESP.flashEraseSector(_sector)) {
136+
if (ESP.flashWrite(_sector * SPI_FLASH_SEC_SIZE, reinterpret_cast<uint32_t*>(_data), _size)) {
144137
_dirty = false;
145-
ret = true;
138+
return true;
146139
}
147140
}
148-
interrupts();
149141

150-
if (flashret != SPI_FLASH_RESULT_OK) {
151-
DEBUGV("EEPROMClass::commit failed, %d\n", (int)flashret);
152-
}
153-
154-
return ret;
142+
DEBUGV("EEPROMClass::commit failed\n");
143+
return false;
155144
}
156145

157146
uint8_t * EEPROMClass::getDataPtr() {

0 commit comments

Comments
 (0)