Skip to content

Commit 89d566b

Browse files
committed
fix(psram): fixed psram init state not in low speed mode issue on c5 c61
1 parent 38628f9 commit 89d566b

File tree

3 files changed

+40
-6
lines changed

3 files changed

+40
-6
lines changed

components/esp_psram/device/esp_psram_impl_ap_quad.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -247,16 +247,22 @@ static void psram_gpio_config(void)
247247
}
248248

249249
#if !SOC_SPI_MEM_SUPPORT_TIMING_TUNING
250-
static void s_config_psram_clock(void)
250+
static void s_config_psram_clock(bool init_state)
251251
{
252-
// This function can be extended if we have other psram frequency
253252
uint32_t clock_conf = 0;
253+
if (init_state) {
254+
clock_conf = psram_ctrlr_ll_calculate_clock_reg(4);
255+
psram_ctrlr_ll_set_spi1_bus_clock(PSRAM_CTRLR_LL_MSPI_ID_1, clock_conf);
256+
} else {
257+
// This function can be extended if we have other psram frequency
258+
254259
#if (CONFIG_SPIRAM_SPEED == 80)
255-
clock_conf = psram_ctrlr_ll_calculate_clock_reg(1);
260+
clock_conf = psram_ctrlr_ll_calculate_clock_reg(1);
256261
#elif (CONFIG_SPIRAM_SPEED == 40)
257-
clock_conf = psram_ctrlr_ll_calculate_clock_reg(2);
262+
clock_conf = psram_ctrlr_ll_calculate_clock_reg(2);
258263
#endif
259-
psram_ctrlr_ll_set_bus_clock(PSRAM_CTRLR_LL_MSPI_ID_0, clock_conf);
264+
psram_ctrlr_ll_set_bus_clock(PSRAM_CTRLR_LL_MSPI_ID_0, clock_conf);
265+
}
260266
}
261267
#endif //#if !SOC_SPI_MEM_SUPPORT_TIMING_TUNING
262268

@@ -289,6 +295,8 @@ esp_err_t esp_psram_impl_enable(void)
289295
#if SOC_SPI_MEM_SUPPORT_TIMING_TUNING
290296
//enter MSPI slow mode to init PSRAM device registers
291297
mspi_timing_enter_low_speed_mode(true);
298+
#else
299+
s_config_psram_clock(true);
292300
#endif // SOC_SPI_MEM_SUPPORT_TIMING_TUNING
293301

294302
uint32_t psram_id = 0;
@@ -339,7 +347,7 @@ esp_err_t esp_psram_impl_enable(void)
339347
//Back to the high speed mode. Flash/PSRAM clocks are set to the clock that user selected. SPI0/1 registers are all set correctly
340348
mspi_timing_enter_high_speed_mode(true);
341349
#else
342-
s_config_psram_clock();
350+
s_config_psram_clock(false);
343351
//Configure SPI0 PSRAM related SPI Phases
344352
config_psram_spi_phases();
345353
#endif

components/hal/esp32c5/include/hal/psram_ctrlr_ll.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,19 @@ static inline void psram_ctrlr_ll_set_bus_clock(uint32_t mspi_id, uint32_t clock
126126
SPIMEM0.mem_sram_clk.val = clock_conf;
127127
}
128128

129+
/**
130+
* @brief Set SPI1 bus clock to initialise PSRAM
131+
*
132+
* @param mspi_id mspi_id
133+
* @param clock_conf Configuration value for psram clock
134+
*/
135+
__attribute__((always_inline))
136+
static inline void psram_ctrlr_ll_set_spi1_bus_clock(uint32_t mspi_id, uint32_t clock_conf)
137+
{
138+
HAL_ASSERT(mspi_id == PSRAM_CTRLR_LL_MSPI_ID_1);
139+
SPIMEM1.clock.val = clock_conf;
140+
}
141+
129142
/**
130143
* Calculate spi_flash clock frequency division parameters for register.
131144
*

components/hal/esp32c61/include/hal/psram_ctrlr_ll.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,19 @@ static inline void psram_ctrlr_ll_set_bus_clock(uint32_t mspi_id, uint32_t clock
126126
SPIMEM0.mem_sram_clk.val = clock_conf;
127127
}
128128

129+
/**
130+
* @brief Set SPI1 bus clock to initialise PSRAM
131+
*
132+
* @param mspi_id mspi_id
133+
* @param clock_conf Configuration value for psram clock
134+
*/
135+
__attribute__((always_inline))
136+
static inline void psram_ctrlr_ll_set_spi1_bus_clock(uint32_t mspi_id, uint32_t clock_conf)
137+
{
138+
HAL_ASSERT(mspi_id == PSRAM_CTRLR_LL_MSPI_ID_1);
139+
SPIMEM1.clock.val = clock_conf;
140+
}
141+
129142
/**
130143
* Calculate spi_flash clock frequency division parameters for register.
131144
*

0 commit comments

Comments
 (0)