Просмотр исходного кода

Merge branch 'fix/ci_ut_psram_wroverb_v3.3' into 'release/v3.3'

ci: fix one ut issue when using Wrover-B module with newer ver of PSRAM (backport v3.3)

See merge request espressif/esp-idf!6594
Angus Gratton 6 лет назад
Родитель
Сommit
efdddbb253

+ 8 - 0
.gitlab-ci.yml

@@ -1230,6 +1230,14 @@ UT_032:
     - UT_T1_1
     - psram
 
+UT_033:
+  extends: .unit_test_template
+  parallel: 2
+  tags:
+    - ESP32_IDF
+    - UT_T1_PSRAMV0
+    - psram
+
 IT_001:
   <<: *test_template
   parallel: 3

+ 3 - 0
components/esp32/Kconfig

@@ -267,6 +267,9 @@ menu "ESP32-specific"
                 bool "HSPI host (SPI2)"
             config SPIRAM_OCCUPY_VSPI_HOST
                 bool "VSPI host (SPI3)"
+            config SPIRAM_OCCUPY_NO_HOST
+                bool "Will not try to use any host, will abort if not able to use the PSRAM"
+
         endchoice
 
         menu "PSRAM clock and cs IO for ESP32-DOWD"

+ 12 - 1
components/esp32/spiram_psram.c

@@ -611,6 +611,12 @@ psram_size_t psram_get_size()
     }
 }
 
+//used in UT only
+bool psram_is_32mbit_ver0(void)
+{
+    return PSRAM_IS_32MBIT_VER0(s_psram_id);
+}
+
 /*
  * Psram mode init will overwrite original flash speed mode, so that it is possible to change psram and flash speed after OTA.
  * Flash read mode(QIO/QOUT/DIO/DOUT) will not be changed in app bin. It is decided by bootloader, OTA can not change this mode.
@@ -721,9 +727,13 @@ esp_err_t IRAM_ATTR psram_enable(psram_cache_mode_t mode, psram_vaddr_mode_t vad
         return ESP_FAIL;
     }
 
-    if (PSRAM_IS_32MBIT_VER0(s_psram_id)) {
+    if (psram_is_32mbit_ver0()) {
         s_clk_mode = PSRAM_CLK_MODE_DCLK;
         if (mode == PSRAM_CACHE_F80M_S80M) {
+#ifdef CONFIG_SPIRAM_OCCUPY_NO_HOST
+            ESP_EARLY_LOGE(TAG, "This version of PSRAM needs to claim an extra SPI peripheral at 80MHz. Please either: choose lower frequency by SPIRAM_SPEED_, or select one SPI peripheral it by SPIRAM_OCCUPY_*SPI_HOST in the menuconfig.");
+            abort();
+#else
             /*   note: If the third mode(80Mhz+80Mhz) is enabled for 32MBit 1V8 psram, one of HSPI/VSPI port will be
                  occupied by the system (according to kconfig).
                  Application code should never touch HSPI/VSPI hardware in this case.  We try to stop applications
@@ -747,6 +757,7 @@ esp_err_t IRAM_ATTR psram_enable(psram_cache_mode_t mode, psram_vaddr_mode_t vad
                     break;
                 }
             }
+#endif
         }
     } else {
         // For other psram, we don't need any extra clock cycles after cs get back to high level

+ 43 - 20
components/esp32/test/test_4mpsram.c

@@ -36,37 +36,60 @@ static void test_psram_content()
 }
 #endif
 
-// NOTE: this unit test rely on the config that PSRAM of 8MB is used only when CONFIG_SPIRAM_BNKSWITCH_ENABLE is set
-TEST_CASE("can use spi when not being used by psram", "[psram_4m]")
-{
-    spi_host_device_t host;
-#if !CONFIG_SPIRAM_SUPPORT || !CONFIG_SPIRAM_SPEED_80M || CONFIG_SPIRAM_BANKSWITCH_ENABLE
-    //currently all 8M psram don't need more SPI peripherals
-    host = -1;
-#elif CONFIG_SPIRAM_OCCUPY_HSPI_HOST
-    host = HSPI_HOST;
-#elif CONFIG_SPIRAM_OCCUPY_VSPI_HOST
-    host = VSPI_HOST;
-#endif
+bool psram_is_32mbit_ver0(void);
 
+static void test_spi_bus_occupy(spi_host_device_t expected_occupied_host)
+{
     bool claim_hspi = spicommon_periph_claim(HSPI_HOST, "ut-hspi");
     if (claim_hspi) ESP_LOGI(TAG, "HSPI claimed.");
 
     bool claim_vspi = spicommon_periph_claim(VSPI_HOST, "ut-vspi");
     if (claim_vspi) ESP_LOGI(TAG, "VSPI claimed.");
 
-    if (host == HSPI_HOST) {
-        TEST_ASSERT(claim_hspi==false);
-        TEST_ASSERT(claim_vspi==true);
-    } else if (host == VSPI_HOST) {
-        TEST_ASSERT(claim_vspi==false);
-        TEST_ASSERT(claim_hspi==true);
+    if (expected_occupied_host == HSPI_HOST) {
+        TEST_ASSERT_FALSE(claim_hspi);
+        TEST_ASSERT(claim_vspi);
+    } else if (expected_occupied_host == VSPI_HOST) {
+        TEST_ASSERT_FALSE(claim_vspi);
+        TEST_ASSERT(claim_hspi);
     } else {
-        TEST_ASSERT(claim_hspi==true);
-        TEST_ASSERT(claim_vspi==true);
+        TEST_ASSERT(claim_hspi);
+        TEST_ASSERT(claim_vspi);
     }
 
 #ifdef CONFIG_SPIRAM_SUPPORT
     test_psram_content();
 #endif
 }
+
+#if CONFIG_SPIRAM_OCCUPY_HSPI_HOST || CONFIG_SPIRAM_OCCUPY_VSPI_HOST
+TEST_CASE("some spi bus occpied by psram", "[psram_4m][test_env=UT_T1_PSRAMV0]")
+{
+// NOTE: this unit test rely on the config that PSRAM of 8MB is used only when CONFIG_SPIRAM_BNKSWITCH_ENABLE is set
+//currently all 8M psram don't need more SPI peripherals
+#if !CONFIG_SPIRAM_SUPPORT || !CONFIG_SPIRAM_SPEED_80M || CONFIG_SPIRAM_BANKSWITCH_ENABLE
+#error unexpected test config, only psram 32MBit ver 0 at 80MHz will trigger the workaround
+#endif
+
+    spi_host_device_t host;
+    if (!psram_is_32mbit_ver0()) {
+        TEST_FAIL_MESSAGE("unexpected psram version");
+    }
+
+#if CONFIG_SPIRAM_OCCUPY_HSPI_HOST
+    host = HSPI_HOST;
+#elif CONFIG_SPIRAM_OCCUPY_VSPI_HOST
+    host = VSPI_HOST;
+#endif
+    test_spi_bus_occupy(host);
+}
+#else
+TEST_CASE("can use spi when not being used by psram", "[psram_4m]")
+{
+#if CONFIG_SPIRAM_SUPPORT && CONFIG_SPIRAM_SPEED_80M
+#error unexpected test config, some runners using the UT_T1_PSRAMV0 but still perform this test.\
+they will not pass this test at 80MHz.
+#endif
+    test_spi_bus_occupy(-1);
+}
+#endif

+ 1 - 0
tools/unit-test-app/configs/psram

@@ -1,2 +1,3 @@
 TEST_EXCLUDE_COMPONENTS=libsodium bt app_update driver esp32 spi_flash
 CONFIG_SPIRAM_SUPPORT=y
+CONFIG_SPIRAM_OCCUPY_NO_HOST=y

+ 1 - 0
tools/unit-test-app/configs/psram_2

@@ -1,2 +1,3 @@
 TEST_COMPONENTS=driver esp32 spi_flash
 CONFIG_SPIRAM_SUPPORT=y
+CONFIG_SPIRAM_OCCUPY_NO_HOST=y

+ 1 - 0
tools/unit-test-app/configs/psram_8m

@@ -2,3 +2,4 @@ TEST_COMPONENTS=esp32
 CONFIG_SPIRAM_SUPPORT=y
 CONFIG_SPIRAM_BANKSWITCH_ENABLE=y
 CONFIG_SPIRAM_BANKSWITCH_RESERVE=8
+CONFIG_SPIRAM_OCCUPY_NO_HOST=y