1 /*
2  * Copyright (c) 2006-2022, Synwit Technology Co.,Ltd.
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Change Logs:
7  * Date           Author       Notes
8  * 2018-05-31     ZYH          first version
9  * 2018-12-10     Zohar_Lee    format file
10  * 2020-07-10     lik          rewrite
11  */
12 
13 #include "drv_sram.h"
14 
15 #ifdef BSP_USING_EXT_SRAM
16 
17 #define DRV_DEBUG
18 #define LOG_TAG "drv.ext_sram"
19 #include <drv_log.h>
20 
21 #ifdef RT_USING_MEMHEAP_AS_HEAP
22 static struct rt_memheap system_heap;
23 #endif
24 
rt_hw_sram_init(void)25 static int rt_hw_sram_init(void)
26 {
27     SRAM_InitStructure SRAM_InitStruct;
28 
29     PORT->PORTP_SEL0 = 0xAAAAAAAA; //PP0-23 => ADDR0-23
30     PORT->PORTP_SEL1 = 0xAAAA;
31 
32     PORT->PORTM_SEL0 = 0xAAAAAAAA; //PM0-15 => DATA15-0
33     PORT->PORTM_INEN = 0xFFFF;
34 
35     PORT->PORTM_SEL1 = 0xAAA; //PM16 => OEN,PM17 => WEN,PM18 => NORFL_CSN,PM19 => SDRAM_CSN,PM20 => SRAM_CSN,PM21 => SDRAM_CKE
36 
37     SRAM_InitStruct.ClkDiv = SRAM_CLKDIV_8;
38     SRAM_InitStruct.DataWidth = SRAM_DATAWIDTH_16;
39     SRAM_Init(&SRAM_InitStruct);
40 
41 #ifdef RT_USING_MEMHEAP_AS_HEAP
42     /* If RT_USING_MEMHEAP_AS_HEAP is enabled, SRAM is initialized to the heap */
43     rt_memheap_init(&system_heap, "sram", (void *)EXT_SRAM_BEGIN, EXT_SRAM_SIZE);
44 #endif
45 
46     return 0;
47 }
48 INIT_BOARD_EXPORT(rt_hw_sram_init);
49 
50 #endif /* BSP_USING_EXT_SRAM */
51