Skip to content

Commit 43b9f6d

Browse files
committed
Merge branch 'feature/do_not_disable_cache_when_xip_from_psram_v4.4' into 'release/v4.4'
system: do not disable cache when xip from psram (v4.4) See merge request espressif/esp-idf!21651
2 parents d6682ce + 7dde97d commit 43b9f6d

File tree

13 files changed

+194
-5
lines changed

13 files changed

+194
-5
lines changed

.gitlab/ci/target-test.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,18 @@ test_app_test_flash_psram_f8r8:
395395
- ESP32S3
396396
- MSPI_F8R8
397397

398+
test_app_test_xip_psram_esp32s2:
399+
extends: .test_app_esp32s2_template
400+
tags:
401+
- ESP32S2
402+
- Example_GENERIC
403+
404+
test_app_test_xip_psram_esp32s3:
405+
extends: .test_app_esp32s3_template
406+
tags:
407+
- ESP32S3
408+
- MSPI_F4R8
409+
398410
.component_ut_template:
399411
extends: .target_test_job_template
400412
needs: # the assign already needs all the build jobs
@@ -747,7 +759,7 @@ UT_C3_SDSPI:
747759

748760
UT_S3:
749761
extends: .unit_test_esp32s3_template
750-
parallel: 32
762+
parallel: 33
751763
tags:
752764
- ESP32S3_IDF
753765
- UT_T1_1

components/spi_flash/cache_utils.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -762,11 +762,11 @@ esp_err_t esp_enable_cache_wrap(bool icache_wrap_enable, bool dcache_wrap_enable
762762
uint32_t instruction_use_spiram = 0;
763763
uint32_t rodata_use_spiram = 0;
764764
#if CONFIG_SPIRAM_FETCH_INSTRUCTIONS
765-
extern uint32_t esp_spiram_instruction_access_enabled();
765+
extern uint32_t esp_spiram_instruction_access_enabled(void);
766766
instruction_use_spiram = esp_spiram_instruction_access_enabled();
767767
#endif
768768
#if CONFIG_SPIRAM_RODATA
769-
extern uint32_t esp_spiram_rodata_access_enabled();
769+
extern uint32_t esp_spiram_rodata_access_enabled(void);
770770
rodata_use_spiram = esp_spiram_rodata_access_enabled();
771771
#endif
772772

components/spi_flash/spi_flash_os_func_app.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#include "driver/spi_common_internal.h"
2323

24+
#define SPI_FLASH_CACHE_NO_DISABLE (CONFIG_SPI_FLASH_AUTO_SUSPEND || (CONFIG_SPIRAM_FETCH_INSTRUCTIONS && CONFIG_SPIRAM_RODATA))
2425
static const char TAG[] = "spi_flash";
2526

2627
/*
@@ -59,14 +60,14 @@ static inline IRAM_ATTR bool on_spi1_check_yield(spi1_app_func_arg_t* ctx);
5960

6061
IRAM_ATTR static void cache_enable(void* arg)
6162
{
62-
#ifndef CONFIG_SPI_FLASH_AUTO_SUSPEND
63+
#if !SPI_FLASH_CACHE_NO_DISABLE
6364
g_flash_guard_default_ops.end();
6465
#endif
6566
}
6667

6768
IRAM_ATTR static void cache_disable(void* arg)
6869
{
69-
#ifndef CONFIG_SPI_FLASH_AUTO_SUSPEND
70+
#if !SPI_FLASH_CACHE_NO_DISABLE
7071
g_flash_guard_default_ops.start();
7172
#endif
7273
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
cmake_minimum_required(VERSION 3.5)
2+
3+
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
4+
project(xip_psram_test)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
| Supported Targets | ESP32-S2 | ESP32-S3 |
2+
| ----------------- | -------- | -------- |
3+
4+
This test app is used to test PSRAM
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
5+
import glob
6+
import os
7+
from typing import Any
8+
9+
import ttfw_idf
10+
from tiny_test_fw import Utility
11+
12+
13+
def test_loop(env, config_names): # type: (Any, Any) -> None
14+
15+
for name in config_names:
16+
Utility.console_log("Checking config \"{}\"... ".format(name), end='')
17+
dut = env.get_dut('xip_from_psram', 'tools/test_apps/system/xip_from_psram', app_config_name=name)
18+
dut.start_app()
19+
dut.expect('Finish')
20+
env.close_dut(dut.name)
21+
Utility.console_log('done')
22+
23+
24+
@ttfw_idf.idf_custom_test(env_tag='Example_GENERIC', target=['esp32s2'])
25+
def test_xip_psram_esp32s2(env, _): # type: (Any, Any) -> None
26+
27+
config_files = glob.glob(os.path.join(os.path.dirname(__file__), 'sdkconfig.ci.esp32s2'))
28+
config_names = [os.path.basename(s).replace('sdkconfig.ci.', '') for s in config_files]
29+
test_loop(env, config_names)
30+
31+
32+
@ttfw_idf.idf_custom_test(env_tag='MSPI_F4R8', target=['esp32s3'])
33+
def test_xip_psram_esp32s3(env, _): # type: (Any, Any) -> None
34+
35+
config_files = glob.glob(os.path.join(os.path.dirname(__file__), 'sdkconfig.ci.esp32s3'))
36+
config_names = [os.path.basename(s).replace('sdkconfig.ci.', '') for s in config_files]
37+
test_loop(env, config_names)
38+
39+
40+
if __name__ == '__main__':
41+
test_xip_psram_esp32s2()
42+
test_xip_psram_esp32s3()
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
idf_build_get_property(target IDF_TARGET)
2+
3+
set(srcs "test_xip_psram.c")
4+
5+
idf_component_register(SRCS ${srcs})
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <sys/param.h>
8+
#include <string.h>
9+
#include <inttypes.h>
10+
#include "sdkconfig.h"
11+
#include "esp_log.h"
12+
#include "esp_attr.h"
13+
#include "freertos/FreeRTOS.h"
14+
#include "freertos/task.h"
15+
#include "unity.h"
16+
#include "esp_heap_caps.h"
17+
#include "esp_flash.h"
18+
#include "esp_partition.h"
19+
20+
__attribute__((unused)) const static char *TAG = "PSRAM";
21+
22+
#if CONFIG_SPIRAM_FETCH_INSTRUCTIONS && CONFIG_SPIRAM_RODATA
23+
#include "esp_partition.h"
24+
#include "esp_timer.h"
25+
#include "esp32s3/rom/spi_flash.h"
26+
27+
#define SECTOR_LEN 4096
28+
#define TEST_NUM 10
29+
#define TEST_BUF {0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9}
30+
31+
static uint32_t s_timer_cb_exe_times;
32+
static const uint8_t s_test_buf[TEST_NUM] = TEST_BUF;
33+
34+
static const esp_partition_t *s_get_partition(void)
35+
{
36+
//Find the "storage1" partition defined in `partitions.csv`
37+
const esp_partition_t *result = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_ANY, "storage1");
38+
if (!result) {
39+
ESP_LOGE(TAG, "Can't find the partition, please define it correctly in `partitions.csv`");
40+
abort();
41+
}
42+
return result;
43+
}
44+
45+
static void NOINLINE_ATTR s_test_rodata(void* arg)
46+
{
47+
s_timer_cb_exe_times ++;
48+
uint8_t cmp_buf[TEST_NUM] = TEST_BUF;
49+
TEST_ASSERT(memcmp(cmp_buf, s_test_buf, TEST_NUM) == 0);
50+
}
51+
52+
void test_spi1_flash_with_xip_psram(void)
53+
{
54+
//Get the partition used for SPI1 erase operation
55+
const esp_partition_t *part = s_get_partition();
56+
ESP_LOGI(TAG, "found partition '%s' at offset 0x%"PRIx32" with size 0x%"PRIx32, part->label, part->address, part->size);
57+
//Erase whole region
58+
TEST_ESP_OK(esp_flash_erase_region(part->flash_chip, part->address, part->size));
59+
60+
61+
esp_timer_handle_t oneshot_timer;
62+
const esp_timer_create_args_t oneshot_timer_args = {
63+
.callback = &s_test_rodata,
64+
.arg = NULL,
65+
.dispatch_method = ESP_TIMER_ISR,
66+
.name = "one-shot"
67+
};
68+
ESP_ERROR_CHECK(esp_timer_create(&oneshot_timer_args, &oneshot_timer));
69+
70+
esp_rom_spiflash_result_t ret;
71+
uint32_t start = part->address;
72+
ESP_LOGI(TAG, "test data partition: 0x%"PRIx32, start);
73+
uint32_t sector_num = start / SECTOR_LEN;
74+
75+
ESP_ERROR_CHECK(esp_timer_start_periodic(oneshot_timer, 1 * 10 * 1000));
76+
ret = esp_rom_spiflash_erase_sector(sector_num);
77+
if (ret != ESP_ROM_SPIFLASH_RESULT_OK) {
78+
ESP_LOGE(TAG, "erase fail!");
79+
TEST_ASSERT(false);
80+
}
81+
82+
TEST_ASSERT(s_timer_cb_exe_times > 0);
83+
printf("timer callback runs %"PRId32" times\n", s_timer_cb_exe_times);
84+
85+
ESP_LOGI(TAG, "Finish");
86+
ESP_ERROR_CHECK(esp_timer_stop(oneshot_timer));
87+
ESP_ERROR_CHECK(esp_timer_delete(oneshot_timer));
88+
}
89+
90+
void app_main(void)
91+
{
92+
test_spi1_flash_with_xip_psram();
93+
}
94+
#endif //CONFIG_SPIRAM_FETCH_INSTRUCTIONS && CONFIG_SPIRAM_RODATA
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Name, Type, SubType, Offset, Size, Flags
2+
# Note: if you have increased the bootloader size, make sure to update the offsets to avoid overlap
3+
nvs, data, nvs, 0x9000, 0x6000,
4+
phy_init, data, phy, 0xf000, 0x1000,
5+
factory, app, factory, 0x10000, 1M,
6+
storage1, data, fat, , 512K,
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
CONFIG_IDF_TARGET="esp32s2"
2+
3+
CONFIG_ESP32S2_SPIRAM_SUPPORT=y
4+
CONFIG_SPIRAM_FETCH_INSTRUCTIONS=y
5+
CONFIG_SPIRAM_RODATA=y

0 commit comments

Comments
 (0)