2015-07-21 08:15 AM
I design a board based on Stm32f429-discovery and add a 8192 Row x 512column x 16 bit Sdram to Sdram Bank 2.
my Sdram is MT48LC16Mhttp://pdf.datasheetarchive.com/datasheetsmain/Datasheets-19/DSA-364195.pdf
I study Datasheet To Setup Timing And Helped by http://asf.atmel.com/docs/3.0.1/avr32.drivers.mdma.example.uc3c_ek/html/mt48lc16m16a2tg7e_8h_source.html http://asf.atmel.com/docs/3.0.1/avr32.drivers.mdma.example.uc3c_ek/html/group__group__avr32__drivers__ebi__sdramc.html#gaa0f99d3a3036fbdaa70fc6365efe0b04 this header file from Atmel. and create my Project At first i tested my program by writing 0XF0 to about 1 KB of Sdram from Address 0XD0000000 (first address of fmc Sdram bank 2) and I Read Back them and They Are Correct! But I Decided to Check whole of Sdram Memory So I Fill 32MB(0X2000000) With 0XF0but there was Errors when i Compare read data with 0Xf0
I then Checked that If i Write More Than 0X10dd8 Length Of Data Sdram Will Lose Data And I Cant Go to Debug Also Because It's Always With Error. I Even Checked Timing With STM32F429-Disco and See i have the Same Pattern HCLK=168 Mhz I Attached FMC.c File I Appreciate Any Help
2015-07-21 04:32 PM
I am using the same part.
Try this:/*----------------------------------------------------------------------------
SDRAM Initialisation - 4194304 Bytes
*----------------------------------------------------------------------------*/
void SDRAM_Init (void) {
uint32_t temp32;
/* GPIO configuration for FMC SDRAM bank */
/*
+-------------------+--------------------+--------------------+--------------------+
+ SDRAM pins assignment +
+-------------------+--------------------+--------------------+--------------------+
| PD0 <-> FMC_D2 | PE0 <-> FMC_NBL0 | PF0 <-> FMC_A0 | PG0 <-> FMC_A10 |
| PD1 <-> FMC_D3 | PE1 <-> FMC_NBL1 | PF1 <-> FMC_A1 | PG1 <-> FMC_A11 |
| PD8 <-> FMC_D13 | PE7 <-> FMC_D4 | PF2 <-> FMC_A2 | PG2 <-> FMC_A12 | <<<
NEW
for 32MB
| PD9 <-> FMC_D14 | PE8 <-> FMC_D5 | PF3 <-> FMC_A3 | PG8 <-> FMC_SDCLK |
| PD10 <-> FMC_D15 | PE9 <-> FMC_D6 | PF4 <-> FMC_A4 | PG15 <-> FMC_NCAS |
| PD14 <-> FMC_D0 | PE10 <-> FMC_D7 | PF5 <-> FMC_A5 |--------------------+
| PD15 <-> FMC_D1 | PE11 <-> FMC_D8 | PF11 <-> FMC_NRAS |
+-------------------| PE12 <-> FMC_D9 | PF12 <-> FMC_A6 |
| PE13 <-> FMC_D10 | PF13 <-> FMC_A7 |
| PE14 <-> FMC_D11 | PF14 <-> FMC_A8 |
| PE15 <-> FMC_D12 | PF15 <-> FMC_A9 |
+-------------------+--------------------+--------------------+
| PB5 <-> FMC_SDCKE1|
| PB6 <-> FMC_SDNE1 |
| PC0 <-> FMC_SDNWE |
+-------------------+
*/
// GPIOB Configuration - PB.6&5
GPIOB->MODER = GPIOB->MODER | 0x2800; // Alt Fn
GPIOB->OSPEEDR = GPIOB->OSPEEDR | 0x2800; // 50MHz
GPIOB->AFR[0] = GPIOB->AFR[0] | 0x0CC00000; // SDRAM
// GPIOC Configuration - PC.0
GPIOC->MODER = GPIOC->MODER | 0x2; // Alt Fn
GPIOC->OSPEEDR = GPIOC->OSPEEDR | 0x2; // 50MHz
GPIOC->AFR[0] = GPIOC->AFR[0] | 0xC; // SDRAM
// GPIOD Configuration - PD.15,14,10,9,8,1,0
GPIOD->MODER = GPIOD->MODER | 0xA02A000A; // Alt Fn
GPIOD->OSPEEDR = GPIOD->OSPEEDR | 0xA02A000A; // 50MHz
GPIOD->AFR[0] = GPIOD->AFR[0] | 0xCC; // SDRAM AFRL
GPIOD->AFR[1] = GPIOD->AFR[1] | 0xCC000CCC; // SDRAM AFRH
// GPIOE Configuration - PE.15,14,13,12,11,10,9,8,7,1,0
GPIOE->MODER = GPIOE->MODER | 0xAAAA800A; // Alt Fn
GPIOE->OSPEEDR = GPIOE->OSPEEDR | 0xAAAA800A; // 50MHz
GPIOE->AFR[0] = GPIOE->AFR[0] | 0xC00000CC; // SDRAM AFRL
GPIOE->AFR[1] = GPIOE->AFR[1] | 0xCCCCCCCC; // SDRAM AFRH
// GPIOF Configuration - PE.15,14,13,12,11,5,4,3,2,1,0
GPIOF->MODER = GPIOF->MODER | 0xAA800AAA; // Alt Fn
GPIOF->OSPEEDR = GPIOF->OSPEEDR | 0xAA800AAA; // 50MHz
GPIOF->AFR[0] = GPIOF->AFR[0] | 0xCCCCCC; // SDRAM AFRL
GPIOF->AFR[1] = GPIOF->AFR[1] | 0xCCCCC000; // SDRAM AFRH
// >>>OLD PRE A12 - 32MB SDRAM
// // GPIOG Configuration - PG.15,8,5,4,1,0
// GPIOG->MODER = GPIOG->MODER | 0x80020A0A; // Alt Fn
// GPIOG->OSPEEDR = GPIOG->OSPEEDR | 0x80020A2A; // 50MHz
// GPIOG->AFR[0] = GPIOG->AFR[0] | 0xCC00CC; // SDRAM AFRL
// GPIOG->AFR[1] = GPIOG->AFR[1] | 0xC000000C; // SDRAM AFRH
// GPIOG Configuration - PG.15,8,5,4,2,1,0 >>>NEW A12<<<
GPIOG-
>MODER = GPIOG->MODER | 0x80020A2A; // Alt Fn
GPIOG->OSPEEDR = GPIOG->OSPEEDR | 0x80020A2A; // 50MHz
GPIOG->AFR[0] = GPIOG->AFR[0] | 0xCC0CCC; // SDRAM AFRL
GPIOG->AFR[1] = GPIOG->AFR[1] | 0xC000000C; // SDRAM AFRH
// Enable Peripheral Clock
RCC->AHB3ENR = RCC->AHB3ENR | 0x1; // Enable FMC
// FMC SDRAM bank initialization
FMC_Bank5_6->SDCR[0] = 0x2800;
// FMC_Bank5_6->SDCR[1] = 0x1D4; //>>>Old 4MB SDRAM<<<
FMC_Bank5_6-
>SDCR[1] = 0x1D9; // 32MB Device
FMC_Bank5_6->SDTR[0] = 0x106000;
FMC_Bank5_6->SDTR[1] = 0x10361;
// FMC SDRAM device initialisation sequence
// Configure a clock configuration enable command
while (FMC_Bank5_6->SDSR & 0x20) { // Controller not ready for new request
};
FMC_Bank5_6->SDCMR = 0x9; // Send Command
//need 100ms delay
for (temp32 = 0x00; temp32 <
0xD0000
; temp32++)
{
temp32
= temp32;
}
// Configure a PALL (precharge all) command
while (FMC_Bank5_6->SDSR & 0x20) { // Controller not ready for new request
};
FMC_Bank5_6->SDCMR = 0xA; // Send Command
// Configure a Auto-Refresh command
while (FMC_Bank5_6->SDSR & 0x20) { // Controller not ready for new request
};
FMC_Bank5_6->SDCMR = 0x6B; // Send First Command
while (FMC_Bank5_6->SDSR & 0x20) { // Controller not ready for new request
};
FMC_Bank5_6->SDCMR = 0x6B; // Send Second Command
// Configure a load Mode register command
while (FMC_Bank5_6->SDSR & 0x20) { // Controller not ready for new request
};
FMC_Bank5_6->SDCMR = 0x4620C; // Send Command
// Set the refresh rate counter
// FMC_Bank5_6->SDRTR = 0x556; // Pre A12
FMC_Bank5_6->SDRTR = 0x2AB;
while (FMC_Bank5_6->SDSR & 0x20) { // Controller not ready for new request
};
/* Disable write protection */
temp32 = FMC_Bank5_6->SDCR[0];
FMC_Bank5_6->SDCR[0] = (temp32 & 0xFFFFFDFF);
}