From bf6ca71630e4e4ed5ac9f577a60725ce35df3ebd Mon Sep 17 00:00:00 2001 From: Armando Date: Thu, 10 Nov 2022 19:46:24 +0800 Subject: [PATCH] esp_psram: return error when fail to detect oct psram --- components/esp_psram/esp32/esp_psram_impl_quad.c | 4 ++-- components/esp_psram/esp32s2/esp_psram_impl_quad.c | 4 ++-- components/esp_psram/esp32s3/esp_psram_impl_octal.c | 5 +++++ components/esp_psram/esp32s3/esp_psram_impl_quad.c | 4 ++-- components/esp_psram/esp_psram_impl.h | 5 +++-- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/components/esp_psram/esp32/esp_psram_impl_quad.c b/components/esp_psram/esp32/esp_psram_impl_quad.c index 69b3982da83..160d0095159 100644 --- a/components/esp_psram/esp32/esp_psram_impl_quad.c +++ b/components/esp_psram/esp32/esp_psram_impl_quad.c @@ -948,8 +948,8 @@ esp_err_t IRAM_ATTR esp_psram_impl_enable(psram_vaddr_mode_t vaddrmode) //psra */ psram_read_id(spi_num, &s_psram_id); if (!PSRAM_IS_VALID(s_psram_id)) { - ESP_EARLY_LOGE(TAG, "PSRAM ID read error: 0x%08x", (uint32_t)s_psram_id); - return ESP_FAIL; + ESP_EARLY_LOGE(TAG, "PSRAM ID read error: 0x%08x, PSRAM chip not found or not supported", (uint32_t)s_psram_id); + return ESP_ERR_NOT_SUPPORTED; } } diff --git a/components/esp_psram/esp32s2/esp_psram_impl_quad.c b/components/esp_psram/esp32s2/esp_psram_impl_quad.c index 8d039f27f92..0f4a0a003bb 100644 --- a/components/esp_psram/esp32s2/esp_psram_impl_quad.c +++ b/components/esp_psram/esp32s2/esp_psram_impl_quad.c @@ -420,8 +420,8 @@ esp_err_t IRAM_ATTR esp_psram_impl_enable(psram_vaddr_mode_t vaddrmode) //psra */ psram_read_id(spi_num, &s_psram_id); if (!PSRAM_IS_VALID(s_psram_id)) { - ESP_EARLY_LOGE(TAG, "PSRAM ID read error: 0x%08x", s_psram_id); - return ESP_FAIL; + ESP_EARLY_LOGE(TAG, "PSRAM ID read error: 0x%08x, PSRAM chip not found or not supported", (uint32_t)s_psram_id); + return ESP_ERR_NOT_SUPPORTED; } } diff --git a/components/esp_psram/esp32s3/esp_psram_impl_octal.c b/components/esp_psram/esp32s3/esp_psram_impl_octal.c index b1e50896bc4..ab472ddda98 100644 --- a/components/esp_psram/esp32s3/esp_psram_impl_octal.c +++ b/components/esp_psram/esp32s3/esp_psram_impl_octal.c @@ -30,6 +30,7 @@ #define OCT_PSRAM_RD_DUMMY_BITLEN (2*(10-1)) #define OCT_PSRAM_WR_DUMMY_BITLEN (2*(5-1)) #define OCT_PSRAM_CS1_IO SPI_CS1_GPIO_NUM +#define OCT_PSRAM_VENDOR_ID 0xD #define OCT_PSRAM_CS_SETUP_TIME 3 #define OCT_PSRAM_CS_HOLD_TIME 3 @@ -310,6 +311,10 @@ esp_err_t esp_psram_impl_enable(psram_vaddr_mode_t vaddrmode) s_init_psram_mode_reg(1, &mode_reg); //Print PSRAM info s_get_psram_mode_reg(1, &mode_reg); + if (mode_reg.mr1.vendor_id != OCT_PSRAM_VENDOR_ID) { + ESP_EARLY_LOGE(TAG, "PSRAM ID read error: 0x%08x, PSRAM chip not found or not supported, or wrong PSRAM line mode", mode_reg.mr1.vendor_id); + return ESP_ERR_NOT_SUPPORTED; + } s_print_psram_info(&mode_reg); s_psram_size = mode_reg.mr2.density == 0x1 ? PSRAM_SIZE_4MB : mode_reg.mr2.density == 0X3 ? PSRAM_SIZE_8MB : diff --git a/components/esp_psram/esp32s3/esp_psram_impl_quad.c b/components/esp_psram/esp32s3/esp_psram_impl_quad.c index 3a2cad377b6..2b6416188d8 100644 --- a/components/esp_psram/esp32s3/esp_psram_impl_quad.c +++ b/components/esp_psram/esp32s3/esp_psram_impl_quad.c @@ -315,8 +315,8 @@ esp_err_t esp_psram_impl_enable(psram_vaddr_mode_t vaddrmode) //psram init */ psram_read_id(SPI1_NUM, &s_psram_id); if (!PSRAM_IS_VALID(s_psram_id)) { - ESP_EARLY_LOGE(TAG, "PSRAM ID read error: 0x%08x", s_psram_id); - return ESP_FAIL; + ESP_EARLY_LOGE(TAG, "PSRAM ID read error: 0x%08x, PSRAM chip not found or not supported, or wrong PSRAM line mode", (uint32_t)s_psram_id); + return ESP_ERR_NOT_SUPPORTED; } } diff --git a/components/esp_psram/esp_psram_impl.h b/components/esp_psram/esp_psram_impl.h index a5a0414189e..12fd28e2996 100644 --- a/components/esp_psram/esp_psram_impl.h +++ b/components/esp_psram/esp_psram_impl.h @@ -52,8 +52,9 @@ esp_err_t esp_psram_impl_get_available_size(uint32_t *out_size_bytes); * * @param vaddrmode Mode the psram cache works in. * @return - * - ESP_OK: On success, - * - ESP_ERR_INVALID_STATE: On esp32, when VSPI peripheral is needed but cannot be claimed. + * - ESP_OK: On success + * - ESP_ERR_NOT_SUPPORTED: PSRAM ID / vendor ID check fail + * - ESP_ERR_INVALID_STATE: On esp32, when VSPI peripheral is needed but cannot be claimed */ esp_err_t esp_psram_impl_enable(psram_vaddr_mode_t vaddrmode);