]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_M4F_STM32F407ZG-SK/startup/system_stm32f4xx.c
Add FreeRTOS-Plus directory.
[freertos] / FreeRTOS / Demo / CORTEX_M4F_STM32F407ZG-SK / startup / system_stm32f4xx.c
1 /**\r
2   ******************************************************************************\r
3   * @file    system_stm32f4xx.c\r
4   * @author  MCD Application Team\r
5   * @version V1.0.0\r
6   * @date    24-October-2011\r
7   * @brief   CMSIS Cortex-M4 Device Peripheral Access Layer System Source File.\r
8   *          This file contains the system clock configuration for STM32F4xx devices,\r
9   *          and is generated by the clock configuration tool\r
10   *          stm32f4xx_Clock_Configuration_V1.0.0.xls\r
11   *             \r
12   * 1.  This file provides two functions and one global variable to be called from \r
13   *     user application:\r
14   *      - SystemInit(): Setups the system clock (System clock source, PLL Multiplier\r
15   *                      and Divider factors, AHB/APBx prescalers and Flash settings),\r
16   *                      depending on the configuration made in the clock xls tool. \r
17   *                      This function is called at startup just after reset and \r
18   *                      before branch to main program. This call is made inside\r
19   *                      the "startup_stm32f4xx.s" file.\r
20   *\r
21   *      - SystemCoreClock variable: Contains the core clock (HCLK), it can be used\r
22   *                                  by the user application to setup the SysTick \r
23   *                                  timer or configure other parameters.\r
24   *                                     \r
25   *      - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must\r
26   *                                 be called whenever the core clock is changed\r
27   *                                 during program execution.\r
28   *\r
29   * 2. After each device reset the HSI (16 MHz) is used as system clock source.\r
30   *    Then SystemInit() function is called, in "startup_stm32f4xx.s" file, to\r
31   *    configure the system clock before to branch to main program.\r
32   *\r
33   * 3. If the system clock source selected by user fails to startup, the SystemInit()\r
34   *    function will do nothing and HSI still used as system clock source. User can \r
35   *    add some code to deal with this issue inside the SetSysClock() function.\r
36   *\r
37   * 4. The default value of HSE crystal is set to 25MHz, refer to "HSE_VALUE" define\r
38   *    in "stm32f4xx.h" file. When HSE is used as system clock source, directly or\r
39   *    through PLL, and you are using different crystal you have to adapt the HSE\r
40   *    value to your own configuration.\r
41   *\r
42   * 5. This file configures the system clock as follows:\r
43   *=============================================================================\r
44   *=============================================================================\r
45   *        Supported STM32F4xx device revision    | Rev A\r
46   *-----------------------------------------------------------------------------\r
47   *        System Clock source                    | PLL (HSE)\r
48   *-----------------------------------------------------------------------------\r
49   *        SYSCLK(Hz)                             | 150000000\r
50   *-----------------------------------------------------------------------------\r
51   *        HCLK(Hz)                               | 150000000\r
52   *-----------------------------------------------------------------------------\r
53   *        AHB Prescaler                          | 1\r
54   *-----------------------------------------------------------------------------\r
55   *        APB1 Prescaler                         | 4\r
56   *-----------------------------------------------------------------------------\r
57   *        APB2 Prescaler                         | 2\r
58   *-----------------------------------------------------------------------------\r
59   *        HSE Frequency(Hz)                      | 25000000\r
60   *-----------------------------------------------------------------------------\r
61   *        PLL_M                                  | 25\r
62   *-----------------------------------------------------------------------------\r
63   *        PLL_N                                  | 300\r
64   *-----------------------------------------------------------------------------\r
65   *        PLL_P                                  | 2\r
66   *-----------------------------------------------------------------------------\r
67   *        PLL_Q                                  | 7\r
68   *-----------------------------------------------------------------------------\r
69   *        PLLI2S_N                               | NA\r
70   *-----------------------------------------------------------------------------\r
71   *        PLLI2S_R                               | NA\r
72   *-----------------------------------------------------------------------------\r
73   *        I2S input clock                        | NA\r
74   *-----------------------------------------------------------------------------\r
75   *        VDD(V)                                 | 3.3\r
76   *-----------------------------------------------------------------------------\r
77   *        Main regulator output voltage          | Scale1 mode\r
78   *-----------------------------------------------------------------------------\r
79   *        Flash Latency(WS)                      | 4\r
80   *-----------------------------------------------------------------------------\r
81   *        Prefetch Buffer                        | OFF\r
82   *-----------------------------------------------------------------------------\r
83   *        Instruction cache                      | ON\r
84   *-----------------------------------------------------------------------------\r
85   *        Data cache                             | ON\r
86   *-----------------------------------------------------------------------------\r
87   *        Require 48MHz for USB OTG FS,          | Disabled\r
88   *        SDIO and RNG clock                     |\r
89   *-----------------------------------------------------------------------------\r
90   *=============================================================================\r
91   ****************************************************************************** \r
92   * @attention\r
93   *\r
94   * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS\r
95   * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE\r
96   * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY\r
97   * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING\r
98   * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE\r
99   * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.\r
100   *\r
101   * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>\r
102   ******************************************************************************\r
103   */\r
104 \r
105 /** @addtogroup CMSIS\r
106   * @{\r
107   */\r
108 \r
109 /** @addtogroup stm32f4xx_system\r
110   * @{\r
111   */  \r
112   \r
113 /** @addtogroup STM32F4xx_System_Private_Includes\r
114   * @{\r
115   */\r
116 \r
117 #include "stm32f4xx.h"\r
118 \r
119 /**\r
120   * @}\r
121   */\r
122 \r
123 /** @addtogroup STM32F4xx_System_Private_TypesDefinitions\r
124   * @{\r
125   */\r
126 \r
127 /**\r
128   * @}\r
129   */\r
130 \r
131 /** @addtogroup STM32F4xx_System_Private_Defines\r
132   * @{\r
133   */\r
134 \r
135 /************************* Miscellaneous Configuration ************************/\r
136 /*!< Uncomment the following line if you need to use external SRAM mounted\r
137      on STM324xG_EVAL board as data memory  */\r
138 /* #define DATA_IN_ExtSRAM */\r
139 \r
140 /*!< Uncomment the following line if you need to relocate your vector Table in\r
141      Internal SRAM. */\r
142 /* #define VECT_TAB_SRAM */\r
143 #define VECT_TAB_OFFSET  0x00 /*!< Vector Table base offset field. \r
144                                    This value must be a multiple of 0x200. */\r
145 /******************************************************************************/\r
146 \r
147 /************************* PLL Parameters *************************************/\r
148 /* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLL_M) * PLL_N */\r
149 #define PLL_M      25\r
150 #define PLL_N      300\r
151 \r
152 /* SYSCLK = PLL_VCO / PLL_P */\r
153 #define PLL_P      2\r
154 \r
155 /* USB OTG FS, SDIO and RNG Clock =  PLL_VCO / PLLQ */\r
156 #define PLL_Q      7\r
157 \r
158 /******************************************************************************/\r
159 \r
160 /**\r
161   * @}\r
162   */\r
163 \r
164 /** @addtogroup STM32F4xx_System_Private_Macros\r
165   * @{\r
166   */\r
167 \r
168 /**\r
169   * @}\r
170   */\r
171 \r
172 /** @addtogroup STM32F4xx_System_Private_Variables\r
173   * @{\r
174   */\r
175 \r
176   uint32_t SystemCoreClock = 150000000;\r
177 \r
178   __I uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9};\r
179 \r
180 /**\r
181   * @}\r
182   */\r
183 \r
184 /** @addtogroup STM32F4xx_System_Private_FunctionPrototypes\r
185   * @{\r
186   */\r
187 \r
188 static void SetSysClock(void);\r
189 #ifdef DATA_IN_ExtSRAM\r
190   static void SystemInit_ExtMemCtl(void); \r
191 #endif /* DATA_IN_ExtSRAM */\r
192 \r
193 /**\r
194   * @}\r
195   */\r
196 \r
197 /** @addtogroup STM32F4xx_System_Private_Functions\r
198   * @{\r
199   */\r
200 \r
201 /**\r
202   * @brief  Setup the microcontroller system\r
203   *         Initialize the Embedded Flash Interface, the PLL and update the \r
204   *         SystemFrequency variable.\r
205   * @param  None\r
206   * @retval None\r
207   */\r
208 void SystemInit(void)\r
209 {\r
210   /* FPU settings ------------------------------------------------------------*/\r
211   #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)\r
212     SCB->CPACR |= ((3UL << 10*2)|(3UL << 11*2));  /* set CP10 and CP11 Full Access */\r
213   #endif\r
214   /* Reset the RCC clock configuration to the default reset state ------------*/\r
215   /* Set HSION bit */\r
216   RCC->CR |= (uint32_t)0x00000001;\r
217 \r
218   /* Reset CFGR register */\r
219   RCC->CFGR = 0x00000000;\r
220 \r
221   /* Reset HSEON, CSSON and PLLON bits */\r
222   RCC->CR &= (uint32_t)0xFEF6FFFF;\r
223 \r
224   /* Reset PLLCFGR register */\r
225   RCC->PLLCFGR = 0x24003010;\r
226 \r
227   /* Reset HSEBYP bit */\r
228   RCC->CR &= (uint32_t)0xFFFBFFFF;\r
229 \r
230   /* Disable all interrupts */\r
231   RCC->CIR = 0x00000000;\r
232 \r
233 #ifdef DATA_IN_ExtSRAM\r
234   SystemInit_ExtMemCtl(); \r
235 #endif /* DATA_IN_ExtSRAM */\r
236          \r
237   /* Configure the System clock source, PLL Multiplier and Divider factors, \r
238      AHB/APBx prescalers and Flash settings ----------------------------------*/\r
239   SetSysClock();\r
240 \r
241   /* Configure the Vector Table location add offset address ------------------*/\r
242 #ifdef VECT_TAB_SRAM\r
243   SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */\r
244 #else\r
245   SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */\r
246 #endif\r
247 }\r
248 \r
249 /**\r
250    * @brief  Update SystemCoreClock variable according to Clock Register Values.\r
251   *         The SystemCoreClock variable contains the core clock (HCLK), it can\r
252   *         be used by the user application to setup the SysTick timer or configure\r
253   *         other parameters.\r
254   *           \r
255   * @note   Each time the core clock (HCLK) changes, this function must be called\r
256   *         to update SystemCoreClock variable value. Otherwise, any configuration\r
257   *         based on this variable will be incorrect.         \r
258   *     \r
259   * @note   - The system frequency computed by this function is not the real \r
260   *           frequency in the chip. It is calculated based on the predefined \r
261   *           constant and the selected clock source:\r
262   *             \r
263   *           - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(*)\r
264   *                                              \r
265   *           - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(**)\r
266   *                          \r
267   *           - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(**) \r
268   *             or HSI_VALUE(*) multiplied/divided by the PLL factors.\r
269   *         \r
270   *         (*) HSI_VALUE is a constant defined in stm32f4xx.h file (default value\r
271   *             16 MHz) but the real value may vary depending on the variations\r
272   *             in voltage and temperature.   \r
273   *    \r
274   *         (**) HSE_VALUE is a constant defined in stm32f4xx.h file (default value\r
275   *              25 MHz), user has to ensure that HSE_VALUE is same as the real\r
276   *              frequency of the crystal used. Otherwise, this function may\r
277   *              have wrong result.\r
278   *                \r
279   *         - The result of this function could be not correct when using fractional\r
280   *           value for HSE crystal.\r
281   *     \r
282   * @param  None\r
283   * @retval None\r
284   */\r
285 void SystemCoreClockUpdate(void)\r
286 {\r
287   uint32_t tmp = 0, pllvco = 0, pllp = 2, pllsource = 0, pllm = 2;\r
288   \r
289   /* Get SYSCLK source -------------------------------------------------------*/\r
290   tmp = RCC->CFGR & RCC_CFGR_SWS;\r
291 \r
292   switch (tmp)\r
293   {\r
294     case 0x00:  /* HSI used as system clock source */\r
295       SystemCoreClock = HSI_VALUE;\r
296       break;\r
297     case 0x04:  /* HSE used as system clock source */\r
298       SystemCoreClock = HSE_VALUE;\r
299       break;\r
300     case 0x08:  /* PLL used as system clock source */\r
301 \r
302       /* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLL_M) * PLL_N\r
303          SYSCLK = PLL_VCO / PLL_P\r
304          */    \r
305       pllsource = (RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) >> 22;\r
306       pllm = RCC->PLLCFGR & RCC_PLLCFGR_PLLM;\r
307       \r
308       if (pllsource != 0)\r
309       {\r
310         /* HSE used as PLL clock source */\r
311         pllvco = (HSE_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6);\r
312       }\r
313       else\r
314       {\r
315         /* HSI used as PLL clock source */\r
316         pllvco = (HSI_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6);      \r
317       }\r
318 \r
319       pllp = (((RCC->PLLCFGR & RCC_PLLCFGR_PLLP) >>16) + 1 ) *2;\r
320       SystemCoreClock = pllvco/pllp;\r
321       break;\r
322     default:\r
323       SystemCoreClock = HSI_VALUE;\r
324       break;\r
325   }\r
326   /* Compute HCLK frequency --------------------------------------------------*/\r
327   /* Get HCLK prescaler */\r
328   tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4)];\r
329   /* HCLK frequency */\r
330   SystemCoreClock >>= tmp;\r
331 }\r
332 \r
333 /**\r
334   * @brief  Configures the System clock source, PLL Multiplier and Divider factors, \r
335   *         AHB/APBx prescalers and Flash settings\r
336   * @Note   This function should be called only once the RCC clock configuration  \r
337   *         is reset to the default reset state (done in SystemInit() function).   \r
338   * @param  None\r
339   * @retval None\r
340   */\r
341 static void SetSysClock(void)\r
342 {\r
343 /******************************************************************************/\r
344 /*            PLL (clocked by HSE) used as System clock source                */\r
345 /******************************************************************************/\r
346   __IO uint32_t StartUpCounter = 0, HSEStatus = 0;\r
347   \r
348   /* Enable HSE */\r
349   RCC->CR |= ((uint32_t)RCC_CR_HSEON);\r
350  \r
351   /* Wait till HSE is ready and if Time out is reached exit */\r
352   do\r
353   {\r
354     HSEStatus = RCC->CR & RCC_CR_HSERDY;\r
355     StartUpCounter++;\r
356   } while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));\r
357 \r
358   if ((RCC->CR & RCC_CR_HSERDY) != RESET)\r
359   {\r
360     HSEStatus = (uint32_t)0x01;\r
361   }\r
362   else\r
363   {\r
364     HSEStatus = (uint32_t)0x00;\r
365   }\r
366 \r
367   if (HSEStatus == (uint32_t)0x01)\r
368   {\r
369     /* Select regulator voltage output Scale 1 mode, System frequency up to 168 MHz */\r
370     RCC->APB1ENR |= RCC_APB1ENR_PWREN;\r
371     PWR->CR |= PWR_CR_VOS;\r
372 \r
373     /* HCLK = SYSCLK / 1*/\r
374     RCC->CFGR |= RCC_CFGR_HPRE_DIV1;\r
375       \r
376     /* PCLK2 = HCLK / 2*/\r
377     RCC->CFGR |= RCC_CFGR_PPRE2_DIV2;\r
378     \r
379     /* PCLK1 = HCLK / 4*/\r
380     RCC->CFGR |= RCC_CFGR_PPRE1_DIV4;\r
381 \r
382     /* Configure the main PLL */\r
383     RCC->PLLCFGR = PLL_M | (PLL_N << 6) | (((PLL_P >> 1) -1) << 16) |\r
384                    (RCC_PLLCFGR_PLLSRC_HSE) | (PLL_Q << 24);\r
385 \r
386     /* Enable the main PLL */\r
387     RCC->CR |= RCC_CR_PLLON;\r
388 \r
389     /* Wait till the main PLL is ready */\r
390     while((RCC->CR & RCC_CR_PLLRDY) == 0)\r
391     {\r
392     }\r
393    \r
394     /* Configure Flash prefetch, Instruction cache, Data cache and wait state */\r
395     FLASH->ACR = FLASH_ACR_ICEN |FLASH_ACR_DCEN |FLASH_ACR_LATENCY_4WS;\r
396 \r
397     /* Select the main PLL as system clock source */\r
398     RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW));\r
399     RCC->CFGR |= RCC_CFGR_SW_PLL;\r
400 \r
401     /* Wait till the main PLL is used as system clock source */\r
402     while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS ) != RCC_CFGR_SWS_PLL);\r
403     {\r
404     }\r
405   }\r
406   else\r
407   { /* If HSE fails to start-up, the application will have wrong clock\r
408          configuration. User can add here some code to deal with this error */\r
409   }\r
410 \r
411 }\r
412 \r
413 /**\r
414   * @brief  Setup the external memory controller. Called in startup_stm32f4xx.s \r
415   *          before jump to __main\r
416   * @param  None\r
417   * @retval None\r
418   */ \r
419 #ifdef DATA_IN_ExtSRAM\r
420 /**\r
421   * @brief  Setup the external memory controller.\r
422   *         Called in startup_stm32f4xx.s before jump to main.\r
423   *         This function configures the external SRAM mounted on STM324xG_EVAL board\r
424   *         This SRAM will be used as program data memory (including heap and stack).\r
425   * @param  None\r
426   * @retval None\r
427   */\r
428 void SystemInit_ExtMemCtl(void)\r
429 {\r
430 /*-- GPIOs Configuration -----------------------------------------------------*/\r
431 /*\r
432  +-------------------+--------------------+------------------+------------------+\r
433  +                       SRAM pins assignment                                   +\r
434  +-------------------+--------------------+------------------+------------------+\r
435  | PD0  <-> FSMC_D2  | PE0  <-> FSMC_NBL0 | PF0  <-> FSMC_A0 | PG0 <-> FSMC_A10 | \r
436  | PD1  <-> FSMC_D3  | PE1  <-> FSMC_NBL1 | PF1  <-> FSMC_A1 | PG1 <-> FSMC_A11 | \r
437  | PD4  <-> FSMC_NOE | PE3  <-> FSMC_A19  | PF2  <-> FSMC_A2 | PG2 <-> FSMC_A12 | \r
438  | PD5  <-> FSMC_NWE | PE4  <-> FSMC_A20  | PF3  <-> FSMC_A3 | PG3 <-> FSMC_A13 | \r
439  | PD8  <-> FSMC_D13 | PE7  <-> FSMC_D4   | PF4  <-> FSMC_A4 | PG4 <-> FSMC_A14 | \r
440  | PD9  <-> FSMC_D14 | PE8  <-> FSMC_D5   | PF5  <-> FSMC_A5 | PG5 <-> FSMC_A15 | \r
441  | PD10 <-> FSMC_D15 | PE9  <-> FSMC_D6   | PF12 <-> FSMC_A6 | PG9 <-> FSMC_NE2 | \r
442  | PD11 <-> FSMC_A16 | PE10 <-> FSMC_D7   | PF13 <-> FSMC_A7 |------------------+\r
443  | PD12 <-> FSMC_A17 | PE11 <-> FSMC_D8   | PF14 <-> FSMC_A8 | \r
444  | PD13 <-> FSMC_A18 | PE12 <-> FSMC_D9   | PF15 <-> FSMC_A9 | \r
445  | PD14 <-> FSMC_D0  | PE13 <-> FSMC_D10  |------------------+\r
446  | PD15 <-> FSMC_D1  | PE14 <-> FSMC_D11  |\r
447  |                   | PE15 <-> FSMC_D12  |\r
448  +-------------------+--------------------+\r
449 */\r
450    /* Enable GPIOD, GPIOE, GPIOF and GPIOG interface clock */\r
451   RCC->AHB1ENR   = 0x00000078;\r
452   \r
453   /* Connect PDx pins to FSMC Alternate function */\r
454   GPIOD->AFR[0]  = 0x00cc00cc;\r
455   GPIOD->AFR[1]  = 0xcc0ccccc;\r
456   /* Configure PDx pins in Alternate function mode */  \r
457   GPIOD->MODER   = 0xaaaa0a0a;\r
458   /* Configure PDx pins speed to 100 MHz */  \r
459   GPIOD->OSPEEDR = 0xffff0f0f;\r
460   /* Configure PDx pins Output type to push-pull */  \r
461   GPIOD->OTYPER  = 0x00000000;\r
462   /* No pull-up, pull-down for PDx pins */ \r
463   GPIOD->PUPDR   = 0x00000000;\r
464 \r
465   /* Connect PEx pins to FSMC Alternate function */\r
466   GPIOE->AFR[0]  = 0xc00cc0cc;\r
467   GPIOE->AFR[1]  = 0xcccccccc;\r
468   /* Configure PEx pins in Alternate function mode */ \r
469   GPIOE->MODER   = 0xaaaa828a;\r
470   /* Configure PEx pins speed to 100 MHz */ \r
471   GPIOE->OSPEEDR = 0xffffc3cf;\r
472   /* Configure PEx pins Output type to push-pull */  \r
473   GPIOE->OTYPER  = 0x00000000;\r
474   /* No pull-up, pull-down for PEx pins */ \r
475   GPIOE->PUPDR   = 0x00000000;\r
476 \r
477   /* Connect PFx pins to FSMC Alternate function */\r
478   GPIOF->AFR[0]  = 0x00cccccc;\r
479   GPIOF->AFR[1]  = 0xcccc0000;\r
480   /* Configure PFx pins in Alternate function mode */   \r
481   GPIOF->MODER   = 0xaa000aaa;\r
482   /* Configure PFx pins speed to 100 MHz */ \r
483   GPIOF->OSPEEDR = 0xff000fff;\r
484   /* Configure PFx pins Output type to push-pull */  \r
485   GPIOF->OTYPER  = 0x00000000;\r
486   /* No pull-up, pull-down for PFx pins */ \r
487   GPIOF->PUPDR   = 0x00000000;\r
488 \r
489   /* Connect PGx pins to FSMC Alternate function */\r
490   GPIOG->AFR[0]  = 0x00cccccc;\r
491   GPIOG->AFR[1]  = 0x000000c0;\r
492   /* Configure PGx pins in Alternate function mode */ \r
493   GPIOG->MODER   = 0x00080aaa;\r
494   /* Configure PGx pins speed to 100 MHz */ \r
495   GPIOG->OSPEEDR = 0x000c0fff;\r
496   /* Configure PGx pins Output type to push-pull */  \r
497   GPIOG->OTYPER  = 0x00000000;\r
498   /* No pull-up, pull-down for PGx pins */ \r
499   GPIOG->PUPDR   = 0x00000000;\r
500   \r
501 /*-- FSMC Configuration ------------------------------------------------------*/\r
502   /* Enable the FSMC interface clock */\r
503   RCC->AHB3ENR         = 0x00000001;\r
504 \r
505   /* Configure and enable Bank1_SRAM2 */\r
506   FSMC_Bank1->BTCR[2]  = 0x00001015;\r
507   FSMC_Bank1->BTCR[3]  = 0x00010603;\r
508   FSMC_Bank1E->BWTR[2] = 0x0fffffff;\r
509  /*\r
510   Bank1_SRAM2 is configured as follow:\r
511 \r
512   p.FSMC_AddressSetupTime = 3;\r
513   p.FSMC_AddressHoldTime = 0;\r
514   p.FSMC_DataSetupTime = 6;\r
515   p.FSMC_BusTurnAroundDuration = 1;\r
516   p.FSMC_CLKDivision = 0;\r
517   p.FSMC_DataLatency = 0;\r
518   p.FSMC_AccessMode = FSMC_AccessMode_A;\r
519 \r
520   FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM2;\r
521   FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable;\r
522   FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_PSRAM;\r
523   FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b;\r
524   FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable;\r
525   FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable;  \r
526   FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;\r
527   FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable;\r
528   FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;\r
529   FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable;\r
530   FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable;\r
531   FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable;\r
532   FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable;\r
533   FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p;\r
534   FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p;\r
535 */  \r
536 }\r
537 #endif /* DATA_IN_ExtSRAM */\r
538 \r
539 \r
540 /**\r
541   * @}\r
542   */\r
543 \r
544 /**\r
545   * @}\r
546   */\r
547   \r
548 /**\r
549   * @}\r
550   */    \r
551 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/\r
552 \r