Skip to content

Commit d71a62e

Browse files
mhightower83hasenradball
authored andcommitted
Fix pre-SDK Cache_Read_Enable for PUYA flash (esp8266#8658)
* 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. * Cleanup comment * Change umm_init to default to IRAM Some flash chips (PUYA) have some unknown requirements for running with early `Cache_Read_Enable`. They work fine after the SDK is started. For now, change umm_init to default to IRAM. Define UMM_INIT_USE_ICACHE to move to ICACHE and free up IRAM. Added some experimental code that may indirectly support PUYA. Note, until this issue is resolved, that HWDT Stack Dump is not going to work with PUYA flash. * typo * Finalize fix for PUYA flash and preSDK use of Cache_Read_Enable. This resolves the exception 0 issue with PUYA flash when using flash/ICACHE for umm_init and/or using HWDT Stack Dump.
1 parent 622fbbc commit d71a62e

File tree

3 files changed

+41
-5
lines changed

3 files changed

+41
-5
lines changed

cores/esp8266/hwdt_app_entry.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@
277277
#include <esp8266_peri.h>
278278
#include <uart.h>
279279
#include <pgmspace.h>
280+
#include "umm_malloc/umm_malloc.h"
280281
#include "mmu_iram.h"
281282

282283
extern "C" {

cores/esp8266/mmu_iram.cpp

+30-1
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,38 @@ 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
201+
* starts. Since the NONOS SDK will do a full and proper flash device init for
202+
* speed and mode, we only do a minimum to make ICACHE functional, keeping IRAM
203+
* use to a minimum. After the SDK has started, this function is not needed and
204+
* must not be called.
201205
*/
202206
void IRAM_ATTR mmu_wrap_irom_fn(void (*fn)(void)) {
207+
// Cache Read must be disabled. This is always the case on entry when called
208+
// from the right context.
209+
// Cache_Read_Disable();
210+
211+
// The SPI_CS_SETUP parameter has been observed set by RTOS SDK and NONOS SDK
212+
// as part of flash init/configuration. It may be necessary for some flash
213+
// chips to perform correctly with ICACHE hardware access. Turning on and
214+
// leaving it on should be okay.
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+
// phy_get_bb_evm is the key function, called from fix_cache_bug in the NONOS
222+
// SDK. This addition resolves the PUYA Flash issue with exception 0, when
223+
// early Cache_Read_Enable is used.
224+
extern uint32_t phy_get_bb_evm(void); // undocumented
225+
phy_get_bb_evm();
226+
227+
// For early Cache_Read_Enable, only do ICACHE_SIZE_16. With this option,
228+
// Cache_Read_Disable will fully restore the original register states. With
229+
// ICACHE_SIZE_32, one bit is missed when disabling. Leave the full access
230+
// calls for the NONOS SDK.
231+
// This only works with image slice 0, which is all we do presently.
203232
Cache_Read_Enable(0, 0, ICACHE_SIZE_16);
204233
fn();
205234
Cache_Read_Disable();

cores/esp8266/umm_malloc/umm_malloc_cfgport.h

+10-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
*/
2828

2929
/*
30-
* -DUMM_INIT_USE_IRAM
30+
* -DUMM_INIT_USE_ICACHE
3131
*
3232
* Historically, the umm_init() call path has been in IRAM. The umm_init() call
3333
* path is now in ICACHE (flash). Use the build option UMM_INIT_USE_IRAM to
@@ -37,10 +37,16 @@
3737
* app_entry_redefinable() in core_esp8266_app_entry_noextra4k.cpp for an
3838
* example of how to toggle between ICACHE and IRAM in your build.
3939
*
40-
* The default is to use ICACHE.
40+
* ~The default is to use ICACHE.~
41+
* For now revert default back to IRAM
42+
* define UMM_INIT_USE_ICACHE to use ICACHE/IROM
4143
*/
42-
// #define UMM_INIT_USE_IRAM 1
43-
44+
#ifdef UMM_INIT_USE_ICACHE
45+
#undef UMM_INIT_USE_IRAM
46+
#else
47+
#undef UMM_INIT_USE_IRAM
48+
#define UMM_INIT_USE_IRAM 1
49+
#endif
4450

4551
/*
4652
* Start addresses and the size of the heap

0 commit comments

Comments
 (0)