Skip to content

Commit 1529d70

Browse files
ficetoficeto
ficeto
authored and
ficeto
committed
disable all interrupts when reading from spiffs
this fixes any possible resets caused by interrupt routines trying to read the flash while there is an ongoing spiffs operation
1 parent 1eb2ee6 commit 1529d70

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

hardware/esp8266com/esp8266/cores/esp8266/Arduino.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ void ets_intr_unlock();
135135
extern uint32_t interruptsState;
136136

137137
#define interrupts() xt_enable_interrupts(interruptsState)
138-
#define noInterrupts() xt_disable_interrupts(interruptsState, 15)
138+
#define noInterrupts() __asm__ __volatile__("rsil %0,15; esync; isync; dsync" : "=a" (interruptsState))
139139

140140
#define clockCyclesPerMicrosecond() ( F_CPU / 1000000L )
141141
#define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() )

hardware/esp8266com/esp8266/cores/esp8266/spiffs/spiffs_flashmem.c

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "flashmem.h"
22
#include "esp8266_peri.h"
3+
#include "Arduino.h"
34

45
// Based on NodeMCU platform_flash
56
// https://github.com/nodemcu/nodemcu-firmware
@@ -98,7 +99,10 @@ uint32_t flashmem_read( void *to, uint32_t fromaddr, uint32_t size )
9899
bool flashmem_erase_sector( uint32_t sector_id )
99100
{
100101
WDT_RESET();
101-
return spi_flash_erase_sector( sector_id ) == SPI_FLASH_RESULT_OK;
102+
noInterrupts();
103+
bool erased = spi_flash_erase_sector( sector_id ) == SPI_FLASH_RESULT_OK;
104+
interrupts();
105+
return erased;
102106
}
103107

104108
SPIFlashInfo flashmem_get_info()
@@ -186,9 +190,9 @@ uint32_t flashmem_write_internal( const void *from, uint32_t toaddr, uint32_t si
186190
os_memcpy(apbuf, from, size);
187191
}
188192
WDT_RESET();
189-
ETS_UART_INTR_DISABLE();
193+
noInterrupts();
190194
r = spi_flash_write(toaddr, apbuf?(uint32 *)apbuf:(uint32 *)from, size);
191-
ETS_UART_INTR_ENABLE();
195+
interrupts();
192196
if(apbuf)
193197
os_free(apbuf);
194198
if(SPI_FLASH_RESULT_OK == r)
@@ -204,9 +208,9 @@ uint32_t flashmem_read_internal( void *to, uint32_t fromaddr, uint32_t size )
204208
fromaddr -= INTERNAL_FLASH_START_ADDRESS;
205209
SpiFlashOpResult r;
206210
WDT_RESET();
207-
ETS_UART_INTR_DISABLE();
211+
noInterrupts();
208212
r = spi_flash_read(fromaddr, (uint32 *)to, size);
209-
ETS_UART_INTR_ENABLE();
213+
interrupts();
210214
if(SPI_FLASH_RESULT_OK == r)
211215
return size;
212216
else{

0 commit comments

Comments
 (0)