cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F429 Discovery Board SDRAM

stefanmerfu
Associate
Posted on January 27, 2015 at 20:07

Good evening, i am a beginner in the stm32f microcontroller and i am trying to learn how to use the SDRAM embedded on the discovery board.I made a function which initialize the sdram gpio and timing characteristics but when i used the debugger the data is lost after a while.Perhaps somebody could explain me why. Thank you in advance !


void SDRAMInit(void)

{

/*-- GPIOs Configuration -----------------------------------------------------*/

/*

+-------------------+--------------------+--------------------+--------------------+

+ 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 | PG4 <-> FMC_BA0 |

| PD9 <-> FMC_D14 | PE8 <-> FMC_D5 | PF3 <-> FMC_A3 | PG5 <-> FMC_BA1 |

| PD10 <-> FMC_D15 | PE9 <-> FMC_D6 | PF4 <-> FMC_A4 | PG8 <-> FMC_SDCLK |

| PD14 <-> FMC_D0 | PE10 <-> FMC_D7 | PF5 <-> FMC_A5 | PG15 <-> FMC_NCAS |

| 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 |

+-------------------+


*/

GPIO_InitTypeDef GPIO_InitStruct;

FMC_SDRAMTimingInitTypeDef FMC_SDRAMTimingStruct;

FMC_SDRAMCommandTypeDef FMC_SDRAMCommandStruct;

FMC_SDRAMInitTypeDef FMC_SDRAMInitStruct;


volatile uint32_t ptr;


RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_GPIOE | RCC_AHB1Periph_GPIOF | RCC_AHB1Periph_GPIOG,ENABLE);

RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FMC,ENABLE);


// GPIOB //


GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;

GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;

GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;

GPIO_InitStruct.GPIO_Speed = GPIO_Speed_100MHz;

GPIO_InitStruct.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6;

GPIO_Init(GPIOB,&GPIO_InitStruct);


GPIO_PinAFConfig(GPIOB,GPIO_PinSource5,GPIO_AF_FMC);

GPIO_PinAFConfig(GPIOB,GPIO_PinSource6,GPIO_AF_FMC);


// GPIOD // 


GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;

GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;

GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;

GPIO_InitStruct.GPIO_Speed = GPIO_Speed_100MHz;

GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_14 | GPIO_Pin_15;

GPIO_Init(GPIOD,&GPIO_InitStruct);


GPIO_PinAFConfig(GPIOD,GPIO_PinSource0,GPIO_AF_FMC);

GPIO_PinAFConfig(GPIOD,GPIO_PinSource1,GPIO_AF_FMC);

GPIO_PinAFConfig(GPIOD,GPIO_PinSource8,GPIO_AF_FMC);

GPIO_PinAFConfig(GPIOD,GPIO_PinSource9,GPIO_AF_FMC);

GPIO_PinAFConfig(GPIOD,GPIO_PinSource10,GPIO_AF_FMC);

GPIO_PinAFConfig(GPIOD,GPIO_PinSource14,GPIO_AF_FMC);

GPIO_PinAFConfig(GPIOD,GPIO_PinSource15,GPIO_AF_FMC);


// GPIOE // 


GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;

GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;

GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;

GPIO_InitStruct.GPIO_Speed = GPIO_Speed_100MHz;

GPIO_InitStruct.GPIO_Pin = GPIO_Pin_All;

GPIO_Init(GPIOE,&GPIO_InitStruct);


GPIO_PinAFConfig(GPIOE,GPIO_PinSource0,GPIO_AF_FMC);

GPIO_PinAFConfig(GPIOE,GPIO_PinSource1,GPIO_AF_FMC);

GPIO_PinAFConfig(GPIOE,GPIO_PinSource2,GPIO_AF_FMC);

GPIO_PinAFConfig(GPIOE,GPIO_PinSource3,GPIO_AF_FMC);

GPIO_PinAFConfig(GPIOE,GPIO_PinSource4,GPIO_AF_FMC);

GPIO_PinAFConfig(GPIOE,GPIO_PinSource5,GPIO_AF_FMC);

GPIO_PinAFConfig(GPIOE,GPIO_PinSource6,GPIO_AF_FMC);

GPIO_PinAFConfig(GPIOE,GPIO_PinSource7,GPIO_AF_FMC);

GPIO_PinAFConfig(GPIOE,GPIO_PinSource8,GPIO_AF_FMC);

GPIO_PinAFConfig(GPIOE,GPIO_PinSource9,GPIO_AF_FMC);

GPIO_PinAFConfig(GPIOE,GPIO_PinSource10,GPIO_AF_FMC);

GPIO_PinAFConfig(GPIOE,GPIO_PinSource11,GPIO_AF_FMC);

GPIO_PinAFConfig(GPIOE,GPIO_PinSource12,GPIO_AF_FMC);

GPIO_PinAFConfig(GPIOE,GPIO_PinSource13,GPIO_AF_FMC);

GPIO_PinAFConfig(GPIOE,GPIO_PinSource14,GPIO_AF_FMC);

GPIO_PinAFConfig(GPIOE,GPIO_PinSource15,GPIO_AF_FMC);


// GPIOF // 


GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;

GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;

GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;

GPIO_InitStruct.GPIO_Speed = GPIO_Speed_100MHz;

GPIO_InitStruct.GPIO_Pin = GPIO_Pin_All;

GPIO_Init(GPIOF,&GPIO_InitStruct);


GPIO_PinAFConfig(GPIOE,GPIO_PinSource0,GPIO_AF_FMC);

GPIO_PinAFConfig(GPIOE,GPIO_PinSource1,GPIO_AF_FMC);

GPIO_PinAFConfig(GPIOE,GPIO_PinSource2,GPIO_AF_FMC);

GPIO_PinAFConfig(GPIOE,GPIO_PinSource3,GPIO_AF_FMC);

GPIO_PinAFConfig(GPIOE,GPIO_PinSource4,GPIO_AF_FMC);

GPIO_PinAFConfig(GPIOE,GPIO_PinSource5,GPIO_AF_FMC);

GPIO_PinAFConfig(GPIOE,GPIO_PinSource6,GPIO_AF_FMC);

GPIO_PinAFConfig(GPIOE,GPIO_PinSource7,GPIO_AF_FMC);

GPIO_PinAFConfig(GPIOE,GPIO_PinSource8,GPIO_AF_FMC);

GPIO_PinAFConfig(GPIOE,GPIO_PinSource9,GPIO_AF_FMC);

GPIO_PinAFConfig(GPIOE,GPIO_PinSource10,GPIO_AF_FMC);

GPIO_PinAFConfig(GPIOE,GPIO_PinSource11,GPIO_AF_FMC);

GPIO_PinAFConfig(GPIOE,GPIO_PinSource12,GPIO_AF_FMC);

GPIO_PinAFConfig(GPIOE,GPIO_PinSource13,GPIO_AF_FMC);

GPIO_PinAFConfig(GPIOE,GPIO_PinSource14,GPIO_AF_FMC);

GPIO_PinAFConfig(GPIOE,GPIO_PinSource15,GPIO_AF_FMC);


// GPIOG // 


GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;

GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;

GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;

GPIO_InitStruct.GPIO_Speed = GPIO_Speed_100MHz;

GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_8 | GPIO_Pin_15;

GPIO_Init(GPIOG,&GPIO_InitStruct);


GPIO_PinAFConfig(GPIOG,GPIO_PinSource0,GPIO_AF_FMC);

GPIO_PinAFConfig(GPIOG,GPIO_PinSource1,GPIO_AF_FMC);

GPIO_PinAFConfig(GPIOG,GPIO_PinSource4,GPIO_AF_FMC);

GPIO_PinAFConfig(GPIOG,GPIO_PinSource5,GPIO_AF_FMC);

GPIO_PinAFConfig(GPIOG,GPIO_PinSource8,GPIO_AF_FMC);

GPIO_PinAFConfig(GPIOG,GPIO_PinSource15,GPIO_AF_FMC);


// init SDRAM


FMC_SDRAMTimingStruct.FMC_ExitSelfRefreshDelay = 7;

FMC_SDRAMTimingStruct.FMC_LoadToActiveDelay = 2;

FMC_SDRAMTimingStruct.FMC_RCDDelay = 2;

FMC_SDRAMTimingStruct.FMC_RowCycleDelay = 7;

FMC_SDRAMTimingStruct.FMC_RPDelay = 7;

FMC_SDRAMTimingStruct.FMC_SelfRefreshTime = 4;

FMC_SDRAMTimingStruct.FMC_WriteRecoveryTime = 2;


FMC_SDRAMInitStruct.FMC_SDRAMTimingStruct = &FMC_SDRAMTimingStruct;

FMC_SDRAMInitStruct.FMC_Bank = FMC_Bank2_SDRAM;

FMC_SDRAMInitStruct.FMC_CASLatency = FMC_CAS_Latency_2;

FMC_SDRAMInitStruct.FMC_ColumnBitsNumber = FMC_ColumnBits_Number_8b;

FMC_SDRAMInitStruct.FMC_InternalBankNumber = FMC_InternalBank_Number_4;

FMC_SDRAMInitStruct.FMC_ReadBurst = FMC_Read_Burst_Enable;

FMC_SDRAMInitStruct.FMC_ReadPipeDelay = FMC_ReadPipe_Delay_1;

FMC_SDRAMInitStruct.FMC_RowBitsNumber = FMC_RowBits_Number_12b;

FMC_SDRAMInitStruct.FMC_SDClockPeriod = FMC_SDClock_Period_2;

FMC_SDRAMInitStruct.FMC_SDMemoryDataWidth = FMC_SDMemory_Width_16b;

FMC_SDRAMInitStruct.FMC_WriteProtection = FMC_WriteBurst_Disable;


FMC_SDRAMInit(&FMC_SDRAMInitStruct);


// Start deliver clock to the SDRAM


FMC_SDRAMCommandStruct.FMC_CommandMode = FMC_Command_Mode_CLK_Enabled;

FMC_SDRAMCommandStruct.FMC_CommandTarget = FMC_Command_Target_bank2;


FMC_SDRAMCmdConfig(&FMC_SDRAMCommandStruct);


// Wait about 100uS


DelayUs(110);


// Precharge all the banks


FMC_SDRAMCommandStruct.FMC_CommandMode = FMC_Command_Mode_PALL;

FMC_SDRAMCommandStruct.FMC_CommandTarget = FMC_Command_Target_bank2;


FMC_SDRAMCmdConfig(&FMC_SDRAMCommandStruct);


while(FMC_Bank5_6->SDSR & FMC_SDSR_BUSY);


// Auto-Refresh command


FMC_SDRAMCommandStruct.FMC_CommandMode = FMC_Command_Mode_AutoRefresh;

FMC_SDRAMCommandStruct.FMC_CommandTarget = FMC_Command_Target_bank2;

FMC_SDRAMCommandStruct.FMC_AutoRefreshNumber = 8;


FMC_SDRAMCmdConfig(&FMC_SDRAMCommandStruct);


while(FMC_Bank5_6->SDSR & FMC_SDSR_BUSY);


// Load Mode Register 


FMC_SDRAMCommandStruct.FMC_CommandMode = FMC_Command_Mode_LoadMode;

FMC_SDRAMCommandStruct.FMC_CommandTarget = FMC_Command_Target_bank2;

FMC_SDRAMCommandStruct.FMC_ModeRegisterDefinition = 0x221;


FMC_SDRAMCmdConfig(&FMC_SDRAMCommandStruct);


while(FMC_Bank5_6->SDSR & FMC_SDSR_BUSY);


// Program the Refresh Rate


FMC_SetRefreshCount(1297);


while(FMC_Bank5_6->SDSR & FMC_SDSR_BUSY);


// Finish


for(ptr = SDRAM_BASE;ptr < (SDRAM_BASE + SDRAM_SIZE);ptr += 4)

*((uint32_t *)ptr) = 0x11111111;

}

The SDRAM_BASE is 0xD0000000 and the SDRAM_SIZE is 0x00800000.I am using the Keil Uvision V5.
0 REPLIES 0