OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [CORTEX_STM32F103_GCC_Rowley/] [ST Library/] [src/] [stm32f10x_gpio.c] - Blame information for rev 582

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.