# How to setting PSRAM in AMB23?

**URL:** https://forum.amebaiot.com/t/how-to-setting-psram-in-amb23/2333
**Category:** SDK
**Created:** [October 21, 2023, 3:28pm UTC](https://forum.amebaiot.com/t/how-to-setting-psram-in-amb23/2333 "2023-10-21T15:28:29Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Allen54a0](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/allen54a0/32/1677_2.png) [@Allen54a0](https://forum.amebaiot.com/u/Allen54a0)
#### Post date: [October 21, 2023, 3:28pm UTC](https://forum.amebaiot.com/t/how-to-setting-psram-in-amb23/2333/1 "2023-10-21T15:28:29Z")

</div>

There are 4 Mb PSRAM in AMB23. Due to the big size of Wifi / FreeRTOS and LVGL v8 in our project. How can we configure the GCC config. files so that we can utilitize PSRAM as the interal ram like SRAM did ?

What we want to do is very similar to the following example，Thanks.

> **[Heap Memory Allocation - ESP32 - — ESP-IDF Programming Guide v5.5.1...](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/mem_alloc.html?highlight=spiram)**

---

<div class="post-metadata">

### Author: ![dakamaster](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/dakamaster/32/1744_2.png) [@dakamaster](https://forum.amebaiot.com/u/dakamaster)
#### Post date: [October 22, 2023, 2:03am UTC](https://forum.amebaiot.com/t/how-to-setting-psram-in-amb23/2333/2 "2023-10-22T02:03:35Z")

</div>

From standard sdk, there is [ambd\_sdk](https://github.com/ambiot/ambd_sdk/tree/dev)/component/os/os\_dep/psram\_reserve.c for configuring PSRAM.

Upon searching for the keyword `configUSE_PSRAM_FOR_HEAP_REGION` as indicated below:

> <https://github.com/ambiot/ambd_sdk/blob/be744260b9230cf01eafcc741d0bd4504cf8c59e/component/os/os_dep/psram_reserve.c#L13>

We could find FreeRTOSConfig.h for configuring the size of PSRAM:

> <https://github.com/ambiot/ambd_sdk/blob/be744260b9230cf01eafcc741d0bd4504cf8c59e/project/realtek_amebaD_va0_example/inc/inc_hp/FreeRTOSConfig.h#L94-L95>

Hope it could help. Thanks

---

<div class="post-metadata">

### Author: ![Allen54a0](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/allen54a0/32/1677_2.png) [@Allen54a0](https://forum.amebaiot.com/u/Allen54a0)
#### Post date: [October 23, 2023, 6:02am UTC](https://forum.amebaiot.com/t/how-to-setting-psram-in-amb23/2333/3 "2023-10-23T06:02:10Z")

</div>

Thanks for your information, I’ll try to adapt it into my project.

---

<div class="post-metadata">

### Author: ![Allen54a0](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/allen54a0/32/1677_2.png) [@Allen54a0](https://forum.amebaiot.com/u/Allen54a0)
#### Post date: [November 3, 2023, 3:55am UTC](https://forum.amebaiot.com/t/how-to-setting-psram-in-amb23/2333/4 "2023-11-03T03:55:55Z")

</div>

目前是用這招解決，可以在Arduino 的開發環境中使用PSRAM。

I am using this code to initial PSRAM in Arduino Environment. It works but not know if it is a right way to do.

```auto
void setup()
{
  /// ------------------------- Enable PSRAM ---------------------------------------------------------
    app_init_psram();

  //user code 
}

void app_init_psram(void)
{
    u32 temp;
    PCTL_InitTypeDef PCTL_InitStruct;

    /*set rwds pull down*/
    temp = HAL_READ32(PINMUX_REG_BASE, 0x104);
    temp &= ~(PAD_BIT_PULL_UP_RESISTOR_EN | PAD_BIT_PULL_DOWN_RESISTOR_EN);
    temp |= PAD_BIT_PULL_DOWN_RESISTOR_EN;
    HAL_WRITE32(PINMUX_REG_BASE, 0x104, temp);

    PSRAM_CTRL_StructInit(&PCTL_InitStruct);
    PSRAM_CTRL_Init(&PCTL_InitStruct);

    PSRAM_PHY_REG_Write(REG_PSRAM_CAL_PARA, 0x02030310);

    /*check psram valid*/
    HAL_WRITE32(PSRAM_BASE, 0, 0);
    assert_param(0 == HAL_READ32(PSRAM_BASE, 0));

    if (SYSCFG_CUT_VERSION_A != SYSCFG_CUTVersion())
    {
        if (_FALSE == PSRAM_calibration())
            return;

        if (FALSE == psram_dev_config.psram_dev_cal_enable)
        {
            temp = PSRAM_PHY_REG_Read(REG_PSRAM_CAL_CTRL);
            temp &= (~BIT_PSRAM_CFG_CAL_EN);
            PSRAM_PHY_REG_Write(REG_PSRAM_CAL_CTRL, temp);
        }
    }

    /*init psram bss area*/
    memset( __psram_bss_start__ , 0, __psram_bss_end__ - __psram_bss_start__ );
}

```
