K66F+16Bit SDRAM

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

K66F+16Bit SDRAM

4,289 Views
a8Chcx
Contributor V

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

Labels (1)
0 Kudos
Reply
21 Replies

3,369 Views
aptron_chad
Contributor II

I once had a problem with SDRAM configuration which was related to the initialization of the SDRAM to set the number of wait states. There was some code in the initialization routine that was being removed by the compiler code optimization features. The solution was to exclude the initialization routine from the optimization process. This could be something to look into and eliminate as a potential cause. Sometimes issues are due to multiple and contributing causes.

0 Kudos
Reply

3,369 Views
a8Chcx
Contributor V

Hi Chad,

Are you saying CAS latency? I confirmed it is there. Based on SDRAM chip, I have to set to 3.

I tried the different CAS latency, the same problem.

Thanks,

Christie

0 Kudos
Reply

3,369 Views
chadwilliams
Contributor III

I'm saying take a look at your SDRAM_Init function and check to see how its being initialised and check if any compiler optimisation may be altering the intended sequence.

Perhaps you can try to set the compiler optimisation to None or  -O0

If the case I was using as an example the SDRAM routine included several writes to the same base address such as

                *base = 0;

                *base = 0;

                *base = 0;

                *base = 0;

                *base = 0;

                *base = 0;

                *base = 0;

                *base = 0;

an the compiler optimised that to

                *base = 0;

which lead to the SDRAm not being correctly initialised.

0 Kudos
Reply

3,369 Views
a8Chcx
Contributor V

Hi Chad,

I checked the base for SDRAM is right and I didn't use optimization for now. It is set for none(-O0) for now.

Thanks,

Christie

0 Kudos
Reply

3,369 Views
Hui_Ma
NXP TechSupport
NXP TechSupport

Hi

First of all, sorry for the later reply.

Could you provide the K66F with SDRAM devices schematics? Thanks.


Have a great day,
Ma Hui

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
Reply

3,369 Views
a8Chcx
Contributor V

Hi Hui,

Please check the attached document and let me know what I need to test?

It is running OK with system clock=180MHz and bus clock==45MHz. but not other frequency, even I tried 30MHx bus clock.

Thanks,

Christie

0 Kudos
Reply

3,369 Views
a8Chcx
Contributor V

Hi Hui,

After I add 12pF on clock, my board is working fine for now.

Could you tell me what is the reason behind it?

1) What the capacitor value should I use because I am going to do next version of PCB?

2) Do I need to add 22ohm on /CAS, /RAS, /SDWE, /SCKE, /SD_CS0, /SD_CS1? How about DQM2/DQM3?

If so, what is the reason behind it?

Thanks,

Christie

0 Kudos
Reply

3,369 Views
Hui_Ma
NXP TechSupport
NXP TechSupport

Hi Christie,

The CLKOUT signal is not clear enough, so add a 12pF capacitor will filter some noise to enhance the clock signal.

1> I don't think customer need to add a capacitor to clock line. The PCB layout need to avoid the clock signal be interfered.

2> The SDRAM is different with DDR SDRAM, which doesn't need the 22ohm serial resistor to SDRAM control signal pins.

I think the most issue caused by the PCB layout.

Please refer this application note about layout guideline for DDR2 SDRAM, some principle is also suitable to SDRAM layout.

Wish it helps.


Have a great day,
Ma Hui

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
Reply

3,369 Views
a8Chcx
Contributor V

Hi Hui,

I am doing the testing and already run for 36 hours, and still works fine.

At the same time, I searched on NXP website to try to find the reason and what is best value needed for clock.

1) It says it is most related to the start-up time of clock is faster than other signals, like address, control, data and etc...

2) The second reason: The clock is not 50%, so need to have extra delay to compensate it.

3) When I am using MCF5282 with SDRAM, it is very similar speed, but there is capacitor and serial resistor on reference design, see attached SCH. I follow the reference design and work fine, no any issue...

For my PCB layout:

a) It is less that 2" between MCU and memory chip.

b) Using 8 layers and should be good enough

c) The trace length of SDRAM related signal is exact same.

I want to know if I need to apply these on K66F design and what is optimized value of these because I am going to next PCB layout version?

Thanks,

Christie

0 Kudos
Reply

3,369 Views
a8Chcx
Contributor V

Hi Hui,

You can check the attached document as well. I do not know if it is possible reason for K66F as well?

Regards,

Christie

0 Kudos
Reply

3,369 Views
a8Chcx
Contributor V

Hi,

Is there any comment regarding to add the serial termination on SDRAM control signal?

Do I need to add it on DQMH and DQML as well?

Thanks,

Christie

0 Kudos
Reply

3,369 Views
Hui_Ma
NXP TechSupport
NXP TechSupport

Hi Christie,

First of all, sorry for the later reply.

Could you try to set the PORTx_PCRn [DSE] bit to using high drive strength of SDRAM related pins?

If the SDRAM trace length more than 10cm, customer can add serial 22ohm resistor to SDRAM control lines as line-impedance matching. I think DQMH and DQML pins also could add serial 22ohm resistors as well.

Thank you for the AN1722 document, which mentioned SDRAM clocking related cases also be suitable with K66 product. There need to avoid the clock offset.

The TWR-K65F180M board design resource [TWR-K65F180M Design Package(REV D)] could be downloaded from here.


Have a great day,
Ma Hui

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
Reply

3,369 Views
a8Chcx
Contributor V

Hi Hui,

Could you confirm that SDRAM used in K66F is similar to the one used in MCF5285?

Thanks,

Christie

0 Kudos
Reply

3,369 Views
Hui_Ma
NXP TechSupport
NXP TechSupport

Hi Christie,

The K65/K66 SDRAM module is updated SDRAM controller IP of MCF5282.

You could refer MCF5282 SDRAM hardware design for K65/K66 product. Thanks.

best regards,

Ma Hui

0 Kudos
Reply

3,369 Views
a8Chcx
Contributor V

Hi Hui,

I am trying to enable DSE on pin used for SDRAM. But, I found that not all SDRAM related pins can use this option(See page 183 on K66F menu).

Thanks,

Christie

0 Kudos
Reply

3,369 Views
Hui_Ma
NXP TechSupport
NXP TechSupport

Hi Christie,

The K65/K66 had made modification about pin drive strength enable control.

Please refer K66F reference manual to set available pin drive strength. Thanks.

best regards,

Ma Hui

0 Kudos
Reply

3,369 Views
a8Chcx
Contributor V

Hi Hui,

The trace length of SDRAM is less than 5cm. The most likely reason is related to clock shifting because it happened on LPC MCU from NXP? I just search on NXP web site, I found this and tried 12pF, it worked for me as well.

I just want to make sure it may happen on K65/K66 as well. It happened on MCF5282 for sure because I experienced it and fixed it by adding 22pF. Based on MCF5282 reference design, it is recommended. But, it didn't apply to TWR_K65F reference design. I want to know why? Still needed on K65/K66 as well because I am going to do the new PCB layout?

I am going to try to set pin to high strength as well to see if it work?

Thanks,

Christie

0 Kudos
Reply

3,369 Views
Hui_Ma
NXP TechSupport
NXP TechSupport

Hi Christie,

Thank you for the detailed info.

I will check your questions and reply later.

It will take sometime and thanks for the patience.

best regards,

Ma Hui

0 Kudos
Reply

3,369 Views
a8Chcx
Contributor V

Hi,

When I am using SDRAM on MCF5282 MCU, I need to add 47p on clock, and 22ohm on control signals(CAS/, _CS0, and etc ).

Can Anyone tell me if I need to this as well on K66F? What are the purpose on these capacitor and resistors?

What is the value I should use?

Thanks,

Christie

0 Kudos
Reply

3,369 Views
a8Chcx
Contributor V

Hi,

I did more testing on this and found:

I can make it work fine if I set the as follows:

1) MCU system clock==180MHz. Not working on 90MHz

2) Busclock=45MHz. not working on 60MHZ, 22.5MHz

3) Latency == 3 as normal. Working on 1 as well. Not working on zero.

Can anybody help me to fix this problem?

Thanks,

Christie

0 Kudos
Reply