-
Notifications
You must be signed in to change notification settings - Fork 7.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY depends on SPIRAM_USE_MALLOC (IDFGH-11604) #12722
Comments
@ftab Which chip and version of ESP-IDF are you using? And what do you mean by the following?
Without Edit: Note that this behavior for allocating FreeRTOS objects changed in version 5.1. Hence your IDF version is of interest, too. |
@0xjakob thanks for the quick response!
ESP32, 5.1.2
When I enable SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY on the default ESP-IDF 5.1.2, I have to set SPIRAM_USE to SPIRAM_USE_MALLOC and my application fails to boot because it runs out of internal RAM. I don't know exactly why yet. I have checked that BT_ALLOCATION_FROM_SPIRAM_FIRST is true, SPIRAM_TRY_ALLOCATE_WIFI_LWIP is true, and all other similar options are set to true. I haven't fully investigated, there's a lot going on in my application (ESP-ADF, WiFi, Bluetooth A2DP/AVRCP/SPP, Bluetooth LE, esp console, esp rainmaker/insights, audio DSP, etc.). My application only successfully boots when SPIRAM_USE is set to SPIRAM_USE_CAPS_ALLOC, but then that disables SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY.
Yes, I saw this and this is the reason I wanted to upgrade to this version of ESP-IDF, so I could use task stack in external memory and free up some internal memory. But in the default esp-idf 5.1.2 it is not possible to use task stack in external memory when SPIRAM_USE method is SPIRAM_USE_CAPS_ALLOC I have made a fork of 5.1.2 that changes SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY to depend on SPIRAM instead of SPIRAM_USE_MALLOC, and the application seems to work, but I don't know enough to know whether this is safe. |
The only issue I have had so far with this arrangement is that esp-idf/components/spi_flash/cache_utils.c is still blissfully unaware of SPIRAM being a valid location for task stack: static inline bool esp_task_stack_is_sane_cache_disabled(void)
{
const void *sp = (const void *)esp_cpu_get_sp();
return esp_ptr_in_dram(sp)
#if CONFIG_ESP_SYSTEM_ALLOW_RTC_FAST_MEM_AS_HEAP
|| esp_ptr_in_rtc_dram_fast(sp)
#endif
;
} Thus anything calling spi_flash_disable_interrupts_caches_and_other_cpu() which includes
causes an assert failure and I have to move that task back to internal RAM, meaning I'm almost out again. |
Came upon this in a google search and I think I see something related. I am using the esp-adf and created my own element that uses himem. By default, adf wants to put element task stacks in SPIRAM as long as it is enabled. The problem is spi_flash_disable_interrupts_caches_and_other_cpu() fails as soon as I try to map himem with the task stack in SPIRAM. I had to specify this particular task stack to be in internal memory and then things work as they should |
Answers checklist.
General issue report
Reporting as per #9011 (comment)
See https://github.com/espressif/esp-idf/blob/master/components/esp_psram/esp32/Kconfig.spiram#L265
I cannot enable task stack in SPIRAM without also enabling SPIRAM allocation by malloc() (instead of only through heap_caps_malloc). However, enabling SPIRAM allocation by malloc() causes all sorts of other things to prefer internal RAM instead of SPIRAM as I want, and my internal RAM is exhausted before I finish booting.
@igrr is it as simple as just changing that line to
depends on SPIRAM
?The text was updated successfully, but these errors were encountered: