Hi,
Overall our transition of CircuitPython to IDF 5.1 has been great. One weird thing I'm hitting is the global kconfig setting that dictates whether an ISR is in IRAM. We have multiple ways we use gptimer but we only want it in IRAM "mode" some of the time. Is there a function we can call to detect if the cache is disabled and return early? That way we can have an IRAM function for the ISR that only runs (using PSRAM memory) if cache is available.
A dynamic config setting would be even better because the user data argument is always validated as in IRAM when the kconfig is set.
Thanks,
Scott
Function to check if cache is active?
-
- Posts: 9708
- Joined: Thu Nov 26, 2015 4:08 am
Re: Function to check if cache is active?
There's the function cache_hal_is_cache_enabled() but that is private-ish (you can link to it but it's not part of the official ESP-IDF public API). That calls cache_hal_is_cache_enabled(CACHE_TYPE_ALL) which is a HAL function and those are also private. If you want, you can make do for now with these functions. I'll see if I can poke the team if we can have some non-private functions for this.
Re: Function to check if cache is active?
Thanks! That's the lead I needed. I think you meant `spi_flash_cache_enabled()` as the first function. It is working well.
Re: Function to check if cache is active?
I take it back. `spi_flash_cache_enabled()` has a race condition. It needs to be false before the disable process begins. Otherwise code can check, continue executing and then lose access. See this backtrace where an isr is interrupting the disable process and calling a function that is in flash.
Code: Select all
0x4203049f: supervisor_start_terminal at ??:?
0x40375d4a: _PM_esp32timerCallback at /home/tannewt/repos/circuitpython/ports/espressif/../../lib/protomatter/src/arch/esp32-common.h:150
0x40380dc8: gptimer_default_isr at /home/tannewt/repos/circuitpython/ports/espressif/esp-idf/components/driver/gptimer/gptimer.c:515
0x40377e4d: shared_intr_isr at /home/tannewt/repos/circuitpython/ports/espressif/esp-idf/components/esp_hw_support/intr_alloc.c:436
0x4037a42d: _xt_lowint1 at /home/tannewt/repos/circuitpython/ports/espressif/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/xtensa_vectors.S:1240
0x4004f3bc: ?? ??:0
0x403841ce: Cache_Suspend_ICache at /home/tannewt/repos/circuitpython/ports/espressif/esp-idf/components/esp_rom/patches/esp_rom_cache_esp32s2_esp32s3.c:55
0x403881f0: cache_hal_suspend at /home/tannewt/repos/circuitpython/ports/espressif/esp-idf/components/hal/cache_hal.c:129
0x4037af79: spi_flash_disable_cache at /home/tannewt/repos/circuitpython/ports/espressif/esp-idf/components/spi_flash/cache_utils.c:366
0x4037b0b0: spi_flash_disable_interrupts_caches_and_other_cpu at /home/tannewt/repos/circuitpython/ports/espressif/esp-idf/components/spi_flash/cache_utils.c:207
0x4037bc57: cache_disable at /home/tannewt/repos/circuitpython/ports/espressif/esp-idf/components/spi_flash/spi_flash_os_func_app.c:70
0x4037bc5f: spi1_start at /home/tannewt/repos/circuitpython/ports/espressif/esp-idf/components/spi_flash/spi_flash_os_func_app.c:122
0x40380c7d: spiflash_start_default at /home/tannewt/repos/circuitpython/ports/espressif/esp-idf/components/spi_flash/esp_flash_api.c:187
0x4037b79d: esp_flash_read at /home/tannewt/repos/circuitpython/ports/espressif/esp-idf/components/spi_flash/esp_flash_api.c:887
0x42095c91: esp_partition_read at /home/tannewt/repos/circuitpython/ports/espressif/esp-idf/components/esp_partition/partition_target.c:38
Re: Function to check if cache is active?
any update on this? were you able to resolve? I'm having a heck of a time trying to get a valid call to spi_flash_cache_enabled(). I can see the method, in "cache_utils.c", which, per the cmake for spi_flash, should be included. How do I access it??!?
Who is online
Users browsing this forum: Google [Bot] and 105 guests