changes to mainDisplay.py
[goodfet] / firmware / lib / 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    19-September-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 8 MHz, 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)                             | 168000000\r
50   *-----------------------------------------------------------------------------\r
51   *        HCLK(Hz)                               | 168000000\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)                      | 8000000\r
60   *-----------------------------------------------------------------------------\r
61   *        PLL_M                                  | 8\r
62   *-----------------------------------------------------------------------------\r
63   *        PLL_N                                  | 336\r
64   *-----------------------------------------------------------------------------\r
65   *        PLL_P                                  | 2\r
66   *-----------------------------------------------------------------------------\r
67   *        PLL_Q                                  | 7\r
68   *-----------------------------------------------------------------------------\r
69   *        PLLI2S_N                               | 192\r
70   *-----------------------------------------------------------------------------\r
71   *        PLLI2S_R                               | 5\r
72   *-----------------------------------------------------------------------------\r
73   *        I2S input clock(Hz)                    | 38400000\r
74   *-----------------------------------------------------------------------------\r
75   *        VDD(V)                                 | 3.3\r
76   *-----------------------------------------------------------------------------\r
77   *        High Performance mode                  | Enabled\r
78   *-----------------------------------------------------------------------------\r
79   *        Flash Latency(WS)                      | 5\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,          | Enabled\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 /*!< Uncomment the following line if you need to use external SRAM mounted\r
136      on STM324xG_EVAL board as data memory  */\r
137 /* #define DATA_IN_ExtSRAM */\r
138 \r
139 /*!< Uncomment the following line if you need to relocate your vector Table in\r
140      Internal SRAM. */\r
141 /* #define VECT_TAB_SRAM */\r
142 #define VECT_TAB_OFFSET  0x00 /*!< Vector Table base offset field. \r
143                                    This value must be a multiple of 0x200. */\r
144 \r
145 \r
146 /* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLL_M) * PLL_N */\r
147 #define PLL_M      8\r
148 #define PLL_N      336\r
149 \r
150 /* SYSCLK = PLL_VCO / PLL_P */\r
151 #define PLL_P      2\r
152 \r
153 /* USB OTG FS, SDIO and RNG Clock =  PLL_VCO / PLLQ */\r
154 #define PLL_Q      7\r
155 \r
156 /* PLLI2S_VCO = (HSE_VALUE Or HSI_VALUE / PLL_M) * PLLI2S_N\r
157    I2SCLK = PLLI2S_VCO / PLLI2S_R */\r
158 #define PLLI2S_N   192\r
159 #define PLLI2S_R   5\r
160 \r
161 /**\r
162   * @}\r
163   */\r
164 \r
165 /** @addtogroup STM32F4xx_System_Private_Macros\r
166   * @{\r
167   */\r
168 \r
169 /**\r
170   * @}\r
171   */\r
172 \r
173 /** @addtogroup STM32F4xx_System_Private_Variables\r
174   * @{\r
175   */\r
176 \r
177   uint32_t SystemCoreClock = 168000000;\r
178 \r
179 //__I uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9};\r
180 __attribute__ ((section (".text"))) uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9};\r
181 \r
182 /**\r
183   * @}\r
184   */\r
185 \r
186 /** @addtogroup STM32F4xx_System_Private_FunctionPrototypes\r
187   * @{\r
188   */\r
189 \r
190 static void SetSysClock(void);\r
191 #ifdef DATA_IN_ExtSRAM\r
192   static void SystemInit_ExtMemCtl(void); \r
193 #endif /* DATA_IN_ExtSRAM */\r
194 \r
195 /**\r
196   * @}\r
197   */\r
198 \r
199 /** @addtogroup STM32F4xx_System_Private_Functions\r
200   * @{\r
201   */\r
202 \r
203 /**\r
204   * @brief  Setup the microcontroller system\r
205   *         Initialize the Embedded Flash Interface, the PLL and update the \r
206   *         SystemFrequency variable.\r
207   * @param  None\r
208   * @retval None\r
209   */\r
210 void SystemInit(void)\r
211 {\r
212   SystemCoreClock = 168000000; //In case global variables aren't initted.\r
213   \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     /* Enable high performance mode, System frequency up to 168 MHz */\r
370     RCC->APB1ENR |= RCC_APB1ENR_PWREN;\r
371     PWR->CR |= PWR_CR_PMODE;  \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_5WS;\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 /*                        I2S clock configuration                             */\r
413 /******************************************************************************/\r
414   /* PLLI2S clock used as I2S clock source */\r
415   RCC->CFGR &= ~RCC_CFGR_I2SSRC;\r
416 \r
417   /* Configure PLLI2S */\r
418   RCC->PLLI2SCFGR = (PLLI2S_N << 6) | (PLLI2S_R << 28);\r
419 \r
420   /* Enable PLLI2S */\r
421   RCC->CR |= ((uint32_t)RCC_CR_PLLI2SON);\r
422 \r
423   /* Wait till PLLI2S is ready */\r
424   while((RCC->CR & RCC_CR_PLLI2SRDY) == 0)\r
425   {\r
426   }\r
427 }\r
428 \r
429 /**\r
430   * @brief  Setup the external memory controller. Called in startup_stm32f4xx.s \r
431   *          before jump to __main\r
432   * @param  None\r
433   * @retval None\r
434   */ \r
435 #ifdef DATA_IN_ExtSRAM\r
436 /**\r
437   * @brief  Setup the external memory controller.\r
438   *         Called in startup_stm32f4xx.s before jump to main.\r
439   *         This function configures the external SRAM mounted on STM324xG_EVAL board\r
440   *         This SRAM will be used as program data memory (including heap and stack).\r
441   * @param  None\r
442   * @retval None\r
443   */\r
444 void SystemInit_ExtMemCtl(void)\r
445 {\r
446 /*-- GPIOs Configuration -----------------------------------------------------*/\r
447 /*\r
448  +-------------------+--------------------+------------------+------------------+\r
449  +                       SRAM pins assignment                                   +\r
450  +-------------------+--------------------+------------------+------------------+\r
451  | PD0  <-> FSMC_D2  | PE0  <-> FSMC_NBL0 | PF0  <-> FSMC_A0 | PG0 <-> FSMC_A10 | \r
452  | PD1  <-> FSMC_D3  | PE1  <-> FSMC_NBL1 | PF1  <-> FSMC_A1 | PG1 <-> FSMC_A11 | \r
453  | PD4  <-> FSMC_NOE | PE3  <-> FSMC_A19  | PF2  <-> FSMC_A2 | PG2 <-> FSMC_A12 | \r
454  | PD5  <-> FSMC_NWE | PE4  <-> FSMC_A20  | PF3  <-> FSMC_A3 | PG3 <-> FSMC_A13 | \r
455  | PD8  <-> FSMC_D13 | PE7  <-> FSMC_D4   | PF4  <-> FSMC_A4 | PG4 <-> FSMC_A14 | \r
456  | PD9  <-> FSMC_D14 | PE8  <-> FSMC_D5   | PF5  <-> FSMC_A5 | PG5 <-> FSMC_A15 | \r
457  | PD10 <-> FSMC_D15 | PE9  <-> FSMC_D6   | PF12 <-> FSMC_A6 | PG9 <-> FSMC_NE2 | \r
458  | PD11 <-> FSMC_A16 | PE10 <-> FSMC_D7   | PF13 <-> FSMC_A7 |------------------+\r
459  | PD12 <-> FSMC_A17 | PE11 <-> FSMC_D8   | PF14 <-> FSMC_A8 | \r
460  | PD13 <-> FSMC_A18 | PE12 <-> FSMC_D9   | PF15 <-> FSMC_A9 | \r
461  | PD14 <-> FSMC_D0  | PE13 <-> FSMC_D10  |------------------+\r
462  | PD15 <-> FSMC_D1  | PE14 <-> FSMC_D11  |\r
463  |                   | PE15 <-> FSMC_D12  |\r
464  +-------------------+--------------------+\r
465 */\r
466    /* Enable GPIOD, GPIOE, GPIOF and GPIOG interface clock */\r
467   RCC->AHB1ENR   = 0x00000078;\r
468   \r
469   /* Connect PDx pins to FSMC Alternate function */\r
470   GPIOD->AFR[0]  = 0x00cc00cc;\r
471   GPIOD->AFR[1]  = 0xcc0ccccc;\r
472   /* Configure PDx pins in Alternate function mode */  \r
473   GPIOD->MODER   = 0xaaaa0a0a;\r
474   /* Configure PDx pins speed to 100 MHz */  \r
475   GPIOD->OSPEEDR = 0xffff0f0f;\r
476   /* Configure PDx pins Output type to push-pull */  \r
477   GPIOD->OTYPER  = 0x00000000;\r
478   /* No pull-up, pull-down for PDx pins */ \r
479   GPIOD->PUPDR   = 0x00000000;\r
480 \r
481   /* Connect PEx pins to FSMC Alternate function */\r
482   GPIOE->AFR[0]  = 0xc00cc0cc;\r
483   GPIOE->AFR[1]  = 0xcccccccc;\r
484   /* Configure PEx pins in Alternate function mode */ \r
485   GPIOE->MODER   = 0xaaaa828a;\r
486   /* Configure PEx pins speed to 100 MHz */ \r
487   GPIOE->OSPEEDR = 0xffffc3cf;\r
488   /* Configure PEx pins Output type to push-pull */  \r
489   GPIOE->OTYPER  = 0x00000000;\r
490   /* No pull-up, pull-down for PEx pins */ \r
491   GPIOE->PUPDR   = 0x00000000;\r
492 \r
493   /* Connect PFx pins to FSMC Alternate function */\r
494   GPIOF->AFR[0]  = 0x00cccccc;\r
495   GPIOF->AFR[1]  = 0xcccc0000;\r
496   /* Configure PFx pins in Alternate function mode */   \r
497   GPIOF->MODER   = 0xaa000aaa;\r
498   /* Configure PFx pins speed to 100 MHz */ \r
499   GPIOF->OSPEEDR = 0xff000fff;\r
500   /* Configure PFx pins Output type to push-pull */  \r
501   GPIOF->OTYPER  = 0x00000000;\r
502   /* No pull-up, pull-down for PFx pins */ \r
503   GPIOF->PUPDR   = 0x00000000;\r
504 \r
505   /* Connect PGx pins to FSMC Alternate function */\r
506   GPIOG->AFR[0]  = 0x00cccccc;\r
507   GPIOG->AFR[1]  = 0x000000c0;\r
508   /* Configure PGx pins in Alternate function mode */ \r
509   GPIOG->MODER   = 0x00080aaa;\r
510   /* Configure PGx pins speed to 100 MHz */ \r
511   GPIOG->OSPEEDR = 0x000c0fff;\r
512   /* Configure PGx pins Output type to push-pull */  \r
513   GPIOG->OTYPER  = 0x00000000;\r
514   /* No pull-up, pull-down for PGx pins */ \r
515   GPIOG->PUPDR   = 0x00000000;\r
516   \r
517 /*-- FSMC Configuration ------------------------------------------------------*/\r
518   /* Enable the FSMC interface clock */\r
519   RCC->AHB3ENR         = 0x00000001;\r
520 \r
521   /* Configure and enable Bank1_SRAM2 */\r
522   FSMC_Bank1->BTCR[2]  = 0x00001015;\r
523   FSMC_Bank1->BTCR[3]  = 0x00010603;//0x00010400;\r
524   FSMC_Bank1E->BWTR[2] = 0x0fffffff;\r
525 /*\r
526   Bank1_SRAM2 is configured as follow:\r
527 \r
528   p.FSMC_AddressSetupTime = 3;//0;\r
529   p.FSMC_AddressHoldTime = 0;\r
530   p.FSMC_DataSetupTime = 6;//4;\r
531   p.FSMC_BusTurnAroundDuration = 1;\r
532   p.FSMC_CLKDivision = 0;\r
533   p.FSMC_DataLatency = 0;\r
534   p.FSMC_AccessMode = FSMC_AccessMode_A;\r
535 \r
536   FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM2;\r
537   FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable;\r
538   FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_PSRAM;\r
539   FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b;\r
540   FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable;\r
541   FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable;  \r
542   FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;\r
543   FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable;\r
544   FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;\r
545   FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable;\r
546   FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable;\r
547   FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable;\r
548   FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable;\r
549   FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p;\r
550   FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p;\r
551 */\r
552   \r
553 }\r
554 #endif /* DATA_IN_ExtSRAM */\r
555 \r
556 \r
557 /**\r
558   * @}\r
559   */\r
560 \r
561 /**\r
562   * @}\r
563   */\r
564   \r
565 /**\r
566   * @}\r
567   */    \r
568 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/\r
569 \r