Skip to content

Commit 935da55

Browse files
committed
Merge branch 'refactor/dma_test_p4_v5.3' into 'release/v5.3'
change(gdma): improve the test cases to be target agnostic (v5.3) See merge request espressif/esp-idf!30486
2 parents 7c57624 + 4fb58d5 commit 935da55

File tree

7 files changed

+298
-259
lines changed

7 files changed

+298
-259
lines changed

components/esp_hw_support/test_apps/dma/main/CMakeLists.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,20 @@ if(CONFIG_SOC_GDMA_SUPPORTED)
88
list(APPEND srcs "test_gdma.c")
99
endif()
1010

11+
if(CONFIG_SOC_ETM_SUPPORTED AND CONFIG_SOC_GDMA_SUPPORT_ETM)
12+
list(APPEND srcs "test_gdma_etm.c")
13+
endif()
14+
1115
if(CONFIG_SOC_DW_GDMA_SUPPORTED)
1216
list(APPEND srcs "test_dw_gdma.c")
1317
endif()
1418

19+
if(CONFIG_SOC_GDMA_SUPPORT_CRC)
20+
list(APPEND srcs "test_gdma_crc.c")
21+
endif()
22+
1523
# In order for the cases defined by `TEST_CASE` to be linked into the final elf,
1624
# the component can be registered as WHOLE_ARCHIVE
1725
idf_component_register(SRCS ${srcs}
18-
PRIV_REQUIRES unity esp_mm
26+
PRIV_REQUIRES unity esp_mm esp_driver_gpio
1927
WHOLE_ARCHIVE)

components/esp_hw_support/test_apps/dma/main/test_async_memcpy.c

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "esp_async_memcpy.h"
1919
#include "soc/soc_caps.h"
2020
#include "hal/dma_types.h"
21+
#include "esp_dma_utils.h"
2122

2223
#define IDF_LOG_PERFORMANCE(item, value_fmt, value, ...) \
2324
printf("[Performance][%s]: " value_fmt "\n", item, value, ##__VA_ARGS__)
@@ -26,10 +27,7 @@
2627
#define ALIGN_DOWN(size, align) ((size) & ~((align) - 1))
2728

2829
#if CONFIG_IDF_TARGET_ESP32P4
29-
#define TEST_MEMCPY_DST_BASE_ALIGN 64
3030
#define TEST_MEMCPY_BUFFER_SIZE_MUST_ALIGN_CACHE 1
31-
#else
32-
#define TEST_MEMCPY_DST_BASE_ALIGN 4
3331
#endif
3432

3533
typedef struct {
@@ -56,23 +54,23 @@ static void async_memcpy_setup_testbench(memcpy_testbench_context_t *test_contex
5654
uint8_t *dst_buf = NULL;
5755
uint8_t *from_addr = NULL;
5856
uint8_t *to_addr = NULL;
59-
#if CONFIG_SPIRAM && SOC_AHB_GDMA_SUPPORT_PSRAM
57+
58+
esp_dma_mem_info_t mem_info = {
59+
.dma_alignment_bytes = test_context->align,
60+
};
6061
if (test_context->src_in_psram) {
61-
src_buf = heap_caps_aligned_alloc(test_context->align, buffer_size, MALLOC_CAP_SPIRAM);
62+
mem_info.extra_heap_caps = MALLOC_CAP_SPIRAM;
6263
} else {
63-
src_buf = heap_caps_aligned_alloc(test_context->align, buffer_size, MALLOC_CAP_8BIT | MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL);
64+
mem_info.extra_heap_caps = 0;
6465
}
66+
TEST_ESP_OK(esp_dma_capable_calloc(1, buffer_size, &mem_info, (void **)&src_buf, NULL));
6567
if (test_context->dst_in_psram) {
66-
dst_buf = heap_caps_aligned_alloc(test_context->align, buffer_size, MALLOC_CAP_SPIRAM);
68+
mem_info.extra_heap_caps = MALLOC_CAP_SPIRAM;
6769
} else {
68-
dst_buf = heap_caps_aligned_alloc(test_context->align, buffer_size, MALLOC_CAP_8BIT | MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL);
70+
mem_info.extra_heap_caps = 0;
6971
}
70-
#else
71-
src_buf = heap_caps_aligned_alloc(test_context->align, buffer_size, MALLOC_CAP_8BIT | MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL);
72-
dst_buf = heap_caps_aligned_alloc(test_context->align, buffer_size, MALLOC_CAP_8BIT | MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL);
73-
#endif
74-
TEST_ASSERT_NOT_NULL_MESSAGE(src_buf, "allocate source buffer failed");
75-
TEST_ASSERT_NOT_NULL_MESSAGE(dst_buf, "allocate destination buffer failed");
72+
TEST_ESP_OK(esp_dma_capable_calloc(1, buffer_size, &mem_info, (void **)&dst_buf, NULL));
73+
7674
// adding extra offset
7775
from_addr = src_buf + test_context->offset;
7876
to_addr = dst_buf;
@@ -113,8 +111,13 @@ TEST_CASE("memory copy the same buffer with different content", "[async mcp]")
113111
async_memcpy_config_t config = ASYNC_MEMCPY_DEFAULT_CONFIG();
114112
async_memcpy_handle_t driver = NULL;
115113
TEST_ESP_OK(esp_async_memcpy_install(&config, &driver));
116-
uint8_t *sbuf = heap_caps_aligned_alloc(TEST_MEMCPY_DST_BASE_ALIGN, 256, MALLOC_CAP_8BIT | MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL);
117-
uint8_t *dbuf = heap_caps_aligned_alloc(TEST_MEMCPY_DST_BASE_ALIGN, 256, MALLOC_CAP_8BIT | MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL);
114+
uint8_t *sbuf = NULL;
115+
uint8_t *dbuf = NULL;
116+
esp_dma_mem_info_t mem_info = {
117+
.dma_alignment_bytes = 4,
118+
};
119+
TEST_ESP_OK(esp_dma_capable_calloc(1, 256, &mem_info, (void **)&sbuf, NULL));
120+
TEST_ESP_OK(esp_dma_capable_calloc(1, 256, &mem_info, (void **)&dbuf, NULL));
118121
for (int j = 0; j < 20; j++) {
119122
TEST_ESP_OK(esp_async_memcpy(driver, dbuf, sbuf, 256, NULL, NULL));
120123
vTaskDelay(pdMS_TO_TICKS(10));
@@ -136,7 +139,7 @@ static void test_memory_copy_one_by_one(async_memcpy_handle_t driver)
136139
{
137140
uint32_t aligned_test_buffer_size[] = {256, 512, 1024, 2048, 4096};
138141
memcpy_testbench_context_t test_context = {
139-
.align = TEST_MEMCPY_DST_BASE_ALIGN,
142+
.align = 4,
140143
};
141144

142145
for (int i = 0; i < sizeof(aligned_test_buffer_size) / sizeof(aligned_test_buffer_size[0]); i++) {
@@ -216,9 +219,13 @@ TEST_CASE("memory copy done callback", "[async mcp]")
216219
async_memcpy_handle_t driver = NULL;
217220
TEST_ESP_OK(esp_async_memcpy_install(&config, &driver));
218221

219-
uint8_t *src_buf = heap_caps_aligned_alloc(TEST_MEMCPY_DST_BASE_ALIGN, 256, MALLOC_CAP_8BIT | MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL);
220-
// destination address should aligned to data cache line
221-
uint8_t *dst_buf = heap_caps_aligned_alloc(TEST_MEMCPY_DST_BASE_ALIGN, 256, MALLOC_CAP_8BIT | MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL);
222+
uint8_t *src_buf = NULL;
223+
uint8_t *dst_buf = NULL;
224+
esp_dma_mem_info_t mem_info = {
225+
.dma_alignment_bytes = 4,
226+
};
227+
TEST_ESP_OK(esp_dma_capable_calloc(1, 256, &mem_info, (void **)&src_buf, NULL));
228+
TEST_ESP_OK(esp_dma_capable_calloc(1, 256, &mem_info, (void **)&dst_buf, NULL));
222229

223230
SemaphoreHandle_t sem = xSemaphoreCreateBinary();
224231
TEST_ESP_OK(esp_async_memcpy(driver, dst_buf, src_buf, 256, test_async_memcpy_cb_v1, sem));
@@ -235,38 +242,39 @@ TEST_CASE("memory copy by DMA on the fly", "[async mcp]")
235242
async_memcpy_handle_t driver = NULL;
236243
TEST_ESP_OK(esp_async_memcpy_install(&config, &driver));
237244

238-
uint32_t test_buffer_len[] = {512, 1024, 2048, 4096, 5011};
245+
uint32_t aligned_test_buffer_size[] = {512, 1024, 2048, 4096, 4608};
239246
memcpy_testbench_context_t test_context[5] = {
240247
[0 ... 4] = {
241-
.align = TEST_MEMCPY_DST_BASE_ALIGN,
248+
.align = 4,
242249
}
243250
};
244251

245252
// Aligned case
246-
for (int i = 0; i < sizeof(test_buffer_len) / sizeof(test_buffer_len[0]); i++) {
253+
for (int i = 0; i < sizeof(aligned_test_buffer_size) / sizeof(aligned_test_buffer_size[0]); i++) {
247254
test_context[i].seed = i;
248-
test_context[i].buffer_size = test_buffer_len[i];
255+
test_context[i].buffer_size = aligned_test_buffer_size[i];
249256
async_memcpy_setup_testbench(&test_context[i]);
250257
}
251-
for (int i = 0; i < sizeof(test_buffer_len) / sizeof(test_buffer_len[0]); i++) {
258+
for (int i = 0; i < sizeof(aligned_test_buffer_size) / sizeof(aligned_test_buffer_size[0]); i++) {
252259
TEST_ESP_OK(esp_async_memcpy(driver, test_context[i].to_addr, test_context[i].from_addr, test_context[i].copy_size, NULL, NULL));
253260
}
254-
for (int i = 0; i < sizeof(test_buffer_len) / sizeof(test_buffer_len[0]); i++) {
261+
for (int i = 0; i < sizeof(aligned_test_buffer_size) / sizeof(aligned_test_buffer_size[0]); i++) {
255262
async_memcpy_verify_and_clear_testbench(i, test_context[i].copy_size, test_context[i].src_buf, test_context[i].dst_buf, test_context[i].from_addr, test_context[i].to_addr);
256263
}
257264

258265
#if !TEST_MEMCPY_BUFFER_SIZE_MUST_ALIGN_CACHE
266+
uint32_t unaligned_test_buffer_size[] = {511, 1023, 2047, 4095, 5011};
259267
// Non-aligned case
260-
for (int i = 0; i < sizeof(test_buffer_len) / sizeof(test_buffer_len[0]); i++) {
268+
for (int i = 0; i < sizeof(unaligned_test_buffer_size) / sizeof(unaligned_test_buffer_size[0]); i++) {
261269
test_context[i].seed = i;
262-
test_context[i].buffer_size = test_buffer_len[i];
270+
test_context[i].buffer_size = unaligned_test_buffer_size[i];
263271
test_context[i].offset = 3;
264272
async_memcpy_setup_testbench(&test_context[i]);
265273
}
266-
for (int i = 0; i < sizeof(test_buffer_len) / sizeof(test_buffer_len[0]); i++) {
274+
for (int i = 0; i < sizeof(unaligned_test_buffer_size) / sizeof(unaligned_test_buffer_size[0]); i++) {
267275
TEST_ESP_OK(esp_async_memcpy(driver, test_context[i].to_addr, test_context[i].from_addr, test_context[i].copy_size, NULL, NULL));
268276
}
269-
for (int i = 0; i < sizeof(test_buffer_len) / sizeof(test_buffer_len[0]); i++) {
277+
for (int i = 0; i < sizeof(unaligned_test_buffer_size) / sizeof(unaligned_test_buffer_size[0]); i++) {
270278
async_memcpy_verify_and_clear_testbench(i, test_context[i].copy_size, test_context[i].src_buf, test_context[i].dst_buf, test_context[i].from_addr, test_context[i].to_addr);
271279
}
272280
#endif
@@ -328,7 +336,7 @@ static void memcpy_performance_test(uint32_t buffer_size)
328336
IDF_LOG_PERFORMANCE("CPU_COPY", "%.2f MB/s, dir: SRAM->SRAM, size: %zu Bytes", throughput, test_context.buffer_size);
329337
async_memcpy_verify_and_clear_testbench(test_context.seed, test_context.copy_size, test_context.src_buf, test_context.dst_buf, test_context.from_addr, test_context.to_addr);
330338

331-
#if CONFIG_SPIRAM && SOC_AHB_GDMA_SUPPORT_PSRAM
339+
#if SOC_AHB_GDMA_SUPPORT_PSRAM
332340
// 2. PSRAM->PSRAM
333341
test_context.src_in_psram = true;
334342
test_context.dst_in_psram = true;

components/esp_hw_support/test_apps/dma/main/test_dw_gdma.c

Lines changed: 64 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,20 @@ TEST_CASE("DW_GDMA M2M Test: Contiguous Mode", "[DW_GDMA]")
5656
TEST_ASSERT_NOT_NULL(done_sem);
5757

5858
printf("prepare the source and destination buffers\r\n");
59-
uint8_t *src_buf = heap_caps_aligned_calloc(64, 1, 256, MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
60-
uint8_t *dst_buf = heap_caps_aligned_calloc(64, 1, 256, MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
59+
size_t sram_alignment = 0;
60+
TEST_ESP_OK(esp_cache_get_alignment(0, &sram_alignment));
61+
size_t alignment = MAX(sram_alignment, 8);
62+
uint8_t *src_buf = heap_caps_aligned_calloc(alignment, 1, 256, MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
63+
uint8_t *dst_buf = heap_caps_aligned_calloc(alignment, 1, 256, MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
6164
TEST_ASSERT_NOT_NULL(src_buf);
6265
TEST_ASSERT_NOT_NULL(dst_buf);
6366
for (int i = 0; i < 256; i++) {
6467
src_buf[i] = i;
6568
}
66-
#if CONFIG_IDF_TARGET_ESP32P4
67-
// do write-back for the source data because it's in the cache
68-
TEST_ESP_OK(esp_cache_msync((void *)src_buf, 256, ESP_CACHE_MSYNC_FLAG_DIR_C2M));
69-
#endif
69+
if (sram_alignment) {
70+
// do write-back for the source data because it's in the cache
71+
TEST_ESP_OK(esp_cache_msync((void *)src_buf, 256, ESP_CACHE_MSYNC_FLAG_DIR_C2M));
72+
}
7073

7174
printf("allocate a channel for memory copy\r\n");
7275
dw_gdma_channel_static_config_t static_config = {
@@ -117,10 +120,10 @@ TEST_CASE("DW_GDMA M2M Test: Contiguous Mode", "[DW_GDMA]")
117120
TEST_ASSERT_EQUAL(pdFALSE, xSemaphoreTake(done_sem, pdMS_TO_TICKS(100)));
118121

119122
printf("check the memory copy result\r\n");
120-
#if CONFIG_IDF_TARGET_ESP32P4
121-
// the destination data are not reflected to the cache, so do an invalidate to ask the cache load new data
122-
TEST_ESP_OK(esp_cache_msync((void *)dst_buf, 256, ESP_CACHE_MSYNC_FLAG_DIR_M2C));
123-
#endif
123+
if (sram_alignment) {
124+
// the destination data are not reflected to the cache, so do an invalidate to ask the cache load new data
125+
TEST_ESP_OK(esp_cache_msync((void *)dst_buf, 256, ESP_CACHE_MSYNC_FLAG_DIR_M2C));
126+
}
124127
for (int i = 0; i < 256; i++) {
125128
TEST_ASSERT_EQUAL_UINT8(i, dst_buf[i]);
126129
}
@@ -145,17 +148,20 @@ TEST_CASE("DW_GDMA M2M Test: Reload Mode", "[DW_GDMA]")
145148
TEST_ASSERT_NOT_NULL(done_sem);
146149

147150
printf("prepare the source and destination buffers\r\n");
148-
uint8_t *src_buf = heap_caps_aligned_calloc(64, 1, 256, MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
149-
uint8_t *dst_buf = heap_caps_aligned_calloc(64, 1, 256, MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
151+
size_t sram_alignment = 0;
152+
TEST_ESP_OK(esp_cache_get_alignment(0, &sram_alignment));
153+
size_t alignment = MAX(sram_alignment, 8);
154+
uint8_t *src_buf = heap_caps_aligned_calloc(alignment, 1, 256, MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
155+
uint8_t *dst_buf = heap_caps_aligned_calloc(alignment, 1, 256, MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
150156
TEST_ASSERT_NOT_NULL(src_buf);
151157
TEST_ASSERT_NOT_NULL(dst_buf);
152158
for (int i = 0; i < 256; i++) {
153159
src_buf[i] = i;
154160
}
155-
#if CONFIG_IDF_TARGET_ESP32P4
156-
// do write-back for the source data because it's in the cache
157-
TEST_ESP_OK(esp_cache_msync((void *)src_buf, 256, ESP_CACHE_MSYNC_FLAG_DIR_C2M));
158-
#endif
161+
if (sram_alignment) {
162+
// do write-back for the source data because it's in the cache
163+
TEST_ESP_OK(esp_cache_msync((void *)src_buf, 256, ESP_CACHE_MSYNC_FLAG_DIR_C2M));
164+
}
159165

160166
printf("allocate a channel for memory copy\r\n");
161167
dw_gdma_channel_static_config_t static_config = {
@@ -212,10 +218,10 @@ TEST_CASE("DW_GDMA M2M Test: Reload Mode", "[DW_GDMA]")
212218
TEST_ASSERT_EQUAL(pdTRUE, xSemaphoreTake(done_sem, pdMS_TO_TICKS(100)));
213219

214220
printf("check the memory copy result\r\n");
215-
#if CONFIG_IDF_TARGET_ESP32P4
216-
// the destination data are not reflected to the cache, so do an invalidate to ask the cache load new data
217-
TEST_ESP_OK(esp_cache_msync((void *)dst_buf, 256, ESP_CACHE_MSYNC_FLAG_DIR_M2C));
218-
#endif
221+
if (sram_alignment) {
222+
// the destination data are not reflected to the cache, so do an invalidate to ask the cache load new data
223+
TEST_ESP_OK(esp_cache_msync((void *)dst_buf, 256, ESP_CACHE_MSYNC_FLAG_DIR_M2C));
224+
}
219225
for (int i = 0; i < 256; i++) {
220226
TEST_ASSERT_EQUAL_UINT8(i, dst_buf[i]);
221227
}
@@ -264,17 +270,20 @@ TEST_CASE("DW_GDMA M2M Test: Shadow Mode", "[DW_GDMA]")
264270
TEST_ASSERT_NOT_NULL(done_sem);
265271

266272
printf("prepare the source and destination buffers\r\n");
267-
uint8_t *src_buf = heap_caps_aligned_calloc(64, 1, 256, MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
268-
uint8_t *dst_buf = heap_caps_aligned_calloc(64, 1, 256, MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
273+
size_t sram_alignment = 0;
274+
TEST_ESP_OK(esp_cache_get_alignment(0, &sram_alignment));
275+
size_t alignment = MAX(sram_alignment, 8);
276+
uint8_t *src_buf = heap_caps_aligned_calloc(alignment, 1, 256, MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
277+
uint8_t *dst_buf = heap_caps_aligned_calloc(alignment, 1, 256, MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
269278
TEST_ASSERT_NOT_NULL(src_buf);
270279
TEST_ASSERT_NOT_NULL(dst_buf);
271280
for (int i = 0; i < 256; i++) {
272281
src_buf[i] = i;
273282
}
274-
#if CONFIG_IDF_TARGET_ESP32P4
275-
// do write-back for the source data because it's in the cache
276-
TEST_ESP_OK(esp_cache_msync((void *)src_buf, 256, ESP_CACHE_MSYNC_FLAG_DIR_C2M));
277-
#endif
283+
if (sram_alignment) {
284+
// do write-back for the source data because it's in the cache
285+
TEST_ESP_OK(esp_cache_msync((void *)src_buf, 256, ESP_CACHE_MSYNC_FLAG_DIR_C2M));
286+
}
278287

279288
printf("allocate a channel for memory copy\r\n");
280289
dw_gdma_channel_static_config_t static_config = {
@@ -334,10 +343,10 @@ TEST_CASE("DW_GDMA M2M Test: Shadow Mode", "[DW_GDMA]")
334343
TEST_ASSERT_EQUAL_UINT8(1, user_data.count);
335344

336345
printf("check the memory copy result\r\n");
337-
#if CONFIG_IDF_TARGET_ESP32P4
338-
// the destination data are not reflected to the cache, so do an invalidate to ask the cache load new data
339-
TEST_ESP_OK(esp_cache_msync((void *)dst_buf, 256, ESP_CACHE_MSYNC_FLAG_DIR_M2C));
340-
#endif
346+
if (sram_alignment) {
347+
// the destination data are not reflected to the cache, so do an invalidate to ask the cache load new data
348+
TEST_ESP_OK(esp_cache_msync((void *)dst_buf, 256, ESP_CACHE_MSYNC_FLAG_DIR_M2C));
349+
}
341350
for (int i = 0; i < 256; i++) {
342351
TEST_ASSERT_EQUAL_UINT8(i, dst_buf[i]);
343352
}
@@ -387,17 +396,20 @@ TEST_CASE("DW_GDMA M2M Test: Link-List Mode", "[DW_GDMA]")
387396
TEST_ASSERT_NOT_NULL(done_sem);
388397

389398
printf("prepare the source and destination buffers\r\n");
390-
uint8_t *src_buf = heap_caps_aligned_calloc(64, 1, 256, MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
391-
uint8_t *dst_buf = heap_caps_aligned_calloc(64, 1, 256, MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
399+
size_t sram_alignment = 0;
400+
TEST_ESP_OK(esp_cache_get_alignment(0, &sram_alignment));
401+
size_t alignment = MAX(sram_alignment, 8);
402+
uint8_t *src_buf = heap_caps_aligned_calloc(alignment, 1, 256, MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
403+
uint8_t *dst_buf = heap_caps_aligned_calloc(alignment, 1, 256, MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
392404
TEST_ASSERT_NOT_NULL(src_buf);
393405
TEST_ASSERT_NOT_NULL(dst_buf);
394406
for (int i = 0; i < 256; i++) {
395407
src_buf[i] = i;
396408
}
397-
#if CONFIG_IDF_TARGET_ESP32P4
398-
// do write-back for the source data because it's in the cache
399-
TEST_ESP_OK(esp_cache_msync((void *)src_buf, 256, ESP_CACHE_MSYNC_FLAG_DIR_C2M));
400-
#endif
409+
if (sram_alignment) {
410+
// do write-back for the source data because it's in the cache
411+
TEST_ESP_OK(esp_cache_msync((void *)src_buf, 256, ESP_CACHE_MSYNC_FLAG_DIR_C2M));
412+
}
401413

402414
printf("allocate a channel for memory copy\r\n");
403415
dw_gdma_channel_static_config_t static_config = {
@@ -472,10 +484,10 @@ TEST_CASE("DW_GDMA M2M Test: Link-List Mode", "[DW_GDMA]")
472484
TEST_ASSERT_EQUAL(pdTRUE, xSemaphoreTake(done_sem, pdMS_TO_TICKS(1000)));
473485

474486
printf("check the memory copy result\r\n");
475-
#if CONFIG_IDF_TARGET_ESP32P4
476-
// the destination data are not reflected to the cache, so do an invalidate to ask the cache load new data
477-
TEST_ESP_OK(esp_cache_msync((void *)dst_buf, 256, ESP_CACHE_MSYNC_FLAG_DIR_M2C));
478-
#endif
487+
if (sram_alignment) {
488+
// the destination data are not reflected to the cache, so do an invalidate to ask the cache load new data
489+
TEST_ESP_OK(esp_cache_msync((void *)dst_buf, 256, ESP_CACHE_MSYNC_FLAG_DIR_M2C));
490+
}
479491
for (int i = 0; i < 256; i++) {
480492
TEST_ASSERT_EQUAL_UINT8(i, dst_buf[i]);
481493
}
@@ -504,10 +516,10 @@ TEST_CASE("DW_GDMA M2M Test: Link-List Mode", "[DW_GDMA]")
504516
TEST_ASSERT_EQUAL_UINT8(1, user_data.count);
505517

506518
printf("check the memory copy result\r\n");
507-
#if CONFIG_IDF_TARGET_ESP32P4
508-
// the destination data are not reflected to the cache, so do an invalidate to ask the cache load new data
509-
TEST_ESP_OK(esp_cache_msync((void *)dst_buf, 256, ESP_CACHE_MSYNC_FLAG_DIR_M2C));
510-
#endif
519+
if (sram_alignment) {
520+
// the destination data are not reflected to the cache, so do an invalidate to ask the cache load new data
521+
TEST_ESP_OK(esp_cache_msync((void *)dst_buf, 256, ESP_CACHE_MSYNC_FLAG_DIR_M2C));
522+
}
511523
for (int i = 0; i < 256; i++) {
512524
TEST_ASSERT_EQUAL_UINT8(i, dst_buf[i]);
513525
}
@@ -536,10 +548,10 @@ TEST_CASE("DW_GDMA M2M Test: memory set with fixed address", "[DW_GDMA]")
536548
src_buf[i] = 0;
537549
}
538550
src_buf[0] = 66;
539-
#if CONFIG_IDF_TARGET_ESP32P4
540-
// do write-back for the source data because it's in the cache
541-
TEST_ESP_OK(esp_cache_msync((void *)src_buf, 256, ESP_CACHE_MSYNC_FLAG_DIR_C2M));
542-
#endif
551+
if (ext_mem_alignment) {
552+
// do write-back for the source data because it's in the cache
553+
TEST_ESP_OK(esp_cache_msync((void *)src_buf, 256, ESP_CACHE_MSYNC_FLAG_DIR_C2M));
554+
}
543555

544556
printf("allocate a channel for memory set\r\n");
545557
dw_gdma_channel_static_config_t static_config = {
@@ -581,10 +593,10 @@ TEST_CASE("DW_GDMA M2M Test: memory set with fixed address", "[DW_GDMA]")
581593
vTaskDelay(pdMS_TO_TICKS(100));
582594

583595
printf("check the memory set result\r\n");
584-
#if CONFIG_IDF_TARGET_ESP32P4
585-
// the destination data are not reflected to the cache, so do an invalidate to ask the cache load new data
586-
TEST_ESP_OK(esp_cache_msync((void *)dst_buf, 256, ESP_CACHE_MSYNC_FLAG_DIR_M2C));
587-
#endif
596+
if (int_mem_alignment) {
597+
// the destination data are not reflected to the cache, so do an invalidate to ask the cache load new data
598+
TEST_ESP_OK(esp_cache_msync((void *)dst_buf, 256, ESP_CACHE_MSYNC_FLAG_DIR_M2C));
599+
}
588600
for (int i = 0; i < 256; i++) {
589601
TEST_ASSERT_EQUAL_UINT8(66, dst_buf[i]);
590602
}

0 commit comments

Comments
 (0)