2022-10-19 22:44:15 +08:00

104 lines
4.0 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/******************************************************************************************************************************************
* <20>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>: SWM320_sdram.c
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: SWM320<32><30>Ƭ<EFBFBD><C6AC><EFBFBD><EFBFBD>SDRAM<41><4D><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <20><><EFBFBD><EFBFBD>֧<EFBFBD><D6A7>: http://www.synwit.com.cn/e/tool/gbook/?bid=1
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:
* <20><EFBFBD><E6B1BE><EFBFBD><EFBFBD>: V1.1.0 2017<31><37>10<31><30>25<32><35>
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼:
*
*
*******************************************************************************************************************************************
* @attention
*
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS WITH CODING INFORMATION
* REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. AS A RESULT, SYNWIT SHALL NOT BE HELD LIABLE
* FOR ANY DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT
* OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION CONTAINED HEREIN IN CONN-
* -ECTION WITH THEIR PRODUCTS.
*
* COPYRIGHT 2012 Synwit Technology
*******************************************************************************************************************************************/
#include "SWM320.h"
#include "SWM320_sdram.h"
/******************************************************************************************************************************************
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: SDRAM_Init()
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: SDRAM<41><4D><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>
* <20><> <20><>: SDRAM_InitStructure * initStruct <20><><EFBFBD><EFBFBD> SDRAM <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>趨ֵ<E8B6A8>Ľṹ<C4BD><E1B9B9>
* <20><> <20><>: <20><>
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><>
******************************************************************************************************************************************/
void SDRAM_Init(SDRAM_InitStructure * initStruct)
{
uint32_t row_n;
SYS->CLKEN |= (1 << SYS_CLKEN_SDRAM_Pos);
SYS->CLKDIV &= ~SYS_CLKDIV_SDRAM_Msk;
SYS->CLKDIV |= (1 << SYS_CLKDIV_SDRAM_Pos); //2<><32>Ƶ
SDRAMC->CR0 = (2 << SDRAMC_CR0_BURSTLEN_Pos) | //2 Burst LengthΪ4
(initStruct->CASLatency << SDRAMC_CR0_CASDELAY_Pos);
SDRAMC->CR1 = (initStruct->CellSize << SDRAMC_CR1_CELLSIZE_Pos) |
(initStruct->CellWidth << SDRAMC_CR1_CELL32BIT_Pos) |
(initStruct->CellBank << SDRAMC_CR1_BANK_Pos) |
(0 << SDRAMC_CR1_32BIT_Pos) |
(initStruct->TimeTMRD << SDRAMC_CR1_TMRD_Pos) |
(initStruct->TimeTRRD << SDRAMC_CR1_TRRD_Pos) |
(initStruct->TimeTRAS << SDRAMC_CR1_TRAS_Pos) |
(initStruct->TimeTRC << SDRAMC_CR1_TRC_Pos) |
(initStruct->TimeTRCD << SDRAMC_CR1_TRCD_Pos) |
(initStruct->TimeTRP << SDRAMC_CR1_TRP_Pos);
SDRAMC->LATCH = 0x02;
switch(initStruct->CellSize)
{
case SDRAM_CELLSIZE_16Mb: row_n = 11; break;
case SDRAM_CELLSIZE_64Mb: row_n = 12; break;
case SDRAM_CELLSIZE_128Mb: row_n = 12; break;
case SDRAM_CELLSIZE_256Mb: row_n = 13; break;
default: row_n = 13; break;
}
SDRAMC->REFRESH = (1 << SDRAMC_REFRESH_EN_Pos) |
(((SystemCoreClock/2)/1000*64 / (1 << row_n)) << SDRAMC_REFRESH_RATE_Pos);
while(SDRAMC->REFDONE == 0);
}
/******************************************************************************************************************************************
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: SDRAM_Enable()
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: SDRAMʹ<4D>ܣ<EFBFBD>ʹ<EFBFBD>ܺ<EFBFBD><DCBA>ɶ<EFBFBD>дSDRAM
* <20><> <20><>: <20><>
* <20><> <20><>: <20><>
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><>
******************************************************************************************************************************************/
void SDRAM_Enable(void)
{
uint32_t i;
SYS->CLKEN |= (1 << SYS_CLKEN_SDRAM_Pos);
SDRAMC->REFRESH |= (1 << SDRAMC_REFRESH_EN_Pos);
for(i = 0; i < 100; i++) __NOP();
}
/******************************************************************************************************************************************
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: SDRAM_Disable()
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: SDRAM<41><4D><EFBFBD>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD>ܺ<EFBFBD>SDRAM<41><4D><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͹<EFBFBD><CDB9><EFBFBD>ģʽ<C4A3><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ˢ<EFBFBD>£<EFBFBD><C2A3><EFBFBD><EFBFBD>ɶ<EFBFBD>д
* <20><> <20><>: <20><>
* <20><> <20><>: <20><>
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><>
******************************************************************************************************************************************/
void SDRAM_Disable(void)
{
uint32_t i;
SYS->CLKEN |= (1 << SYS_CLKEN_SDRAM_Pos);
SDRAMC->REFRESH &= ~(1 << SDRAMC_REFRESH_EN_Pos);
for(i = 0; i < 100; i++) __NOP();
}