W800/W801 PSRAM使用例程

發布於 2022-08-26 17:04:46
1.代碼修改(可能)
wm_gpio_afsel.c裡的添加或者修改psram config函數(關注一下是否一致):
void wm_psram_config(uint8_t numsel)
{
    switch(numsel)
    {
        case 0:
            tls_io_cfg_set(WM_IO_PB_00, WM_IO_OPTION4);/*CK*/
            tls_io_cfg_set(WM_IO_PB_01, WM_IO_OPTION4);/*CS*/
            tls_io_cfg_set(WM_IO_PB_02, WM_IO_OPTION4);/*D0*/
            tls_io_cfg_set(WM_IO_PB_03, WM_IO_OPTION4);/*D1*/
            tls_io_cfg_set(WM_IO_PB_04, WM_IO_OPTION4);/*D2*/
            tls_io_cfg_set(WM_IO_PB_05, WM_IO_OPTION4);/*D3*/
            tls_open_peripheral_clock(TLS_PERIPHERAL_TYPE_PSRAM);            
            break;
        case 1:
            tls_io_cfg_set(WM_IO_PA_15, WM_IO_OPTION1);/*CK*/
            tls_io_cfg_set(WM_IO_PB_27, WM_IO_OPTION1);/*CS*/
            tls_io_cfg_set(WM_IO_PB_02, WM_IO_OPTION1);/*D0*/
            tls_io_cfg_set(WM_IO_PB_03, WM_IO_OPTION1);/*D1*/
            tls_io_cfg_set(WM_IO_PB_04, WM_IO_OPTION1);/*D2*/
            tls_io_cfg_set(WM_IO_PB_05, WM_IO_OPTION1);/*D3*/
            tls_open_peripheral_clock(TLS_PERIPHERAL_TYPE_PSRAM);            
            break;
        case 2: //w861
            tls_io_cfg_set(WM_IO_PA_15, WM_IO_OPTION1);/*CK*/
            tls_io_cfg_set(WM_IO_PB_27, WM_IO_OPTION1);/*CS*/
            tls_io_cfg_set(WM_IO_PB_28, WM_IO_OPTION1);/*D0*/
            tls_io_cfg_set(WM_IO_PB_29, WM_IO_OPTION1);/*D1*/
            tls_io_cfg_set(WM_IO_PB_30, WM_IO_OPTION1);/*D2*/
            tls_io_cfg_set(WM_IO_PB_31, WM_IO_OPTION1);/*D3*/
            tls_open_peripheral_clock(TLS_PERIPHERAL_TYPE_PSRAM);   
            break;
        default:
            TLS_DBGPRT_ERR("psram afsel config error!");
            break;
    }
}
2.PSRAM的初始化
wm_main.c啟動後初始化一下PSRAM(建議放到函數wm_gpio_config):
    wm_psram_config(0);//實際使用的psram管腳選擇0或者1,W861為2
    //初始化psram
    psram_init(1);
3.使用
因為內置的內存和psram的內存不連續,可以參考heap_dram.c[文章末尾附件]的實現來單獨管理這塊內存。
 
這個文件裡只需要關注兩個宏的修改,因為PSRAM起始地址0x30000000,只需要修改實際的PSRAM容量(DRAM_HEAP_SIZE)即可。
/* Heap should align to DRAM_HEAP_ALIGNMENT */
#define DRAM_HEAP_BASE              (0x30000000)
/* Size should be smaller than ~DRAM_HEAP_MAGIC */
#define DRAM_HEAP_SIZE              (2*1024 * 1024)

附件:heap_dram.zip

17 條評論

發布
問題