1 | /**
|
2 | * @brief Configures the FMC and GPIOs to interface with the SRAM memory.
|
3 | * This function must be called before any write/read operation
|
4 | * on the SRAM.
|
5 | * @param None
|
6 | * @retval None
|
7 | */
|
8 | void External_Mem_GPIOConfig(void)
|
9 | {
|
10 | GPIO_InitTypeDef GPIO_InitStructure;
|
11 |
|
12 | /* Enable GPIOs clock */
|
13 | RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_GPIOE | RCC_AHB1Periph_GPIOF |
|
14 | RCC_AHB1Periph_GPIOG, ENABLE);
|
15 |
|
16 |
|
17 |
|
18 | /*-- GPIOs Configuration -----------------------------------------------------*/
|
19 | /*
|
20 | +--------------------+---------------------+-----------------+----------------------+
|
21 | + SRAM pins assignment +
|
22 | +--------------------+---------------------+-----------------+----------------------+
|
23 | | PD0 <-> FMC_D2 | PE0 <-> FMC_NBL | PF0 <-> FMC_A0 | PG0 <-> FMC_A10 |
|
24 | | PD1 <-> FMC_D3 | PE1 <-> FMC_NBL | PF1 <-> FMC_A1 | PG1 <-> FMC_A11 |
|
25 | | PD4 <-> FMC_NOE | PE3 <-> Opt. (A19) | PF2 <-> FMC_A2 | PG2 <-> FMC_A12 |
|
26 | | PD5 <-> FMC_NWE | PE4 <-> Opt. (A20) | PF3 <-> FMC_A3 | PG3 <-> FMC_A13 |
|
27 | | PD6 <-> FMC_NWAIT | PE5 <-> Opt. (A21) | PF4 <-> FMC_A4 | PG4 <-> FMC_A14 |
|
28 | | PD7 <-> FMC_NE1 | PE7 <-> FMC_D4 | PF5 <-> FMC_A5 | PG5 <-> FMC_A15 |
|
29 | | PD8 <-> FMC_D13 | PE8 <-> FMC_D5 | PF12 <-> FMC_A6 | PG9 <-> FMC_NE2 |
|
30 | | PD9 <-> FMC_D14 | PE9 <-> FMC_D6 | PF13 <-> FMC_A7 | PG10 <-> RESETFLASH |
|
31 | | PD10 <-> FMC_D15 | PE10 <-> FMC_D7 | PF14 <-> FMC_A8 |----------------------+
|
32 | | PD11 <-> FMC_A16 | PE11 <-> FMC_D8 | PF15 <-> FMC_A9 |
|
33 | | PD12 <-> FMC_A17 | PE12 <-> FMC_D9 |-----------------+
|
34 | | PD13 <-> FMC_A18 | PE13 <-> FMC_D10 |
|
35 | | PD14 <-> FMC_D0 | PE14 <-> FMC_D11 |
|
36 | | PD15 <-> FMC_D1 | PE15 <-> FMC_D12 |
|
37 | +---------------------|--------------------+
|
38 | */
|
39 |
|
40 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
|
41 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
|
42 | GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
43 | GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
44 |
|
45 | /* GPIOD configuration */
|
46 | GPIO_PinAFConfig(GPIOD, GPIO_PinSource0, GPIO_AF_FMC);
|
47 | GPIO_PinAFConfig(GPIOD, GPIO_PinSource1, GPIO_AF_FMC);
|
48 | GPIO_PinAFConfig(GPIOD, GPIO_PinSource4, GPIO_AF_FMC);
|
49 | GPIO_PinAFConfig(GPIOD, GPIO_PinSource5, GPIO_AF_FMC);
|
50 | GPIO_PinAFConfig(GPIOD, GPIO_PinSource6, GPIO_AF_FMC);
|
51 | GPIO_PinAFConfig(GPIOD, GPIO_PinSource7, GPIO_AF_FMC);
|
52 | GPIO_PinAFConfig(GPIOD, GPIO_PinSource8, GPIO_AF_FMC);
|
53 | GPIO_PinAFConfig(GPIOD, GPIO_PinSource9, GPIO_AF_FMC);
|
54 | GPIO_PinAFConfig(GPIOD, GPIO_PinSource10, GPIO_AF_FMC);
|
55 | GPIO_PinAFConfig(GPIOD, GPIO_PinSource11, GPIO_AF_FMC);
|
56 | GPIO_PinAFConfig(GPIOD, GPIO_PinSource12, GPIO_AF_FMC);
|
57 | GPIO_PinAFConfig(GPIOD, GPIO_PinSource13, GPIO_AF_FMC);
|
58 | GPIO_PinAFConfig(GPIOD, GPIO_PinSource14, GPIO_AF_FMC);
|
59 | GPIO_PinAFConfig(GPIOD, GPIO_PinSource15, GPIO_AF_FMC);
|
60 |
|
61 |
|
62 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_4 | GPIO_Pin_5 |
|
63 | GPIO_Pin_6 | GPIO_Pin_7 |
|
64 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 |
|
65 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
|
66 |
|
67 | GPIO_Init(GPIOD, &GPIO_InitStructure);
|
68 |
|
69 |
|
70 | /* GPIOE configuration */
|
71 | GPIO_PinAFConfig(GPIOE, GPIO_PinSource0 , GPIO_AF_FMC);
|
72 | GPIO_PinAFConfig(GPIOE, GPIO_PinSource1 , GPIO_AF_FMC);
|
73 | GPIO_PinAFConfig(GPIOE, GPIO_PinSource3 , GPIO_AF_FMC);
|
74 | GPIO_PinAFConfig(GPIOE, GPIO_PinSource4 , GPIO_AF_FMC);
|
75 | GPIO_PinAFConfig(GPIOE, GPIO_PinSource5 , GPIO_AF_FMC);
|
76 | GPIO_PinAFConfig(GPIOE, GPIO_PinSource7 , GPIO_AF_FMC);
|
77 | GPIO_PinAFConfig(GPIOE, GPIO_PinSource8 , GPIO_AF_FMC);
|
78 | GPIO_PinAFConfig(GPIOE, GPIO_PinSource9 , GPIO_AF_FMC);
|
79 | GPIO_PinAFConfig(GPIOE, GPIO_PinSource10 , GPIO_AF_FMC);
|
80 | GPIO_PinAFConfig(GPIOE, GPIO_PinSource11 , GPIO_AF_FMC);
|
81 | GPIO_PinAFConfig(GPIOE, GPIO_PinSource12 , GPIO_AF_FMC);
|
82 | GPIO_PinAFConfig(GPIOE, GPIO_PinSource13 , GPIO_AF_FMC);
|
83 | GPIO_PinAFConfig(GPIOE, GPIO_PinSource14 , GPIO_AF_FMC);
|
84 | GPIO_PinAFConfig(GPIOE, GPIO_PinSource15 , GPIO_AF_FMC);
|
85 |
|
86 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_3 |
|
87 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_7 |
|
88 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11|
|
89 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
|
90 |
|
91 | GPIO_Init(GPIOE, &GPIO_InitStructure);
|
92 |
|
93 |
|
94 | /* GPIOF configuration */
|
95 | GPIO_PinAFConfig(GPIOF, GPIO_PinSource0 , GPIO_AF_FMC);
|
96 | GPIO_PinAFConfig(GPIOF, GPIO_PinSource1 , GPIO_AF_FMC);
|
97 | GPIO_PinAFConfig(GPIOF, GPIO_PinSource2 , GPIO_AF_FMC);
|
98 | GPIO_PinAFConfig(GPIOF, GPIO_PinSource3 , GPIO_AF_FMC);
|
99 | GPIO_PinAFConfig(GPIOF, GPIO_PinSource4 , GPIO_AF_FMC);
|
100 | GPIO_PinAFConfig(GPIOF, GPIO_PinSource5 , GPIO_AF_FMC);
|
101 | GPIO_PinAFConfig(GPIOF, GPIO_PinSource12 , GPIO_AF_FMC);
|
102 | GPIO_PinAFConfig(GPIOF, GPIO_PinSource13 , GPIO_AF_FMC);
|
103 | GPIO_PinAFConfig(GPIOF, GPIO_PinSource14 , GPIO_AF_FMC);
|
104 | GPIO_PinAFConfig(GPIOF, GPIO_PinSource15 , GPIO_AF_FMC);
|
105 |
|
106 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 |
|
107 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_12 | GPIO_Pin_13 |
|
108 | GPIO_Pin_14 | GPIO_Pin_15;
|
109 |
|
110 | GPIO_Init(GPIOF, &GPIO_InitStructure);
|
111 |
|
112 |
|
113 | /* GPIOG configuration */
|
114 | GPIO_PinAFConfig(GPIOG, GPIO_PinSource0 , GPIO_AF_FMC);
|
115 | GPIO_PinAFConfig(GPIOG, GPIO_PinSource1 , GPIO_AF_FMC);
|
116 | GPIO_PinAFConfig(GPIOG, GPIO_PinSource2 , GPIO_AF_FMC);
|
117 | GPIO_PinAFConfig(GPIOG, GPIO_PinSource3 , GPIO_AF_FMC);
|
118 | GPIO_PinAFConfig(GPIOG, GPIO_PinSource4 , GPIO_AF_FMC);
|
119 | GPIO_PinAFConfig(GPIOG, GPIO_PinSource5 , GPIO_AF_FMC);
|
120 | GPIO_PinAFConfig(GPIOG, GPIO_PinSource9 , GPIO_AF_FMC);
|
121 |
|
122 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 |
|
123 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_9;
|
124 |
|
125 | GPIO_Init(GPIOG, &GPIO_InitStructure);
|
126 |
|
127 | /* Last but not least configure the RESET Pin for the NOR Flash */
|
128 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
|
129 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
|
130 | GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
131 | GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
132 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
133 | GPIO_Init(GPIOG, &GPIO_InitStructure);
|
134 | /* Set RESET Pin to high => Activate NOR Flash */
|
135 | GPIO_WriteBit(GPIOG, GPIO_Pin_10, Bit_SET);
|
136 |
|
137 | return;
|
138 | }
|
139 |
|
140 | void External_Mem_SRAM_Init(void)
|
141 | {
|
142 |
|
143 | FMC_NORSRAMInitTypeDef FMC_NORSRAMInitStructure;
|
144 | FMC_NORSRAMTimingInitTypeDef FMC_NORSRAMTimingStructure; /* Enable FMC clock */
|
145 |
|
146 | RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FMC, ENABLE); /* RCC_AHB3Periph_FMC and RCC_AHB3Periph_FMC, are the same but with makro switches */
|
147 |
|
148 | /*-- FMC Configuration ------------------------------------------------------*/
|
149 | #if 0
|
150 | /* Use this access times @ 168 MHz */
|
151 | FMC_NORSRAMTimingStructure.FMC_AddressSetupTime = 8;
|
152 | FMC_NORSRAMTimingStructure.FMC_AddressHoldTime = 8;
|
153 | FMC_NORSRAMTimingStructure.FMC_DataSetupTime = 8;
|
154 | FMC_NORSRAMTimingStructure.FMC_BusTurnAroundDuration = 8;
|
155 | FMC_NORSRAMTimingStructure.FMC_CLKDivision = 8;
|
156 | FMC_NORSRAMTimingStructure.FMC_DataLatency = 8;
|
157 | FMC_NORSRAMTimingStructure.FMC_AccessMode = FMC_AccessMode_A;
|
158 | #else
|
159 | /* Use this access times @ 168 MHz */
|
160 | FMC_NORSRAMTimingStructure.FMC_AddressSetupTime = 15;
|
161 | FMC_NORSRAMTimingStructure.FMC_AddressHoldTime = 15;
|
162 | FMC_NORSRAMTimingStructure.FMC_DataSetupTime = 20;
|
163 | FMC_NORSRAMTimingStructure.FMC_BusTurnAroundDuration = 15;
|
164 | FMC_NORSRAMTimingStructure.FMC_CLKDivision = 15;
|
165 | FMC_NORSRAMTimingStructure.FMC_DataLatency = 15;
|
166 | FMC_NORSRAMTimingStructure.FMC_AccessMode = FMC_AccessMode_A;
|
167 | #endif
|
168 |
|
169 | FMC_NORSRAMInitStructure.FMC_Bank = FMC_Bank1_NORSRAM1;
|
170 | FMC_NORSRAMInitStructure.FMC_DataAddressMux = FMC_DataAddressMux_Disable;
|
171 | FMC_NORSRAMInitStructure.FMC_MemoryType = FMC_MemoryType_SRAM;
|
172 | FMC_NORSRAMInitStructure.FMC_MemoryDataWidth = FMC_NORSRAM_MemoryDataWidth_16b;
|
173 | FMC_NORSRAMInitStructure.FMC_BurstAccessMode = FMC_BurstAccessMode_Disable;
|
174 | FMC_NORSRAMInitStructure.FMC_AsynchronousWait = FMC_AsynchronousWait_Disable;
|
175 | FMC_NORSRAMInitStructure.FMC_WaitSignalPolarity = FMC_WaitSignalPolarity_Low;
|
176 | FMC_NORSRAMInitStructure.FMC_WrapMode = FMC_WrapMode_Disable;
|
177 | FMC_NORSRAMInitStructure.FMC_WaitSignalActive = FMC_WaitSignalActive_BeforeWaitState;
|
178 | FMC_NORSRAMInitStructure.FMC_WriteOperation = FMC_WriteOperation_Enable;
|
179 | FMC_NORSRAMInitStructure.FMC_WaitSignal = FMC_WaitSignal_Disable;
|
180 | FMC_NORSRAMInitStructure.FMC_ExtendedMode = FMC_ExtendedMode_Disable;
|
181 | FMC_NORSRAMInitStructure.FMC_WriteBurst = FMC_WriteBurst_Disable;
|
182 | FMC_NORSRAMInitStructure.FMC_ReadWriteTimingStruct = &FMC_NORSRAMTimingStructure;
|
183 | FMC_NORSRAMInitStructure.FMC_WriteTimingStruct = &FMC_NORSRAMTimingStructure;
|
184 |
|
185 | /* FMC SRAM Banke = Bank1_SRAM1 Bank */
|
186 | /* FMC SRAM memory de-initializtion */
|
187 | FMC_NORSRAMDeInit(FMC_Bank1_NORSRAM1);
|
188 |
|
189 | /* FMC SRAM bank initialization */
|
190 | FMC_NORSRAMInit(&FMC_NORSRAMInitStructure);
|
191 |
|
192 | /* Enable the SRAM memory bank */
|
193 | FMC_NORSRAMCmd(FMC_Bank1_NORSRAM1, ENABLE);
|
194 |
|
195 | return;
|
196 | }
|