PSRAM

PSRAM is a memory type that combines the advantages of DRAM and SRAM, with the ease of use of SRAM and the cost-effectiveness of DRAM. Compared to SRAM, PSRAM is slightly slower but has lower cost and power consumption; compared to Flash, PSRAM is faster but lacks non-volatility. PSRAM is suitable for scenarios requiring relatively fast storage speeds. Currently, RTL87x2G cannot use external PSRAM, and RTL8762GTP, RTL8772GWP, RTL8772GWP-VI, RTL8772GWP-VM, and RTL8772GWP-VA feature MCM PSRAM, model W955D8MKY. The following text introduces the usage of PSRAM.

Initialization steps

  1. Setting the power-on option for PSRAM in config file. When PSRAM Power Supply is set to Enable, it will internally supply 1.8V power to the PSRAM. Otherwise, the PSRAM will be in a power-off state, consuming no power.

../../../../_images/Config_File_Setting.png

Config File Setting

  1. Defining the macro USE_PSRAM ( #define USE_PSRAM 1 ) in mem_config.h will automatically invoke the psram_winbond_opi_init() to complete the initialization settings for PSRAM.

  2. After initialization, the default PSRAM clock is set to 20MHz. Users can invoke the function pm_spic1_freq_set() to switch the PSRAM clock. It is generally recommended to directly switch to PSRAM 80MHz.

    Function Name

    pm_spic1_freq_set

    Function Prototype

    int32_t pm_spic1_freq_set(uint32_t required_mhz, uint32_t *actual_mhz)

    Function Description

    setting PSRAM clock

    Input Parameter

    required_mhz: twice the target speed of PSRAM clock (maximum setting is 160MHz, corresponding to 80MHz for PSRAM.

    actual_mhz: return the actual switched value, where actual_mhz equals required_mhz in the case of a successful clock switch.

    Prerequisite

    None

    uint32_t actual_mhz;
    pm_spic1_freq_set(160, &actual_mhz);
    

Read and Write operations

The method of reading and writing PSRAM is the same as that for SRAM, where direct access to PSRAM addresses (using functions like memcpy and memset) is used without the need for a driver.

The example of PSRAM clock switching:

#define PSRAM_ADDR        0x08000000
#define TEST_ADDR         0x00100000
memcpy((uint8_t *) PSRAM_ADDR, (uint8_t *) TEST_ADDR, 1024);   //write

备注

The PSRAM model only supports W955D8MKY, with a starting address of 0x8000000 and a size of 4MB.

Low power mode setting

PSRAM offers two low Power modes:

  • DPD (Deep Power Down) mode
    If use DPD mode, all content in PSRAM will be lost when entering system low power mode (DLPS).
  • Hybrid Sleep mode
    If Hybrid Sleep mode is used, users can select parts of the PSRAM to retention, and the power consumption will be relatively increased.

For user convenience, the low power settings for PSRAM are integrated into the system's low power mode. Users can modify the following two sections to select the desired PSRAM low power mode.

  1. Add #define USE_PSRAM_DEEP_POWER_HALF_SLEEP_MODE 1 in io_dlps.c to select the Hybrid Sleep mode; otherwise, the DPD mode will be used.

  2. If user selects the Hybrid Sleep mode, they can modify the second parameter of the function fmc_psram_wb_set_partial_refresh in io_dlps.c to choose the region where the content is not lost after entering system low power mode. It is important to note that the larger region retention, the higher the power consumption.

    Function Name

    fmc_psram_wb_set_partial_refresh

    Function Prototype

    bool fmc_psram_wb_set_partial_refresh(FMC_FLASH_NOR_IDX_TYPE idx, FMC_PSRAM_WB_PARTIAL_ARRAY_REFRESH partial)

    Function Description

    Configure certain regions of PSRAM to retain their content after entering and exiting low-power mode

    Input Parameter

    FMC_FLASH_NOR_IDX_TYPE: the default value is FMC FLASH NOR IDX1.

    FMC_PSRAM_WB_PARTIAL_ARRAY_REFRESH: the following values can be set.

    • FMC_PSRAM_WB_REFRESH_FULL

    • FMC_PSRAM_WB_REFRESH_BOTTOM_1_2

    • FMC_PSRAM_WB_REFRESH_BOTTOM_1_4

    • FMC_PSRAM_WB_REFRESH_BOTTOM_1_8

    • FMC_PSRAM_WB_REFRESH_TOP_1_2

    • FMC_PSRAM_WB_REFRESH_TOP_1_4

    • FMC_PSRAM_WB_REFRESH_TOP_1_8

    Prerequisite

    None

    备注

    The larger region retention, the higher the power consumption.

    Example usage: (In the example, Hybrid Sleep mode is selected, and the PSRAM retention area is the second half of the region)

    #define USE_PSRAM_DEEP_POWER_HALF_SLEEP_MODE  1
    
    #if USE_PSRAM
    #if USE_PSRAM_DEEP_POWER_HALF_SLEEP_MODE
       fmc_psram_wb_set_partial_refresh(FMC_FLASH_NOR_IDX1, FMC_PSRAM_WB_REFRESH_TOP_1_2);
       fmc_psram_enter_lpm(FMC_FLASH_NOR_IDX1, FMC_PSRAM_LPM_HALF_SLEEP_MODE);
    #else
       fmc_psram_enter_lpm(FMC_FLASH_NOR_IDX1, FMC_PSRAM_LPM_DEEP_POWER_DOWN_MODE);
    #endif
    
    #else
       shut_down_spic_pad_imp(FMC_FLASH_NOR_IDX1, true);
    
    #endif
    

    The power consumption data is shown below.

    power consumption data

    Power mode

    Retention region

    Current(uA)

    Hybrid Sleep mode

    Full Array

    20

    Bottom 1/2 Array

    18

    Bottom 1/4 Array

    16

    Bottom 1/8 Array

    15

    Top 1/2 Array

    18

    Top 1/4 Array

    16

    Top 1/8 Array

    15

    Deep power down mode

    0~0.2