Skip to content

Commit 253fc4f

Browse files
committed
test(mmu): added test for checking esp_mmu_vaddr_to_paddr with psram vaddrs
1 parent 7bbfe91 commit 253fc4f

File tree

5 files changed

+49
-2
lines changed

5 files changed

+49
-2
lines changed

components/esp_mm/test_apps/mm/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ set(COMPONENTS main esp_psram)
1010
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
1111
project(mm_test)
1212

13+
string(JOIN "," ignore_refs)
14+
15+
if(CONFIG_SOC_MMU_PER_EXT_MEM_TARGET AND CONFIG_SPIRAM_FLASH_LOAD_TO_PSRAM)
16+
# On SOC_MMU_PER_EXT_MEM_TARGET chips, when xip_psram, we need
17+
# - _instruction_reserved_start, _instruction_reserved_end
18+
# - _rodata_reserved_start, _rodata_reserved_end
19+
# to do some calculation. As we don't access the addresses, so we disable this check
20+
list(APPEND ignore_refs esp_mmu_map_init/*)
21+
endif()
22+
1323
if(CONFIG_COMPILER_DUMP_RTL_FILES)
1424
add_custom_target(check_test_app_sections ALL
1525
COMMAND ${PYTHON} $ENV{IDF_PATH}/tools/ci/check_callgraph.py
@@ -18,6 +28,7 @@ if(CONFIG_COMPILER_DUMP_RTL_FILES)
1828
find-refs
1929
--from-sections=.iram0.text
2030
--to-sections=.flash.text,.flash.rodata
31+
--ignore-refs=${ignore_refs}
2132
--exit-code
2233
DEPENDS ${elf}
2334
)

components/esp_mm/test_apps/mm/main/test_mmap.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -70,3 +70,26 @@ TEST_CASE("Can find paddr caps by any paddr offset", "[mmu]")
7070

7171
TEST_ESP_OK(esp_mmu_unmap(ptr0));
7272
}
73+
74+
#if CONFIG_SPIRAM
75+
#if !CONFIG_IDF_TARGET_ESP32 //ESP32 doesn't support using `esp_mmu_map` to map to PSRAM
76+
TEST_CASE("Can find paddr when mapping to psram", "[mmu]")
77+
{
78+
esp_paddr_t paddr = 0;
79+
mmu_target_t target = MMU_TARGET_FLASH0;
80+
81+
void *vaddr = NULL;
82+
esp_err_t err = ESP_FAIL;
83+
84+
vaddr = heap_caps_malloc(10, MALLOC_CAP_SPIRAM);
85+
err = esp_mmu_vaddr_to_paddr(vaddr, &paddr, &target);
86+
if (err == ESP_OK) {
87+
ESP_LOGI("MMU", "Virtual Address: %p, Physical Address: 0x%lx, Target: %d", vaddr, paddr, target);
88+
} else {
89+
ESP_LOGE("MMU", "Failed to convert virtual address to physical address: %s", esp_err_to_name(err));
90+
}
91+
92+
TEST_ASSERT(target == MMU_TARGET_PSRAM0);
93+
}
94+
#endif //#if !CONFIG_IDF_TARGET_ESP32
95+
#endif //#if CONFIG_SPIRAM

components/esp_mm/test_apps/mm/pytest_mmap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
22
# SPDX-License-Identifier: CC0-1.0
3-
43
import pytest
54
from pytest_embedded import Dut
65

@@ -24,6 +23,7 @@ def test_mmap(dut: Dut) -> None:
2423
pytest.param('psram_release_esp32', marks=[pytest.mark.esp32]),
2524
pytest.param('psram_release_esp32s2', marks=[pytest.mark.esp32s2]),
2625
pytest.param('psram_release_esp32s3', marks=[pytest.mark.esp32s3]),
26+
pytest.param('psram_release_esp32p4', marks=[pytest.mark.esp32p4]),
2727
]
2828

2929

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CONFIG_IDF_TARGET="esp32p4"
2+
CONFIG_COMPILER_OPTIMIZATION_SIZE=y
3+
CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_SIZE=y
4+
CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENT=y
5+
6+
CONFIG_SPIRAM=y
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CONFIG_IDF_TARGET="esp32p4"
2+
CONFIG_COMPILER_OPTIMIZATION_SIZE=y
3+
CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_SIZE=y
4+
CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENT=y
5+
6+
CONFIG_SPIRAM=y
7+
CONFIG_SPIRAM_XIP_FROM_PSRAM=y

0 commit comments

Comments
 (0)