at91sam9m10-ek-ddram.ini
上传用户:xukun0987
上传日期:2022-07-16
资源大小:216k
文件大小:10k
- // ----------------------------------------------------------------------------
- // ATMEL Microcontroller Software Support
- // ----------------------------------------------------------------------------
- // Copyright (c) 2008, Atmel Corporation
- //
- // All rights reserved.
- //
- // Redistribution and use in source and binary forms, with or without
- // modification, are permitted provided that the following conditions are met:
- //
- // - Redistributions of source code must retain the above copyright notice,
- // this list of conditions and the disclaimer below.
- //
- // Atmel's name may not be used to endorse or promote products derived from
- // this software without specific prior written permission.
- //
- // DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
- // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
- // DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
- // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
- // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
- // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- // ----------------------------------------------------------------------------
- //----------------------------------------------------------------------------
- // File Name : at91sam9m10-ek-ddram.ini
- // Object : Generic Macro File for KEIL
- //----------------------------------------------------------------------------
- //----------------------------------------------------------------------------
- // _MapRAMAt0()
- // Function description: Maps RAM at 0.
- //----------------------------------------------------------------------------
- DEFINE LONG hold;
- DEFINE LONG tempVal;
- FUNC void _MapRAMAt0(){
-
- printf ("Changing mapping: RAM mapped to 0n");
- // Test and set Remap
- hold = _RDWORD(0x00000000);
- _WDWORD(0x00000000,0xAAAAAAAA);
- if(_RDWORD(0x00000000) != 0xAAAAAAAA)
- {
- _WDWORD(0xFFFFED00,0x03); // toggle remap bits
- }
- else
- {
- _WDWORD(0x00000000,hold);
- }
- }
- //----------------------------------------------------------------------------
- // _InitRSTC()
- // Function description
- // Initializes the RSTC (Reset controller).
- // This makes sense since the default is to not allow user resets, which makes it impossible to
- // apply a second RESET via J-Link
- //----------------------------------------------------------------------------
- FUNC void _InitRSTC() {
- _WDWORD(0xFFFFFD08,0xA5000001); // Allow user reset
- }
- //----------------------------------------------------------------------------
- //
- // _PllSetting()
- // Function description
- // Initializes the PMC.
- // 1. Enable the Main Oscillator
- // 2. Configure PLL
- // 3. Switch Master
- //----------------------------------------------------------------------------
- FUNC void __PllSetting()
- {
- //* pPmc->PMC_MOR = (( AT91C_CKGR_OSCOUNT & (0x40 <<8) | AT91C_CKGR_MOSCEN ));
- _WDWORD(0xFFFFFC20,0x00004001);
- _sleep_(100);
- //* AT91C_BASE_CKGR->CKGR_PLLAR = (AT91C_CKGR_SRCA | ((96 << 16) & AT91C_CKGR_MULA) |
- // (AT91C_CKGR_PLLACOUNT | (AT91C_CKGR_OUTA_0 | (9);
- _WDWORD(0xFFFFFC28,0x2060BF09);
- _sleep_(100);
- // Configure PLLB
- _WDWORD(0xFFFFFC2C,0x207C3F0C);
- _sleep_(100);
- //* AT91C_BASE_PMC->PMC_MCKR = AT91C_PMC_CSS_PLLA_CLK | AT91C_PMC_PRES_CLK | AT91C_PMC_MDIV_2;;
- _WDWORD(0xFFFFFC30,0x00001300);
- _sleep_(100);
- }
- //----------------------------------------------------------------------------
- // __initDDRAM()
- // Function description
- // Configuring the MICRON DDRAM controller
- //----------------------------------------------------------------------------
- FUNC void __initDDRAM()
- {
-
- printf( "-------------------------------Configuring the DDRAM controller------------n");
- printf( "-------------------------------MICRON DDRAM configuration------------------n");
- // 0xFFFFE600 DDR2C Base Address
- // Enable DDR2 clock x2 in PMC
- // AT91C_BASE_PMC, PMC_SCER, AT91C_PMC_DDR
-
- _WDWORD(0xFFFFFC00,0x04);
-
- // Configure the DDR controller
- // HDDRSDRC2_MDR, AT91C_DDRC2_DBW_16_BITS | // 16-bit DDR
- // AT91C_DDRC2_MD_DDR2_SDRAM // DDR2
-
- _WDWORD(0xFFFFE620,0x16);
- // Program the DDR Controller
- // HDDRSDRC2_CR, AT91C_DDRC2_NC_DDR10_SDR9 | // 10 column bits (1K)
- // AT91C_DDRC2_NR_14 | // 14 row bits (8K)
- // AT91C_DDRC2_CAS_3 | // CAS Latency 3
- // AT91C_DDRC2_DLL_RESET_DISABLED // DLL not reset
-
- _WDWORD(0xFFFFE608,0x3D);
-
- // assume timings for 7.5ns min clock period
- // HDDRSDRC2_T0PR, AT91C_DDRC2_TRAS_6 | // 6 * 7.5 = 45 ns
- // AT91C_DDRC2_TRCD_2 | // 3 * 7.5 = 22.5 ns
- // AT91C_DDRC2_TWR_2 | // 2 * 7.5 = 15 ns
- // AT91C_DDRC2_TRC_8 | // 10 * 7.5 = 75 ns
- // AT91C_DDRC2_TRP_2 | // 3 * 7.5 = 22.5 ns
- // AT91C_DDRC2_TRRD_1 | // 2 * 7.5 = 15 ns
- // AT91C_DDRC2_TWTR_1 | // 1 clock cycle
- // AT91C_DDRC2_TMRD_2 // 2 clock cycles
-
- _WDWORD(0xFFFFE60C,0x21128226);
- // pSDDRC->HDDRSDRC2_T1PR = 0x00000008;
- // HDDRSDRC2_T1PR, AT91C_DDRC2_TXP_2 | // 2 * 7.5 = 15 ns
- // 200 << 16 | // 200 clock cycles, TXSRD: Exit self refresh delay to Read command
- // 27 << 8 | // 27 * 7.5 = 202 ns TXSNR: Exit self refresh delay to non read command
- // AT91C_DDRC2_TRFC_14 << 0 // 19 * 7.5 = 142 ns (must be 140 ns for 1Gb DDR)
- _WDWORD(0xFFFFE610,0x02C81B0E);
- // HDDRSDRC2_T2PR, AT91C_DDRC2_TRTP_2 | // 2 * 7.5 = 15 ns
- // AT91C_DDRC2_TRPA_2 | // 2 * 7.5 = 15 ns
- // AT91C_DDRC2_TXARDS_7 | // 7 clock cycles
- // AT91C_DDRC2_TXARD_7 // 2 clock cycles
- _WDWORD(0xFFFFE614,0x02020707);
-
- // Initialization Step 1 + 2: NOP command -> allow to enable clk
- // HDDRSDRC2_MR, AT91C_DDRC2_MODE_NOP_CMD
-
- _WDWORD(0xFFFFE600,0x1);
- _WDWORD(0x70000000,0x0);
-
- // Initialization Step 3 (must wait 200 us) (6 core cycles per iteration, core is at 396MHz: min 13200 loops)
- _sleep_(1);
- // NOP command -> allow to enable cke
- // HDDRSDRC2_MR, AT91C_DDRC2_MODE_NOP_CMD
- _WDWORD(0xFFFFE600,0x1);
- _WDWORD(0x70000000,0x0);
-
- // wait 400 ns min
- _sleep_(1);
-
- // Initialization Step 4: Set All Bank Precharge
- // HDDRSDRC2_MR, AT91C_DDRC2_MODE_PRCGALL_CMD
- _WDWORD(0xFFFFE600,0x2);
- _WDWORD(0x70000000,0x0);
-
- // wait 400 ns min
- _sleep_(1);
- // Initialization Step 5: Set EMR operation (EMRS2)
- // HDDRSDRC2_MR, AT91C_DDRC2_MODE_EXT_LMR_CMD
-
- _WDWORD(0xFFFFE600,0x5);
- _WDWORD(0x70000000,0x0);
-
- // wait 2 cycles min
- _sleep_(1);
-
- // Initialization Step 6: Set EMR operation (EMRS3)
- // HDDRSDRC2_MR, AT91C_DDRC2_MODE_EXT_LMR_CMD
-
- _WDWORD(0xFFFFE600,0x5);
- _WDWORD(0x76000000,0x0);
-
- // wait 2 cycles min
- _sleep_(1);
-
- // Initialization Step 7: Set EMR operation (EMRS1)
- // HDDRSDRC2_MR, AT91C_DDRC2_MODE_EXT_LMR_CMD
- _WDWORD(0xFFFFE600,0x5);
- _WDWORD(0x72000000,0x0);
-
- // wait 2 cycles min
- _sleep_(1);
- // Initialization Step 8a: enable DLL reset
- // HDDRSDRC2_CR, cr | AT91C_DDRC2_DLL_RESET_ENABLED
-
- tempVal = _RDWORD(0xFFFFE608);
- tempVal |= 0xBD;
- _WDWORD(0xFFFFE608,0xBD);
-
- // Initialization Step 8b: reset DLL
- // HDDRSDRC2_MR, AT91C_DDRC2_MODE_EXT_LMR_CMD
-
- _WDWORD(0xFFFFE600,0x5);
- _WDWORD(0x70000000,0x0);
-
- // wait 2 cycles min
- _sleep_(1);
-
- // Initialization Step 9: Set All Bank Precharge
- // HDDRSDRC2_MR, AT91C_DDRC2_MODE_PRCGALL_CMD
-
- _WDWORD(0xFFFFE600,0x2);
- _WDWORD(0x70000000,0x0);
-
- // wait 2 cycles min
- _sleep_(1);
- // Initialization Step 11: Set 1st CBR
- // HDDRSDRC2_MR, AT91C_DDRC2_MODE_RFSH_CMD
-
- _WDWORD(0xFFFFE600,0x4);
- _WDWORD(0x70000000,0x0);
-
- // wait 2 cycles min
- _sleep_(1);
-
- // Set 2nd CBR
- // HDDRSDRC2_MR, AT91C_DDRC2_MODE_RFSH_CMD
-
- _WDWORD(0xFFFFE600,0x4);
- _WDWORD(0x70000000,0x0);
-
- // wait 2 cycles min
- _sleep_(1);
-
- // Initialization Step 12: disable DLL reset
- // HDDRSDRC2_CR, cr & (~AT91C_DDRC2_DLL_RESET_ENABLED)
-
- _WDWORD(0xFFFFE608,0x3D);
- // wait 2 cycles min
- _sleep_(1);
-
- // Initialization Step 13: Set LMR operation
- // HDDRSDRC2_MR, AT91C_DDRC2_MODE_LMR_CMD
-
- _WDWORD(0xFFFFE600,0x3);
- _WDWORD(0x70000000,0x0);
- // wait 2 cycles min
- _sleep_(1);
-
-
- // Skip Initialization Step 14 to 17 (not supported by the DDR2 model)
- // Initialization Step 18: Set Normal mode
- // HDDRSDRC2_MR, AT91C_DDRC2_MODE_NORMAL_CMD
-
- _WDWORD(0xFFFFE600,0x0);
- _WDWORD(0x70000000,0x0);
- // wait 2 cycles min
- _sleep_(1);
-
-
- // Set Refresh timer
- // HDDRSDRC2_RTR, 0x00000520
- _WDWORD(0xFFFFE604,0x00000520);
-
- // OK now we are ready to work on the DDRSDR
- // wait for end of calibration
- _sleep_(1);
- printf( "------------------------------- DDRAM configuration done -------------------------------n");
- }
- __PllSetting(); //* Init PLL
- __initDDRAM();
- _MapRAMAt0(); //* Set the RAM memory at 0x00300000 & 0x0000 0000
- _InitRSTC();
- LOAD at91sam9m10-sdram\at91sam9m10-sdram.axf INCREMENTAL
- PC = 0x70000000;
- g,main