]> git.sur5r.net Git - freertos/blob - Demo/CORTEX_STM32F103_GCC_Rowley/ST Library/src/stm32f10x_gpio.c
Start to re-arrange files to include FreeRTOS+ in main download.
[freertos] / Demo / CORTEX_STM32F103_GCC_Rowley / ST Library / src / stm32f10x_gpio.c
1 /******************** (C) COPYRIGHT 2008 STMicroelectronics ********************\r
2 * File Name          : stm32f10x_gpio.c\r
3 * Author             : MCD Application Team\r
4 * Version            : V2.0.1\r
5 * Date               : 06/13/2008\r
6 * Description        : This file provides all the GPIO firmware functions.\r
7 ********************************************************************************\r
8 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS\r
9 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.\r
10 * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,\r
11 * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE\r
12 * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING\r
13 * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.\r
14 *******************************************************************************/\r
15 \r
16 /* Includes ------------------------------------------------------------------*/\r
17 #include "stm32f10x_gpio.h"\r
18 #include "stm32f10x_rcc.h"\r
19 \r
20 /* Private typedef -----------------------------------------------------------*/\r
21 /* Private define ------------------------------------------------------------*/\r
22 /* ------------ RCC registers bit address in the alias region ----------- */\r
23 #define AFIO_OFFSET                 (AFIO_BASE - PERIPH_BASE)\r
24 \r
25 /* --- EVENTCR Register ---*/\r
26 /* Alias word address of EVOE bit */\r
27 #define EVCR_OFFSET                 (AFIO_OFFSET + 0x00)\r
28 #define EVOE_BitNumber              ((u8)0x07)\r
29 #define EVCR_EVOE_BB                (PERIPH_BB_BASE + (EVCR_OFFSET * 32) + (EVOE_BitNumber * 4))\r
30 \r
31 #define EVCR_PORTPINCONFIG_MASK     ((u16)0xFF80)\r
32 #define LSB_MASK                    ((u16)0xFFFF)\r
33 #define DBGAFR_POSITION_MASK        ((u32)0x000F0000)\r
34 #define DBGAFR_SWJCFG_MASK          ((u32)0xF0FFFFFF)\r
35 #define DBGAFR_LOCATION_MASK        ((u32)0x00200000)\r
36 #define DBGAFR_NUMBITS_MASK         ((u32)0x00100000)\r
37 \r
38 /* Private macro -------------------------------------------------------------*/\r
39 /* Private variables ---------------------------------------------------------*/\r
40 /* Private function prototypes -----------------------------------------------*/\r
41 /* Private functions ---------------------------------------------------------*/\r
42 \r
43 /*******************************************************************************\r
44 * Function Name  : GPIO_DeInit\r
45 * Description    : Deinitializes the GPIOx peripheral registers to their default\r
46 *                  reset values.\r
47 * Input          : - GPIOx: where x can be (A..G) to select the GPIO peripheral.\r
48 * Output         : None\r
49 * Return         : None\r
50 *******************************************************************************/\r
51 void GPIO_DeInit(GPIO_TypeDef* GPIOx)\r
52 {\r
53   /* Check the parameters */\r
54   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));\r
55   \r
56   switch (*(u32*)&GPIOx)\r
57   {\r
58     case GPIOA_BASE:\r
59       RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOA, ENABLE);\r
60       RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOA, DISABLE);\r
61       break;\r
62 \r
63     case GPIOB_BASE:\r
64       RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOB, ENABLE);\r
65       RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOB, DISABLE);\r
66       break;\r
67 \r
68     case GPIOC_BASE:\r
69       RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOC, ENABLE);\r
70       RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOC, DISABLE);\r
71       break;\r
72 \r
73     case GPIOD_BASE:\r
74       RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOD, ENABLE);\r
75       RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOD, DISABLE);\r
76       break;\r
77       \r
78     case GPIOE_BASE:\r
79       RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOE, ENABLE);\r
80       RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOE, DISABLE);\r
81       break; \r
82 \r
83     case GPIOF_BASE:\r
84       RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOF, ENABLE);\r
85       RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOF, DISABLE);\r
86       break;\r
87 \r
88     case GPIOG_BASE:\r
89       RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOG, ENABLE);\r
90       RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOG, DISABLE);\r
91       break;                       \r
92 \r
93     default:\r
94       break;\r
95   }\r
96 }\r
97 \r
98 /*******************************************************************************\r
99 * Function Name  : GPIO_AFIODeInit\r
100 * Description    : Deinitializes the Alternate Functions (remap, event control\r
101 *                  and EXTI configuration) registers to their default reset\r
102 *                  values.\r
103 * Input          : None\r
104 * Output         : None\r
105 * Return         : None\r
106 *******************************************************************************/\r
107 void GPIO_AFIODeInit(void)\r
108 {\r
109   RCC_APB2PeriphResetCmd(RCC_APB2Periph_AFIO, ENABLE);\r
110   RCC_APB2PeriphResetCmd(RCC_APB2Periph_AFIO, DISABLE);\r
111 }\r
112 \r
113 /*******************************************************************************\r
114 * Function Name  : GPIO_Init\r
115 * Description    : Initializes the GPIOx peripheral according to the specified\r
116 *                  parameters in the GPIO_InitStruct.\r
117 * Input          : - GPIOx: where x can be (A..G) to select the GPIO peripheral.\r
118 *                  - GPIO_InitStruct: pointer to a GPIO_InitTypeDef structure that\r
119 *                    contains the configuration information for the specified GPIO\r
120 *                    peripheral.\r
121 * Output         : None\r
122 * Return         : None\r
123 *******************************************************************************/\r
124 void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct)\r
125 {\r
126   u32 currentmode = 0x00, currentpin = 0x00, pinpos = 0x00, pos = 0x00;\r
127   u32 tmpreg = 0x00, pinmask = 0x00;\r
128 \r
129   /* Check the parameters */\r
130   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));\r
131   assert_param(IS_GPIO_MODE(GPIO_InitStruct->GPIO_Mode));\r
132   assert_param(IS_GPIO_PIN(GPIO_InitStruct->GPIO_Pin));  \r
133   \r
134 /*---------------------------- GPIO Mode Configuration -----------------------*/\r
135   currentmode = ((u32)GPIO_InitStruct->GPIO_Mode) & ((u32)0x0F);\r
136 \r
137   if ((((u32)GPIO_InitStruct->GPIO_Mode) & ((u32)0x10)) != 0x00)\r
138   { \r
139     /* Check the parameters */\r
140     assert_param(IS_GPIO_SPEED(GPIO_InitStruct->GPIO_Speed));\r
141     /* Output mode */\r
142     currentmode |= (u32)GPIO_InitStruct->GPIO_Speed;\r
143   }\r
144 \r
145 /*---------------------------- GPIO CRL Configuration ------------------------*/\r
146   /* Configure the eight low port pins */\r
147   if (((u32)GPIO_InitStruct->GPIO_Pin & ((u32)0x00FF)) != 0x00)\r
148   {\r
149     tmpreg = GPIOx->CRL;\r
150 \r
151     for (pinpos = 0x00; pinpos < 0x08; pinpos++)\r
152     {\r
153       pos = ((u32)0x01) << pinpos;\r
154       /* Get the port pins position */\r
155       currentpin = (GPIO_InitStruct->GPIO_Pin) & pos;\r
156 \r
157       if (currentpin == pos)\r
158       {\r
159         pos = pinpos << 2;\r
160         /* Clear the corresponding low control register bits */\r
161         pinmask = ((u32)0x0F) << pos;\r
162         tmpreg &= ~pinmask;\r
163 \r
164         /* Write the mode configuration in the corresponding bits */\r
165         tmpreg |= (currentmode << pos);\r
166 \r
167         /* Reset the corresponding ODR bit */\r
168         if (GPIO_InitStruct->GPIO_Mode == GPIO_Mode_IPD)\r
169         {\r
170           GPIOx->BRR = (((u32)0x01) << pinpos);\r
171         }\r
172         /* Set the corresponding ODR bit */\r
173         if (GPIO_InitStruct->GPIO_Mode == GPIO_Mode_IPU)\r
174         {\r
175           GPIOx->BSRR = (((u32)0x01) << pinpos);\r
176         }\r
177       }\r
178     }\r
179     GPIOx->CRL = tmpreg;\r
180   }\r
181 \r
182 /*---------------------------- GPIO CRH Configuration ------------------------*/\r
183   /* Configure the eight high port pins */\r
184   if (GPIO_InitStruct->GPIO_Pin > 0x00FF)\r
185   {\r
186     tmpreg = GPIOx->CRH;\r
187     for (pinpos = 0x00; pinpos < 0x08; pinpos++)\r
188     {\r
189       pos = (((u32)0x01) << (pinpos + 0x08));\r
190       /* Get the port pins position */\r
191       currentpin = ((GPIO_InitStruct->GPIO_Pin) & pos);\r
192       if (currentpin == pos)\r
193       {\r
194         pos = pinpos << 2;\r
195         /* Clear the corresponding high control register bits */\r
196         pinmask = ((u32)0x0F) << pos;\r
197         tmpreg &= ~pinmask;\r
198 \r
199         /* Write the mode configuration in the corresponding bits */\r
200         tmpreg |= (currentmode << pos);\r
201 \r
202         /* Reset the corresponding ODR bit */\r
203         if (GPIO_InitStruct->GPIO_Mode == GPIO_Mode_IPD)\r
204         {\r
205           GPIOx->BRR = (((u32)0x01) << (pinpos + 0x08));\r
206         }\r
207         /* Set the corresponding ODR bit */\r
208         if (GPIO_InitStruct->GPIO_Mode == GPIO_Mode_IPU)\r
209         {\r
210           GPIOx->BSRR = (((u32)0x01) << (pinpos + 0x08));\r
211         }\r
212       }\r
213     }\r
214     GPIOx->CRH = tmpreg;\r
215   }\r
216 }\r
217 \r
218 /*******************************************************************************\r
219 * Function Name  : GPIO_StructInit\r
220 * Description    : Fills each GPIO_InitStruct member with its default value.\r
221 * Input          : - GPIO_InitStruct : pointer to a GPIO_InitTypeDef structure\r
222 *                    which will be initialized.\r
223 * Output         : None\r
224 * Return         : None\r
225 *******************************************************************************/\r
226 void GPIO_StructInit(GPIO_InitTypeDef* GPIO_InitStruct)\r
227 {\r
228   /* Reset GPIO init structure parameters values */\r
229   GPIO_InitStruct->GPIO_Pin  = GPIO_Pin_All;\r
230   GPIO_InitStruct->GPIO_Speed = GPIO_Speed_2MHz;\r
231   GPIO_InitStruct->GPIO_Mode = GPIO_Mode_IN_FLOATING;\r
232 }\r
233 \r
234 /*******************************************************************************\r
235 * Function Name  : GPIO_ReadInputDataBit\r
236 * Description    : Reads the specified input port pin.\r
237 * Input          : - GPIOx: where x can be (A..G) to select the GPIO peripheral.\r
238 *                : - GPIO_Pin:  specifies the port bit to read.\r
239 *                    This parameter can be GPIO_Pin_x where x can be (0..15).\r
240 * Output         : None\r
241 * Return         : The input port pin value.\r
242 *******************************************************************************/\r
243 u8 GPIO_ReadInputDataBit(GPIO_TypeDef* GPIOx, u16 GPIO_Pin)\r
244 {\r
245   u8 bitstatus = 0x00;\r
246   \r
247   /* Check the parameters */\r
248   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));\r
249   assert_param(IS_GET_GPIO_PIN(GPIO_Pin)); \r
250   \r
251   if ((GPIOx->IDR & GPIO_Pin) != (u32)Bit_RESET)\r
252   {\r
253     bitstatus = (u8)Bit_SET;\r
254   }\r
255   else\r
256   {\r
257     bitstatus = (u8)Bit_RESET;\r
258   }\r
259   return bitstatus;\r
260 }\r
261 \r
262 /*******************************************************************************\r
263 * Function Name  : GPIO_ReadInputData\r
264 * Description    : Reads the specified GPIO input data port.\r
265 * Input          : - GPIOx: where x can be (A..G) to select the GPIO peripheral.\r
266 * Output         : None\r
267 * Return         : GPIO input data port value.\r
268 *******************************************************************************/\r
269 u16 GPIO_ReadInputData(GPIO_TypeDef* GPIOx)\r
270 {\r
271   /* Check the parameters */\r
272   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));\r
273   \r
274   return ((u16)GPIOx->IDR);\r
275 }\r
276 \r
277 /*******************************************************************************\r
278 * Function Name  : GPIO_ReadOutputDataBit\r
279 * Description    : Reads the specified output data port bit.\r
280 * Input          : - GPIOx: where x can be (A..G) to select the GPIO peripheral.\r
281 *                : - GPIO_Pin:  specifies the port bit to read.\r
282 *                    This parameter can be GPIO_Pin_x where x can be (0..15).\r
283 * Output         : None\r
284 * Return         : The output port pin value.\r
285 *******************************************************************************/\r
286 u8 GPIO_ReadOutputDataBit(GPIO_TypeDef* GPIOx, u16 GPIO_Pin)\r
287 {\r
288   u8 bitstatus = 0x00;\r
289 \r
290   /* Check the parameters */\r
291   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));\r
292   assert_param(IS_GET_GPIO_PIN(GPIO_Pin)); \r
293   \r
294   if ((GPIOx->ODR & GPIO_Pin) != (u32)Bit_RESET)\r
295   {\r
296     bitstatus = (u8)Bit_SET;\r
297   }\r
298   else\r
299   {\r
300     bitstatus = (u8)Bit_RESET;\r
301   }\r
302   return bitstatus;\r
303 }\r
304 \r
305 /*******************************************************************************\r
306 * Function Name  : GPIO_ReadOutputData\r
307 * Description    : Reads the specified GPIO output data port.\r
308 * Input          : - GPIOx: where x can be (A..G) to select the GPIO peripheral.\r
309 * Output         : None\r
310 * Return         : GPIO output data port value.\r
311 *******************************************************************************/\r
312 u16 GPIO_ReadOutputData(GPIO_TypeDef* GPIOx)\r
313 {\r
314   /* Check the parameters */\r
315   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));\r
316     \r
317   return ((u16)GPIOx->ODR);\r
318 }\r
319 \r
320 /*******************************************************************************\r
321 * Function Name  : GPIO_SetBits\r
322 * Description    : Sets the selected data port bits.\r
323 * Input          : - GPIOx: where x can be (A..G) to select the GPIO peripheral.\r
324 *                  - GPIO_Pin: specifies the port bits to be written.\r
325 *                    This parameter can be any combination of GPIO_Pin_x where \r
326 *                    x can be (0..15).\r
327 * Output         : None\r
328 * Return         : None\r
329 *******************************************************************************/\r
330 void GPIO_SetBits(GPIO_TypeDef* GPIOx, u16 GPIO_Pin)\r
331 {\r
332   /* Check the parameters */\r
333   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));\r
334   assert_param(IS_GPIO_PIN(GPIO_Pin));\r
335   \r
336   GPIOx->BSRR = GPIO_Pin;\r
337 }\r
338 \r
339 /*******************************************************************************\r
340 * Function Name  : GPIO_ResetBits\r
341 * Description    : Clears the selected data port bits.\r
342 * Input          : - GPIOx: where x can be (A..G) to select the GPIO peripheral.\r
343 *                  - GPIO_Pin: specifies the port bits to be written.\r
344 *                    This parameter can be any combination of GPIO_Pin_x where \r
345 *                    x can be (0..15).\r
346 * Output         : None\r
347 * Return         : None\r
348 *******************************************************************************/\r
349 void GPIO_ResetBits(GPIO_TypeDef* GPIOx, u16 GPIO_Pin)\r
350 {\r
351   /* Check the parameters */\r
352   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));\r
353   assert_param(IS_GPIO_PIN(GPIO_Pin));\r
354   \r
355   GPIOx->BRR = GPIO_Pin;\r
356 }\r
357 \r
358 /*******************************************************************************\r
359 * Function Name  : GPIO_WriteBit\r
360 * Description    : Sets or clears the selected data port bit.\r
361 * Input          : - GPIOx: where x can be (A..G) to select the GPIO peripheral.\r
362 *                  - GPIO_Pin: specifies the port bit to be written.\r
363 *                    This parameter can be one of GPIO_Pin_x where x can be (0..15).\r
364 *                  - BitVal: specifies the value to be written to the selected bit.\r
365 *                    This parameter can be one of the BitAction enum values:\r
366 *                       - Bit_RESET: to clear the port pin\r
367 *                       - Bit_SET: to set the port pin\r
368 * Output         : None\r
369 * Return         : None\r
370 *******************************************************************************/\r
371 void GPIO_WriteBit(GPIO_TypeDef* GPIOx, u16 GPIO_Pin, BitAction BitVal)\r
372 {\r
373   /* Check the parameters */\r
374   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));\r
375   assert_param(IS_GET_GPIO_PIN(GPIO_Pin));\r
376   assert_param(IS_GPIO_BIT_ACTION(BitVal)); \r
377   \r
378   if (BitVal != Bit_RESET)\r
379   {\r
380     GPIOx->BSRR = GPIO_Pin;\r
381   }\r
382   else\r
383   {\r
384     GPIOx->BRR = GPIO_Pin;\r
385   }\r
386 }\r
387 \r
388 /*******************************************************************************\r
389 * Function Name  : GPIO_Write\r
390 * Description    : Writes data to the specified GPIO data port.\r
391 * Input          : - GPIOx: where x can be (A..G) to select the GPIO peripheral.\r
392 *                  - PortVal: specifies the value to be written to the port output\r
393 *                    data register.\r
394 * Output         : None\r
395 * Return         : None\r
396 *******************************************************************************/\r
397 void GPIO_Write(GPIO_TypeDef* GPIOx, u16 PortVal)\r
398 {\r
399   /* Check the parameters */\r
400   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));\r
401   \r
402   GPIOx->ODR = PortVal;\r
403 }\r
404 \r
405 /*******************************************************************************\r
406 * Function Name  : GPIO_PinLockConfig\r
407 * Description    : Locks GPIO Pins configuration registers.\r
408 * Input          : - GPIOx: where x can be (A..G) to select the GPIO peripheral.\r
409 *                  - GPIO_Pin: specifies the port bit to be written.\r
410 *                    This parameter can be any combination of GPIO_Pin_x where \r
411 *                    x can be (0..15).\r
412 * Output         : None\r
413 * Return         : None\r
414 *******************************************************************************/\r
415 void GPIO_PinLockConfig(GPIO_TypeDef* GPIOx, u16 GPIO_Pin)\r
416 {\r
417   u32 tmp = 0x00010000;\r
418   \r
419   /* Check the parameters */\r
420   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));\r
421   assert_param(IS_GPIO_PIN(GPIO_Pin));\r
422   \r
423   tmp |= GPIO_Pin;\r
424   /* Set LCKK bit */\r
425   GPIOx->LCKR = tmp;\r
426   /* Reset LCKK bit */\r
427   GPIOx->LCKR =  GPIO_Pin;\r
428   /* Set LCKK bit */\r
429   GPIOx->LCKR = tmp;\r
430   /* Read LCKK bit*/\r
431   tmp = GPIOx->LCKR;\r
432   /* Read LCKK bit*/\r
433   tmp = GPIOx->LCKR;\r
434 }\r
435 \r
436 /*******************************************************************************\r
437 * Function Name  : GPIO_EventOutputConfig\r
438 * Description    : Selects the GPIO pin used as Event output.\r
439 * Input          : - GPIO_PortSource: selects the GPIO port to be used as source\r
440 *                    for Event output.\r
441 *                    This parameter can be GPIO_PortSourceGPIOx where x can be\r
442 *                    (A..E).\r
443 *                  - GPIO_PinSource: specifies the pin for the Event output.\r
444 *                    This parameter can be GPIO_PinSourcex where x can be (0..15).\r
445 * Output         : None\r
446 * Return         : None\r
447 *******************************************************************************/\r
448 void GPIO_EventOutputConfig(u8 GPIO_PortSource, u8 GPIO_PinSource)\r
449 {\r
450   u32 tmpreg = 0x00;\r
451 \r
452   /* Check the parameters */\r
453   assert_param(IS_GPIO_EVENTOUT_PORT_SOURCE(GPIO_PortSource));\r
454   assert_param(IS_GPIO_PIN_SOURCE(GPIO_PinSource));\r
455     \r
456   tmpreg = AFIO->EVCR;\r
457   /* Clear the PORT[6:4] and PIN[3:0] bits */\r
458   tmpreg &= EVCR_PORTPINCONFIG_MASK;\r
459   tmpreg |= (u32)GPIO_PortSource << 0x04;\r
460   tmpreg |= GPIO_PinSource;\r
461 \r
462   AFIO->EVCR = tmpreg;\r
463 }\r
464 \r
465 /*******************************************************************************\r
466 * Function Name  : GPIO_EventOutputCmd\r
467 * Description    : Enables or disables the Event Output.\r
468 * Input          : - NewState: new state of the Event output.\r
469 *                    This parameter can be: ENABLE or DISABLE.\r
470 * Output         : None\r
471 * Return         : None\r
472 *******************************************************************************/\r
473 void GPIO_EventOutputCmd(FunctionalState NewState)\r
474 {\r
475   /* Check the parameters */\r
476   assert_param(IS_FUNCTIONAL_STATE(NewState));\r
477   \r
478   *(vu32 *) EVCR_EVOE_BB = (u32)NewState;\r
479 }\r
480 \r
481 /*******************************************************************************\r
482 * Function Name  : GPIO_PinRemapConfig\r
483 * Description    : Changes the mapping of the specified pin.\r
484 * Input          : - GPIO_Remap: selects the pin to remap.\r
485 *                    This parameter can be one of the following values:\r
486 *                       - GPIO_Remap_SPI1\r
487 *                       - GPIO_Remap_I2C1\r
488 *                       - GPIO_Remap_USART1\r
489 *                       - GPIO_Remap_USART2\r
490 *                       - GPIO_PartialRemap_USART3\r
491 *                       - GPIO_FullRemap_USART3\r
492 *                       - GPIO_PartialRemap_TIM1\r
493 *                       - GPIO_FullRemap_TIM1\r
494 *                       - GPIO_PartialRemap1_TIM2\r
495 *                       - GPIO_PartialRemap2_TIM2\r
496 *                       - GPIO_FullRemap_TIM2\r
497 *                       - GPIO_PartialRemap_TIM3\r
498 *                       - GPIO_FullRemap_TIM3\r
499 *                       - GPIO_Remap_TIM4\r
500 *                       - GPIO_Remap1_CAN\r
501 *                       - GPIO_Remap2_CAN\r
502 *                       - GPIO_Remap_PD01\r
503 *                       - GPIO_Remap_TIM5CH4_LSI\r
504 *                       - GPIO_Remap_ADC1_ETRGINJ\r
505 *                       - GPIO_Remap_ADC1_ETRGREG\r
506 *                       - GPIO_Remap_ADC2_ETRGINJ\r
507 *                       - GPIO_Remap_ADC2_ETRGREG\r
508 *                       - GPIO_Remap_SWJ_NoJTRST\r
509 *                       - GPIO_Remap_SWJ_JTAGDisable\r
510 *                       - GPIO_Remap_SWJ_Disable\r
511 *                  - NewState: new state of the port pin remapping.\r
512 *                    This parameter can be: ENABLE or DISABLE.\r
513 * Output         : None\r
514 * Return         : None\r
515 *******************************************************************************/\r
516 void GPIO_PinRemapConfig(u32 GPIO_Remap, FunctionalState NewState)\r
517 {\r
518   u32 tmp = 0x00, tmp1 = 0x00, tmpreg = 0x00, tmpmask = 0x00;\r
519 \r
520   /* Check the parameters */\r
521   assert_param(IS_GPIO_REMAP(GPIO_Remap));\r
522   assert_param(IS_FUNCTIONAL_STATE(NewState));  \r
523   \r
524   tmpreg = AFIO->MAPR;\r
525 \r
526   tmpmask = (GPIO_Remap & DBGAFR_POSITION_MASK) >> 0x10;\r
527   tmp = GPIO_Remap & LSB_MASK;\r
528 \r
529   if ((GPIO_Remap & (DBGAFR_LOCATION_MASK | DBGAFR_NUMBITS_MASK)) == (DBGAFR_LOCATION_MASK | DBGAFR_NUMBITS_MASK))\r
530   {\r
531     tmpreg &= DBGAFR_SWJCFG_MASK;\r
532     AFIO->MAPR &= DBGAFR_SWJCFG_MASK;\r
533   }\r
534   else if ((GPIO_Remap & DBGAFR_NUMBITS_MASK) == DBGAFR_NUMBITS_MASK)\r
535   {\r
536     tmp1 = ((u32)0x03) << tmpmask;\r
537     tmpreg &= ~tmp1;\r
538     tmpreg |= ~DBGAFR_SWJCFG_MASK;\r
539   }\r
540   else\r
541   {\r
542     tmpreg &= ~(tmp << ((GPIO_Remap >> 0x15)*0x10));\r
543     tmpreg |= ~DBGAFR_SWJCFG_MASK;\r
544   }\r
545 \r
546   if (NewState != DISABLE)\r
547   {\r
548     tmpreg |= (tmp << ((GPIO_Remap >> 0x15)*0x10));\r
549   }\r
550 \r
551   AFIO->MAPR = tmpreg;\r
552 }\r
553 \r
554 /*******************************************************************************\r
555 * Function Name  : GPIO_EXTILineConfig\r
556 * Description    : Selects the GPIO pin used as EXTI Line.\r
557 * Input          : - GPIO_PortSource: selects the GPIO port to be used as\r
558 *                    source for EXTI lines.\r
559 *                    This parameter can be GPIO_PortSourceGPIOx where x can be\r
560 *                    (A..G).\r
561 *                  - GPIO_PinSource: specifies the EXTI line to be configured.\r
562 *                   This parameter can be GPIO_PinSourcex where x can be (0..15).\r
563 * Output         : None\r
564 * Return         : None\r
565 *******************************************************************************/\r
566 void GPIO_EXTILineConfig(u8 GPIO_PortSource, u8 GPIO_PinSource)\r
567 {\r
568   u32 tmp = 0x00;\r
569 \r
570   /* Check the parameters */\r
571   assert_param(IS_GPIO_EXTI_PORT_SOURCE(GPIO_PortSource));\r
572   assert_param(IS_GPIO_PIN_SOURCE(GPIO_PinSource));\r
573   \r
574   tmp = ((u32)0x0F) << (0x04 * (GPIO_PinSource & (u8)0x03));\r
575 \r
576   AFIO->EXTICR[GPIO_PinSource >> 0x02] &= ~tmp;\r
577   AFIO->EXTICR[GPIO_PinSource >> 0x02] |= (((u32)GPIO_PortSource) << (0x04 * (GPIO_PinSource & (u8)0x03)));\r
578 }\r
579 \r
580 /******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/\r