Skip to content

Commit 1464884

Browse files
committed
Enable SPI_CS_SETUP for early ICACHE use
The SPI_CS_SETUP parameter has been observed set by RTOS SDK and NONOS SDK as part of flash init/configuration. It may be necessary for some flash chips to perform correctly with ICACHE hardware access. Turning on and leaving it on should be okay.
1 parent 313b3c0 commit 1464884

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

cores/esp8266/mmu_iram.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,31 @@ extern void Cache_Read_Enable(uint8_t map, uint8_t p, uint8_t v);
197197
#endif // #if (MMU_ICACHE_SIZE == 0x4000)
198198

199199
/*
200-
* This wrapper is for running code from IROM (flash) before the SDK starts.
200+
* This wrapper is for running code early from IROM (flash) before the SDK starts.
201+
* Since the NONOS SDK will do a full/proper init for handling the flash device,
202+
* we only do a minimum to make ICACHE functional, keeping IRAM use to a minimum.
201203
*/
202204
void IRAM_ATTR mmu_wrap_irom_fn(void (*fn)(void)) {
205+
// The SPI_CS_SETUP parameter has been observed set by RTOS SDK and NONOS SDK
206+
// as part of flash init/configuration. It may be necessary for some flash
207+
// chips to perform correctly with ICACHE hardware access. Turning on and
208+
// leaving it on should be okay.
209+
//
210+
// Upon reflection, most ESP8266 boards have a series resistor to the Flash
211+
// CLK pin. While reducing ringing, it causes a slight delay of the CLK signal
212+
// due to the effective RC circuit formed with the chip's input capacitance.
213+
// This narrows the gap between #CS active and the rising CLK edge as seen by
214+
// the chip. SPI_CS_SETUP can restore the safety margin for the #CS to CLK.
215+
//
216+
// One SPI bus clock cycle time is inserted between #CS active and 1st SPI bus
217+
// clock cycle. The number of clock cycles is in SPI_CNTRL2 SPI_SETUP_TIME,
218+
// defaults to 1.
219+
SPI0U |= SPIUCSSETUP; // SPI_CS_SETUP or BIT5
220+
221+
// For early Cache_Read_Enable only do ICACHE_SIZE_16. The affected registers
222+
// are fully restored when Cache_Read_Disable is called. With ICACHE_SIZE_32
223+
// one bit is missed at disable. Leave the full commitment to ICACHE_SIZE_32
224+
// for the NONOS SDK.
203225
Cache_Read_Enable(0, 0, ICACHE_SIZE_16);
204226
fn();
205227
Cache_Read_Disable();

0 commit comments

Comments
 (0)