Skip to content

Commit f04dedf

Browse files
committed
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.
1 parent f19c3db commit f04dedf

File tree

3 files changed

+35
-7
lines changed

3 files changed

+35
-7
lines changed

Diff for: 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" {

Diff for: cores/esp8266/mmu_iram.cpp

+24-3
Original file line numberDiff line numberDiff line change
@@ -196,12 +196,18 @@ extern void Cache_Read_Disable(void);
196196
extern void Cache_Read_Enable(uint8_t map, uint8_t p, uint8_t v);
197197
#endif // #if (MMU_ICACHE_SIZE == 0x4000)
198198

199+
#if 1 // New experimental code
199200
/*
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.
201+
* This wrapper is for running code early from IROM (flash) before the SDK
202+
* starts. Since the NONOS SDK will do a full and proper flash device init for
203+
* speed and mode, we only do a minimum to make ICACHE functional, keeping IRAM
204+
* use to a minimum. After the SDK has started, this function is not needed and
205+
* should not be called.
203206
*/
204207
void IRAM_ATTR mmu_wrap_irom_fn(void (*fn)(void)) {
208+
//?? If the problem is not resolved add this line back.
209+
//?? Cache_Read_Disable();
210+
205211
// The SPI_CS_SETUP parameter has been observed set by RTOS SDK and NONOS SDK
206212
// as part of flash init/configuration. It may be necessary for some flash
207213
// chips to perform correctly with ICACHE hardware access. Turning on and
@@ -212,13 +218,28 @@ void IRAM_ATTR mmu_wrap_irom_fn(void (*fn)(void)) {
212218
// defaults to 1.
213219
SPI0U |= SPIUCSSETUP; // SPI_CS_SETUP or BIT5
214220

221+
// I am not sure what this is does. It appears to be the key function called
222+
// from `fix_cache_bug` in the NONOS SDK - Will this help PUYA Flash work?
223+
// It appears to do some, lowlevel undocumented register maniplation and
224+
// device specific init based on OTP CHIPID model bits.
225+
extern uint32_t phy_get_bb_evm(void); // undocumented
226+
phy_get_bb_evm();
227+
215228
// For early Cache_Read_Enable only do ICACHE_SIZE_16. The affected registers
216229
// are fully restored when Cache_Read_Disable is called. With ICACHE_SIZE_32
217230
// one bit is missed at disable. Leave the full commitment to ICACHE_SIZE_32
218231
// for the NONOS SDK.
232+
// This only works with image slice 0, which is all we do presently.
219233
Cache_Read_Enable(0, 0, ICACHE_SIZE_16);
220234
fn();
221235
Cache_Read_Disable();
222236
}
237+
#else
238+
void IRAM_ATTR mmu_wrap_irom_fn(void (*fn)(void)) {
239+
Cache_Read_Enable(0, 0, ICACHE_SIZE_16);
240+
fn();
241+
Cache_Read_Disable();
242+
}
243+
#endif
223244

224245
};

Diff for: cores/esp8266/umm_malloc/umm_malloc_cfgport.h

+10-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include "c_types.h"
2121

2222
/*
23-
* -DUMM_INIT_USE_IRAM
23+
* -DUMM_INIT_USE_ICACHE
2424
*
2525
* Historically, the umm_init() call path has been in IRAM. The umm_init() call
2626
* path is now in ICACHE (flash). Use the build option UMM_INIT_USE_IRAM to
@@ -30,10 +30,16 @@
3030
* app_entry_redefinable() in core_esp8266_app_entry_noextra4k.cpp for an
3131
* example of how to toggle between ICACHE and IRAM in your build.
3232
*
33-
* The default is to use ICACHE.
33+
* ~The default is to use ICACHE.~
34+
* For now revert default back to IRAM
35+
* define UMM_INIT_USE_ICACHE to use ICACHE/IROM
3436
*/
35-
// #define UMM_INIT_USE_IRAM 1
36-
37+
#ifdef UMM_INIT_USE_ICACHE
38+
#undef UMM_INIT_USE_IRAM
39+
#else
40+
#undef UMM_INIT_USE_IRAM
41+
#define UMM_INIT_USE_IRAM 1
42+
#endif
3743

3844
/*
3945
* Start addresses and the size of the heap

0 commit comments

Comments
 (0)