Skip to content

Commit ac0a72a

Browse files
committed
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 1cf6e48 commit ac0a72a

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

Diff for: cores/esp8266/mmu_iram.cpp

+11-19
Original file line numberDiff line numberDiff line change
@@ -196,17 +196,17 @@ 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
200199
/*
201200
* This wrapper is for running code early from IROM (flash) before the SDK
202201
* starts. Since the NONOS SDK will do a full and proper flash device init for
203202
* speed and mode, we only do a minimum to make ICACHE functional, keeping IRAM
204203
* use to a minimum. After the SDK has started, this function is not needed and
205-
* should not be called.
204+
* must not be called.
206205
*/
207206
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();
207+
// Cache Read must be disabled. This is always the case on entry when called
208+
// from the right context.
209+
// Cache_Read_Disable();
210210

211211
// The SPI_CS_SETUP parameter has been observed set by RTOS SDK and NONOS SDK
212212
// as part of flash init/configuration. It may be necessary for some flash
@@ -218,28 +218,20 @@ void IRAM_ATTR mmu_wrap_irom_fn(void (*fn)(void)) {
218218
// defaults to 1.
219219
SPI0U |= SPIUCSSETUP; // SPI_CS_SETUP or BIT5
220220

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.
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.
225224
extern uint32_t phy_get_bb_evm(void); // undocumented
226225
phy_get_bb_evm();
227226

228-
// For early Cache_Read_Enable only do ICACHE_SIZE_16. The affected registers
229-
// are fully restored when Cache_Read_Disable is called. With ICACHE_SIZE_32
230-
// one bit is missed at disable. Leave the full commitment to ICACHE_SIZE_32
231-
// for the NONOS SDK.
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.
232231
// This only works with image slice 0, which is all we do presently.
233232
Cache_Read_Enable(0, 0, ICACHE_SIZE_16);
234233
fn();
235234
Cache_Read_Disable();
236235
}
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
244236

245237
};

0 commit comments

Comments
 (0)