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 条评论

发布
问题