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