Skip to content

Commit 6505bcd

Browse files
committed
refactor(psram): rename quad psram related naming
1 parent d816622 commit 6505bcd

File tree

3 files changed

+109
-105
lines changed

3 files changed

+109
-105
lines changed

components/esp_psram/device/esp_psram_impl_ap_quad.c

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -16,7 +16,7 @@
1616
#include "esp_private/mspi_timing_tuning.h"
1717
#include "esp_private/esp_gpio_reserve.h"
1818
#include "hal/psram_ctrlr_ll.h"
19-
#include "esp_quad_psram_defs.h"
19+
#include "esp_quad_psram_defs_ap.h"
2020
#include "soc/soc_caps.h"
2121

2222
static const char* TAG = "quad_psram";
@@ -60,7 +60,7 @@ void psram_exec_cmd(int spi_num, psram_hal_cmd_mode_t mode,
6060
static void psram_disable_qio_mode(int spi_num)
6161
{
6262
psram_exec_cmd(spi_num, PSRAM_HAL_CMD_QPI,
63-
PSRAM_EXIT_QMODE, 8, /* command and command bit len*/
63+
PSRAM_QUAD_EXIT_QMODE, 8, /* command and command bit len*/
6464
0, 0, /* address and address bit len*/
6565
0, /* dummy bit len */
6666
NULL, 0, /* tx data and tx bit len*/
@@ -75,7 +75,7 @@ static void psram_disable_qio_mode(int spi_num)
7575
static void psram_set_wrap_burst_length(int spi_num, psram_hal_cmd_mode_t mode)
7676
{
7777
psram_exec_cmd(spi_num, mode,
78-
PSRAM_SET_BURST_LEN, 8, /* command and command bit len*/
78+
PSRAM_QUAD_SET_BURST_LEN, 8, /* command and command bit len*/
7979
0, 0, /* address and address bit len*/
8080
0, /* dummy bit len */
8181
NULL, 0, /* tx data and tx bit len*/
@@ -88,7 +88,7 @@ static void psram_set_wrap_burst_length(int spi_num, psram_hal_cmd_mode_t mode)
8888
static void psram_reset_mode(int spi_num)
8989
{
9090
psram_exec_cmd(spi_num, PSRAM_HAL_CMD_SPI,
91-
PSRAM_RESET_EN, 8, /* command and command bit len*/
91+
PSRAM_QUAD_RESET_EN, 8, /* command and command bit len*/
9292
0, 0, /* address and address bit len*/
9393
0, /* dummy bit len */
9494
NULL, 0, /* tx data and tx bit len*/
@@ -97,7 +97,7 @@ static void psram_reset_mode(int spi_num)
9797
false); /* whether is program/erase operation */
9898

9999
psram_exec_cmd(spi_num, PSRAM_HAL_CMD_SPI,
100-
PSRAM_RESET, 8, /* command and command bit len*/
100+
PSRAM_QUAD_RESET, 8, /* command and command bit len*/
101101
0, 0, /* address and address bit len*/
102102
0, /* dummy bit len */
103103
NULL, 0, /* tx data and tx bit len*/
@@ -144,7 +144,7 @@ bool psram_support_wrap_size(uint32_t wrap_size)
144144
static void psram_read_id(int spi_num, uint8_t* dev_id, int id_bits)
145145
{
146146
psram_exec_cmd(spi_num, PSRAM_HAL_CMD_SPI,
147-
PSRAM_DEVICE_ID, 8, /* command and command bit len*/
147+
PSRAM_QUAD_DEVICE_ID, 8, /* command and command bit len*/
148148
0, 24, /* address and address bit len*/
149149
0, /* dummy bit len */
150150
NULL, 0, /* tx data and tx bit len*/
@@ -157,7 +157,7 @@ static void psram_read_id(int spi_num, uint8_t* dev_id, int id_bits)
157157
static void psram_enable_qio_mode(int spi_num)
158158
{
159159
psram_exec_cmd(spi_num, PSRAM_HAL_CMD_SPI,
160-
PSRAM_ENTER_QMODE, 8, /* command and command bit len*/
160+
PSRAM_QUAD_ENTER_QMODE, 8, /* command and command bit len*/
161161
0, 0, /* address and address bit len*/
162162
0, /* dummy bit len */
163163
NULL, 0, /* tx data and tx bit len*/
@@ -168,14 +168,14 @@ static void psram_enable_qio_mode(int spi_num)
168168

169169
static void psram_set_cs_timing(void)
170170
{
171-
psram_ctrlr_ll_set_cs_hold(PSRAM_CTRLR_LL_MSPI_ID_0, PSRAM_CS_HOLD_VAL);
172-
psram_ctrlr_ll_set_cs_setup(PSRAM_CTRLR_LL_MSPI_ID_0, PSRAM_CS_SETUP_VAL);
171+
psram_ctrlr_ll_set_cs_hold(PSRAM_CTRLR_LL_MSPI_ID_0, PSRAM_QUAD_CS_HOLD_VAL);
172+
psram_ctrlr_ll_set_cs_setup(PSRAM_CTRLR_LL_MSPI_ID_0, PSRAM_QUAD_CS_SETUP_VAL);
173173
}
174174

175175
static void psram_gpio_config(void)
176176
{
177177
//CS1
178-
uint8_t cs1_io = PSRAM_CS_IO;
178+
uint8_t cs1_io = PSRAM_QUAD_CS_IO;
179179
if (cs1_io == MSPI_IOMUX_PIN_NUM_CS1) {
180180
gpio_ll_func_sel(&GPIO, cs1_io, FUNC_SPICS1_SPICS1);
181181
} else {
@@ -185,7 +185,7 @@ static void psram_gpio_config(void)
185185
s_psram_cs_io = cs1_io;
186186

187187
//WP HD
188-
uint8_t wp_io = PSRAM_SPIWP_SD3_IO;
188+
uint8_t wp_io = PSRAM_QUAD_SPIWP_SD3_IO;
189189
#if SOC_SPI_MEM_SUPPORT_CONFIG_GPIO_BY_EFUSE
190190
const uint32_t spiconfig = esp_rom_efuse_get_flash_gpio_info();
191191
if (spiconfig == ESP_ROM_EFUSE_FLASH_DEFAULT_SPI) {
@@ -224,7 +224,7 @@ static void s_config_psram_clock(void)
224224
bool s_check_aps3204_2tmode(void)
225225
{
226226
uint64_t full_eid = 0;
227-
psram_read_id(PSRAM_CTRLR_LL_MSPI_ID_1, (uint8_t *)&full_eid, PSRAM_EID_BITS_NUM);
227+
psram_read_id(PSRAM_CTRLR_LL_MSPI_ID_1, (uint8_t *)&full_eid, PSRAM_QUAD_EID_BITS_NUM);
228228

229229
bool is_2t = false;
230230
uint32_t eid_47_16 = __builtin_bswap32((full_eid >> 16) & UINT32_MAX);
@@ -250,31 +250,31 @@ esp_err_t esp_psram_impl_enable(void)
250250

251251
//We use SPI1 to init PSRAM
252252
psram_disable_qio_mode(PSRAM_CTRLR_LL_MSPI_ID_1);
253-
psram_read_id(PSRAM_CTRLR_LL_MSPI_ID_1, (uint8_t *)&psram_id, PSRAM_ID_BITS_NUM);
254-
if (!PSRAM_IS_VALID(psram_id)) {
253+
psram_read_id(PSRAM_CTRLR_LL_MSPI_ID_1, (uint8_t *)&psram_id, PSRAM_QUAD_ID_BITS_NUM);
254+
if (!PSRAM_QUAD_IS_VALID(psram_id)) {
255255
/* 16Mbit psram ID read error workaround:
256256
* treat the first read id as a dummy one as the pre-condition,
257257
* Send Read ID command again
258258
*/
259-
psram_read_id(PSRAM_CTRLR_LL_MSPI_ID_1, (uint8_t *)&psram_id, PSRAM_ID_BITS_NUM);
260-
if (!PSRAM_IS_VALID(psram_id)) {
259+
psram_read_id(PSRAM_CTRLR_LL_MSPI_ID_1, (uint8_t *)&psram_id, PSRAM_QUAD_ID_BITS_NUM);
260+
if (!PSRAM_QUAD_IS_VALID(psram_id)) {
261261
ESP_EARLY_LOGE(TAG, "PSRAM ID read error: 0x%08x, PSRAM chip not found or not supported, or wrong PSRAM line mode", (uint32_t)psram_id);
262262
return ESP_ERR_NOT_SUPPORTED;
263263
}
264264
}
265265

266-
if (PSRAM_IS_64MBIT_TRIAL(psram_id)) {
266+
if (PSRAM_QUAD_IS_64MBIT_TRIAL(psram_id)) {
267267
s_psram_size = PSRAM_SIZE_8MB;
268268
} else {
269-
uint8_t density = PSRAM_SIZE_ID(psram_id);
270-
const int eid = PSRAM_EID_BIT_47_40(psram_id);
269+
uint8_t density = PSRAM_QUAD_SIZE_ID(psram_id);
270+
const int eid = PSRAM_QUAD_EID_BIT_47_40(psram_id);
271271
s_psram_size = density == 0x0 ? PSRAM_SIZE_2MB :
272272
density == 0x1 ? PSRAM_SIZE_4MB :
273273
density == 0x2 ? PSRAM_SIZE_8MB :
274274
/* Do not use `density` for QEMU PSRAM since we don't want any future QSPI PSRAM
275275
* that are 16MB or 32MB to be interpreted as QEMU PSRAM devices */
276-
eid == PSRAM_QEMU_16MB_ID ? PSRAM_SIZE_16MB :
277-
eid == PSRAM_QEMU_32MB_ID ? PSRAM_SIZE_32MB : 0;
276+
eid == PSRAM_QUAD_QEMU_16MB_ID ? PSRAM_SIZE_16MB :
277+
eid == PSRAM_QUAD_QEMU_32MB_ID ? PSRAM_SIZE_32MB : 0;
278278
}
279279

280280
if ((s_psram_size == PSRAM_SIZE_8MB) && s_check_aps3204_2tmode()) {
@@ -306,10 +306,10 @@ esp_err_t esp_psram_impl_enable(void)
306306
static void config_psram_spi_phases(void)
307307
{
308308
psram_ctrlr_ll_set_read_mode(PSRAM_CTRLR_LL_MSPI_ID_0, PSRAM_HAL_CMD_QPI);
309-
psram_ctrlr_ll_set_wr_cmd(PSRAM_CTRLR_LL_MSPI_ID_0, PSRAM_CMD_LENGTH, PSRAM_QUAD_WRITE);
310-
psram_ctrlr_ll_set_rd_cmd(PSRAM_CTRLR_LL_MSPI_ID_0, PSRAM_CMD_LENGTH, PSRAM_FAST_READ_QUAD);
311-
psram_ctrlr_ll_set_addr_bitlen(PSRAM_CTRLR_LL_MSPI_ID_0, PSRAM_ADDR_LENGTH);
312-
psram_ctrlr_ll_set_rd_dummy(PSRAM_CTRLR_LL_MSPI_ID_0, PSRAM_FAST_READ_QUAD_DUMMY);
309+
psram_ctrlr_ll_set_wr_cmd(PSRAM_CTRLR_LL_MSPI_ID_0, PSRAM_QUAD_CMD_LENGTH, PSRAM_QUAD_WRITE_QUAD);
310+
psram_ctrlr_ll_set_rd_cmd(PSRAM_CTRLR_LL_MSPI_ID_0, PSRAM_QUAD_CMD_LENGTH, PSRAM_QUAD_FAST_READ_QUAD);
311+
psram_ctrlr_ll_set_addr_bitlen(PSRAM_CTRLR_LL_MSPI_ID_0, PSRAM_QUAD_ADDR_LENGTH);
312+
psram_ctrlr_ll_set_rd_dummy(PSRAM_CTRLR_LL_MSPI_ID_0, PSRAM_QUAD_FAST_READ_QUAD_DUMMY);
313313
psram_ctrlr_ll_set_cs_pin(PSRAM_CTRLR_LL_MSPI_ID_0, PSRAM_LL_CS_ID_1);
314314
}
315315

components/esp_psram/device/esp_quad_psram_defs.h

Lines changed: 0 additions & 79 deletions
This file was deleted.
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
//Commands for PSRAM chip
8+
9+
#pragma once
10+
11+
#include "soc/spi_pins.h"
12+
13+
#ifdef __cplusplus
14+
extern "C" {
15+
#endif
16+
17+
/*---------------------------------------------------------------------------------
18+
* AP Memory PSRAM
19+
*-------------------------------------------------------------------------------*/
20+
21+
#define PSRAM_QUAD_READ 0x03
22+
#define PSRAM_QUAD_FAST_READ 0x0B
23+
#define PSRAM_QUAD_FAST_READ_QUAD 0xEB
24+
#define PSRAM_QUAD_WRITE 0x02
25+
#define PSRAM_QUAD_WRITE_QUAD 0x38
26+
#define PSRAM_QUAD_ENTER_QMODE 0x35
27+
#define PSRAM_QUAD_EXIT_QMODE 0xF5
28+
#define PSRAM_QUAD_RESET_EN 0x66
29+
#define PSRAM_QUAD_RESET 0x99
30+
#define PSRAM_QUAD_SET_BURST_LEN 0xC0
31+
#define PSRAM_QUAD_DEVICE_ID 0x9F
32+
33+
#define PSRAM_QUAD_FAST_READ_DUMMY 4
34+
#define PSRAM_QUAD_FAST_READ_QUAD_DUMMY 6
35+
36+
// ID
37+
#define PSRAM_QUAD_ID_BITS_NUM 24
38+
#define PSRAM_QUAD_EID_BITS_NUM 48
39+
#define PSRAM_QUAD_ID_KGD_M 0xff
40+
#define PSRAM_QUAD_ID_KGD_S 8
41+
#define PSRAM_QUAD_ID_KGD 0x5d
42+
#define PSRAM_QUAD_ID_EID_BIT_47_40_M 0xff
43+
#define PSRAM_QUAD_ID_EID_BIT_47_40_S 16
44+
45+
// Use the [47:45](bit47~bit45) of EID to distinguish the psram size:
46+
//
47+
// BIT47 | BIT46 | BIT45 | SIZE(MBIT)
48+
// -------------------------------------
49+
// 0 | 0 | 0 | 16
50+
// 0 | 0 | 1 | 32
51+
// 0 | 1 | 0 | 64
52+
#define PSRAM_QUAD_EID_BIT_47_45_M 0x07
53+
#define PSRAM_QUAD_EID_BIT_47_45_S 5
54+
55+
#define PSRAM_QUAD_KGD(id) (((id) >> PSRAM_QUAD_ID_KGD_S) & PSRAM_QUAD_ID_KGD_M)
56+
#define PSRAM_QUAD_EID_BIT_47_40(id) (((id) >> PSRAM_QUAD_ID_EID_BIT_47_40_S) & PSRAM_QUAD_ID_EID_BIT_47_40_M)
57+
#define PSRAM_QUAD_SIZE_ID(id) ((PSRAM_QUAD_EID_BIT_47_40(id) >> PSRAM_QUAD_EID_BIT_47_45_S) & PSRAM_QUAD_EID_BIT_47_45_M)
58+
#define PSRAM_QUAD_IS_VALID(id) (PSRAM_QUAD_KGD(id) == PSRAM_QUAD_ID_KGD)
59+
60+
#define PSRAM_QUAD_IS_64MBIT_TRIAL(id) (PSRAM_QUAD_EID_BIT_47_40(id) == 0x26)
61+
62+
// IO-pins for PSRAM.
63+
// PSRAM clock and cs IO should be configured based on hardware design.
64+
#define PSRAM_QUAD_CLK_IO MSPI_IOMUX_PIN_NUM_CLK
65+
#define PSRAM_QUAD_CS_IO MSPI_IOMUX_PIN_NUM_CS1
66+
#define PSRAM_QUAD_SPIQ_SD0_IO MSPI_IOMUX_PIN_NUM_MISO
67+
#define PSRAM_QUAD_SPID_SD1_IO MSPI_IOMUX_PIN_NUM_MOSI
68+
#define PSRAM_QUAD_SPIWP_SD3_IO MSPI_IOMUX_PIN_NUM_WP
69+
#define PSRAM_QUAD_SPIHD_SD2_IO MSPI_IOMUX_PIN_NUM_HD
70+
71+
#define PSRAM_QUAD_CMD_LENGTH 8
72+
#define PSRAM_QUAD_ADDR_LENGTH 24
73+
74+
#define PSRAM_QUAD_CS_HOLD_VAL 1
75+
#define PSRAM_QUAD_CS_SETUP_VAL 1
76+
77+
// QEMU has a simulated 16MB and 32MB Quad SPI PSRAM. Use a fake ID for these.
78+
#define PSRAM_QUAD_QEMU_16MB_ID 0x6a
79+
#define PSRAM_QUAD_QEMU_32MB_ID 0x8e
80+
81+
#ifdef __cplusplus
82+
}
83+
#endif

0 commit comments

Comments
 (0)