]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_STM32F100_Atollic/Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_gpio.c
Add FreeRTOS-Plus directory.
[freertos] / FreeRTOS / Demo / CORTEX_STM32F100_Atollic / Libraries / STM32F10x_StdPeriph_Driver / src / stm32f10x_gpio.c
1 /**\r
2   ******************************************************************************\r
3   * @file    stm32f10x_gpio.c\r
4   * @author  MCD Application Team\r
5   * @version V3.4.0\r
6   * @date    10/15/2010\r
7   * @brief   This file provides all the GPIO firmware functions.\r
8   ******************************************************************************\r
9   * @copy\r
10   *\r
11   * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS\r
12   * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE\r
13   * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY\r
14   * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING\r
15   * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE\r
16   * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.\r
17   *\r
18   * <h2><center>&copy; COPYRIGHT 2010 STMicroelectronics</center></h2>\r
19   */ \r
20 \r
21 /* Includes ------------------------------------------------------------------*/\r
22 #include "stm32f10x_gpio.h"\r
23 #include "stm32f10x_rcc.h"\r
24 \r
25 /** @addtogroup STM32F10x_StdPeriph_Driver\r
26   * @{\r
27   */\r
28 \r
29 /** @defgroup GPIO \r
30   * @brief GPIO driver modules\r
31   * @{\r
32   */ \r
33 \r
34 /** @defgroup GPIO_Private_TypesDefinitions\r
35   * @{\r
36   */\r
37 \r
38 /**\r
39   * @}\r
40   */\r
41 \r
42 /** @defgroup GPIO_Private_Defines\r
43   * @{\r
44   */\r
45 \r
46 /* ------------ RCC registers bit address in the alias region ----------------*/\r
47 #define AFIO_OFFSET                 (AFIO_BASE - PERIPH_BASE)\r
48 \r
49 /* --- EVENTCR Register -----*/\r
50 \r
51 /* Alias word address of EVOE bit */\r
52 #define EVCR_OFFSET                 (AFIO_OFFSET + 0x00)\r
53 #define EVOE_BitNumber              ((uint8_t)0x07)\r
54 #define EVCR_EVOE_BB                (PERIPH_BB_BASE + (EVCR_OFFSET * 32) + (EVOE_BitNumber * 4))\r
55 \r
56 \r
57 /* ---  MAPR Register ---*/ \r
58 /* Alias word address of MII_RMII_SEL bit */ \r
59 #define MAPR_OFFSET                 (AFIO_OFFSET + 0x04) \r
60 #define MII_RMII_SEL_BitNumber      ((u8)0x17) \r
61 #define MAPR_MII_RMII_SEL_BB        (PERIPH_BB_BASE + (MAPR_OFFSET * 32) + (MII_RMII_SEL_BitNumber * 4))\r
62 \r
63 \r
64 #define EVCR_PORTPINCONFIG_MASK     ((uint16_t)0xFF80)\r
65 #define LSB_MASK                    ((uint16_t)0xFFFF)\r
66 #define DBGAFR_POSITION_MASK        ((uint32_t)0x000F0000)\r
67 #define DBGAFR_SWJCFG_MASK          ((uint32_t)0xF0FFFFFF)\r
68 #define DBGAFR_LOCATION_MASK        ((uint32_t)0x00200000)\r
69 #define DBGAFR_NUMBITS_MASK         ((uint32_t)0x00100000)\r
70 /**\r
71   * @}\r
72   */\r
73 \r
74 /** @defgroup GPIO_Private_Macros\r
75   * @{\r
76   */\r
77 \r
78 /**\r
79   * @}\r
80   */\r
81 \r
82 /** @defgroup GPIO_Private_Variables\r
83   * @{\r
84   */\r
85 \r
86 /**\r
87   * @}\r
88   */\r
89 \r
90 /** @defgroup GPIO_Private_FunctionPrototypes\r
91   * @{\r
92   */\r
93 \r
94 /**\r
95   * @}\r
96   */\r
97 \r
98 /** @defgroup GPIO_Private_Functions\r
99   * @{\r
100   */\r
101 \r
102 /**\r
103   * @brief  Deinitializes the GPIOx peripheral registers to their default reset values.\r
104   * @param  GPIOx: where x can be (A..G) to select the GPIO peripheral.\r
105   * @retval None\r
106   */\r
107 void GPIO_DeInit(GPIO_TypeDef* GPIOx)\r
108 {\r
109   /* Check the parameters */\r
110   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));\r
111   \r
112   if (GPIOx == GPIOA)\r
113   {\r
114     RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOA, ENABLE);\r
115     RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOA, DISABLE);\r
116   }\r
117   else if (GPIOx == GPIOB)\r
118   {\r
119     RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOB, ENABLE);\r
120     RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOB, DISABLE);\r
121   }\r
122   else if (GPIOx == GPIOC)\r
123   {\r
124     RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOC, ENABLE);\r
125     RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOC, DISABLE);\r
126   }\r
127   else if (GPIOx == GPIOD)\r
128   {\r
129     RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOD, ENABLE);\r
130     RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOD, DISABLE);\r
131   }    \r
132   else if (GPIOx == GPIOE)\r
133   {\r
134     RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOE, ENABLE);\r
135     RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOE, DISABLE);\r
136   } \r
137   else if (GPIOx == GPIOF)\r
138   {\r
139     RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOF, ENABLE);\r
140     RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOF, DISABLE);\r
141   }\r
142   else\r
143   {\r
144     if (GPIOx == GPIOG)\r
145     {\r
146       RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOG, ENABLE);\r
147       RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOG, DISABLE);\r
148     }\r
149   }\r
150 }\r
151 \r
152 /**\r
153   * @brief  Deinitializes the Alternate Functions (remap, event control\r
154   *   and EXTI configuration) registers to their default reset values.\r
155   * @param  None\r
156   * @retval None\r
157   */\r
158 void GPIO_AFIODeInit(void)\r
159 {\r
160   RCC_APB2PeriphResetCmd(RCC_APB2Periph_AFIO, ENABLE);\r
161   RCC_APB2PeriphResetCmd(RCC_APB2Periph_AFIO, DISABLE);\r
162 }\r
163 \r
164 /**\r
165   * @brief  Initializes the GPIOx peripheral according to the specified\r
166   *   parameters in the GPIO_InitStruct.\r
167   * @param  GPIOx: where x can be (A..G) to select the GPIO peripheral.\r
168   * @param  GPIO_InitStruct: pointer to a GPIO_InitTypeDef structure that\r
169   *   contains the configuration information for the specified GPIO peripheral.\r
170   * @retval None\r
171   */\r
172 void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct)\r
173 {\r
174   uint32_t currentmode = 0x00, currentpin = 0x00, pinpos = 0x00, pos = 0x00;\r
175   uint32_t tmpreg = 0x00, pinmask = 0x00;\r
176   /* Check the parameters */\r
177   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));\r
178   assert_param(IS_GPIO_MODE(GPIO_InitStruct->GPIO_Mode));\r
179   assert_param(IS_GPIO_PIN(GPIO_InitStruct->GPIO_Pin));  \r
180   \r
181 /*---------------------------- GPIO Mode Configuration -----------------------*/\r
182   currentmode = ((uint32_t)GPIO_InitStruct->GPIO_Mode) & ((uint32_t)0x0F);\r
183   if ((((uint32_t)GPIO_InitStruct->GPIO_Mode) & ((uint32_t)0x10)) != 0x00)\r
184   { \r
185     /* Check the parameters */\r
186     assert_param(IS_GPIO_SPEED(GPIO_InitStruct->GPIO_Speed));\r
187     /* Output mode */\r
188     currentmode |= (uint32_t)GPIO_InitStruct->GPIO_Speed;\r
189   }\r
190 /*---------------------------- GPIO CRL Configuration ------------------------*/\r
191   /* Configure the eight low port pins */\r
192   if (((uint32_t)GPIO_InitStruct->GPIO_Pin & ((uint32_t)0x00FF)) != 0x00)\r
193   {\r
194     tmpreg = GPIOx->CRL;\r
195     for (pinpos = 0x00; pinpos < 0x08; pinpos++)\r
196     {\r
197       pos = ((uint32_t)0x01) << pinpos;\r
198       /* Get the port pins position */\r
199       currentpin = (GPIO_InitStruct->GPIO_Pin) & pos;\r
200       if (currentpin == pos)\r
201       {\r
202         pos = pinpos << 2;\r
203         /* Clear the corresponding low control register bits */\r
204         pinmask = ((uint32_t)0x0F) << pos;\r
205         tmpreg &= ~pinmask;\r
206         /* Write the mode configuration in the corresponding bits */\r
207         tmpreg |= (currentmode << pos);\r
208         /* Reset the corresponding ODR bit */\r
209         if (GPIO_InitStruct->GPIO_Mode == GPIO_Mode_IPD)\r
210         {\r
211           GPIOx->BRR = (((uint32_t)0x01) << pinpos);\r
212         }\r
213         else\r
214         {\r
215           /* Set the corresponding ODR bit */\r
216           if (GPIO_InitStruct->GPIO_Mode == GPIO_Mode_IPU)\r
217           {\r
218             GPIOx->BSRR = (((uint32_t)0x01) << pinpos);\r
219           }\r
220         }\r
221       }\r
222     }\r
223     GPIOx->CRL = tmpreg;\r
224   }\r
225 /*---------------------------- GPIO CRH Configuration ------------------------*/\r
226   /* Configure the eight high port pins */\r
227   if (GPIO_InitStruct->GPIO_Pin > 0x00FF)\r
228   {\r
229     tmpreg = GPIOx->CRH;\r
230     for (pinpos = 0x00; pinpos < 0x08; pinpos++)\r
231     {\r
232       pos = (((uint32_t)0x01) << (pinpos + 0x08));\r
233       /* Get the port pins position */\r
234       currentpin = ((GPIO_InitStruct->GPIO_Pin) & pos);\r
235       if (currentpin == pos)\r
236       {\r
237         pos = pinpos << 2;\r
238         /* Clear the corresponding high control register bits */\r
239         pinmask = ((uint32_t)0x0F) << pos;\r
240         tmpreg &= ~pinmask;\r
241         /* Write the mode configuration in the corresponding bits */\r
242         tmpreg |= (currentmode << pos);\r
243         /* Reset the corresponding ODR bit */\r
244         if (GPIO_InitStruct->GPIO_Mode == GPIO_Mode_IPD)\r
245         {\r
246           GPIOx->BRR = (((uint32_t)0x01) << (pinpos + 0x08));\r
247         }\r
248         /* Set the corresponding ODR bit */\r
249         if (GPIO_InitStruct->GPIO_Mode == GPIO_Mode_IPU)\r
250         {\r
251           GPIOx->BSRR = (((uint32_t)0x01) << (pinpos + 0x08));\r
252         }\r
253       }\r
254     }\r
255     GPIOx->CRH = tmpreg;\r
256   }\r
257 }\r
258 \r
259 /**\r
260   * @brief  Fills each GPIO_InitStruct member with its default value.\r
261   * @param  GPIO_InitStruct : pointer to a GPIO_InitTypeDef structure which will\r
262   *   be initialized.\r
263   * @retval None\r
264   */\r
265 void GPIO_StructInit(GPIO_InitTypeDef* GPIO_InitStruct)\r
266 {\r
267   /* Reset GPIO init structure parameters values */\r
268   GPIO_InitStruct->GPIO_Pin  = GPIO_Pin_All;\r
269   GPIO_InitStruct->GPIO_Speed = GPIO_Speed_2MHz;\r
270   GPIO_InitStruct->GPIO_Mode = GPIO_Mode_IN_FLOATING;\r
271 }\r
272 \r
273 /**\r
274   * @brief  Reads the specified input port pin.\r
275   * @param  GPIOx: where x can be (A..G) to select the GPIO peripheral.\r
276   * @param  GPIO_Pin:  specifies the port bit to read.\r
277   *   This parameter can be GPIO_Pin_x where x can be (0..15).\r
278   * @retval The input port pin value.\r
279   */\r
280 uint8_t GPIO_ReadInputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)\r
281 {\r
282   uint8_t bitstatus = 0x00;\r
283   \r
284   /* Check the parameters */\r
285   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));\r
286   assert_param(IS_GET_GPIO_PIN(GPIO_Pin)); \r
287   \r
288   if ((GPIOx->IDR & GPIO_Pin) != (uint32_t)Bit_RESET)\r
289   {\r
290     bitstatus = (uint8_t)Bit_SET;\r
291   }\r
292   else\r
293   {\r
294     bitstatus = (uint8_t)Bit_RESET;\r
295   }\r
296   return bitstatus;\r
297 }\r
298 \r
299 /**\r
300   * @brief  Reads the specified GPIO input data port.\r
301   * @param  GPIOx: where x can be (A..G) to select the GPIO peripheral.\r
302   * @retval GPIO input data port value.\r
303   */\r
304 uint16_t GPIO_ReadInputData(GPIO_TypeDef* GPIOx)\r
305 {\r
306   /* Check the parameters */\r
307   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));\r
308   \r
309   return ((uint16_t)GPIOx->IDR);\r
310 }\r
311 \r
312 /**\r
313   * @brief  Reads the specified output data port bit.\r
314   * @param  GPIOx: where x can be (A..G) to select the GPIO peripheral.\r
315   * @param  GPIO_Pin:  specifies the port bit to read.\r
316   *   This parameter can be GPIO_Pin_x where x can be (0..15).\r
317   * @retval The output port pin value.\r
318   */\r
319 uint8_t GPIO_ReadOutputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)\r
320 {\r
321   uint8_t bitstatus = 0x00;\r
322   /* Check the parameters */\r
323   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));\r
324   assert_param(IS_GET_GPIO_PIN(GPIO_Pin)); \r
325   \r
326   if ((GPIOx->ODR & GPIO_Pin) != (uint32_t)Bit_RESET)\r
327   {\r
328     bitstatus = (uint8_t)Bit_SET;\r
329   }\r
330   else\r
331   {\r
332     bitstatus = (uint8_t)Bit_RESET;\r
333   }\r
334   return bitstatus;\r
335 }\r
336 \r
337 /**\r
338   * @brief  Reads the specified GPIO output data port.\r
339   * @param  GPIOx: where x can be (A..G) to select the GPIO peripheral.\r
340   * @retval GPIO output data port value.\r
341   */\r
342 uint16_t GPIO_ReadOutputData(GPIO_TypeDef* GPIOx)\r
343 {\r
344   /* Check the parameters */\r
345   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));\r
346     \r
347   return ((uint16_t)GPIOx->ODR);\r
348 }\r
349 \r
350 /**\r
351   * @brief  Sets the selected data port bits.\r
352   * @param  GPIOx: where x can be (A..G) to select the GPIO peripheral.\r
353   * @param  GPIO_Pin: specifies the port bits to be written.\r
354   *   This parameter can be any combination of GPIO_Pin_x where x can be (0..15).\r
355   * @retval None\r
356   */\r
357 void GPIO_SetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)\r
358 {\r
359   /* Check the parameters */\r
360   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));\r
361   assert_param(IS_GPIO_PIN(GPIO_Pin));\r
362   \r
363   GPIOx->BSRR = GPIO_Pin;\r
364 }\r
365 \r
366 /**\r
367   * @brief  Clears the selected data port bits.\r
368   * @param  GPIOx: where x can be (A..G) to select the GPIO peripheral.\r
369   * @param  GPIO_Pin: specifies the port bits to be written.\r
370   *   This parameter can be any combination of GPIO_Pin_x where x can be (0..15).\r
371   * @retval None\r
372   */\r
373 void GPIO_ResetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)\r
374 {\r
375   /* Check the parameters */\r
376   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));\r
377   assert_param(IS_GPIO_PIN(GPIO_Pin));\r
378   \r
379   GPIOx->BRR = GPIO_Pin;\r
380 }\r
381 \r
382 /**\r
383   * @brief  Sets or clears the selected data port bit.\r
384   * @param  GPIOx: where x can be (A..G) to select the GPIO peripheral.\r
385   * @param  GPIO_Pin: specifies the port bit to be written.\r
386   *   This parameter can be one of GPIO_Pin_x where x can be (0..15).\r
387   * @param  BitVal: specifies the value to be written to the selected bit.\r
388   *   This parameter can be one of the BitAction enum values:\r
389   *     @arg Bit_RESET: to clear the port pin\r
390   *     @arg Bit_SET: to set the port pin\r
391   * @retval None\r
392   */\r
393 void GPIO_WriteBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, BitAction BitVal)\r
394 {\r
395   /* Check the parameters */\r
396   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));\r
397   assert_param(IS_GET_GPIO_PIN(GPIO_Pin));\r
398   assert_param(IS_GPIO_BIT_ACTION(BitVal)); \r
399   \r
400   if (BitVal != Bit_RESET)\r
401   {\r
402     GPIOx->BSRR = GPIO_Pin;\r
403   }\r
404   else\r
405   {\r
406     GPIOx->BRR = GPIO_Pin;\r
407   }\r
408 }\r
409 \r
410 /**\r
411   * @brief  Writes data to the specified GPIO data port.\r
412   * @param  GPIOx: where x can be (A..G) to select the GPIO peripheral.\r
413   * @param  PortVal: specifies the value to be written to the port output data register.\r
414   * @retval None\r
415   */\r
416 void GPIO_Write(GPIO_TypeDef* GPIOx, uint16_t PortVal)\r
417 {\r
418   /* Check the parameters */\r
419   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));\r
420   \r
421   GPIOx->ODR = PortVal;\r
422 }\r
423 \r
424 /**\r
425   * @brief  Locks GPIO Pins configuration registers.\r
426   * @param  GPIOx: where x can be (A..G) to select the GPIO peripheral.\r
427   * @param  GPIO_Pin: specifies the port bit to be written.\r
428   *   This parameter can be any combination of GPIO_Pin_x where x can be (0..15).\r
429   * @retval None\r
430   */\r
431 void GPIO_PinLockConfig(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)\r
432 {\r
433   uint32_t tmp = 0x00010000;\r
434   \r
435   /* Check the parameters */\r
436   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));\r
437   assert_param(IS_GPIO_PIN(GPIO_Pin));\r
438   \r
439   tmp |= GPIO_Pin;\r
440   /* Set LCKK bit */\r
441   GPIOx->LCKR = tmp;\r
442   /* Reset LCKK bit */\r
443   GPIOx->LCKR =  GPIO_Pin;\r
444   /* Set LCKK bit */\r
445   GPIOx->LCKR = tmp;\r
446   /* Read LCKK bit*/\r
447   tmp = GPIOx->LCKR;\r
448   /* Read LCKK bit*/\r
449   tmp = GPIOx->LCKR;\r
450 }\r
451 \r
452 /**\r
453   * @brief  Selects the GPIO pin used as Event output.\r
454   * @param  GPIO_PortSource: selects the GPIO port to be used as source\r
455   *   for Event output.\r
456   *   This parameter can be GPIO_PortSourceGPIOx where x can be (A..E).\r
457   * @param  GPIO_PinSource: specifies the pin for the Event output.\r
458   *   This parameter can be GPIO_PinSourcex where x can be (0..15).\r
459   * @retval None\r
460   */\r
461 void GPIO_EventOutputConfig(uint8_t GPIO_PortSource, uint8_t GPIO_PinSource)\r
462 {\r
463   uint32_t tmpreg = 0x00;\r
464   /* Check the parameters */\r
465   assert_param(IS_GPIO_EVENTOUT_PORT_SOURCE(GPIO_PortSource));\r
466   assert_param(IS_GPIO_PIN_SOURCE(GPIO_PinSource));\r
467     \r
468   tmpreg = AFIO->EVCR;\r
469   /* Clear the PORT[6:4] and PIN[3:0] bits */\r
470   tmpreg &= EVCR_PORTPINCONFIG_MASK;\r
471   tmpreg |= (uint32_t)GPIO_PortSource << 0x04;\r
472   tmpreg |= GPIO_PinSource;\r
473   AFIO->EVCR = tmpreg;\r
474 }\r
475 \r
476 /**\r
477   * @brief  Enables or disables the Event Output.\r
478   * @param  NewState: new state of the Event output.\r
479   *   This parameter can be: ENABLE or DISABLE.\r
480   * @retval None\r
481   */\r
482 void GPIO_EventOutputCmd(FunctionalState NewState)\r
483 {\r
484   /* Check the parameters */\r
485   assert_param(IS_FUNCTIONAL_STATE(NewState));\r
486   \r
487   *(__IO uint32_t *) EVCR_EVOE_BB = (uint32_t)NewState;\r
488 }\r
489 \r
490 /**\r
491   * @brief  Changes the mapping of the specified pin.\r
492   * @param  GPIO_Remap: selects the pin to remap.\r
493   *   This parameter can be one of the following values:\r
494   *     @arg GPIO_Remap_SPI1             : SPI1 Alternate Function mapping\r
495   *     @arg GPIO_Remap_I2C1             : I2C1 Alternate Function mapping\r
496   *     @arg GPIO_Remap_USART1           : USART1 Alternate Function mapping\r
497   *     @arg GPIO_Remap_USART2           : USART2 Alternate Function mapping\r
498   *     @arg GPIO_PartialRemap_USART3    : USART3 Partial Alternate Function mapping\r
499   *     @arg GPIO_FullRemap_USART3       : USART3 Full Alternate Function mapping\r
500   *     @arg GPIO_PartialRemap_TIM1      : TIM1 Partial Alternate Function mapping\r
501   *     @arg GPIO_FullRemap_TIM1         : TIM1 Full Alternate Function mapping\r
502   *     @arg GPIO_PartialRemap1_TIM2     : TIM2 Partial1 Alternate Function mapping\r
503   *     @arg GPIO_PartialRemap2_TIM2     : TIM2 Partial2 Alternate Function mapping\r
504   *     @arg GPIO_FullRemap_TIM2         : TIM2 Full Alternate Function mapping\r
505   *     @arg GPIO_PartialRemap_TIM3      : TIM3 Partial Alternate Function mapping\r
506   *     @arg GPIO_FullRemap_TIM3         : TIM3 Full Alternate Function mapping\r
507   *     @arg GPIO_Remap_TIM4             : TIM4 Alternate Function mapping\r
508   *     @arg GPIO_Remap1_CAN1            : CAN1 Alternate Function mapping\r
509   *     @arg GPIO_Remap2_CAN1            : CAN1 Alternate Function mapping\r
510   *     @arg GPIO_Remap_PD01             : PD01 Alternate Function mapping\r
511   *     @arg GPIO_Remap_TIM5CH4_LSI      : LSI connected to TIM5 Channel4 input capture for calibration\r
512   *     @arg GPIO_Remap_ADC1_ETRGINJ     : ADC1 External Trigger Injected Conversion remapping\r
513   *     @arg GPIO_Remap_ADC1_ETRGREG     : ADC1 External Trigger Regular Conversion remapping\r
514   *     @arg GPIO_Remap_ADC2_ETRGINJ     : ADC2 External Trigger Injected Conversion remapping\r
515   *     @arg GPIO_Remap_ADC2_ETRGREG     : ADC2 External Trigger Regular Conversion remapping\r
516   *     @arg GPIO_Remap_ETH              : Ethernet remapping (only for Connectivity line devices)\r
517   *     @arg GPIO_Remap_CAN2             : CAN2 remapping (only for Connectivity line devices)\r
518   *     @arg GPIO_Remap_SWJ_NoJTRST      : Full SWJ Enabled (JTAG-DP + SW-DP) but without JTRST\r
519   *     @arg GPIO_Remap_SWJ_JTAGDisable  : JTAG-DP Disabled and SW-DP Enabled\r
520   *     @arg GPIO_Remap_SWJ_Disable      : Full SWJ Disabled (JTAG-DP + SW-DP)\r
521   *     @arg GPIO_Remap_SPI3             : SPI3/I2S3 Alternate Function mapping (only for Connectivity line devices)\r
522   *     @arg GPIO_Remap_TIM2ITR1_PTP_SOF : Ethernet PTP output or USB OTG SOF (Start of Frame) connected\r
523   *                                        to TIM2 Internal Trigger 1 for calibration (only for Connectivity line devices)\r
524   *                                        If the GPIO_Remap_TIM2ITR1_PTP_SOF is enabled the TIM2 ITR1 is connected to \r
525   *                                        Ethernet PTP output. When Reset TIM2 ITR1 is connected to USB OTG SOF output.    \r
526   *     @arg GPIO_Remap_PTP_PPS          : Ethernet MAC PPS_PTS output on PB05 (only for Connectivity line devices)\r
527   *     @arg GPIO_Remap_TIM15            : TIM15 Alternate Function mapping (only for Value line devices)\r
528   *     @arg GPIO_Remap_TIM16            : TIM16 Alternate Function mapping (only for Value line devices)\r
529   *     @arg GPIO_Remap_TIM17            : TIM17 Alternate Function mapping (only for Value line devices)\r
530   *     @arg GPIO_Remap_CEC              : CEC Alternate Function mapping (only for Value line devices)\r
531   *     @arg GPIO_Remap_TIM1_DMA         : TIM1 DMA requests mapping (only for Value line devices)\r
532   *     @arg GPIO_Remap_TIM9             : TIM9 Alternate Function mapping (only for XL-density devices)\r
533   *     @arg GPIO_Remap_TIM10            : TIM10 Alternate Function mapping (only for XL-density devices)\r
534   *     @arg GPIO_Remap_TIM11            : TIM11 Alternate Function mapping (only for XL-density devices)\r
535   *     @arg GPIO_Remap_TIM13            : TIM13 Alternate Function mapping (only for High density Value line and XL-density devices)\r
536   *     @arg GPIO_Remap_TIM14            : TIM14 Alternate Function mapping (only for High density Value line and XL-density devices)\r
537   *     @arg GPIO_Remap_FSMC_NADV        : FSMC_NADV Alternate Function mapping (only for High density Value line and XL-density devices)\r
538   *     @arg GPIO_Remap_TIM67_DAC_DMA    : TIM6/TIM7 and DAC DMA requests remapping (only for High density Value line devices)\r
539   *     @arg GPIO_Remap_TIM12            : TIM12 Alternate Function mapping (only for High density Value line devices)\r
540   *     @arg GPIO_Remap_MISC             : Miscellaneous Remap (DMA2 Channel5 Position and DAC Trigger remapping, \r
541   *                                        only for High density Value line devices)     \r
542   * @param  NewState: new state of the port pin remapping.\r
543   *   This parameter can be: ENABLE or DISABLE.\r
544   * @retval None\r
545   */\r
546 void GPIO_PinRemapConfig(uint32_t GPIO_Remap, FunctionalState NewState)\r
547 {\r
548   uint32_t tmp = 0x00, tmp1 = 0x00, tmpreg = 0x00, tmpmask = 0x00;\r
549 \r
550   /* Check the parameters */\r
551   assert_param(IS_GPIO_REMAP(GPIO_Remap));\r
552   assert_param(IS_FUNCTIONAL_STATE(NewState));  \r
553   \r
554   if((GPIO_Remap & 0x80000000) == 0x80000000)\r
555   {\r
556     tmpreg = AFIO->MAPR2;\r
557   }\r
558   else\r
559   {\r
560     tmpreg = AFIO->MAPR;\r
561   }\r
562 \r
563   tmpmask = (GPIO_Remap & DBGAFR_POSITION_MASK) >> 0x10;\r
564   tmp = GPIO_Remap & LSB_MASK;\r
565 \r
566   if ((GPIO_Remap & (DBGAFR_LOCATION_MASK | DBGAFR_NUMBITS_MASK)) == (DBGAFR_LOCATION_MASK | DBGAFR_NUMBITS_MASK))\r
567   {\r
568     tmpreg &= DBGAFR_SWJCFG_MASK;\r
569     AFIO->MAPR &= DBGAFR_SWJCFG_MASK;\r
570   }\r
571   else if ((GPIO_Remap & DBGAFR_NUMBITS_MASK) == DBGAFR_NUMBITS_MASK)\r
572   {\r
573     tmp1 = ((uint32_t)0x03) << tmpmask;\r
574     tmpreg &= ~tmp1;\r
575     tmpreg |= ~DBGAFR_SWJCFG_MASK;\r
576   }\r
577   else\r
578   {\r
579     tmpreg &= ~(tmp << ((GPIO_Remap >> 0x15)*0x10));\r
580     tmpreg |= ~DBGAFR_SWJCFG_MASK;\r
581   }\r
582 \r
583   if (NewState != DISABLE)\r
584   {\r
585     tmpreg |= (tmp << ((GPIO_Remap >> 0x15)*0x10));\r
586   }\r
587 \r
588   if((GPIO_Remap & 0x80000000) == 0x80000000)\r
589   {\r
590     AFIO->MAPR2 = tmpreg;\r
591   }\r
592   else\r
593   {\r
594     AFIO->MAPR = tmpreg;\r
595   }  \r
596 }\r
597 \r
598 /**\r
599   * @brief  Selects the GPIO pin used as EXTI Line.\r
600   * @param  GPIO_PortSource: selects the GPIO port to be used as source for EXTI lines.\r
601   *   This parameter can be GPIO_PortSourceGPIOx where x can be (A..G).\r
602   * @param  GPIO_PinSource: specifies the EXTI line to be configured.\r
603   *   This parameter can be GPIO_PinSourcex where x can be (0..15).\r
604   * @retval None\r
605   */\r
606 void GPIO_EXTILineConfig(uint8_t GPIO_PortSource, uint8_t GPIO_PinSource)\r
607 {\r
608   uint32_t tmp = 0x00;\r
609   /* Check the parameters */\r
610   assert_param(IS_GPIO_EXTI_PORT_SOURCE(GPIO_PortSource));\r
611   assert_param(IS_GPIO_PIN_SOURCE(GPIO_PinSource));\r
612   \r
613   tmp = ((uint32_t)0x0F) << (0x04 * (GPIO_PinSource & (uint8_t)0x03));\r
614   AFIO->EXTICR[GPIO_PinSource >> 0x02] &= ~tmp;\r
615   AFIO->EXTICR[GPIO_PinSource >> 0x02] |= (((uint32_t)GPIO_PortSource) << (0x04 * (GPIO_PinSource & (uint8_t)0x03)));\r
616 }\r
617 \r
618 /**\r
619   * @brief  Selects the Ethernet media interface.\r
620   * @note   This function applies only to STM32 Connectivity line devices.  \r
621   * @param  GPIO_ETH_MediaInterface: specifies the Media Interface mode.\r
622   *   This parameter can be one of the following values:\r
623   *     @arg GPIO_ETH_MediaInterface_MII: MII mode\r
624   *     @arg GPIO_ETH_MediaInterface_RMII: RMII mode    \r
625   * @retval None\r
626   */\r
627 void GPIO_ETH_MediaInterfaceConfig(uint32_t GPIO_ETH_MediaInterface) \r
628\r
629   assert_param(IS_GPIO_ETH_MEDIA_INTERFACE(GPIO_ETH_MediaInterface)); \r
630 \r
631   /* Configure MII_RMII selection bit */ \r
632   *(__IO uint32_t *) MAPR_MII_RMII_SEL_BB = GPIO_ETH_MediaInterface; \r
633 }\r
634   \r
635 /**\r
636   * @}\r
637   */\r
638 \r
639 /**\r
640   * @}\r
641   */\r
642 \r
643 /**\r
644   * @}\r
645   */\r
646 \r
647 /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/\r