I try to use EMIF1 on F28377D to interface with sdram (IS42S16400F). I already spend a couple days on it. I still can not figure out how to program it. The emif to sdram examples I can find are all about DSPs, nothing about this MCU. Does anybody can help me take a look at the following program? I know it has a lot of mistakes.
I just want to write some digital numbers into SDRAM, and read them out.
#include "F28x_Project.h" // Device Headerfile and Examples Include File
#include "F2837xD_Emif.h"
#include <stdio.h>
//#include <std.h>
Uint32 *Src_StartAdd;
Uint32 *Dst_StartAdd;
Uint32 *Src_EndAdd;
Uint32 *Dst_EndAdd;
Uint32 TempData;
Uint32 DataBuff[2048]={0};
Uint32 ReceiveData[2048] = {0};
void Emif_sdram_config(void);
void Emif_sdram_gpio(void);
void Emif_sdram_gpio(void)
{
EALLOW;
GpioCtrlRegs.GPAMUX2.bit.GPIO29 = 2;//GPIO29 EM1SDCKE
GpioCtrlRegs.GPAMUX2.bit.GPIO30 = 2;//CLK
GpioCtrlRegs.GPAMUX2.bit.GPIO31 = 2;//WE
GpioCtrlRegs.GPBMUX1.bit.GPIO32 = 2;//CS0 GPIO B Mux 1 Register (GPIO32 to 47)
GpioCtrlRegs.GPBMUX1.bit.GPIO38 = 2;//A0
GpioCtrlRegs.GPBMUX1.bit.GPIO39 = 2;//A1
GpioCtrlRegs.GPBMUX1.bit.GPIO40 = 2;//A2
GpioCtrlRegs.GPBMUX1.bit.GPIO41 = 2;//A3
GpioCtrlRegs.GPBMUX1.bit.GPIO44 = 2;//A4
GpioCtrlRegs.GPBMUX1.bit.GPIO45 = 2;//A5
GpioCtrlRegs.GPBMUX1.bit.GPIO46 = 2;//A6
GpioCtrlRegs.GPBMUX1.bit.GPIO47 = 2;//A7
GpioCtrlRegs.GPBMUX2.bit.GPIO48 = 2;//A8 GPIO B Mux 2 Register (GPIO48 to 63)
GpioCtrlRegs.GPBMUX2.bit.GPIO49 = 2;//A9
GpioCtrlRegs.GPBMUX2.bit.GPIO50 = 2;//A10
GpioCtrlRegs.GPBMUX2.bit.GPIO51 = 2;//A11
GpioCtrlRegs.GPCMUX1.bit.GPIO69 = 2;//D15
GpioCtrlRegs.GPCMUX1.bit.GPIO70 = 2;//D14
GpioCtrlRegs.GPCMUX1.bit.GPIO71 = 2;//D13
GpioCtrlRegs.GPCMUX1.bit.GPIO72 = 2;//D12
GpioCtrlRegs.GPCMUX1.bit.GPIO73 = 2;//D11
GpioCtrlRegs.GPCMUX1.bit.GPIO74 = 2;//D10
GpioCtrlRegs.GPCMUX1.bit.GPIO75 = 2;//D9
GpioCtrlRegs.GPCMUX1.bit.GPIO76 = 2;//D8
GpioCtrlRegs.GPCMUX1.bit.GPIO77 = 2;//D7
GpioCtrlRegs.GPCMUX1.bit.GPIO78 = 2;//D6
GpioCtrlRegs.GPCMUX1.bit.GPIO79 = 2;//D5
GpioCtrlRegs.GPCMUX2.bit.GPIO80 = 2;//D4
GpioCtrlRegs.GPCMUX2.bit.GPIO81 = 2;//D3
GpioCtrlRegs.GPCMUX2.bit.GPIO82 = 2;//D2
GpioCtrlRegs.GPCMUX2.bit.GPIO83 = 2;//D1
GpioCtrlRegs.GPCMUX2.bit.GPIO85 = 2;//D0
GpioCtrlRegs.GPCMUX2.bit.GPIO86 = 3;//CAS
GpioCtrlRegs.GPCMUX2.bit.GPIO87 = 3;//RAS
GpioCtrlRegs.GPCMUX2.bit.GPIO88 = 3;//DQM0
GpioCtrlRegs.GPCMUX2.bit.GPIO89 = 3;//DQM1
GpioCtrlRegs.GPCMUX2.bit.GPIO92 = 3;//BA1
GpioCtrlRegs.GPCMUX2.bit.GPIO93 = 3;//BA0
//set GPIO Direction as output
EDIS;
}
void Emif_sdram_config(void)
{
//STEP 1 SDRAM should be placed in Self-Refresh Mode by setting the SR bit in
//the SDRAM configuration register (SDCR). The SR bit should be set using a byte-write to the upper byte
//of the SDCR to avoid triggering the SDRAM Initialization Sequence
Emif1Regs.SDRAM_CR.bit.SR = 1;
//STEP 2 The device global clock module (GCM) should first be programmed to select the desired EMIF_CLK frequency
ClkCfgRegs.PERCLKDIVSEL.bit.EMIF1CLKDIV = 1; ///2 of PLLSYSCLK is selected, PLLSYSCLK = PLLCLK / SYSCLKDIVSEL
//STEP 3 selecting the appropriate clock source for the VCLK3 domain
//STEP 4 remove the SDRAM from Self-Refresh by clearing the SR bit in SDCR, again with a byte-write.
Emif1Regs.SDRAM_CR.bit.SR = 0;
//STEP 5
Emif1Regs.SDRAM_TR.all = 0x61114610; //SDRAM Timing Register
Emif1Regs.SDR_EXT_TMNG.all = 0x6; //self refresh exit timing register
Emif1Regs.SDRAM_RCR.all = 0x61A; //Refresh Control Register
Emif1Regs.SDRAM_CR.all = 0x4720; //configuration register
}
/********************************************************************************/
main()
{
InitSysCtrl();
InitGpio();
InitPieCtrl();
IER = 0x0000;// Disable CPU interrupts and clear all CPU interrupt flags:
IFR = 0x0000;
InitPieVectTable();
Uint32 i;
Src_StartAdd = (Uint32 *)0x80000000;//
Src_EndAdd = (Uint32 *)0x80000FFC;//
Emif_sdram_gpio();
Emif_sdram_config();
for(i=0;i<0x400000;i++)
{
*(Src_StartAdd++) = i;
}
printf("\nFinish writing Source data.");
Src_StartAdd = (Uint32 *)0x80000000;
/* READ DATA*/
for(i=0;i<0x400000;i++)
{
TempData = *(Src_StartAdd ++);
if(TempData != i)
{
printf("\nTesting is failure");
// exit(0);
}
else ReceiveData[i] = TempData;
// else continue;
}
for(;;);
}