summaryrefslogtreecommitdiff
path: root/bsp/synwit/libraries/SWM320_drivers/drv_sram.c
blob: 409ebd3d9fb67b1b898aa1271cded78f4a9c2a0b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
 * Copyright (c) 2006-2022, Synwit Technology Co.,Ltd.
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2018-05-31     ZYH          first version
 * 2018-12-10     Zohar_Lee    format file
 * 2020-07-10     lik          rewrite
 */

#include "drv_sram.h"

#ifdef BSP_USING_EXT_SRAM

#define DRV_DEBUG
#define LOG_TAG "drv.ext_sram"
#include <drv_log.h>

#ifdef RT_USING_MEMHEAP_AS_HEAP
static struct rt_memheap system_heap;
#endif

static int rt_hw_sram_init(void)
{
    SRAM_InitStructure SRAM_InitStruct;

    PORT->PORTP_SEL0 = 0xAAAAAAAA; //PP0-23 => ADDR0-23
    PORT->PORTP_SEL1 = 0xAAAA;

    PORT->PORTM_SEL0 = 0xAAAAAAAA; //PM0-15 => DATA15-0
    PORT->PORTM_INEN = 0xFFFF;

    PORT->PORTM_SEL1 = 0xAAA; //PM16 => OEN,PM17 => WEN,PM18 => NORFL_CSN,PM19 => SDRAM_CSN,PM20 => SRAM_CSN,PM21 => SDRAM_CKE

    SRAM_InitStruct.ClkDiv = SRAM_CLKDIV_8;
    SRAM_InitStruct.DataWidth = SRAM_DATAWIDTH_16;
    SRAM_Init(&SRAM_InitStruct);

#ifdef RT_USING_MEMHEAP_AS_HEAP
    /* If RT_USING_MEMHEAP_AS_HEAP is enabled, SRAM is initialized to the heap */
    rt_memheap_init(&system_heap, "sram", (void *)EXT_SRAM_BEGIN, EXT_SRAM_SIZE);
#endif

    return 0;
}
INIT_BOARD_EXPORT(rt_hw_sram_init);

#endif /* BSP_USING_EXT_SRAM */