1 |
582 |
jeremybenn |
/**
|
2 |
|
|
******************************************************************************
|
3 |
|
|
* @file stm32l1xx_gpio.c
|
4 |
|
|
* @author MCD Application Team
|
5 |
|
|
* @version V1.0.0RC1
|
6 |
|
|
* @date 07/02/2010
|
7 |
|
|
* @brief This file provides all the GPIO firmware functions.
|
8 |
|
|
******************************************************************************
|
9 |
|
|
* @copy
|
10 |
|
|
*
|
11 |
|
|
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
|
12 |
|
|
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
|
13 |
|
|
* TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
|
14 |
|
|
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
|
15 |
|
|
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
|
16 |
|
|
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
|
17 |
|
|
*
|
18 |
|
|
* <h2><center>© COPYRIGHT 2010 STMicroelectronics</center></h2>
|
19 |
|
|
*/
|
20 |
|
|
|
21 |
|
|
/* Includes ------------------------------------------------------------------*/
|
22 |
|
|
#include "stm32l1xx_gpio.h"
|
23 |
|
|
#include "stm32l1xx_rcc.h"
|
24 |
|
|
|
25 |
|
|
/** @addtogroup STM32L1xx_StdPeriph_Driver
|
26 |
|
|
* @{
|
27 |
|
|
*/
|
28 |
|
|
|
29 |
|
|
/** @defgroup GPIO
|
30 |
|
|
* @brief GPIO driver modules
|
31 |
|
|
* @{
|
32 |
|
|
*/
|
33 |
|
|
|
34 |
|
|
/** @defgroup GPIO_Private_TypesDefinitions
|
35 |
|
|
* @{
|
36 |
|
|
*/
|
37 |
|
|
|
38 |
|
|
/**
|
39 |
|
|
* @}
|
40 |
|
|
*/
|
41 |
|
|
|
42 |
|
|
/** @defgroup GPIO_Private_Defines
|
43 |
|
|
* @{
|
44 |
|
|
*/
|
45 |
|
|
|
46 |
|
|
/**
|
47 |
|
|
* @}
|
48 |
|
|
*/
|
49 |
|
|
|
50 |
|
|
/** @defgroup GPIO_Private_Macros
|
51 |
|
|
* @{
|
52 |
|
|
*/
|
53 |
|
|
/**
|
54 |
|
|
* @}
|
55 |
|
|
*/
|
56 |
|
|
|
57 |
|
|
/** @defgroup GPIO_Private_Variables
|
58 |
|
|
* @{
|
59 |
|
|
*/
|
60 |
|
|
/**
|
61 |
|
|
* @}
|
62 |
|
|
*/
|
63 |
|
|
|
64 |
|
|
/** @defgroup GPIO_Private_FunctionPrototypes
|
65 |
|
|
* @{
|
66 |
|
|
*/
|
67 |
|
|
/**
|
68 |
|
|
* @}
|
69 |
|
|
*/
|
70 |
|
|
|
71 |
|
|
/** @defgroup GPIO_Private_Functions
|
72 |
|
|
* @{
|
73 |
|
|
*/
|
74 |
|
|
|
75 |
|
|
/**
|
76 |
|
|
* @brief Deinitializes the GPIOx peripheral registers to their default reset
|
77 |
|
|
* values.
|
78 |
|
|
* @param GPIOx: where x can be (A, B, C, D, E or H) to select the GPIO peripheral.
|
79 |
|
|
* @retval None
|
80 |
|
|
*/
|
81 |
|
|
void GPIO_DeInit(GPIO_TypeDef* GPIOx)
|
82 |
|
|
{
|
83 |
|
|
/* Check the parameters */
|
84 |
|
|
assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
|
85 |
|
|
|
86 |
|
|
if(GPIOx == GPIOA)
|
87 |
|
|
{
|
88 |
|
|
RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOA, ENABLE);
|
89 |
|
|
RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOA, DISABLE);
|
90 |
|
|
}
|
91 |
|
|
else if(GPIOx == GPIOB)
|
92 |
|
|
{
|
93 |
|
|
RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOB, ENABLE);
|
94 |
|
|
RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOB, DISABLE);
|
95 |
|
|
}
|
96 |
|
|
else if(GPIOx == GPIOC)
|
97 |
|
|
{
|
98 |
|
|
RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOC, ENABLE);
|
99 |
|
|
RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOC, DISABLE);
|
100 |
|
|
}
|
101 |
|
|
else if(GPIOx == GPIOD)
|
102 |
|
|
{
|
103 |
|
|
RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOD, ENABLE);
|
104 |
|
|
RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOD, DISABLE);
|
105 |
|
|
}
|
106 |
|
|
else if(GPIOx == GPIOE)
|
107 |
|
|
{
|
108 |
|
|
RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOE, ENABLE);
|
109 |
|
|
RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOE, DISABLE);
|
110 |
|
|
}
|
111 |
|
|
else
|
112 |
|
|
{
|
113 |
|
|
if(GPIOx == GPIOH)
|
114 |
|
|
{
|
115 |
|
|
RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOH, ENABLE);
|
116 |
|
|
RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOH, DISABLE);
|
117 |
|
|
}
|
118 |
|
|
}
|
119 |
|
|
}
|
120 |
|
|
|
121 |
|
|
/**
|
122 |
|
|
* @brief Initializes the GPIOx peripheral according to the specified
|
123 |
|
|
* parameters in the GPIO_InitStruct.
|
124 |
|
|
* @param GPIOx: where x can be (A, B, C, D, E or H) to select the GPIO peripheral.
|
125 |
|
|
* @param GPIO_InitStruct: pointer to a GPIO_InitTypeDef structure that
|
126 |
|
|
* contains the configuration information for the specified GPIO
|
127 |
|
|
* peripheral.
|
128 |
|
|
* @retval None
|
129 |
|
|
*/
|
130 |
|
|
void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct)
|
131 |
|
|
{
|
132 |
|
|
uint32_t pinpos = 0x00, pos = 0x00 , currentpin = 0x00;
|
133 |
|
|
|
134 |
|
|
/* Check the parameters */
|
135 |
|
|
assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
|
136 |
|
|
assert_param(IS_GPIO_PIN(GPIO_InitStruct->GPIO_Pin));
|
137 |
|
|
assert_param(IS_GPIO_MODE(GPIO_InitStruct->GPIO_Mode));
|
138 |
|
|
assert_param(IS_GPIO_PUPD(GPIO_InitStruct->GPIO_PuPd));
|
139 |
|
|
|
140 |
|
|
/* -------------------------Configure the port pins---------------- */
|
141 |
|
|
/*-- GPIO Mode Configuration --*/
|
142 |
|
|
for (pinpos = 0x00; pinpos < 0x10; pinpos++)
|
143 |
|
|
{
|
144 |
|
|
pos = ((uint32_t)0x01) << pinpos;
|
145 |
|
|
|
146 |
|
|
/* Get the port pins position */
|
147 |
|
|
currentpin = (GPIO_InitStruct->GPIO_Pin) & pos;
|
148 |
|
|
|
149 |
|
|
if (currentpin == pos)
|
150 |
|
|
{
|
151 |
|
|
GPIOx->MODER &= ~(GPIO_MODER_MODER0 << (pinpos * 2));
|
152 |
|
|
|
153 |
|
|
GPIOx->MODER |= (((uint32_t)GPIO_InitStruct->GPIO_Mode) << (pinpos * 2));
|
154 |
|
|
|
155 |
|
|
if ((GPIO_InitStruct->GPIO_Mode == GPIO_Mode_OUT) || (GPIO_InitStruct->GPIO_Mode == GPIO_Mode_AF))
|
156 |
|
|
{
|
157 |
|
|
/*Check Speed mode parameters */
|
158 |
|
|
assert_param(IS_GPIO_SPEED(GPIO_InitStruct->GPIO_Speed));
|
159 |
|
|
|
160 |
|
|
/*Speed mode configuration */
|
161 |
|
|
GPIOx->OSPEEDR &= ~(GPIO_OSPEEDER_OSPEEDR0 << (pinpos * 2));
|
162 |
|
|
GPIOx->OSPEEDR |= ((uint32_t)(GPIO_InitStruct->GPIO_Speed) << (pinpos * 2));
|
163 |
|
|
|
164 |
|
|
/*Check Output mode parameters */
|
165 |
|
|
assert_param(IS_GPIO_OTYPE(GPIO_InitStruct->GPIO_OType));
|
166 |
|
|
|
167 |
|
|
/* Output mode configuartion*/
|
168 |
|
|
GPIOx->OTYPER &= ~((GPIO_OTYPER_OT_0) << ((uint16_t)pinpos)) ;
|
169 |
|
|
GPIOx->OTYPER |= (uint16_t)(((uint16_t)GPIO_InitStruct->GPIO_OType) << ((uint16_t)pinpos));
|
170 |
|
|
}
|
171 |
|
|
|
172 |
|
|
/*Pull-up Pull down resistor configuration*/
|
173 |
|
|
GPIOx->PUPDR &= ~(GPIO_PUPDR_PUPDR0 << ((uint16_t)pinpos * 2));
|
174 |
|
|
GPIOx->PUPDR |= (((uint32_t)GPIO_InitStruct->GPIO_PuPd) << (pinpos * 2));
|
175 |
|
|
}
|
176 |
|
|
}
|
177 |
|
|
}
|
178 |
|
|
|
179 |
|
|
/**
|
180 |
|
|
* @brief Fills each GPIO_InitStruct member with its default value.
|
181 |
|
|
* @param GPIO_InitStruct : pointer to a GPIO_InitTypeDef structure which will
|
182 |
|
|
* be initialized.
|
183 |
|
|
* @retval None
|
184 |
|
|
*/
|
185 |
|
|
void GPIO_StructInit(GPIO_InitTypeDef* GPIO_InitStruct)
|
186 |
|
|
{
|
187 |
|
|
/* Reset GPIO init structure parameters values */
|
188 |
|
|
GPIO_InitStruct->GPIO_Pin = GPIO_Pin_All;
|
189 |
|
|
GPIO_InitStruct->GPIO_Mode = GPIO_Mode_IN;
|
190 |
|
|
GPIO_InitStruct->GPIO_Speed = GPIO_Speed_400KHz;
|
191 |
|
|
GPIO_InitStruct->GPIO_OType = GPIO_OType_PP;
|
192 |
|
|
GPIO_InitStruct->GPIO_PuPd = GPIO_PuPd_NOPULL;
|
193 |
|
|
}
|
194 |
|
|
|
195 |
|
|
/**
|
196 |
|
|
* @brief Reads the specified input port pin.
|
197 |
|
|
* @param GPIOx: where x can be (A, B, C, D, E or H) to select the GPIO peripheral.
|
198 |
|
|
* @param GPIO_Pin: specifies the port bit to read.
|
199 |
|
|
* This parameter can be GPIO_Pin_x where x can be (0..15).
|
200 |
|
|
* @retval The input port pin value.
|
201 |
|
|
*/
|
202 |
|
|
uint8_t GPIO_ReadInputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
|
203 |
|
|
{
|
204 |
|
|
uint8_t bitstatus = 0x00;
|
205 |
|
|
|
206 |
|
|
/* Check the parameters */
|
207 |
|
|
assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
|
208 |
|
|
assert_param(IS_GET_GPIO_PIN(GPIO_Pin));
|
209 |
|
|
|
210 |
|
|
if ((GPIOx->IDR & GPIO_Pin) != (uint32_t)Bit_RESET)
|
211 |
|
|
{
|
212 |
|
|
bitstatus = (uint8_t)Bit_SET;
|
213 |
|
|
}
|
214 |
|
|
else
|
215 |
|
|
{
|
216 |
|
|
bitstatus = (uint8_t)Bit_RESET;
|
217 |
|
|
}
|
218 |
|
|
return bitstatus;
|
219 |
|
|
}
|
220 |
|
|
|
221 |
|
|
/**
|
222 |
|
|
* @brief Reads the specified GPIO input data port.
|
223 |
|
|
* @param GPIOx: where x can be (A, B, C, D, E or H) to select the GPIO peripheral.
|
224 |
|
|
* @retval GPIO input data port value.
|
225 |
|
|
*/
|
226 |
|
|
uint16_t GPIO_ReadInputData(GPIO_TypeDef* GPIOx)
|
227 |
|
|
{
|
228 |
|
|
/* Check the parameters */
|
229 |
|
|
assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
|
230 |
|
|
|
231 |
|
|
return ((uint16_t)GPIOx->IDR);
|
232 |
|
|
}
|
233 |
|
|
|
234 |
|
|
/**
|
235 |
|
|
* @brief Reads the specified output data port bit.
|
236 |
|
|
* @param GPIOx: where x can be (A, B, C, D, E or H) to select the GPIO peripheral.
|
237 |
|
|
* @param GPIO_Pin: Specifies the port bit to read.
|
238 |
|
|
* This parameter can be GPIO_Pin_x where x can be (0..15).
|
239 |
|
|
* @retval The output port pin value.
|
240 |
|
|
*/
|
241 |
|
|
uint8_t GPIO_ReadOutputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
|
242 |
|
|
{
|
243 |
|
|
uint8_t bitstatus = 0x00;
|
244 |
|
|
|
245 |
|
|
/* Check the parameters */
|
246 |
|
|
assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
|
247 |
|
|
assert_param(IS_GET_GPIO_PIN(GPIO_Pin));
|
248 |
|
|
|
249 |
|
|
if ((GPIOx->ODR & GPIO_Pin) != (uint32_t)Bit_RESET)
|
250 |
|
|
{
|
251 |
|
|
bitstatus = (uint8_t)Bit_SET;
|
252 |
|
|
}
|
253 |
|
|
else
|
254 |
|
|
{
|
255 |
|
|
bitstatus = (uint8_t)Bit_RESET;
|
256 |
|
|
}
|
257 |
|
|
return bitstatus;
|
258 |
|
|
}
|
259 |
|
|
|
260 |
|
|
/**
|
261 |
|
|
* @brief Reads the specified GPIO output data port.
|
262 |
|
|
* @param GPIOx: where x can be (A, B, C, D, E or H) to select the GPIO peripheral.
|
263 |
|
|
* @retval GPIO output data port value.
|
264 |
|
|
*/
|
265 |
|
|
uint16_t GPIO_ReadOutputData(GPIO_TypeDef* GPIOx)
|
266 |
|
|
{
|
267 |
|
|
/* Check the parameters */
|
268 |
|
|
assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
|
269 |
|
|
|
270 |
|
|
return ((uint16_t)GPIOx->ODR);
|
271 |
|
|
}
|
272 |
|
|
|
273 |
|
|
/**
|
274 |
|
|
* @brief Sets the selected data port bits.
|
275 |
|
|
* @param GPIOx: where x can be (A, B, C, D, E or H) to select the GPIO peripheral.
|
276 |
|
|
* @param GPIO_Pin: specifies the port bits to be written.
|
277 |
|
|
* This parameter can be any combination of GPIO_Pin_x where x can be (0..15).
|
278 |
|
|
* @retval None
|
279 |
|
|
*/
|
280 |
|
|
void GPIO_SetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
|
281 |
|
|
{
|
282 |
|
|
/* Check the parameters */
|
283 |
|
|
assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
|
284 |
|
|
assert_param(IS_GPIO_PIN(GPIO_Pin));
|
285 |
|
|
|
286 |
|
|
GPIOx->BSRRL = GPIO_Pin;
|
287 |
|
|
}
|
288 |
|
|
|
289 |
|
|
/**
|
290 |
|
|
* @brief Clears the selected data port bits.
|
291 |
|
|
* @param GPIOx: where x can be (A, B, C, D, E or H) to select the GPIO peripheral.
|
292 |
|
|
* @param GPIO_Pin: specifies the port bits to be written.
|
293 |
|
|
* This parameter can be any combination of GPIO_Pin_x where x can be (0..15).
|
294 |
|
|
* @retval None
|
295 |
|
|
*/
|
296 |
|
|
void GPIO_ResetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
|
297 |
|
|
{
|
298 |
|
|
/* Check the parameters */
|
299 |
|
|
assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
|
300 |
|
|
assert_param(IS_GPIO_PIN(GPIO_Pin));
|
301 |
|
|
|
302 |
|
|
GPIOx->BSRRH = GPIO_Pin;
|
303 |
|
|
}
|
304 |
|
|
|
305 |
|
|
/**
|
306 |
|
|
* @brief Sets or clears the selected data port bit.
|
307 |
|
|
* @param GPIOx: where x can be (A, B, C, D, E or H) to select the GPIO peripheral.
|
308 |
|
|
* @param GPIO_Pin: specifies the port bit to be written.
|
309 |
|
|
* This parameter can be one of GPIO_Pin_x where x can be (0..15).
|
310 |
|
|
* @param BitVal: specifies the value to be written to the selected bit.
|
311 |
|
|
* This parameter can be one of the BitAction enum values:
|
312 |
|
|
* @arg Bit_RESET: to clear the port pin
|
313 |
|
|
* @arg Bit_SET: to set the port pin
|
314 |
|
|
* @retval None
|
315 |
|
|
*/
|
316 |
|
|
void GPIO_WriteBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, BitAction BitVal)
|
317 |
|
|
{
|
318 |
|
|
/* Check the parameters */
|
319 |
|
|
assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
|
320 |
|
|
assert_param(IS_GET_GPIO_PIN(GPIO_Pin));
|
321 |
|
|
assert_param(IS_GPIO_BIT_ACTION(BitVal));
|
322 |
|
|
|
323 |
|
|
if (BitVal != Bit_RESET)
|
324 |
|
|
{
|
325 |
|
|
GPIOx->BSRRL = GPIO_Pin;
|
326 |
|
|
}
|
327 |
|
|
else
|
328 |
|
|
{
|
329 |
|
|
GPIOx->BSRRH = GPIO_Pin ;
|
330 |
|
|
}
|
331 |
|
|
}
|
332 |
|
|
|
333 |
|
|
/**
|
334 |
|
|
* @brief Writes data to the specified GPIO data port.
|
335 |
|
|
* @param GPIOx: where x can be (A, B, C, D, E or H) to select the GPIO peripheral.
|
336 |
|
|
* @param PortVal: specifies the value to be written to the port output data
|
337 |
|
|
* register.
|
338 |
|
|
* @retval None
|
339 |
|
|
*/
|
340 |
|
|
void GPIO_Write(GPIO_TypeDef* GPIOx, uint16_t PortVal)
|
341 |
|
|
{
|
342 |
|
|
/* Check the parameters */
|
343 |
|
|
assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
|
344 |
|
|
|
345 |
|
|
GPIOx->ODR = PortVal;
|
346 |
|
|
}
|
347 |
|
|
|
348 |
|
|
/**
|
349 |
|
|
* @brief Locks GPIO Pins configuration registers.
|
350 |
|
|
* @param GPIOx: where x can be (A, B, C, D, E or H) to select the GPIO peripheral.
|
351 |
|
|
* @param GPIO_Pin: specifies the port bit to be written.
|
352 |
|
|
* This parameter can be any combination of GPIO_Pin_x where x can be (0..15).
|
353 |
|
|
* @retval None
|
354 |
|
|
*/
|
355 |
|
|
void GPIO_PinLockConfig(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
|
356 |
|
|
{
|
357 |
|
|
uint32_t tmp = 0x00010000;
|
358 |
|
|
|
359 |
|
|
/* Check the parameters */
|
360 |
|
|
assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
|
361 |
|
|
assert_param(IS_GPIO_PIN(GPIO_Pin));
|
362 |
|
|
|
363 |
|
|
tmp |= GPIO_Pin;
|
364 |
|
|
/* Set LCKK bit */
|
365 |
|
|
GPIOx->LCKR = tmp;
|
366 |
|
|
/* Reset LCKK bit */
|
367 |
|
|
GPIOx->LCKR = GPIO_Pin;
|
368 |
|
|
/* Set LCKK bit */
|
369 |
|
|
GPIOx->LCKR = tmp;
|
370 |
|
|
/* Read LCKK bit*/
|
371 |
|
|
tmp = GPIOx->LCKR;
|
372 |
|
|
/* Read LCKK bit*/
|
373 |
|
|
tmp = GPIOx->LCKR;
|
374 |
|
|
}
|
375 |
|
|
|
376 |
|
|
/**
|
377 |
|
|
* @brief Changes the mapping of the specified pin.
|
378 |
|
|
* @param GPIOx: where x can be (A, B, C, D, E or H) to select the GPIO peripheral.
|
379 |
|
|
* @param GPIO_PinSource: specifies the pin for the Alternate function.
|
380 |
|
|
* This parameter can be GPIO_PinSourcex where x can be (0..15).
|
381 |
|
|
* @param GPIO_AFSelection: selects the pin to used as Alternat function.
|
382 |
|
|
* This parameter can be one of the following values:
|
383 |
|
|
* @arg GPIO_AF_RTC_50Hz
|
384 |
|
|
* @arg GPIO_AF_MCO
|
385 |
|
|
* @arg GPIO_AF_TAMPER
|
386 |
|
|
* @arg GPIO_AF_WKUP
|
387 |
|
|
* @arg GPIO_AF_SWJ
|
388 |
|
|
* @arg GPIO_AF_TRACE
|
389 |
|
|
* @arg GPIO_AF_TIMESTAMP
|
390 |
|
|
* @arg GPIO_AF_CALIB
|
391 |
|
|
* @arg GPIO_AF_TIM2
|
392 |
|
|
* @arg GPIO_AF_TIM3
|
393 |
|
|
* @arg GPIO_AF_TIM4
|
394 |
|
|
* @arg GPIO_AF_TIM9
|
395 |
|
|
* @arg GPIO_AF_TIM10
|
396 |
|
|
* @arg GPIO_AF_TIM11
|
397 |
|
|
* @arg GPIO_AF_I2C1
|
398 |
|
|
* @arg GPIO_AF_I2C2
|
399 |
|
|
* @arg GPIO_AF_SPI1
|
400 |
|
|
* @arg GPIO_AF_SPI2
|
401 |
|
|
* @arg GPIO_AF_USART1
|
402 |
|
|
* @arg GPIO_AF_USART2
|
403 |
|
|
* @arg GPIO_AF_USART3
|
404 |
|
|
* @arg GPIO_AF_USB
|
405 |
|
|
* @arg GPIO_AF_LCD
|
406 |
|
|
* @arg GPIO_AF_RI
|
407 |
|
|
* @arg GPIO_AF_EVENTOUT
|
408 |
|
|
* @retval None
|
409 |
|
|
*/
|
410 |
|
|
void GPIO_PinAFConfig(GPIO_TypeDef* GPIOx, uint16_t GPIO_PinSource, uint8_t GPIO_AF)
|
411 |
|
|
{
|
412 |
|
|
uint32_t temp = 0x00;
|
413 |
|
|
uint32_t temp_2 = 0x00;
|
414 |
|
|
|
415 |
|
|
/* Check the parameters */
|
416 |
|
|
assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
|
417 |
|
|
assert_param(IS_GPIO_PIN_SOURCE(GPIO_PinSource));
|
418 |
|
|
assert_param(IS_GPIO_AF(GPIO_AF));
|
419 |
|
|
|
420 |
|
|
temp = ((uint32_t)(GPIO_AF) << ((uint32_t)((uint32_t)GPIO_PinSource & (uint32_t)0x07) * 4)) ;
|
421 |
|
|
GPIOx->AFR[GPIO_PinSource >> 0x03] &= ~((uint32_t)0xF << ((uint32_t)((uint32_t)GPIO_PinSource & (uint32_t)0x07) * 4)) ;
|
422 |
|
|
temp_2 = GPIOx->AFR[GPIO_PinSource >> 0x03] | temp;
|
423 |
|
|
GPIOx->AFR[GPIO_PinSource >> 0x03] = temp_2;
|
424 |
|
|
}
|
425 |
|
|
|
426 |
|
|
/**
|
427 |
|
|
* @}
|
428 |
|
|
*/
|
429 |
|
|
|
430 |
|
|
/**
|
431 |
|
|
* @}
|
432 |
|
|
*/
|
433 |
|
|
|
434 |
|
|
/**
|
435 |
|
|
* @}
|
436 |
|
|
*/
|
437 |
|
|
/******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/
|