From 2efd6859ed69acc83ec125b47406132478a57547 Mon Sep 17 00:00:00 2001 From: Jack Date: Mon, 9 Jul 2018 17:15:22 +0800 Subject: [PATCH 1/3] release memory not used in single core mode 1. do not start ipc task in single core mode 2. do not use APP cpu cache memory in single core mode 3. relase data used in rom by APP cpu --- components/esp32/cpu_start.c | 2 +- components/soc/esp32/soc_memory_layout.c | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/components/esp32/cpu_start.c b/components/esp32/cpu_start.c index bda8b8cc82..634a63eb0a 100644 --- a/components/esp32/cpu_start.c +++ b/components/esp32/cpu_start.c @@ -350,8 +350,8 @@ void start_cpu0_default(void) #endif esp_cache_err_int_init(); esp_crosscore_int_init(); - esp_ipc_init(); #ifndef CONFIG_FREERTOS_UNICORE + esp_ipc_init(); esp_dport_access_int_init(); #endif spi_flash_init(); diff --git a/components/soc/esp32/soc_memory_layout.c b/components/soc/esp32/soc_memory_layout.c index c6fa4635d2..de884cd45c 100644 --- a/components/soc/esp32/soc_memory_layout.c +++ b/components/soc/esp32/soc_memory_layout.c @@ -131,7 +131,9 @@ const size_t soc_memory_region_count = sizeof(soc_memory_regions)/sizeof(soc_mem These are removed from the soc_memory_regions array when heaps are created. */ SOC_RESERVE_MEMORY_REGION(0x40070000, 0x40078000, cpu0_cache); +#ifndef CONFIG_FREERTOS_UNICORE SOC_RESERVE_MEMORY_REGION(0x40078000, 0x40080000, cpu1_cache); +#endif /* Warning: The ROM stack is located in the 0x3ffe0000 area. We do not specifically disable that area here because after the scheduler has started, the ROM stack is not used anymore by anything. We handle it instead by not allowing @@ -150,7 +152,9 @@ SOC_RESERVE_MEMORY_REGION(0x40078000, 0x40080000, cpu1_cache); */ SOC_RESERVE_MEMORY_REGION(0x3ffe0000, 0x3ffe0440, rom_pro_data); //Reserve ROM PRO data region -SOC_RESERVE_MEMORY_REGION(0x3ffe4000, 0x3ffe4350, rom_app_data); //Reserve ROM APP data region +#ifndef CONFIG_FREERTOS_UNICORE +SOC_RESERVE_MEMORY_REGION(0x3ffe3f20, 0x3ffe4350, rom_app_data); //Reserve ROM APP data region +#endif SOC_RESERVE_MEMORY_REGION(0x3ffae000, 0x3ffae6e0, rom_data); From 4ff262ecff7757c6ead90ebca2cdd5e67dd21b12 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Tue, 18 Sep 2018 14:37:12 +0800 Subject: [PATCH 2/3] ipc: initialise automatically, if called from the app --- components/esp32/cpu_start.c | 1 - components/esp32/include/esp_ipc.h | 15 --------------- components/esp32/ipc.c | 14 +++++++++++++- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/components/esp32/cpu_start.c b/components/esp32/cpu_start.c index 634a63eb0a..93379801b8 100644 --- a/components/esp32/cpu_start.c +++ b/components/esp32/cpu_start.c @@ -351,7 +351,6 @@ void start_cpu0_default(void) esp_cache_err_int_init(); esp_crosscore_int_init(); #ifndef CONFIG_FREERTOS_UNICORE - esp_ipc_init(); esp_dport_access_int_init(); #endif spi_flash_init(); diff --git a/components/esp32/include/esp_ipc.h b/components/esp32/include/esp_ipc.h index b229cb3377..477b3d0af4 100644 --- a/components/esp32/include/esp_ipc.h +++ b/components/esp32/include/esp_ipc.h @@ -33,21 +33,6 @@ typedef void (*esp_ipc_func_t)(void* arg); * These APIs can only be used when FreeRTOS scheduler is running. */ - -/* - * Initialize inter-processor call module. This function is called automatically - * on CPU start and should not be called from the application. - * - * This function start two tasks, one on each CPU. These tasks are started - * with high priority. These tasks are normally inactive, waiting until one of - * the esp_ipc_call_* functions to be used. One of these tasks will be - * woken up to execute the callback provided to esp_ipc_call_nonblocking or - * esp_ipc_call_blocking. - */ -/** @cond */ -void esp_ipc_init(); -/** @endcond */ - /** * @brief Execute a function on the given CPU * diff --git a/components/esp32/ipc.c b/components/esp32/ipc.c index d10e8e819e..b54ae2846f 100644 --- a/components/esp32/ipc.c +++ b/components/esp32/ipc.c @@ -72,7 +72,19 @@ static void IRAM_ATTR ipc_task(void* arg) vTaskDelete(NULL); } -void esp_ipc_init() +/* + * Initialize inter-processor call module. This function is called automatically + * on CPU start and should not be called from the application. + * + * This function start two tasks, one on each CPU. These tasks are started + * with high priority. These tasks are normally inactive, waiting until one of + * the esp_ipc_call_* functions to be used. One of these tasks will be + * woken up to execute the callback provided to esp_ipc_call_nonblocking or + * esp_ipc_call_blocking. + */ +static void esp_ipc_init() __attribute__((constructor)); + +static void esp_ipc_init() { s_ipc_mutex = xSemaphoreCreateMutex(); s_ipc_ack = xSemaphoreCreateBinary(); From 0139749ba6b3c6cce6c8dba6f011dda5c70af01c Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Wed, 19 Sep 2018 13:46:59 +0800 Subject: [PATCH 3/3] esp32: only touch g_ticks_per_us_app in dual core mode --- components/esp32/clk.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/components/esp32/clk.c b/components/esp32/clk.c index 54abc18b72..9e30121fc8 100644 --- a/components/esp32/clk.c +++ b/components/esp32/clk.c @@ -61,7 +61,9 @@ static void select_rtc_slow_clk(slow_clk_sel_t slow_clk); // g_ticks_us defined in ROMs for PRO and APP CPU extern uint32_t g_ticks_per_us_pro; +#ifndef CONFIG_FREERTOS_UNICORE extern uint32_t g_ticks_per_us_app; +#endif static const char* TAG = "clk"; @@ -155,7 +157,9 @@ void IRAM_ATTR ets_update_cpu_frequency(uint32_t ticks_per_us) { /* Update scale factors used by ets_delay_us */ g_ticks_per_us_pro = ticks_per_us; +#ifndef CONFIG_FREERTOS_UNICORE g_ticks_per_us_app = ticks_per_us; +#endif } static void select_rtc_slow_clk(slow_clk_sel_t slow_clk)