From b9f42e7baeeed7337e016f426d13438a5808b1da Mon Sep 17 00:00:00 2001 From: John Boiles Date: Tue, 20 May 2025 16:40:48 -0700 Subject: [PATCH 1/2] fix(memory-utils): Check TCM in esp_ptr_internal and esp_ptr_byte_accessible Modifies `esp_ptr_internal` and `esp_ptr_byte_accessible` to also check TCM when `SOC_MEM_TCM_SUPPORTED`. --- components/esp_hw_support/esp_memory_utils.c | 3 +++ components/esp_hw_support/include/esp_memory_utils.h | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/components/esp_hw_support/esp_memory_utils.c b/components/esp_hw_support/esp_memory_utils.c index a75a769b52..277f82d5df 100644 --- a/components/esp_hw_support/esp_memory_utils.c +++ b/components/esp_hw_support/esp_memory_utils.c @@ -52,6 +52,9 @@ bool esp_ptr_byte_accessible(const void *p) intptr_t ip = (intptr_t) p; bool r; r = (ip >= SOC_BYTE_ACCESSIBLE_LOW && ip < SOC_BYTE_ACCESSIBLE_HIGH); +#if SOC_MEM_TCM_SUPPORTED + r |= (ip >= SOC_TCM_LOW && ip < SOC_TCM_HIGH); +#endif #if CONFIG_ESP_SYSTEM_ALLOW_RTC_FAST_MEM_AS_HEAP /* For ESP32 case, RTC fast memory is accessible to PRO cpu only and hence * for single core configuration (where it gets added to system heap) following diff --git a/components/esp_hw_support/include/esp_memory_utils.h b/components/esp_hw_support/include/esp_memory_utils.h index e664623539..7b5f423a19 100644 --- a/components/esp_hw_support/include/esp_memory_utils.h +++ b/components/esp_hw_support/include/esp_memory_utils.h @@ -278,6 +278,10 @@ inline static bool esp_ptr_internal(const void *p) { bool r; r = ((intptr_t)p >= SOC_MEM_INTERNAL_LOW && (intptr_t)p < SOC_MEM_INTERNAL_HIGH); +#if SOC_MEM_TCM_SUPPORTED + r |= ((intptr_t)p >= SOC_TCM_LOW && (intptr_t)p < SOC_TCM_HIGH); +#endif + #if SOC_RTC_SLOW_MEM_SUPPORTED r |= ((intptr_t)p >= SOC_RTC_DATA_LOW && (intptr_t)p < SOC_RTC_DATA_HIGH); #endif From d8c054c8c1612dc2404f927746bd2df8ff16fb96 Mon Sep 17 00:00:00 2001 From: John Boiles Date: Thu, 22 May 2025 08:25:26 -0700 Subject: [PATCH 2/2] fix(memory-utils): Use esp_ptr_in_tcm to check TCM range --- components/esp_hw_support/esp_memory_utils.c | 2 +- components/esp_hw_support/include/esp_memory_utils.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/components/esp_hw_support/esp_memory_utils.c b/components/esp_hw_support/esp_memory_utils.c index 277f82d5df..a2539da92e 100644 --- a/components/esp_hw_support/esp_memory_utils.c +++ b/components/esp_hw_support/esp_memory_utils.c @@ -53,7 +53,7 @@ bool esp_ptr_byte_accessible(const void *p) bool r; r = (ip >= SOC_BYTE_ACCESSIBLE_LOW && ip < SOC_BYTE_ACCESSIBLE_HIGH); #if SOC_MEM_TCM_SUPPORTED - r |= (ip >= SOC_TCM_LOW && ip < SOC_TCM_HIGH); + r |= esp_ptr_in_tcm(p); #endif #if CONFIG_ESP_SYSTEM_ALLOW_RTC_FAST_MEM_AS_HEAP /* For ESP32 case, RTC fast memory is accessible to PRO cpu only and hence diff --git a/components/esp_hw_support/include/esp_memory_utils.h b/components/esp_hw_support/include/esp_memory_utils.h index 7b5f423a19..0379c76a84 100644 --- a/components/esp_hw_support/include/esp_memory_utils.h +++ b/components/esp_hw_support/include/esp_memory_utils.h @@ -279,7 +279,7 @@ inline static bool esp_ptr_internal(const void *p) { r = ((intptr_t)p >= SOC_MEM_INTERNAL_LOW && (intptr_t)p < SOC_MEM_INTERNAL_HIGH); #if SOC_MEM_TCM_SUPPORTED - r |= ((intptr_t)p >= SOC_TCM_LOW && (intptr_t)p < SOC_TCM_HIGH); + r |= esp_ptr_in_tcm(p); #endif #if SOC_RTC_SLOW_MEM_SUPPORTED