@@ -247,31 +247,53 @@ 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
263269/**
264- * For certain wafer version and 8MB case, we consider it as 4MB mode as it uses 2T mode
270+ * For mrj069000aa, this wafer version and 8MB case, we consider it as 4MB mode as it uses 2T mode
265271 */
266- bool s_check_aps3204_2tmode (void )
272+ static bool s_check_mrj069000aa_2tmode (uint32_t eid_47_16 )
273+ {
274+ bool is_2t = false;
275+ ESP_EARLY_LOGD (TAG , "(eid_47_16 >> 5) & 0xfffff: 0x%" PRIx32 , (eid_47_16 >> 5 ) & 0xfffff );
276+ if (((eid_47_16 >> 5 ) & 0xfffff ) == 0x8a445 ) {
277+ is_2t = true;
278+ }
279+
280+ return is_2t ;
281+ }
282+
283+ static bool s_check_2tmode (void )
267284{
268285 uint64_t full_eid = 0 ;
269286 psram_read_id (PSRAM_CTRLR_LL_MSPI_ID_1 , (uint8_t * )& full_eid , PSRAM_QUAD_EID_BITS_NUM );
270287
271288 bool is_2t = false;
272289 uint32_t eid_47_16 = __builtin_bswap32 ((full_eid >> 16 ) & UINT32_MAX );
273- ESP_EARLY_LOGD (TAG , "full_eid: 0x%" PRIx64 ", eid_47_16: 0x%" PRIx32 ", (eid_47_16 >> 5) & 0xfffff: 0x%" PRIx32 , full_eid , eid_47_16 , (eid_47_16 >> 5 ) & 0xfffff );
274- if (((eid_47_16 >> 5 ) & 0xfffff ) == 0x8a445 ) {
290+ ESP_EARLY_LOGD (TAG , "full_eid: 0x%" PRIx64 ", eid_47_16: 0x%" PRIx32 ", (eid_47_16 >> 25) & 0x1: 0x%" PRIx32 , full_eid , eid_47_16 , (eid_47_16 >> 25 ) & 0x1 );
291+ //EID[41]: 0 for 2t mode; 1 for non-2t mode
292+ if (((eid_47_16 >> 25 ) & 0x1 ) == 0 ) {
293+ is_2t = true;
294+ }
295+
296+ if (s_check_mrj069000aa_2tmode (eid_47_16 )) {
275297 is_2t = true;
276298 }
277299
@@ -289,6 +311,8 @@ esp_err_t esp_psram_impl_enable(void)
289311#if SOC_SPI_MEM_SUPPORT_TIMING_TUNING
290312 //enter MSPI slow mode to init PSRAM device registers
291313 mspi_timing_enter_low_speed_mode (true);
314+ #else
315+ s_config_psram_clock (true);
292316#endif // SOC_SPI_MEM_SUPPORT_TIMING_TUNING
293317
294318 uint32_t psram_id = 0 ;
@@ -320,10 +344,11 @@ esp_err_t esp_psram_impl_enable(void)
320344 * that are 16MB or 32MB to be interpreted as QEMU PSRAM devices */
321345 eid == PSRAM_QUAD_QEMU_16MB_ID ? PSRAM_SIZE_16MB :
322346 eid == PSRAM_QUAD_QEMU_32MB_ID ? PSRAM_SIZE_32MB : 0 ;
323- }
324347
325- if ((s_psram_size == PSRAM_SIZE_8MB ) && s_check_aps3204_2tmode ()) {
326- s_psram_size = PSRAM_SIZE_4MB ;
348+ if ((s_psram_size == PSRAM_SIZE_8MB ) && s_check_2tmode ()) {
349+ //2t mode is only valid for EID[47:45] == 0x10 chips
350+ s_psram_size = s_psram_size / 2 ;
351+ }
327352 }
328353
329354 //SPI1: send psram reset command
@@ -339,7 +364,7 @@ esp_err_t esp_psram_impl_enable(void)
339364 //Back to the high speed mode. Flash/PSRAM clocks are set to the clock that user selected. SPI0/1 registers are all set correctly
340365 mspi_timing_enter_high_speed_mode (true);
341366#else
342- s_config_psram_clock ();
367+ s_config_psram_clock (false );
343368 //Configure SPI0 PSRAM related SPI Phases
344369 config_psram_spi_phases ();
345370#endif
0 commit comments