AnsweredAssumed Answered

K66F+16Bit SDRAM

Question asked by Christie Su on Jun 9, 2017
Latest reply on Jun 18, 2017 by Hui_Ma

Hi,

 

Finally, I got the customized board on my hand. When I am testing SDRAM, I can't see any data read from SDRAM.

So, there are something wrong there.

1) MCU: MK66FN2M0VLQ18

2) SDRAM:MT48LC8M16A2(2 chips). See attached.

 

3) Here is pin_mux:

void BOARD_InitPins(void)

{

CLOCK_EnableClock(kCLOCK_PortA); /* Port A Clock Gate Control: Clock enabled */

CLOCK_EnableClock(kCLOCK_PortB); /* Port B Clock Gate Control: Clock enabled */

CLOCK_EnableClock(kCLOCK_PortC); /* Port C Clock Gate Control: Clock enabled */

CLOCK_EnableClock(kCLOCK_PortD); /* Port D Clock Gate Control: Clock enabled */

CLOCK_EnableClock(kCLOCK_PortE); /* Port E Clock Gate Control: Clock enabled */

 

//-----*****Just doing re-arrangement from pin_mux.c that is generated by pin tool*****-----

 

//-----*****UART0 used as DEBUG interface on Demo Board*****-----

// PORT_SetPinMux(PORTB, PIN16_IDX, kPORT_MuxAlt3); /* PORTB16 (pin E10) is configured as UART0_RX(Demo Board) */

// PORT_SetPinMux(PORTB, PIN17_IDX, kPORT_MuxAlt3); /* PORTB17 (pin E9) is configured as UART0_TX(Demo Board) */

//----Configured on iNetVu 7710 Version 5.0

//-----*****UART1 used as DEBUG interface*****-----

PORT_SetPinMux(PORTE, PIN0_IDX, kPORT_MuxAlt3); /* PORTE0 (pin 1) is configured as UART1_TX */

PORT_SetPinMux(PORTE, PIN1_IDX, kPORT_MuxAlt3); /* PORTE1 (pin 2) is configured as UART1_RX */

 

//-----*****Configure UART3*****-----

PORT_SetPinMux(PORTE, PIN4_IDX, kPORT_MuxAlt3); /* PORTE4 (pin 7) is configured as UART3_TX */

PORT_SetPinMux(PORTE, PIN5_IDX, kPORT_MuxAlt3); /* PORTE5 (pin 8) is configured as UART3_RX */

 

//-----*****Configure LPUART0*****-----

PORT_SetPinMux(PORTE, PIN8_IDX, kPORT_MuxAlt5); /* PORTE8 (pin 11) is configured as LPUART0_TX */

PORT_SetPinMux(PORTE, PIN9_IDX, kPORT_MuxAlt5); /* PORTE9 (pin 12) is configured as LPUART0_RX */

 

//-----*****ENET Configuration*****-----

PORT_SetPinMux(PORTA, PIN12_IDX, kPORT_MuxAlt4); /* PORTA12 (pin 64) is configured as RMII0_RXD1 */

PORT_SetPinMux(PORTA, PIN13_IDX, kPORT_MuxAlt4); /* PORTA13 (pin 65) is configured as RMII0_RXD0 */

PORT_SetPinMux(PORTA, PIN14_IDX, kPORT_MuxAlt4); /* PORTA14 (pin 66) is configured as RMII0_CRS_DV */

PORT_SetPinMux(PORTA, PIN15_IDX, kPORT_MuxAlt4); /* PORTA15 (pin 67) is configured as RMII0_TXEN */

PORT_SetPinMux(PORTA, PIN16_IDX, kPORT_MuxAlt4); /* PORTA16 (pin 68) is configured as RMII0_TXD0 */

PORT_SetPinMux(PORTA, PIN17_IDX, kPORT_MuxAlt4); /* PORTA17 (pin 69) is configured as RMII0_TXD1 */

PORT_SetPinMux(PORTA, PIN5_IDX, kPORT_MuxAlt4); /* PORTA5 (pin 55) is configured as RMII0_RXER */

// On Demo Board

// PORT_SetPinMux(PORTB, PIN0_IDX, kPORT_MuxAlt4); /* PORTB0 (pin H10) is configured as RMII0_MDIO */

// PORTB->PCR[0] = ((PORTB->PCR[0] &

// (~(PORT_PCR_ODE_MASK | PORT_PCR_ISF_MASK))) /* Mask bits to zero which are setting */

// | PORT_PCR_ODE(PCR_ODE_ENABLED) /* Open Drain Enable: Open drain output is enabled on the corresponding pin, if the pin is configured as a digital output. */

// );

// PORT_SetPinMux(PORTB, PIN1_IDX, kPORT_MuxAlt4); /* PORTB1 (pin H9) is configured as RMII0_MDC */

//----Configured on iNetVu 7710 Version 5.0

PORT_SetPinMux(PORTA, PIN7_IDX, kPORT_MuxAlt5); /* PORTA7 (pin 59) is configured as RMII0_MDIO */

PORTA->PCR[7] = ((PORTB->PCR[7] &

(~(PORT_PCR_ODE_MASK | PORT_PCR_ISF_MASK))) /* Mask bits to zero which are setting */

| PORT_PCR_ODE(PCR_ODE_ENABLED) /* Open Drain Enable: Open drain output is enabled on the corresponding pin, if the pin is configured as a digital output. */

);

PORT_SetPinMux(PORTA, PIN8_IDX, kPORT_MuxAlt5); /* PORTA8 (pin 60) is configured as RMII0_MDC */

PORT_SetPinMux(PORTE, PIN26_IDX, kPORT_MuxAlt2); /* PORTE26 (pin 47) is configured as ENET_1588_CLKIN */

 

  

//-----*****Initialize the SDRAMC pins*****-----

PORT_SetPinMux(PORTA, PIN6_IDX, kPORT_MuxAlt5); /* PORTA6 (pin 58) is configured as CLKOUT */

// Configured for RMII Network on Demo Board

PORT_SetPinMux(PORTB, PIN0_IDX, kPORT_MuxAlt5); /* PORTB0 (pin 81) is configured as SDRAM_CAS_b---Configured for RMII Network on Demo Board */

PORT_SetPinMux(PORTB, PIN1_IDX, kPORT_MuxAlt5); /* PORTB1 (pin 82) is configured as SDRAM_RAS_b---Configured for RMII Network on Demo Board */

PORT_SetPinMux(PORTB, PIN2_IDX, kPORT_MuxAlt5); /* PORTB2 (pin 83) is configured as SDRAM_WE */

PORT_SetPinMux(PORTB, PIN3_IDX, kPORT_MuxAlt5); /* PORTB3 (pin 84) is configured as SDRAM_CS0_b */

PORT_SetPinMux(PORTB, PIN4_IDX, kPORT_MuxAlt5); /* PORTB4 (pin 85) is configured as SDRAM_CS1_b */

 

  

// Configure SDRAM Data Pins

PORT_SetPinMux(PORTB, PIN20_IDX, kPORT_MuxAlt5); /* PORTB20 (pin 99) is configured as SDRAM_D31, FB_AD31 */

PORT_SetPinMux(PORTB, PIN21_IDX, kPORT_MuxAlt5); /* PORTB21 (pin 100) is configured as FB_AD30, SDRAM_D30 */

PORT_SetPinMux(PORTB, PIN22_IDX, kPORT_MuxAlt5); /* PORTB22 (pin 101) is configured as FB_AD29, SDRAM_D29 */

PORT_SetPinMux(PORTB, PIN23_IDX, kPORT_MuxAlt5); /* PORTB23 (pin 102) is configured as SDRAM_D28, FB_AD28 */

PORT_SetPinMux(PORTC, PIN12_IDX, kPORT_MuxAlt5); /* PORTC12 (pin 117) is configured as FB_AD27, SDRAM_D27 */

PORT_SetPinMux(PORTC, PIN13_IDX, kPORT_MuxAlt5); /* PORTC13 (pin 118) is configured as SDRAM_D26, FB_AD26 */

PORT_SetPinMux(PORTC, PIN14_IDX, kPORT_MuxAlt5); /* PORTC14 (pin 119) is configured as SDRAM_D25, FB_AD25 */

PORT_SetPinMux(PORTC, PIN15_IDX, kPORT_MuxAlt5); /* PORTC15 (pin 120) is configured as FB_AD24, SDRAM_D24 */

PORT_SetPinMux(PORTB, PIN5_IDX, kPORT_MuxAsGpio); /* PORTB5 (pin 86) is configured as PTB5 */

PORT_SetPinMux(PORTB, PIN6_IDX, kPORT_MuxAlt5); /* PORTB6 (pin 87) is configured as FB_AD23, SDRAM_D23 */

PORT_SetPinMux(PORTB, PIN7_IDX, kPORT_MuxAlt5); /* PORTB7 (pin 88) is configured as SDRAM_D22, FB_AD22 */

PORT_SetPinMux(PORTB, PIN8_IDX, kPORT_MuxAlt5); /* PORTB8 (pin 89) is configured as FB_AD21, SDRAM_D21 */

PORT_SetPinMux(PORTB, PIN9_IDX, kPORT_MuxAlt5); /* PORTB9 (pin 90) is configured as FB_AD20, SDRAM_D20 */

PORT_SetPinMux(PORTB, PIN10_IDX, kPORT_MuxAlt5); /* PORTB10 (pin 91) is configured as FB_AD19, SDRAM_D19 */

PORT_SetPinMux(PORTB, PIN11_IDX, kPORT_MuxAlt5); /* PORTB11 (pin 92) is configured as SDRAM_D18, FB_AD18 */

//-----*****UART0 used as DEBUG interface on Demo Board*****-----

PORT_SetPinMux(PORTB, PIN16_IDX, kPORT_MuxAlt5); /* PORTB16 (pin 95) is configured as FB_AD17, SDRAM_D17---Used as DEBUG interface on Demo Board */

PORT_SetPinMux(PORTB, PIN17_IDX, kPORT_MuxAlt5); /* PORTB17 (pin 96) is configured as FB_AD16, SDRAM_D16---Used as DEBUG interface on Demo Board */

 

// Configure SDRAM Address

PORT_SetPinMux(PORTB, PIN18_IDX, kPORT_MuxAlt5); /* PORTB18 (pin 97) is configured as SDRAM_A23, FB_AD15 */

PORT_SetPinMux(PORTC, PIN0_IDX, kPORT_MuxAlt5); /* PORTC0 (pin 103) is configured as FB_AD14, SDRAM_A22 */

PORT_SetPinMux(PORTC, PIN1_IDX, kPORT_MuxAlt5); /* PORTC1 (pin 104) is configured as SDRAM_A21, FB_AD13 */

PORT_SetPinMux(PORTC, PIN2_IDX, kPORT_MuxAlt5); /* PORTC2 (pin 105) is configured as SDRAM_A20, FB_AD12 */

PORT_SetPinMux(PORTC, PIN4_IDX, kPORT_MuxAlt5); /* PORTC4 (pin 109) is configured as FB_AD11, SDRAM_A19 */

PORT_SetPinMux(PORTC, PIN5_IDX, kPORT_MuxAlt5); /* PORTC5 (pin 110) is configured as FB_AD10, SDRAM_A18 */

PORT_SetPinMux(PORTC, PIN6_IDX, kPORT_MuxAlt5); /* PORTC6 (pin 111) is configured as SDRAM_A17, FB_AD9 */

PORT_SetPinMux(PORTC, PIN7_IDX, kPORT_MuxAlt5); /* PORTC7 (pin 112) is configured as SDRAM_A16, FB_AD8 */

PORT_SetPinMux(PORTC, PIN8_IDX, kPORT_MuxAlt5); /* PORTC8 (pin 113) is configured as SDRAM_A15, FB_AD7 */

PORT_SetPinMux(PORTC, PIN9_IDX, kPORT_MuxAlt5); /* PORTC9 (pin 114) is configured as SDRAM_A14, FB_AD6 */

PORT_SetPinMux(PORTC, PIN10_IDX, kPORT_MuxAlt5); /* PORTC10 (pin 115) is configured as SDRAM_A13, FB_AD5 */

PORT_SetPinMux(PORTD, PIN2_IDX, kPORT_MuxAlt5); /* PORTD2 (pin 129) is configured as SDRAM_A12, FB_AD4 */

PORT_SetPinMux(PORTD, PIN3_IDX, kPORT_MuxAlt5); /* PORTD3 (pin 130) is configured as SDRAM_A11, FB_AD3 */

PORT_SetPinMux(PORTD, PIN4_IDX, kPORT_MuxAlt5); /* PORTD4 (pin 131) is configured as SDRAM_A10, FB_AD2 */

PORT_SetPinMux(PORTD, PIN5_IDX, kPORT_MuxAlt5); /* PORTD5 (pin 132) is configured as FB_AD1, SDRAM_A9 */

 

// Configure SDRAM Control signal

PORT_SetPinMux(PORTD, PIN7_IDX, kPORT_MuxAlt5); /* PORTD7 (pin 136) is configured as SDRAM_CKE */

PORT_SetPinMux(PORTC, PIN17_IDX, kPORT_MuxAlt5); /* PORTC17 (pin 124) is configured as SDRAM_DQM3 */

PORT_SetPinMux(PORTC, PIN16_IDX, kPORT_MuxAlt5); /* PORTC16 (pin 123) is configured as SDRAM_DQM2 */

PORT_SetPinMux(PORTC, PIN18_IDX, kPORT_MuxAlt5); /* PORTC18 (pin 125) is configured as SDRAM_DQM1 */

PORT_SetPinMux(PORTC, PIN19_IDX, kPORT_MuxAlt5); /* PORTC19 (pin 126) is configured as SDRAM_DQM0 */

 

//-----*****Configure Flexbus high address*****-----

PORT_SetPinMux(PORTA, PIN28_IDX, kPORT_MuxAlt6); /* PORTA28 (pin 79) is configured as FB_A25 */

PORT_SetPinMux(PORTA, PIN29_IDX, kPORT_MuxAlt6); /* PORTA29 (pin 80) is configured as FB_A24 */

PORT_SetPinMux(PORTD, PIN15_IDX, kPORT_MuxAlt6); /* PORTD15 (pin 144) is configured as FB_A23 */

PORT_SetPinMux(PORTD, PIN14_IDX, kPORT_MuxAlt6); /* PORTD14 (pin 143) is configured as FB_A22 */

PORT_SetPinMux(PORTD, PIN13_IDX, kPORT_MuxAlt6); /* PORTD13 (pin 142) is configured as FB_A21 */

PORT_SetPinMux(PORTD, PIN12_IDX, kPORT_MuxAlt6); /* PORTD12 (pin 141) is configured as FB_A20 */

PORT_SetPinMux(PORTD, PIN11_IDX, kPORT_MuxAlt6); /* PORTD11 (pin 140) is configured as FB_A19 */

PORT_SetPinMux(PORTD, PIN10_IDX, kPORT_MuxAlt6); /* PORTD10 (pin 139) is configured as FB_A18 */

PORT_SetPinMux(PORTD, PIN9_IDX, kPORT_MuxAlt6); /* PORTD9 (pin 138) is configured as FB_A17 */

PORT_SetPinMux(PORTD, PIN8_IDX, kPORT_MuxAlt6); /* PORTD8 (pin 137) is configured as FB_A16 */

 

// Configure Flexbus RW, OE, chip select and etc Control signal

PORT_SetPinMux(PORTB, PIN19_IDX, kPORT_MuxAlt5); /* PORTB19 (pin 98) is configured as FB_OE_b */

PORT_SetPinMux(PORTC, PIN11_IDX, kPORT_MuxAlt5); /* PORTC11 (pin 116) is configured as FB_RW_b */

PORT_SetPinMux(PORTD, PIN0_IDX, kPORT_MuxAlt5); /* PORTD0 (pin 127) is configured as FB_CS1_b */

PORT_SetPinMux(PORTD, PIN1_IDX, kPORT_MuxAlt5); /* PORTD1 (pin 128) is configured as FB_CS0_b */

 

//----*****Configure I2C0*****-----

PORT_SetPinMux(PORTE, PIN10_IDX, kPORT_MuxAlt2); /* PORTE10 (pin 13) is configured as I2C3_SDA */

PORT_SetPinMux(PORTE, PIN11_IDX, kPORT_MuxAlt2); /* PORTE11 (pin 14) is configured as I2C3_SCL */

 

//----*****Configure CANBUS*****-----

PORT_SetPinMux(PORTE, PIN24_IDX, kPORT_MuxAlt2); /* PORTE24 (pin 45) is configured as CAN1_TX */

PORT_SetPinMux(PORTE, PIN25_IDX, kPORT_MuxAlt2); /* PORTE25 (pin 46) is configured as CAN1_RX */

 

  

//----*****Configure as GPIO*****-----

// Configured on Demo Board

PORT_SetPinMux(PORTA, PIN10_IDX, kPORT_MuxAsGpio); /* PORTA10 (pin M9) is configured as PTA10 */

PORTA->PCR[10] = ((PORTA->PCR[10] &

(~(PORT_PCR_PS_MASK | PORT_PCR_PE_MASK | PORT_PCR_ISF_MASK))) /* Mask bits to zero which are setting */

| PORT_PCR_PS(PCR_PS_UP) /* Pull Select: Internal pullup resistor is enabled on the corresponding pin, if the corresponding PE field is set. */

| PORT_PCR_PE(PCR_PE_ENABLED) /* Pull Enable: Internal pullup or pulldown resistor is enabled on the corresponding pin, if the pin is configured as a digital input. */

);

 

// PORT_SetPinMux(PORTA, PIN10_IDX, kPORT_MuxAsGpio); /* PORTA10 (pin 62) is configured as PTA10 */

PORT_SetPinMux(PORTA, PIN11_IDX, kPORT_MuxAsGpio); /* PORTA11 (pin 63) is configured as PTA11 */

 

PORT_SetPinMux(PORTC, PIN3_IDX, kPORT_MuxAsGpio); /* PORTC3 (pin 106) is configured as PTC3 */

PORT_SetPinMux(PORTC, PIN9_IDX, kPORT_MuxAsGpio); /* PORTC9 (pin D7) is configured as PTC9 */

 

PORT_SetPinMux(PORTD, PIN6_IDX, kPORT_MuxAsGpio); /* PORTD6 (pin 133) is configured as PTD6 */

 

PORT_SetPinMux(PORTE, PIN2_IDX, kPORT_MuxAsGpio); /* PORTE2 (pin 3) is configured as PTE2 */

PORT_SetPinMux(PORTE, PIN3_IDX, kPORT_MuxAsGpio); /* PORTE3 (pin 4) is configured as PTE3 */

PORT_SetPinMux(PORTE, PIN6_IDX, kPORT_MuxAsGpio); /* PORTE6 (pin 9) is configured as PTE6 */

PORT_SetPinMux(PORTE, PIN7_IDX, kPORT_MuxAsGpio); /* PORTE7 (pin 10) is configured as PTE7 */

PORT_SetPinMux(PORTE, PIN12_IDX, kPORT_MuxAsGpio); /* PORTE12 (pin 15) is configured as PTE12 */

PORT_SetPinMux(PORTE, PIN27_IDX, kPORT_MuxAsGpio); /* PORTE27 (pin 48) is configured as PTE27 */

PORT_SetPinMux(PORTE, PIN28_IDX, kPORT_MuxAsGpio); /* PORTE28 (pin 49) is configured as PTE28 */

 

//----*****Configure JTAG*****-----

PORT_SetPinMux(PORTA, PIN0_IDX, kPORT_MuxAlt7); /* PORTA0 (pin 50) is configured as JTAG_TCLK */

PORT_SetPinMux(PORTA, PIN1_IDX, kPORT_MuxAlt7); /* PORTA1 (pin 51) is configured as JTAG_TDI */

PORT_SetPinMux(PORTA, PIN2_IDX, kPORT_MuxAlt7); /* PORTA2 (pin 52) is configured as JTAG_TDO */

PORT_SetPinMux(PORTA, PIN3_IDX, kPORT_MuxAlt7); /* PORTA3 (pin 53) is configured as JTAG_TMS */

PORT_SetPinMux(PORTA, PIN4_IDX, kPORT_MuxAlt7); /* PORTA4 (pin 54) is configured as NMI_b */

 

//-----The initialization done by tool generation

// Select RMII clock src.

SIM->SOPT2 = ((SIM->SOPT2 & (~(SIM_SOPT2_RMIISRC_MASK))) | SIM_SOPT2_RMIISRC(SOPT2_RMIISRC_ENET)); // Bit19==1---RMII clock source select: External bypass clock (ENET_1588_CLKIN).

 

SIM->SOPT5 = ((SIM->SOPT5 &

(~(SIM_SOPT5_UART1TXSRC_MASK | SIM_SOPT5_LPUART0TXSRC_MASK))) /* Mask bits to zero which are setting */

| SIM_SOPT5_UART1TXSRC(SOPT5_UART1TXSRC_UART_TX) /* UART 1 transmit data source select: UART1_TX pin */

| SIM_SOPT5_LPUART0TXSRC(SOPT5_LPUART0TXSRC_LPUART_TX) /* LPUART0 transmit data source select: LPUART0_TX pin */

);

SIM->USBPHYCTL = ((SIM->USBPHYCTL &

(~(SIM_USBPHYCTL_USBVREGSEL_MASK))) /* Mask bits to zero which are setting */

| SIM_USBPHYCTL_USBVREGSEL(USBPHYCTL_USBVREGSEL_VREG_IN0) /* Selects the default input voltage source to the USB Regulator in case both VREG_IN0 and VREG_IN1 are powered. If only one of the regulator inputs is powered, it will automatically be selected by the regulator's power mux circuitry.: VREG_IN0 will be selected if both regulator inputs are powered */

);

}

 

 

 

4) Here is initialization and write, read that I copied from TWR-K65F demo.

 

status_t SDRAM_Init(SDRAM_Type *base, uint32_t busClock_Hz)

{

sdramc_config_t config;

sdramc_refresh_config_t refConfig;

sdramc_blockctl_config_t ctlConfig;

 

/* SDRAM refresh timing configuration. */

refConfig.refreshTime = kSDRAMC_RefreshThreeClocks;

/* Refresh time 4096 rows/ 64ms. */

refConfig.sdramRefreshRow = 15625;

refConfig.busClock_Hz = busClock_Hz;

/* SDRAM controller configuration. */

// /*SDRAM Port size: 32 bit, command bit 20. */

// ctlConfig.portSize = kSDRAMC_PortSize32Bit;

/*SDRAM Port size: 16 bit, command bit 20.---Modified by SU */

ctlConfig.portSize = kSDRAMC_PortSize16Bit;

ctlConfig.location = kSDRAMC_Commandbit20;

ctlConfig.block = kSDRAMC_Block0;

/* SDRAM with trcd-15ns(min), trp-15ns(min), tras-37ns (min). */

ctlConfig.latency = kSDRAMC_LatencyOne;

ctlConfig.address = SDRAM_START_ADDRESS;

ctlConfig.addressMask = 0x7c0000;

 

config.refreshConfig = &refConfig;

config.blockConfig = &ctlConfig;

config.numBlockConfig = 1;

 

/* Initializes the SDRAM controller. */

SDRAMC_Init(base, &config);

 

/* The external SDRAM initialization sequence. */

return SDRAM_InitSequence(base, kSDRAMC_Block0, kSDRAM_MrsBurstLenOne, kSDRAM_MrsSequential, kSDRAM_MrsLatencyTwo,

kSDRAM_MrsStandOperation, kSDRAM_MrsWriteBurst);

}

 

 

BOARD_InitPins();

BOARD_BootClockRUN();

BOARD_InitDebugConsole();

 

// BOARD_InitPins();

// BOARD_BootClockRUN();

// BOARD_InitDebugConsole();

 

//-----*****Copied from Httpsrv demo*****-----

// Disable MPU.

base->CESR &= ~MPU_CESR_VLD_MASK;

// // Set RMII clock src.

// SIM->SOPT2 |= SIM_SOPT2_RMIISRC_MASK; // Done in BOARD_InitPins(void)

 

//-----Copied from Flexbus driver demo on TWR-K65F180M-----

/* Set clock out to flexbus CLKOUT. */

CLOCK_SetClkOutClock(0); // Select clock on CLKOUT pin(0---Flexbus CLOCK)

 

// //-----*****Set RMII clock src.*****----- //-----Copied from http server demo application-----

// // Select RMII clock source(Bit19==1---External bypass clock(ENET_1588_CLKIN), ==0---EXTAL clock)

// SIM->SOPT2 |= SIM_SOPT2_RMIISRC_MASK; // Done in BOARD_InitPins(void)-----

 

//-----*****Sets the Flexbus security level*****-----

soptReg = SIM->SOPT2 & ~SIM_SOPT2_FBSL_MASK;

SIM->SOPT2 = soptReg | SIM_SOPT2_FBSL(3); //Bit9:8==11---Off-chip instruction accesses and data accesses are allowed

 

/* Enable the FB_BE_xx_yy signal in Flexbus */

// SIM_base==0x4004_7000+0x1040==0x4004_8040(SIM_SCGC7, Bit0---Flexbus clock enable/disable)

// CLOCK_EnableClock(kCLOCK_Flexbus0); // Done in FLEXBUS_Init()--- kCLOCK_Flexbus0 == 0x1040_0000

 

// /* Set clock out to flexbus CLKOUT. */

// CLOCK_SetClkOutClock(0);

//

// /* Sets the Flexbus security level*/

// soptReg = SIM->SOPT2 & ~SIM_SOPT2_FBSL_MASK;

// SIM->SOPT2 = soptReg | SIM_SOPT2_FBSL(3);

//

// /* Enable the FB_BE_xx_yy signal in Flexbus */

CLOCK_EnableClock(kCLOCK_Flexbus0);

 

fbReg = FB->CSPMCR & ~FB_CSPMCR_GROUP2_MASK;

FB->CSPMCR = fbReg | FB_CSPMCR_GROUP2(2);

fbReg = FB->CSPMCR & ~FB_CSPMCR_GROUP3_MASK;

FB->CSPMCR = fbReg | FB_CSPMCR_GROUP3(2);

fbReg = FB->CSPMCR & ~FB_CSPMCR_GROUP4_MASK;

FB->CSPMCR = fbReg | FB_CSPMCR_GROUP4(2);

fbReg = FB->CSPMCR & ~FB_CSPMCR_GROUP5_MASK;

FB->CSPMCR = fbReg | FB_CSPMCR_GROUP5(2);

 

/* SDRAM initialize. */

clockSrc = CLOCK_GetFreq(kCLOCK_BusClk);

PRINTF("\r\n SDRAM Example Start!\r\n");

if (SDRAM_Init(EXAMPLE_SDRAMC, clockSrc) != kStatus_Success)

{

PRINTF("\r\n SDRAM Init Failed\r\n");

}

 

PRINTF("\r\n SDRAM Memory Write Start, Start Address 0x%x, Data Length %d !\r\n", sdram, datalen);

//-----*****Prepare data and write to SDRAM.*****-----

for (index = 0; index < datalen; index++)

{

sdram_writeBuffer[index] = index;

*(uint32_t *)(sdram + index) = sdram_writeBuffer[index];

}

PRINTF("\r\n SDRAM Write finished!\r\n");

 

PRINTF("\r\n SDRAM Read Start, Start Address 0x%x, Data Length %d !\r\n", sdram, datalen);

//-----*****Read data from the SDRAM.*****-----

for (index = 0; index < datalen; index++)

{

sdram_readBuffer[index] = *(uint32_t *)(sdram + index);

// sdram_readBuffer[index] >>= 16;

}

PRINTF("\r\n SDRAM Read finished!\r\n");

 

PRINTF("\r\n SDRAM Write Data and Read Data Compare Start!\r\n");

//-----*****Compare the two buffers.*****-----

while (datalen--)

{

if (sdram_writeBuffer[datalen] != sdram_readBuffer[datalen])

{

result = false;

PRINTF("\r\n SDRAM Write Data and Read Data Check Error=0x%x_0x%x_0x%x!\r\n", datalen, sdram_writeBuffer[datalen], sdram_readBuffer[datalen]);

// break;

}

else

{

if ((datalen % 1024) == 0)

{

PRINTF("\r\n SDRAM Write Data and Read Data_%d=%d_%d!\r\n", datalen, sdram_writeBuffer[datalen], sdram_readBuffer[datalen]);

}

 

PRINTF("\r\n SDRAM Write Data and Read Data Check_00=0x%x_0x%x_0x%x!\r\n", datalen, sdram_writeBuffer[datalen], sdram_readBuffer[datalen]);

 

}

}

 

if (result)

{

PRINTF("\r\n SDRAM Write Data and Read Data Succeed.\r\n");

}

else

{

PRINTF("\r\n SDRAM Write Data and Read Data Failed.\r\n");

}

PRINTF("\r\n SDRAM Example End.\r\n");

 

 

 

5. Could you tell me where the possible problems are? The SDRAM configuration is right?

 

 

6. I did more testing today and found the following:

1) When I change the latency to 0(1 before), I can write and read, but there is 20% error.

2) If I write 16 bit, I found the error only on lob byte. High byte always right.

There is eh same result on block0 and block1.

Is it possible to be related on SDRAM timing setting?

 

7. I checked SDRAM chip spec. and should set the latency to 3(3-3-3). I tried 3,2,1 and always read 0.

If I set to 0, it reads back the right data, but not reliable.

 

Can anyone help me to find out where the problem is and how to configure SDRAM timing?

 

Thanks,

 

Christie

Outcomes