Hallo Leute, ich versuche auf dem STM32F427 den SDRAM in Betrieb zu nehmen. Jedoch funktioniert es nicht - könnt ihr vielleicht mal über meinen Initialisierung schauen? Danke euch ;)
1 | int main(void) |
2 | {
|
3 | /* STM32F4xx HAL library initialization:
|
4 | - Configure the Flash prefetch, instruction and Data caches
|
5 | - Configure the Systick to generate an interrupt each 1 msec
|
6 | - Set NVIC Group Priority to 4
|
7 | - Global MSP (MCU Support Package) initialization
|
8 | */
|
9 | HAL_Init(); //OK |
10 | |
11 | //Configure the System clock to have a frequency of 180 MHz
|
12 | SystemClock_Config(); |
13 | |
14 | /*##-1- Configure the SDRAM device*/
|
15 | /* SDRAM device configuration */
|
16 | hsdram.Instance = FMC_SDRAM_DEVICE; |
17 | SDRAM_Timing.LoadToActiveDelay = 2; |
18 | SDRAM_Timing.ExitSelfRefreshDelay = 7; |
19 | SDRAM_Timing.SelfRefreshTime = 4; |
20 | SDRAM_Timing.RowCycleDelay = 7; |
21 | SDRAM_Timing.WriteRecoveryTime = 2; |
22 | SDRAM_Timing.RPDelay = 2; |
23 | SDRAM_Timing.RCDDelay = 2; |
24 | |
25 | hsdram.Init.SDBank = FMC_SDRAM_BANK2; |
26 | hsdram.Init.ColumnBitsNumber = FMC_SDRAM_COLUMN_BITS_NUM_8; |
27 | hsdram.Init.RowBitsNumber = FMC_SDRAM_ROW_BITS_NUM_12; |
28 | hsdram.Init.MemoryDataWidth = FMC_SDRAM_MEM_BUS_WIDTH_32; |
29 | hsdram.Init.InternalBankNumber = FMC_SDRAM_INTERN_BANKS_NUM_4; |
30 | hsdram.Init.CASLatency = FMC_SDRAM_CAS_LATENCY_3; |
31 | hsdram.Init.WriteProtection = FMC_SDRAM_WRITE_PROTECTION_DISABLE; |
32 | hsdram.Init.SDClockPeriod = FMC_SDRAM_CLOCK_PERIOD_3; |
33 | hsdram.Init.ReadBurst = FMC_SDRAM_RBURST_DISABLE; |
34 | hsdram.Init.ReadPipeDelay = FMC_SDRAM_RPIPE_DELAY_1; |
35 | |
36 | |
37 | if(HAL_SDRAM_Init(&hsdram,&SDRAM_Timing)!=HAL_OK){ |
38 | Error_Handler(); |
39 | }
|
40 | |
41 | SDRAM_Initialization_Sequence(&hsdram,&cmd); |
42 | |
43 | |
44 | for(i=0;i<100;i++){ |
45 | buffi[i]=i; |
46 | }
|
47 | |
48 | /* Write data to the SDRAM memory */
|
49 | for (i = 0; i < 100; i++) |
50 | {
|
51 | *(__IO uint32_t*) (SDRAM_BANK_ADDR + 4*i) = buffi[i]; |
52 | }
|
53 | |
54 | }
|
Letzte Möglichkeit für einen Fehler wäre hier:
1 | static void SDRAM_Initialization_Sequence(SDRAM_HandleTypeDef *hsdram, FMC_SDRAM_CommandTypeDef *Command) |
2 | {
|
3 | __IO uint32_t tmpmrd =0; |
4 | /* Step 3: Configure a clock configuration enable command */
|
5 | Command->CommandMode = FMC_SDRAM_CMD_CLK_ENABLE; |
6 | Command->CommandTarget = FMC_SDRAM_CMD_TARGET_BANK2; |
7 | Command->AutoRefreshNumber = 1; |
8 | Command->ModeRegisterDefinition = 0; |
9 | |
10 | /* Send the command */
|
11 | HAL_SDRAM_SendCommand(hsdram, Command, 0x1000); |
12 | |
13 | /* Step 4: Insert 100 ms delay */
|
14 | HAL_Delay(100); |
15 | |
16 | /* Step 5: Configure a PALL (precharge all) command */
|
17 | Command->CommandMode = FMC_SDRAM_CMD_PALL; |
18 | Command->CommandTarget = FMC_SDRAM_CMD_TARGET_BANK2; |
19 | Command->AutoRefreshNumber = 1; |
20 | Command->ModeRegisterDefinition = 0; |
21 | |
22 | /* Send the command */
|
23 | HAL_SDRAM_SendCommand(hsdram, Command, 0x1000); |
24 | |
25 | /* Step 6 : Configure a Auto-Refresh command */
|
26 | Command->CommandMode = FMC_SDRAM_CMD_AUTOREFRESH_MODE; |
27 | Command->CommandTarget = FMC_SDRAM_CMD_TARGET_BANK2; |
28 | Command->AutoRefreshNumber = 4; |
29 | Command->ModeRegisterDefinition = 0; |
30 | |
31 | /* Send the command */
|
32 | HAL_SDRAM_SendCommand(hsdram, Command, 0x1000); |
33 | |
34 | /* Step 7: Program the external memory mode register */
|
35 | tmpmrd = (uint32_t)SDRAM_MODEREG_BURST_LENGTH_2 | |
36 | SDRAM_MODEREG_BURST_TYPE_SEQUENTIAL | |
37 | SDRAM_MODEREG_CAS_LATENCY_3 | |
38 | SDRAM_MODEREG_OPERATING_MODE_STANDARD | |
39 | SDRAM_MODEREG_WRITEBURST_MODE_SINGLE; |
40 | |
41 | Command->CommandMode = FMC_SDRAM_CMD_LOAD_MODE; |
42 | Command->CommandTarget = FMC_SDRAM_CMD_TARGET_BANK2; |
43 | Command->AutoRefreshNumber = 1; |
44 | Command->ModeRegisterDefinition = tmpmrd; |
45 | |
46 | /* Send the command */
|
47 | HAL_SDRAM_SendCommand(hsdram, Command, 0x1000); |
48 | |
49 | /* Step 8: Set the refresh rate counter */
|
50 | /* (15.62 us x Freq) - 20 */
|
51 | /* Set the device refresh counter */
|
52 | HAL_SDRAM_ProgramRefreshRate(hsdram, REFRESH_COUNT); |
53 | }
|
Hier seht ihr meine Msp-Init Methode - ist hier vielleicht was falsch?
1 | __weak void HAL_SDRAM_MspInit(SDRAM_HandleTypeDef *hsdram) |
2 | {
|
3 | /* NOTE: This function Should not be modified, when the callback is needed,
|
4 | the HAL_SDRAM_MspInit could be implemented in the user file
|
5 | */
|
6 | GPIO_InitTypeDef GPIO_Init_Structure; |
7 | |
8 | /*##-1- Enable peripherals and GPIO Clocks #################################*/
|
9 | /* Enable GPIO clocks */
|
10 | __HAL_RCC_GPIOD_CLK_ENABLE(); |
11 | __HAL_RCC_GPIOE_CLK_ENABLE(); |
12 | __HAL_RCC_GPIOF_CLK_ENABLE(); |
13 | __HAL_RCC_GPIOG_CLK_ENABLE(); |
14 | __HAL_RCC_GPIOH_CLK_ENABLE(); |
15 | __HAL_RCC_GPIOI_CLK_ENABLE(); |
16 | __HAL_RCC_FMC_CLK_ENABLE(); |
17 | |
18 | /*##-2- Configure peripheral GPIO ##########################################*/
|
19 | /*-- GPIOs Configuration -----------------------------------------------------*/
|
20 | /*
|
21 | +-------------------+--------------------+--------------------+--------------------+
|
22 | + SDRAM pins assignment +
|
23 | +-------------------+--------------------+--------------------+--------------------+
|
24 | | PD0 <-> FMC_D2 +OK | PE0 <-> FMC_NBL0 +OK | PF0 <-> FMC_A0 +ok | PG0 <-> FMC_A10 +ok|
|
25 | | PD1 <-> FMC_D3 +OK | PE1 <-> FMC_NBL1 +OK | PF1 <-> FMC_A1 +ok | PG1 <-> FMC_A11 +ok|
|
26 | | PD8 <-> FMC_D13 +OK | PE7 <-> FMC_D4 +ok | PF2 <-> FMC_A2 +ok | PG8 <-> FMC_SDCLK +ok|
|
27 | | PD9 <-> FMC_D14 +OK | PE8 <-> FMC_D5 +ok | PF3 <-> FMC_A3 +ok | PG15 <-> FMC_NCAS +ok|
|
28 | | PD10 <-> FMC_D15 +OK | PE9 <-> FMC_D6 +ok | PF4 <-> FMC_A4 +ok | PG4 <-> FMC_BA0 +ok|
|
29 | | PD14 <-> FMC_D0 +OK | PE10 <-> FMC_D7 +ok | PF5 <-> FMC_A5 +ok | PG5 <-> FMC_BA1 +ok|
|
30 | | PD15 <-> FMC_D1 +OK | PE11 <-> FMC_D8 +ok | PF11 <-> FMC_NRAS +ok |
|
31 | +----------------------| PE12 <-> FMC_D9 +ok | PF12 <-> FMC_A6 +ok |
|
32 | | PE13 <-> FMC_D10 +ok | PF13 <-> FMC_A7 +ok |
|
33 | | PE14 <-> FMC_D11 +ok | PF14 <-> FMC_A8 +ok |
|
34 | | PE15 <-> FMC_D12 +ok | PF15 <-> FMC_A9 +ok |
|
35 | +----------------------+-------------------------+-----------------------+
|
36 | |
37 |
|
38 | //NEW INIT STUFF
|
39 | +--------------------+-------------------------+
|
40 | | PH2 <-> FMC_SDCKE0 | PI0 <-> FMC_D24
|
41 | | PH3 <-> FMC_SDNE0 | PI1 <-> FMC_D25
|
42 | | PH5 <-> FMC_SDNWE | PI2 <-> FMC_D26
|
43 | | PH8 <-> FMC_D16 | PI3 <-> FMC_D27
|
44 | | PH9 <-> FMC_D17 | PI4 <-> FMC_SDNDQM2
|
45 | | PH10 <-> FMC_D18 | PI5 <-> FMC_SDNDQM3
|
46 | | PH11 <-> FMC_D19 | PI6 <-> FMC_D28
|
47 | | PH12 <-> FMC_D20 | PI7 <-> FMC_D29
|
48 | | PH13 <-> FMC_D21 | PI9 <-> FMC_D30
|
49 | | PH14 <-> FMC_D22 | PI10 <-> FMC_D31
|
50 | | PH15 <-> FMC_D23 |
|
51 | +--------------------+-------------------------+
|
52 | */
|
53 | |
54 | /* Common GPIO configuration */
|
55 | GPIO_Init_Structure.Mode = GPIO_MODE_AF_PP; |
56 | GPIO_Init_Structure.Speed = GPIO_SPEED_FAST; |
57 | GPIO_Init_Structure.Pull = GPIO_NOPULL; |
58 | GPIO_Init_Structure.Alternate = GPIO_AF12_FMC; |
59 | |
60 | /* GPIOB configuration */
|
61 | // GPIO_Init_Structure.Pin = GPIO_PIN_5 | GPIO_PIN_6;
|
62 | // HAL_GPIO_Init(GPIOB, &GPIO_Init_Structure);
|
63 | |
64 | /* GPIOC configuration */
|
65 | // GPIO_Init_Structure.Pin = GPIO_PIN_0;
|
66 | // HAL_GPIO_Init(GPIOC, &GPIO_Init_Structure);
|
67 | |
68 | /* GPIOD configuration */
|
69 | GPIO_Init_Structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_8 | |
70 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_14 | |
71 | GPIO_PIN_15; |
72 | HAL_GPIO_Init(GPIOD, &GPIO_Init_Structure); |
73 | |
74 | /* GPIOE configuration */
|
75 | GPIO_Init_Structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_7 | |
76 | GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | |
77 | GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_13 | |
78 | GPIO_PIN_14 | GPIO_PIN_15; |
79 | HAL_GPIO_Init(GPIOE, &GPIO_Init_Structure); |
80 | |
81 | /* GPIOF configuration */
|
82 | GPIO_Init_Structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | |
83 | GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_5 | |
84 | GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_13 | |
85 | GPIO_PIN_14 | GPIO_PIN_15; |
86 | HAL_GPIO_Init(GPIOF, &GPIO_Init_Structure); |
87 | |
88 | /* GPIOG configuration */
|
89 | GPIO_Init_Structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_4 | |
90 | GPIO_PIN_5 | GPIO_PIN_8 | GPIO_PIN_15; |
91 | HAL_GPIO_Init(GPIOG, &GPIO_Init_Structure); |
92 | |
93 | /*GPIOH configuration */
|
94 | GPIO_Init_Structure.Pin = GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_5 | GPIO_PIN_8 | GPIO_PIN_9 | |
95 | GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15; |
96 | HAL_GPIO_Init(GPIOH,&GPIO_Init_Structure); |
97 | |
98 | /*GPIOI configuration */
|
99 | GPIO_Init_Structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_5 | |
100 | GPIO_PIN_6 | GPIO_PIN_7 | GPIO_PIN_9 | GPIO_PIN_10; |
101 | HAL_GPIO_Init(GPIOI, &GPIO_Init_Structure); |
102 | |
103 | |
104 | }
|
Oder ist aber meine Clock falsch gesetzt?
1 | static void SystemClock_Config(void) |
2 | {
|
3 | RCC_ClkInitTypeDef RCC_ClkInitStruct; //OK |
4 | RCC_OscInitTypeDef RCC_OscInitStruct; //OK |
5 | |
6 | /* Enable Power Control clock */
|
7 | __PWR_CLK_ENABLE(); //OK |
8 | |
9 | /* The voltage scaling allows optimizing the power consumption when the device is
|
10 | clocked below the maximum system frequency, to update the voltage scaling value
|
11 | regarding system frequency refer to product datasheet. */
|
12 | __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); //OK |
13 | |
14 | /* Enable HSE Oscillator and activate PLL with HSE as source */
|
15 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; //OK |
16 | RCC_OscInitStruct.HSEState = RCC_HSE_ON; //OK |
17 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; //OK |
18 | RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; //OK |
19 | RCC_OscInitStruct.PLL.PLLM = 16; // NOT -> WHY 16? -> Demoboard is 8 |
20 | RCC_OscInitStruct.PLL.PLLN = 360; //OK |
21 | RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; //OK |
22 | RCC_OscInitStruct.PLL.PLLQ = 7; //OK |
23 | if(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) //OK |
24 | {
|
25 | /* Initialization Error */
|
26 | Error_Handler(); |
27 | }
|
28 | |
29 | |
30 | if(HAL_PWREx_ActivateOverDrive() != HAL_OK) //OK |
31 | {
|
32 | /* Initialization Error */
|
33 | Error_Handler(); |
34 | }
|
35 | |
36 | /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
|
37 | clocks dividers */
|
38 | RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2); //OK |
39 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; //OK |
40 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; //OK |
41 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4; //OK |
42 | RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2; //OK |
43 | if(HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK) //OK |
44 | {
|
45 | /* Initialization Error */
|
46 | Error_Handler(); |
47 | }
|
48 | }
|
Ich hoffe ihr könnt mir weiter helfen. Ich habe als SDRAM folgenden auf dem Board: IS42S32400F -> Danke schonmal.