From 36ef485c4e9f5616271165bfdd2b6d2cd418f3ed Mon Sep 17 00:00:00 2001 From: Marius Vikhammer Date: Wed, 5 Jan 2022 12:37:34 +0800 Subject: [PATCH] soc: support placing task stacks in external memory for S2 and S3 --- components/bt/esp_ble_mesh/mesh_core/adv.c | 12 ++++++------ components/esp32s2/Kconfig | 7 ++++++- components/esp32s3/Kconfig | 4 ++++ docs/en/api-guides/external-ram.rst | 8 +++++++- 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/components/bt/esp_ble_mesh/mesh_core/adv.c b/components/bt/esp_ble_mesh/mesh_core/adv.c index 1d019feaec..b8bcf38966 100644 --- a/components/bt/esp_ble_mesh/mesh_core/adv.c +++ b/components/bt/esp_ble_mesh/mesh_core/adv.c @@ -2,7 +2,7 @@ /* * SPDX-FileCopyrightText: 2017 Intel Corporation - * SPDX-FileContributor: 2018-2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileContributor: 2018-2022 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -110,7 +110,7 @@ static void bt_mesh_ble_adv_deinit(void); struct bt_mesh_adv_task { TaskHandle_t handle; #if (CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC_EXTERNAL && \ - CONFIG_SPIRAM_CACHE_WORKAROUND && \ + (CONFIG_SPIRAM_CACHE_WORKAROUND || !CONFIG_IDF_TARGET_ESP32) && \ CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY) StaticTask_t *task; StackType_t *stack; @@ -639,7 +639,7 @@ void bt_mesh_adv_init(void) #endif /* defined(CONFIG_BLE_MESH_RELAY_ADV_BUF) */ #if (CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC_EXTERNAL && \ - CONFIG_SPIRAM_CACHE_WORKAROUND && \ + (CONFIG_SPIRAM_CACHE_WORKAROUND || !CONFIG_IDF_TARGET_ESP32) && \ CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY) adv_task.task = heap_caps_calloc(1, sizeof(StaticTask_t), MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); __ASSERT(adv_task.task, "Failed to create adv thread task"); @@ -648,12 +648,12 @@ void bt_mesh_adv_init(void) adv_task.handle = xTaskCreateStaticPinnedToCore(adv_thread, BLE_MESH_ADV_TASK_NAME, BLE_MESH_ADV_TASK_STACK_SIZE, NULL, BLE_MESH_ADV_TASK_PRIO, adv_task.stack, adv_task.task, BLE_MESH_ADV_TASK_CORE); __ASSERT(adv_task.handle, "Failed to create static adv thread"); -#else /* CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC_EXTERNAL && CONFIG_SPIRAM_CACHE_WORKAROUND && CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY */ +#else /* CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC_EXTERNAL && (CONFIG_SPIRAM_CACHE_WORKAROUND || !CONFIG_IDF_TARGET_ESP32) && CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY */ int ret = xTaskCreatePinnedToCore(adv_thread, BLE_MESH_ADV_TASK_NAME, BLE_MESH_ADV_TASK_STACK_SIZE, NULL, BLE_MESH_ADV_TASK_PRIO, &adv_task.handle, BLE_MESH_ADV_TASK_CORE); __ASSERT(ret == pdTRUE, "Failed to create adv thread"); (void)ret; -#endif /* CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC_EXTERNAL && CONFIG_SPIRAM_CACHE_WORKAROUND && CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY */ +#endif /* CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC_EXTERNAL && (CONFIG_SPIRAM_CACHE_WORKAROUND || !CONFIG_IDF_TARGET_ESP32) && CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY */ } #if CONFIG_BLE_MESH_DEINIT @@ -666,7 +666,7 @@ void bt_mesh_adv_deinit(void) vTaskDelete(adv_task.handle); adv_task.handle = NULL; #if (CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC_EXTERNAL && \ - CONFIG_SPIRAM_CACHE_WORKAROUND && \ + (CONFIG_SPIRAM_CACHE_WORKAROUND || !CONFIG_IDF_TARGET_ESP32) && \ CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY) heap_caps_free(adv_task.stack); adv_task.stack = NULL; diff --git a/components/esp32s2/Kconfig b/components/esp32s2/Kconfig index 33c3b5af0b..e6102314ec 100644 --- a/components/esp32s2/Kconfig +++ b/components/esp32s2/Kconfig @@ -118,6 +118,10 @@ menu "ESP32S2-specific" menu "SPI RAM config" depends on ESP32S2_SPIRAM_SUPPORT + config SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY + bool + default "y" + choice SPIRAM_TYPE prompt "Type of SPI RAM chip in use" default SPIRAM_TYPE_AUTO @@ -191,7 +195,8 @@ menu "ESP32S2-specific" bool "20Mhz clock speed" endchoice - # insert non-chip-specific items here + + # insert non-chip-specific items here NOERROR source "$IDF_PATH/components/esp_hw_support/Kconfig.spiram.common" endmenu diff --git a/components/esp32s3/Kconfig b/components/esp32s3/Kconfig index 84bd13543a..c05ea01eea 100644 --- a/components/esp32s3/Kconfig +++ b/components/esp32s3/Kconfig @@ -175,6 +175,10 @@ menu "ESP32S3-Specific" menu "SPI RAM config" depends on ESP32S3_SPIRAM_SUPPORT + config SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY + bool + default "y" + choice SPIRAM_MODE prompt "Mode (QUAD/OCT) of SPI RAM chip in use" default SPIRAM_MODE_QUAD diff --git a/docs/en/api-guides/external-ram.rst b/docs/en/api-guides/external-ram.rst index 2d1f8609d8..dab9191fe9 100644 --- a/docs/en/api-guides/external-ram.rst +++ b/docs/en/api-guides/external-ram.rst @@ -137,12 +137,18 @@ External RAM use has the following restrictions: * External RAM uses the same cache region as the external flash. This means that frequently accessed variables in external RAM can be read and modified almost as quickly as in internal ram. However, when accessing large chunks of data (>32 KB), the cache can be insufficient, and speeds will fall back to the access speed of the external RAM. Moreover, accessing large chunks of data can "push out" cached flash, possibly making the execution of code slower afterwards. - * In general, external RAM cannot be used as task stack memory. Due to this, :cpp:func:`xTaskCreate` and similar functions will always allocate internal memory for stack and task TCBs, and functions such as :cpp:func:`xTaskCreateStatic` will check if the buffers passed are internal. + * In general, external RAM will not be used as task stack memory. :cpp:func:`xTaskCreate` and similar functions will always allocate internal memory for stack and task TCBs. .. only:: esp32 The option :ref:`CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY` can be used to place task stacks into external memory. In these cases :cpp:func:`xTaskCreateStatic` must be used to specify a task stack buffer allocated from external memory, otherwise task stacks will still be allocated from internal memory. + +.. only:: not esp32 + + :cpp:func:`xTaskCreateStatic` can be used to explicitly place task stacks into external memory. + + Failure to initialize =====================