You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

585 regels
21 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_gpio.c
  4. * @author MCD Application Team
  5. * @version V1.1.0
  6. * @date 11-January-2013
  7. * @brief This file provides firmware functions to manage the following
  8. * functionalities of the GPIO peripheral:
  9. * + Initialization and Configuration
  10. * + GPIO Read and Write
  11. * + GPIO Alternate functions configuration
  12. *
  13. @verbatim
  14. ===============================================================================
  15. ##### How to use this driver #####
  16. ===============================================================================
  17. [..]
  18. (#) Enable the GPIO AHB clock using the following function
  19. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOx, ENABLE);
  20. (#) Configure the GPIO pin(s) using GPIO_Init()
  21. Four possible configuration are available for each pin:
  22. (++) Input: Floating, Pull-up, Pull-down.
  23. (++) Output: Push-Pull (Pull-up, Pull-down or no Pull)
  24. Open Drain (Pull-up, Pull-down or no Pull). In output mode, the speed
  25. is configurable: 2 MHz, 25 MHz, 50 MHz or 100 MHz.
  26. (++) Alternate Function: Push-Pull (Pull-up, Pull-down or no Pull) Open
  27. Drain (Pull-up, Pull-down or no Pull).
  28. (++) Analog: required mode when a pin is to be used as ADC channel or DAC
  29. output.
  30. (#) Peripherals alternate function:
  31. (++) For ADC and DAC, configure the desired pin in analog mode using
  32. GPIO_InitStruct->GPIO_Mode = GPIO_Mode_AN;
  33. (+++) For other peripherals (TIM, USART...):
  34. (+++) Connect the pin to the desired peripherals' Alternate
  35. Function (AF) using GPIO_PinAFConfig() function
  36. (+++) Configure the desired pin in alternate function mode using
  37. GPIO_InitStruct->GPIO_Mode = GPIO_Mode_AF
  38. (+++) Select the type, pull-up/pull-down and output speed via
  39. GPIO_PuPd, GPIO_OType and GPIO_Speed members
  40. (+++) Call GPIO_Init() function
  41. (#) To get the level of a pin configured in input mode use GPIO_ReadInputDataBit()
  42. (#) To set/reset the level of a pin configured in output mode use
  43. GPIO_SetBits()/GPIO_ResetBits()
  44. (#) During and just after reset, the alternate functions are not
  45. active and the GPIO pins are configured in input floating mode (except JTAG
  46. pins).
  47. (#) The LSE oscillator pins OSC32_IN and OSC32_OUT can be used as general purpose
  48. (PC14 and PC15, respectively) when the LSE oscillator is off. The LSE has
  49. priority over the GPIO function.
  50. (#) The HSE oscillator pins OSC_IN/OSC_OUT can be used as
  51. general purpose PH0 and PH1, respectively, when the HSE oscillator is off.
  52. The HSE has priority over the GPIO function.
  53. @endverbatim
  54. *
  55. ******************************************************************************
  56. * @attention
  57. *
  58. * <h2><center>&copy; COPYRIGHT 2013 STMicroelectronics</center></h2>
  59. *
  60. * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  61. * You may not use this file except in compliance with the License.
  62. * You may obtain a copy of the License at:
  63. *
  64. * http://www.st.com/software_license_agreement_liberty_v2
  65. *
  66. * Unless required by applicable law or agreed to in writing, software
  67. * distributed under the License is distributed on an "AS IS" BASIS,
  68. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  69. * See the License for the specific language governing permissions and
  70. * limitations under the License.
  71. *
  72. ******************************************************************************
  73. */
  74. /* Includes ------------------------------------------------------------------*/
  75. #include "stm32f4xx_gpio.h"
  76. #include "stm32f4xx_rcc.h"
  77. /** @addtogroup STM32F4xx_StdPeriph_Driver
  78. * @{
  79. */
  80. /** @defgroup GPIO
  81. * @brief GPIO driver modules
  82. * @{
  83. */
  84. /* Private typedef -----------------------------------------------------------*/
  85. /* Private define ------------------------------------------------------------*/
  86. /* Private macro -------------------------------------------------------------*/
  87. /* Private variables ---------------------------------------------------------*/
  88. /* Private function prototypes -----------------------------------------------*/
  89. /* Private functions ---------------------------------------------------------*/
  90. /** @defgroup GPIO_Private_Functions
  91. * @{
  92. */
  93. /** @defgroup GPIO_Group1 Initialization and Configuration
  94. * @brief Initialization and Configuration
  95. *
  96. @verbatim
  97. ===============================================================================
  98. ##### Initialization and Configuration #####
  99. ===============================================================================
  100. @endverbatim
  101. * @{
  102. */
  103. /**
  104. * @brief De-initializes the GPIOx peripheral registers to their default reset values.
  105. * @note By default, The GPIO pins are configured in input floating mode (except JTAG pins).
  106. * @param GPIOx: where x can be (A..I) to select the GPIO peripheral for
  107. * STM32F40xx/41xx and STM32F427x/437x devices.
  108. * @retval None
  109. */
  110. void GPIO_DeInit(GPIO_TypeDef* GPIOx)
  111. {
  112. /* Check the parameters */
  113. assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
  114. if (GPIOx == GPIOA)
  115. {
  116. RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_GPIOA, ENABLE);
  117. RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_GPIOA, DISABLE);
  118. }
  119. else if (GPIOx == GPIOB)
  120. {
  121. RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_GPIOB, ENABLE);
  122. RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_GPIOB, DISABLE);
  123. }
  124. else if (GPIOx == GPIOC)
  125. {
  126. RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_GPIOC, ENABLE);
  127. RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_GPIOC, DISABLE);
  128. }
  129. else if (GPIOx == GPIOD)
  130. {
  131. RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_GPIOD, ENABLE);
  132. RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_GPIOD, DISABLE);
  133. }
  134. else if (GPIOx == GPIOE)
  135. {
  136. RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_GPIOE, ENABLE);
  137. RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_GPIOE, DISABLE);
  138. }
  139. else if (GPIOx == GPIOF)
  140. {
  141. RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_GPIOF, ENABLE);
  142. RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_GPIOF, DISABLE);
  143. }
  144. else if (GPIOx == GPIOG)
  145. {
  146. RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_GPIOG, ENABLE);
  147. RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_GPIOG, DISABLE);
  148. }
  149. else if (GPIOx == GPIOH)
  150. {
  151. RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_GPIOH, ENABLE);
  152. RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_GPIOH, DISABLE);
  153. }
  154. else
  155. {
  156. if (GPIOx == GPIOI)
  157. {
  158. RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_GPIOI, ENABLE);
  159. RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_GPIOI, DISABLE);
  160. }
  161. }
  162. }
  163. /**
  164. * @brief Initializes the GPIOx peripheral according to the specified parameters in the GPIO_InitStruct.
  165. * @param GPIOx: where x can be (A..I) to select the GPIO peripheral for
  166. * STM32F40xx/41xx and STM32F427x/437x devices.
  167. * @param GPIO_InitStruct: pointer to a GPIO_InitTypeDef structure that contains
  168. * the configuration information for the specified GPIO peripheral.
  169. * @retval None
  170. */
  171. void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct)
  172. {
  173. uint32_t pinpos = 0x00, pos = 0x00 , currentpin = 0x00;
  174. /* Check the parameters */
  175. assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
  176. assert_param(IS_GPIO_PIN(GPIO_InitStruct->GPIO_Pin));
  177. assert_param(IS_GPIO_MODE(GPIO_InitStruct->GPIO_Mode));
  178. assert_param(IS_GPIO_PUPD(GPIO_InitStruct->GPIO_PuPd));
  179. /* ------------------------- Configure the port pins ---------------- */
  180. /*-- GPIO Mode Configuration --*/
  181. for (pinpos = 0x00; pinpos < 0x10; pinpos++)
  182. {
  183. pos = ((uint32_t)0x01) << pinpos;
  184. /* Get the port pins position */
  185. currentpin = (GPIO_InitStruct->GPIO_Pin) & pos;
  186. if (currentpin == pos)
  187. {
  188. GPIOx->MODER &= ~(GPIO_MODER_MODER0 << (pinpos * 2));
  189. GPIOx->MODER |= (((uint32_t)GPIO_InitStruct->GPIO_Mode) << (pinpos * 2));
  190. if ((GPIO_InitStruct->GPIO_Mode == GPIO_Mode_OUT) || (GPIO_InitStruct->GPIO_Mode == GPIO_Mode_AF))
  191. {
  192. /* Check Speed mode parameters */
  193. assert_param(IS_GPIO_SPEED(GPIO_InitStruct->GPIO_Speed));
  194. /* Speed mode configuration */
  195. GPIOx->OSPEEDR &= ~(GPIO_OSPEEDER_OSPEEDR0 << (pinpos * 2));
  196. GPIOx->OSPEEDR |= ((uint32_t)(GPIO_InitStruct->GPIO_Speed) << (pinpos * 2));
  197. /* Check Output mode parameters */
  198. assert_param(IS_GPIO_OTYPE(GPIO_InitStruct->GPIO_OType));
  199. /* Output mode configuration*/
  200. GPIOx->OTYPER &= ~((GPIO_OTYPER_OT_0) << ((uint16_t)pinpos)) ;
  201. GPIOx->OTYPER |= (uint16_t)(((uint16_t)GPIO_InitStruct->GPIO_OType) << ((uint16_t)pinpos));
  202. }
  203. /* Pull-up Pull down resistor configuration*/
  204. GPIOx->PUPDR &= ~(GPIO_PUPDR_PUPDR0 << ((uint16_t)pinpos * 2));
  205. GPIOx->PUPDR |= (((uint32_t)GPIO_InitStruct->GPIO_PuPd) << (pinpos * 2));
  206. }
  207. }
  208. }
  209. /**
  210. * @brief Fills each GPIO_InitStruct member with its default value.
  211. * @param GPIO_InitStruct : pointer to a GPIO_InitTypeDef structure which will be initialized.
  212. * @retval None
  213. */
  214. void GPIO_StructInit(GPIO_InitTypeDef* GPIO_InitStruct)
  215. {
  216. /* Reset GPIO init structure parameters values */
  217. GPIO_InitStruct->GPIO_Pin = GPIO_Pin_All;
  218. GPIO_InitStruct->GPIO_Mode = GPIO_Mode_IN;
  219. GPIO_InitStruct->GPIO_Speed = GPIO_Speed_2MHz;
  220. GPIO_InitStruct->GPIO_OType = GPIO_OType_PP;
  221. GPIO_InitStruct->GPIO_PuPd = GPIO_PuPd_NOPULL;
  222. }
  223. /**
  224. * @brief Locks GPIO Pins configuration registers.
  225. * @note The locked registers are GPIOx_MODER, GPIOx_OTYPER, GPIOx_OSPEEDR,
  226. * GPIOx_PUPDR, GPIOx_AFRL and GPIOx_AFRH.
  227. * @note The configuration of the locked GPIO pins can no longer be modified
  228. * until the next reset.
  229. * @param GPIOx: where x can be (A..I) to select the GPIO peripheral for
  230. * STM32F40xx/41xx and STM32F427x/437x devices.
  231. * @param GPIO_Pin: specifies the port bit to be locked.
  232. * This parameter can be any combination of GPIO_Pin_x where x can be (0..15).
  233. * @retval None
  234. */
  235. void GPIO_PinLockConfig(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
  236. {
  237. __IO uint32_t tmp = 0x00010000;
  238. /* Check the parameters */
  239. assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
  240. assert_param(IS_GPIO_PIN(GPIO_Pin));
  241. tmp |= GPIO_Pin;
  242. /* Set LCKK bit */
  243. GPIOx->LCKR = tmp;
  244. /* Reset LCKK bit */
  245. GPIOx->LCKR = GPIO_Pin;
  246. /* Set LCKK bit */
  247. GPIOx->LCKR = tmp;
  248. /* Read LCKK bit*/
  249. tmp = GPIOx->LCKR;
  250. /* Read LCKK bit*/
  251. tmp = GPIOx->LCKR;
  252. }
  253. /**
  254. * @}
  255. */
  256. /** @defgroup GPIO_Group2 GPIO Read and Write
  257. * @brief GPIO Read and Write
  258. *
  259. @verbatim
  260. ===============================================================================
  261. ##### GPIO Read and Write #####
  262. ===============================================================================
  263. @endverbatim
  264. * @{
  265. */
  266. /**
  267. * @brief Reads the specified input port pin.
  268. * @param GPIOx: where x can be (A..I) to select the GPIO peripheral for
  269. * STM32F40xx/41xx and STM32F427x/437x devices.
  270. * @param GPIO_Pin: specifies the port bit to read.
  271. * This parameter can be GPIO_Pin_x where x can be (0..15).
  272. * @retval The input port pin value.
  273. */
  274. uint8_t GPIO_ReadInputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
  275. {
  276. uint8_t bitstatus = 0x00;
  277. /* Check the parameters */
  278. assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
  279. assert_param(IS_GET_GPIO_PIN(GPIO_Pin));
  280. if ((GPIOx->IDR & GPIO_Pin) != (uint32_t)Bit_RESET)
  281. {
  282. bitstatus = (uint8_t)Bit_SET;
  283. }
  284. else
  285. {
  286. bitstatus = (uint8_t)Bit_RESET;
  287. }
  288. return bitstatus;
  289. }
  290. /**
  291. * @brief Reads the specified GPIO input data port.
  292. * @param GPIOx: where x can be (A..I) to select the GPIO peripheral for
  293. * STM32F40xx/41xx and STM32F427x/437x devices.
  294. * @retval GPIO input data port value.
  295. */
  296. uint16_t GPIO_ReadInputData(GPIO_TypeDef* GPIOx)
  297. {
  298. /* Check the parameters */
  299. assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
  300. return ((uint16_t)GPIOx->IDR);
  301. }
  302. /**
  303. * @brief Reads the specified output data port bit.
  304. * @param GPIOx: where x can be (A..I) to select the GPIO peripheral for
  305. * STM32F40xx/41xx and STM32F427x/437x devices.
  306. * @param GPIO_Pin: specifies the port bit to read.
  307. * This parameter can be GPIO_Pin_x where x can be (0..15).
  308. * @retval The output port pin value.
  309. */
  310. uint8_t GPIO_ReadOutputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
  311. {
  312. uint8_t bitstatus = 0x00;
  313. /* Check the parameters */
  314. assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
  315. assert_param(IS_GET_GPIO_PIN(GPIO_Pin));
  316. if (((GPIOx->ODR) & GPIO_Pin) != (uint32_t)Bit_RESET)
  317. {
  318. bitstatus = (uint8_t)Bit_SET;
  319. }
  320. else
  321. {
  322. bitstatus = (uint8_t)Bit_RESET;
  323. }
  324. return bitstatus;
  325. }
  326. /**
  327. * @brief Reads the specified GPIO output data port.
  328. * @param GPIOx: where x can be (A..I) to select the GPIO peripheral for
  329. * STM32F40xx/41xx and STM32F427x/437x devices.
  330. * @retval GPIO output data port value.
  331. */
  332. uint16_t GPIO_ReadOutputData(GPIO_TypeDef* GPIOx)
  333. {
  334. /* Check the parameters */
  335. assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
  336. return ((uint16_t)GPIOx->ODR);
  337. }
  338. /**
  339. * @brief Sets the selected data port bits.
  340. * @note This functions uses GPIOx_BSRR register to allow atomic read/modify
  341. * accesses. In this way, there is no risk of an IRQ occurring between
  342. * the read and the modify access.
  343. * @param GPIOx: where x can be (A..I) to select the GPIO peripheral for
  344. * STM32F40xx/41xx and STM32F427x/437x devices.
  345. * @param GPIO_Pin: specifies the port bits to be written.
  346. * This parameter can be any combination of GPIO_Pin_x where x can be (0..15).
  347. * @retval None
  348. */
  349. void GPIO_SetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
  350. {
  351. /* Check the parameters */
  352. assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
  353. assert_param(IS_GPIO_PIN(GPIO_Pin));
  354. GPIOx->BSRRL = GPIO_Pin;
  355. }
  356. /**
  357. * @brief Clears the selected data port bits.
  358. * @note This functions uses GPIOx_BSRR register to allow atomic read/modify
  359. * accesses. In this way, there is no risk of an IRQ occurring between
  360. * the read and the modify access.
  361. * @param GPIOx: where x can be (A..I) to select the GPIO peripheral for
  362. * STM32F40xx/41xx and STM32F427x/437x devices.
  363. * @param GPIO_Pin: specifies the port bits to be written.
  364. * This parameter can be any combination of GPIO_Pin_x where x can be (0..15).
  365. * @retval None
  366. */
  367. void GPIO_ResetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
  368. {
  369. /* Check the parameters */
  370. assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
  371. assert_param(IS_GPIO_PIN(GPIO_Pin));
  372. GPIOx->BSRRH = GPIO_Pin;
  373. }
  374. /**
  375. * @brief Sets or clears the selected data port bit.
  376. * @param GPIOx: where x can be (A..I) to select the GPIO peripheral for
  377. * STM32F40xx/41xx and STM32F427x/437x devices.
  378. * @param GPIO_Pin: specifies the port bit to be written.
  379. * This parameter can be one of GPIO_Pin_x where x can be (0..15).
  380. * @param BitVal: specifies the value to be written to the selected bit.
  381. * This parameter can be one of the BitAction enum values:
  382. * @arg Bit_RESET: to clear the port pin
  383. * @arg Bit_SET: to set the port pin
  384. * @retval None
  385. */
  386. void GPIO_WriteBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, BitAction BitVal)
  387. {
  388. /* Check the parameters */
  389. assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
  390. assert_param(IS_GET_GPIO_PIN(GPIO_Pin));
  391. assert_param(IS_GPIO_BIT_ACTION(BitVal));
  392. if (BitVal != Bit_RESET)
  393. {
  394. GPIOx->BSRRL = GPIO_Pin;
  395. }
  396. else
  397. {
  398. GPIOx->BSRRH = GPIO_Pin ;
  399. }
  400. }
  401. /**
  402. * @brief Writes data to the specified GPIO data port.
  403. * @param GPIOx: where x can be (A..I) to select the GPIO peripheral for
  404. * STM32F40xx/41xx and STM32F427x/437x devices.
  405. * @param PortVal: specifies the value to be written to the port output data register.
  406. * @retval None
  407. */
  408. void GPIO_Write(GPIO_TypeDef* GPIOx, uint16_t PortVal)
  409. {
  410. /* Check the parameters */
  411. assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
  412. GPIOx->ODR = PortVal;
  413. }
  414. /**
  415. * @brief Toggles the specified GPIO pins..
  416. * @param GPIOx: where x can be (A..I) to select the GPIO peripheral for
  417. * STM32F40xx/41xx and STM32F427x/437x devices.
  418. * @param GPIO_Pin: Specifies the pins to be toggled.
  419. * @retval None
  420. */
  421. void GPIO_ToggleBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
  422. {
  423. /* Check the parameters */
  424. assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
  425. GPIOx->ODR ^= GPIO_Pin;
  426. }
  427. /**
  428. * @}
  429. */
  430. /** @defgroup GPIO_Group3 GPIO Alternate functions configuration function
  431. * @brief GPIO Alternate functions configuration function
  432. *
  433. @verbatim
  434. ===============================================================================
  435. ##### GPIO Alternate functions configuration function #####
  436. ===============================================================================
  437. @endverbatim
  438. * @{
  439. */
  440. /**
  441. * @brief Changes the mapping of the specified pin.
  442. * @param GPIOx: where x can be (A..I) to select the GPIO peripheral for
  443. * STM32F40xx/41xx and STM32F427x/437x devices.
  444. * @param GPIO_PinSource: specifies the pin for the Alternate function.
  445. * This parameter can be GPIO_PinSourcex where x can be (0..15).
  446. * @param GPIO_AFSelection: selects the pin to used as Alternate function.
  447. * This parameter can be one of the following values:
  448. * @arg GPIO_AF_RTC_50Hz: Connect RTC_50Hz pin to AF0 (default after reset)
  449. * @arg GPIO_AF_MCO: Connect MCO pin (MCO1 and MCO2) to AF0 (default after reset)
  450. * @arg GPIO_AF_TAMPER: Connect TAMPER pins (TAMPER_1 and TAMPER_2) to AF0 (default after reset)
  451. * @arg GPIO_AF_SWJ: Connect SWJ pins (SWD and JTAG)to AF0 (default after reset)
  452. * @arg GPIO_AF_TRACE: Connect TRACE pins to AF0 (default after reset)
  453. * @arg GPIO_AF_TIM1: Connect TIM1 pins to AF1
  454. * @arg GPIO_AF_TIM2: Connect TIM2 pins to AF1
  455. * @arg GPIO_AF_TIM3: Connect TIM3 pins to AF2
  456. * @arg GPIO_AF_TIM4: Connect TIM4 pins to AF2
  457. * @arg GPIO_AF_TIM5: Connect TIM5 pins to AF2
  458. * @arg GPIO_AF_TIM8: Connect TIM8 pins to AF3
  459. * @arg GPIO_AF_TIM9: Connect TIM9 pins to AF3
  460. * @arg GPIO_AF_TIM10: Connect TIM10 pins to AF3
  461. * @arg GPIO_AF_TIM11: Connect TIM11 pins to AF3
  462. * @arg GPIO_AF_I2C1: Connect I2C1 pins to AF4
  463. * @arg GPIO_AF_I2C2: Connect I2C2 pins to AF4
  464. * @arg GPIO_AF_I2C3: Connect I2C3 pins to AF4
  465. * @arg GPIO_AF_SPI1: Connect SPI1 pins to AF5
  466. * @arg GPIO_AF_SPI2: Connect SPI2/I2S2 pins to AF5
  467. * @arg GPIO_AF_SPI4: Connect SPI4 pins to AF5
  468. * @arg GPIO_AF_SPI5: Connect SPI5 pins to AF5
  469. * @arg GPIO_AF_SPI6: Connect SPI6 pins to AF5
  470. * @arg GPIO_AF_SPI3: Connect SPI3/I2S3 pins to AF6
  471. * @arg GPIO_AF_I2S3ext: Connect I2S3ext pins to AF7
  472. * @arg GPIO_AF_USART1: Connect USART1 pins to AF7
  473. * @arg GPIO_AF_USART2: Connect USART2 pins to AF7
  474. * @arg GPIO_AF_USART3: Connect USART3 pins to AF7
  475. * @arg GPIO_AF_UART4: Connect UART4 pins to AF8
  476. * @arg GPIO_AF_UART5: Connect UART5 pins to AF8
  477. * @arg GPIO_AF_USART6: Connect USART6 pins to AF8
  478. * @arg GPIO_AF_UART7: Connect UART7 pins to AF8
  479. * @arg GPIO_AF_UART8: Connect UART8 pins to AF8
  480. * @arg GPIO_AF_CAN1: Connect CAN1 pins to AF9
  481. * @arg GPIO_AF_CAN2: Connect CAN2 pins to AF9
  482. * @arg GPIO_AF_TIM12: Connect TIM12 pins to AF9
  483. * @arg GPIO_AF_TIM13: Connect TIM13 pins to AF9
  484. * @arg GPIO_AF_TIM14: Connect TIM14 pins to AF9
  485. * @arg GPIO_AF_OTG_FS: Connect OTG_FS pins to AF10
  486. * @arg GPIO_AF_OTG_HS: Connect OTG_HS pins to AF10
  487. * @arg GPIO_AF_ETH: Connect ETHERNET pins to AF11
  488. * @arg GPIO_AF_FSMC: Connect FSMC pins to AF12
  489. * @arg GPIO_AF_OTG_HS_FS: Connect OTG HS (configured in FS) pins to AF12
  490. * @arg GPIO_AF_SDIO: Connect SDIO pins to AF12
  491. * @arg GPIO_AF_DCMI: Connect DCMI pins to AF13
  492. * @arg GPIO_AF_EVENTOUT: Connect EVENTOUT pins to AF15
  493. * @retval None
  494. */
  495. void GPIO_PinAFConfig(GPIO_TypeDef* GPIOx, uint16_t GPIO_PinSource, uint8_t GPIO_AF)
  496. {
  497. uint32_t temp = 0x00;
  498. uint32_t temp_2 = 0x00;
  499. /* Check the parameters */
  500. assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
  501. assert_param(IS_GPIO_PIN_SOURCE(GPIO_PinSource));
  502. assert_param(IS_GPIO_AF(GPIO_AF));
  503. temp = ((uint32_t)(GPIO_AF) << ((uint32_t)((uint32_t)GPIO_PinSource & (uint32_t)0x07) * 4)) ;
  504. GPIOx->AFR[GPIO_PinSource >> 0x03] &= ~((uint32_t)0xF << ((uint32_t)((uint32_t)GPIO_PinSource & (uint32_t)0x07) * 4)) ;
  505. temp_2 = GPIOx->AFR[GPIO_PinSource >> 0x03] | temp;
  506. GPIOx->AFR[GPIO_PinSource >> 0x03] = temp_2;
  507. }
  508. /**
  509. * @}
  510. */
  511. /**
  512. * @}
  513. */
  514. /**
  515. * @}
  516. */
  517. /**
  518. * @}
  519. */
  520. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/