mbed library sources
Dependents: Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more
Superseded
This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.
Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.
If you are looking for a stable and tested release, please import one of the official mbed library releases:
Import librarymbed
The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.
targets/cmsis/TARGET_STM/TARGET_NUCLEO_F302R8/stm32f30x_gpio.c@125:23cc3068a9e4, 2014-03-19 (annotated)
- Committer:
- mbed_official
- Date:
- Wed Mar 19 10:15:22 2014 +0000
- Revision:
- 125:23cc3068a9e4
Synchronized with git revision ace35dfba3748c7cdc102eb38ec6b9e1067c3252
Full URL: https://github.com/mbedmicro/mbed/commit/ace35dfba3748c7cdc102eb38ec6b9e1067c3252/
[NUCLEO_F302R8] Add cmsis and hal files + change F401RE clock to 84MHz
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 125:23cc3068a9e4 | 1 | /** |
mbed_official | 125:23cc3068a9e4 | 2 | ****************************************************************************** |
mbed_official | 125:23cc3068a9e4 | 3 | * @file stm32f30x_gpio.c |
mbed_official | 125:23cc3068a9e4 | 4 | * @author MCD Application Team |
mbed_official | 125:23cc3068a9e4 | 5 | * @version V1.1.0 |
mbed_official | 125:23cc3068a9e4 | 6 | * @date 27-February-2014 |
mbed_official | 125:23cc3068a9e4 | 7 | * @brief This file provides firmware functions to manage the following |
mbed_official | 125:23cc3068a9e4 | 8 | * functionalities of the GPIO peripheral: |
mbed_official | 125:23cc3068a9e4 | 9 | * + Initialization and Configuration functions |
mbed_official | 125:23cc3068a9e4 | 10 | * + GPIO Read and Write functions |
mbed_official | 125:23cc3068a9e4 | 11 | * + GPIO Alternate functions configuration functions |
mbed_official | 125:23cc3068a9e4 | 12 | * |
mbed_official | 125:23cc3068a9e4 | 13 | * @verbatim |
mbed_official | 125:23cc3068a9e4 | 14 | |
mbed_official | 125:23cc3068a9e4 | 15 | |
mbed_official | 125:23cc3068a9e4 | 16 | =============================================================================== |
mbed_official | 125:23cc3068a9e4 | 17 | ##### How to use this driver ##### |
mbed_official | 125:23cc3068a9e4 | 18 | =============================================================================== |
mbed_official | 125:23cc3068a9e4 | 19 | [..] |
mbed_official | 125:23cc3068a9e4 | 20 | (#) Enable the GPIO AHB clock using RCC_AHBPeriphClockCmd() |
mbed_official | 125:23cc3068a9e4 | 21 | (#) Configure the GPIO pin(s) using GPIO_Init() |
mbed_official | 125:23cc3068a9e4 | 22 | Four possible configuration are available for each pin: |
mbed_official | 125:23cc3068a9e4 | 23 | (++) Input: Floating, Pull-up, Pull-down. |
mbed_official | 125:23cc3068a9e4 | 24 | (++) Output: Push-Pull (Pull-up, Pull-down or no Pull), |
mbed_official | 125:23cc3068a9e4 | 25 | Open Drain (Pull-up, Pull-down or no Pull). |
mbed_official | 125:23cc3068a9e4 | 26 | In output mode, the speed is configurable: Low, Medium, Fast or High. |
mbed_official | 125:23cc3068a9e4 | 27 | (++) Alternate Function: Push-Pull (Pull-up, Pull-down or no Pull), |
mbed_official | 125:23cc3068a9e4 | 28 | Open Drain (Pull-up, Pull-down or no Pull). |
mbed_official | 125:23cc3068a9e4 | 29 | (++) Analog: required mode when a pin is to be used as ADC channel, |
mbed_official | 125:23cc3068a9e4 | 30 | DAC output or comparator input. |
mbed_official | 125:23cc3068a9e4 | 31 | (#) Peripherals alternate function: |
mbed_official | 125:23cc3068a9e4 | 32 | (++) For ADC, DAC and comparators, configure the desired pin in |
mbed_official | 125:23cc3068a9e4 | 33 | analog mode using GPIO_InitStruct->GPIO_Mode = GPIO_Mode_AN |
mbed_official | 125:23cc3068a9e4 | 34 | (++) For other peripherals (TIM, USART...): |
mbed_official | 125:23cc3068a9e4 | 35 | (+++) Connect the pin to the desired peripherals' Alternate |
mbed_official | 125:23cc3068a9e4 | 36 | Function (AF) using GPIO_PinAFConfig() function. |
mbed_official | 125:23cc3068a9e4 | 37 | (+++) Configure the desired pin in alternate function mode using |
mbed_official | 125:23cc3068a9e4 | 38 | GPIO_InitStruct->GPIO_Mode = GPIO_Mode_AF |
mbed_official | 125:23cc3068a9e4 | 39 | (+++) Select the type, pull-up/pull-down and output speed via |
mbed_official | 125:23cc3068a9e4 | 40 | GPIO_PuPd, GPIO_OType and GPIO_Speed members. |
mbed_official | 125:23cc3068a9e4 | 41 | (+++) Call GPIO_Init() function. |
mbed_official | 125:23cc3068a9e4 | 42 | (#) To get the level of a pin configured in input mode use GPIO_ReadInputDataBit() |
mbed_official | 125:23cc3068a9e4 | 43 | (#) To set/reset the level of a pin configured in output mode use |
mbed_official | 125:23cc3068a9e4 | 44 | GPIO_SetBits()/GPIO_ResetBits() |
mbed_official | 125:23cc3068a9e4 | 45 | (#) During and just after reset, the alternate functions are not active |
mbed_official | 125:23cc3068a9e4 | 46 | and the GPIO pins are configured in input floating mode (except JTAG pins). |
mbed_official | 125:23cc3068a9e4 | 47 | (#) The LSE oscillator pins OSC32_IN and OSC32_OUT can be used as |
mbed_official | 125:23cc3068a9e4 | 48 | general-purpose (PC14 and PC15, respectively) when the LSE |
mbed_official | 125:23cc3068a9e4 | 49 | oscillator is off. The LSE has priority over the GPIO function. |
mbed_official | 125:23cc3068a9e4 | 50 | (#) The HSE oscillator pins OSC_IN/OSC_OUT can be used as general-purpose |
mbed_official | 125:23cc3068a9e4 | 51 | (PF0 and PF1 respectively) when the HSE oscillator is off. The HSE has |
mbed_official | 125:23cc3068a9e4 | 52 | the priority over the GPIO function. |
mbed_official | 125:23cc3068a9e4 | 53 | |
mbed_official | 125:23cc3068a9e4 | 54 | @endverbatim |
mbed_official | 125:23cc3068a9e4 | 55 | |
mbed_official | 125:23cc3068a9e4 | 56 | ****************************************************************************** |
mbed_official | 125:23cc3068a9e4 | 57 | * @attention |
mbed_official | 125:23cc3068a9e4 | 58 | * |
mbed_official | 125:23cc3068a9e4 | 59 | * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> |
mbed_official | 125:23cc3068a9e4 | 60 | * |
mbed_official | 125:23cc3068a9e4 | 61 | * Redistribution and use in source and binary forms, with or without modification, |
mbed_official | 125:23cc3068a9e4 | 62 | * are permitted provided that the following conditions are met: |
mbed_official | 125:23cc3068a9e4 | 63 | * 1. Redistributions of source code must retain the above copyright notice, |
mbed_official | 125:23cc3068a9e4 | 64 | * this list of conditions and the following disclaimer. |
mbed_official | 125:23cc3068a9e4 | 65 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
mbed_official | 125:23cc3068a9e4 | 66 | * this list of conditions and the following disclaimer in the documentation |
mbed_official | 125:23cc3068a9e4 | 67 | * and/or other materials provided with the distribution. |
mbed_official | 125:23cc3068a9e4 | 68 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
mbed_official | 125:23cc3068a9e4 | 69 | * may be used to endorse or promote products derived from this software |
mbed_official | 125:23cc3068a9e4 | 70 | * without specific prior written permission. |
mbed_official | 125:23cc3068a9e4 | 71 | * |
mbed_official | 125:23cc3068a9e4 | 72 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
mbed_official | 125:23cc3068a9e4 | 73 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
mbed_official | 125:23cc3068a9e4 | 74 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
mbed_official | 125:23cc3068a9e4 | 75 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
mbed_official | 125:23cc3068a9e4 | 76 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
mbed_official | 125:23cc3068a9e4 | 77 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
mbed_official | 125:23cc3068a9e4 | 78 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
mbed_official | 125:23cc3068a9e4 | 79 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
mbed_official | 125:23cc3068a9e4 | 80 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
mbed_official | 125:23cc3068a9e4 | 81 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
mbed_official | 125:23cc3068a9e4 | 82 | * |
mbed_official | 125:23cc3068a9e4 | 83 | ****************************************************************************** |
mbed_official | 125:23cc3068a9e4 | 84 | */ |
mbed_official | 125:23cc3068a9e4 | 85 | |
mbed_official | 125:23cc3068a9e4 | 86 | /* Includes ------------------------------------------------------------------*/ |
mbed_official | 125:23cc3068a9e4 | 87 | #include "stm32f30x_gpio.h" |
mbed_official | 125:23cc3068a9e4 | 88 | #include "stm32f30x_rcc.h" |
mbed_official | 125:23cc3068a9e4 | 89 | |
mbed_official | 125:23cc3068a9e4 | 90 | /** @addtogroup STM32F30x_StdPeriph_Driver |
mbed_official | 125:23cc3068a9e4 | 91 | * @{ |
mbed_official | 125:23cc3068a9e4 | 92 | */ |
mbed_official | 125:23cc3068a9e4 | 93 | |
mbed_official | 125:23cc3068a9e4 | 94 | /** @defgroup GPIO |
mbed_official | 125:23cc3068a9e4 | 95 | * @brief GPIO driver modules |
mbed_official | 125:23cc3068a9e4 | 96 | * @{ |
mbed_official | 125:23cc3068a9e4 | 97 | */ |
mbed_official | 125:23cc3068a9e4 | 98 | |
mbed_official | 125:23cc3068a9e4 | 99 | |
mbed_official | 125:23cc3068a9e4 | 100 | /* Private typedef -----------------------------------------------------------*/ |
mbed_official | 125:23cc3068a9e4 | 101 | /* Private define ------------------------------------------------------------*/ |
mbed_official | 125:23cc3068a9e4 | 102 | |
mbed_official | 125:23cc3068a9e4 | 103 | |
mbed_official | 125:23cc3068a9e4 | 104 | /* Private macro -------------------------------------------------------------*/ |
mbed_official | 125:23cc3068a9e4 | 105 | /* Private variables ---------------------------------------------------------*/ |
mbed_official | 125:23cc3068a9e4 | 106 | /* Private function prototypes -----------------------------------------------*/ |
mbed_official | 125:23cc3068a9e4 | 107 | /* Private functions ---------------------------------------------------------*/ |
mbed_official | 125:23cc3068a9e4 | 108 | |
mbed_official | 125:23cc3068a9e4 | 109 | /** @defgroup GPIO_Private_Functions |
mbed_official | 125:23cc3068a9e4 | 110 | * @{ |
mbed_official | 125:23cc3068a9e4 | 111 | */ |
mbed_official | 125:23cc3068a9e4 | 112 | |
mbed_official | 125:23cc3068a9e4 | 113 | /** @defgroup GPIO_Group1 Initialization and Configuration |
mbed_official | 125:23cc3068a9e4 | 114 | * @brief Initialization and Configuration |
mbed_official | 125:23cc3068a9e4 | 115 | * |
mbed_official | 125:23cc3068a9e4 | 116 | @verbatim |
mbed_official | 125:23cc3068a9e4 | 117 | =============================================================================== |
mbed_official | 125:23cc3068a9e4 | 118 | ##### Initialization and Configuration ##### |
mbed_official | 125:23cc3068a9e4 | 119 | =============================================================================== |
mbed_official | 125:23cc3068a9e4 | 120 | |
mbed_official | 125:23cc3068a9e4 | 121 | @endverbatim |
mbed_official | 125:23cc3068a9e4 | 122 | * @{ |
mbed_official | 125:23cc3068a9e4 | 123 | */ |
mbed_official | 125:23cc3068a9e4 | 124 | |
mbed_official | 125:23cc3068a9e4 | 125 | /** |
mbed_official | 125:23cc3068a9e4 | 126 | * @brief Deinitializes the GPIOx peripheral registers to their default reset |
mbed_official | 125:23cc3068a9e4 | 127 | * values. |
mbed_official | 125:23cc3068a9e4 | 128 | * @param GPIOx: where x can be (A, B, C, D, E or F) to select the GPIO peripheral. |
mbed_official | 125:23cc3068a9e4 | 129 | * @retval None |
mbed_official | 125:23cc3068a9e4 | 130 | */ |
mbed_official | 125:23cc3068a9e4 | 131 | void GPIO_DeInit(GPIO_TypeDef* GPIOx) |
mbed_official | 125:23cc3068a9e4 | 132 | { |
mbed_official | 125:23cc3068a9e4 | 133 | /* Check the parameters */ |
mbed_official | 125:23cc3068a9e4 | 134 | assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); |
mbed_official | 125:23cc3068a9e4 | 135 | |
mbed_official | 125:23cc3068a9e4 | 136 | if(GPIOx == GPIOA) |
mbed_official | 125:23cc3068a9e4 | 137 | { |
mbed_official | 125:23cc3068a9e4 | 138 | RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOA, ENABLE); |
mbed_official | 125:23cc3068a9e4 | 139 | RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOA, DISABLE); |
mbed_official | 125:23cc3068a9e4 | 140 | } |
mbed_official | 125:23cc3068a9e4 | 141 | else if(GPIOx == GPIOB) |
mbed_official | 125:23cc3068a9e4 | 142 | { |
mbed_official | 125:23cc3068a9e4 | 143 | RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOB, ENABLE); |
mbed_official | 125:23cc3068a9e4 | 144 | RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOB, DISABLE); |
mbed_official | 125:23cc3068a9e4 | 145 | } |
mbed_official | 125:23cc3068a9e4 | 146 | else if(GPIOx == GPIOC) |
mbed_official | 125:23cc3068a9e4 | 147 | { |
mbed_official | 125:23cc3068a9e4 | 148 | RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOC, ENABLE); |
mbed_official | 125:23cc3068a9e4 | 149 | RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOC, DISABLE); |
mbed_official | 125:23cc3068a9e4 | 150 | } |
mbed_official | 125:23cc3068a9e4 | 151 | else if(GPIOx == GPIOD) |
mbed_official | 125:23cc3068a9e4 | 152 | { |
mbed_official | 125:23cc3068a9e4 | 153 | RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOD, ENABLE); |
mbed_official | 125:23cc3068a9e4 | 154 | RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOD, DISABLE); |
mbed_official | 125:23cc3068a9e4 | 155 | } |
mbed_official | 125:23cc3068a9e4 | 156 | else if(GPIOx == GPIOE) |
mbed_official | 125:23cc3068a9e4 | 157 | { |
mbed_official | 125:23cc3068a9e4 | 158 | RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOE, ENABLE); |
mbed_official | 125:23cc3068a9e4 | 159 | RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOE, DISABLE); |
mbed_official | 125:23cc3068a9e4 | 160 | } |
mbed_official | 125:23cc3068a9e4 | 161 | else |
mbed_official | 125:23cc3068a9e4 | 162 | { |
mbed_official | 125:23cc3068a9e4 | 163 | if(GPIOx == GPIOF) |
mbed_official | 125:23cc3068a9e4 | 164 | { |
mbed_official | 125:23cc3068a9e4 | 165 | RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOF, ENABLE); |
mbed_official | 125:23cc3068a9e4 | 166 | RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOF, DISABLE); |
mbed_official | 125:23cc3068a9e4 | 167 | } |
mbed_official | 125:23cc3068a9e4 | 168 | } |
mbed_official | 125:23cc3068a9e4 | 169 | } |
mbed_official | 125:23cc3068a9e4 | 170 | |
mbed_official | 125:23cc3068a9e4 | 171 | /** |
mbed_official | 125:23cc3068a9e4 | 172 | * @brief Initializes the GPIOx peripheral according to the specified |
mbed_official | 125:23cc3068a9e4 | 173 | * parameters in the GPIO_InitStruct. |
mbed_official | 125:23cc3068a9e4 | 174 | * @param GPIOx: where x can be (A, B, C, D, E or F) to select the GPIO peripheral. |
mbed_official | 125:23cc3068a9e4 | 175 | * @param GPIO_InitStruct: pointer to a GPIO_InitTypeDef structure that |
mbed_official | 125:23cc3068a9e4 | 176 | * contains the configuration information for the specified GPIO |
mbed_official | 125:23cc3068a9e4 | 177 | * peripheral. |
mbed_official | 125:23cc3068a9e4 | 178 | * @note GPIO_Pin: selects the pin to be configured: |
mbed_official | 125:23cc3068a9e4 | 179 | * GPIO_Pin_0->GPIO_Pin_15 for GPIOA, GPIOB, GPIOC, GPIOD and GPIOE; |
mbed_official | 125:23cc3068a9e4 | 180 | * GPIO_Pin_0->GPIO_Pin_2, GPIO_Pin_4, GPIO_Pin_6, GPIO_Pin_9 |
mbed_official | 125:23cc3068a9e4 | 181 | * and GPIO_Pin_10 for GPIOF. |
mbed_official | 125:23cc3068a9e4 | 182 | * @retval None |
mbed_official | 125:23cc3068a9e4 | 183 | */ |
mbed_official | 125:23cc3068a9e4 | 184 | void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct) |
mbed_official | 125:23cc3068a9e4 | 185 | { |
mbed_official | 125:23cc3068a9e4 | 186 | uint32_t pinpos = 0x00, pos = 0x00 , currentpin = 0x00; |
mbed_official | 125:23cc3068a9e4 | 187 | uint32_t tmpreg = 0x00; |
mbed_official | 125:23cc3068a9e4 | 188 | |
mbed_official | 125:23cc3068a9e4 | 189 | /* Check the parameters */ |
mbed_official | 125:23cc3068a9e4 | 190 | assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); |
mbed_official | 125:23cc3068a9e4 | 191 | assert_param(IS_GPIO_PIN(GPIO_InitStruct->GPIO_Pin)); |
mbed_official | 125:23cc3068a9e4 | 192 | assert_param(IS_GPIO_MODE(GPIO_InitStruct->GPIO_Mode)); |
mbed_official | 125:23cc3068a9e4 | 193 | assert_param(IS_GPIO_PUPD(GPIO_InitStruct->GPIO_PuPd)); |
mbed_official | 125:23cc3068a9e4 | 194 | |
mbed_official | 125:23cc3068a9e4 | 195 | /*-------------------------- Configure the port pins -----------------------*/ |
mbed_official | 125:23cc3068a9e4 | 196 | /*-- GPIO Mode Configuration --*/ |
mbed_official | 125:23cc3068a9e4 | 197 | for (pinpos = 0x00; pinpos < 0x10; pinpos++) |
mbed_official | 125:23cc3068a9e4 | 198 | { |
mbed_official | 125:23cc3068a9e4 | 199 | pos = ((uint32_t)0x01) << pinpos; |
mbed_official | 125:23cc3068a9e4 | 200 | |
mbed_official | 125:23cc3068a9e4 | 201 | /* Get the port pins position */ |
mbed_official | 125:23cc3068a9e4 | 202 | currentpin = (GPIO_InitStruct->GPIO_Pin) & pos; |
mbed_official | 125:23cc3068a9e4 | 203 | |
mbed_official | 125:23cc3068a9e4 | 204 | if (currentpin == pos) |
mbed_official | 125:23cc3068a9e4 | 205 | { |
mbed_official | 125:23cc3068a9e4 | 206 | if ((GPIO_InitStruct->GPIO_Mode == GPIO_Mode_OUT) || (GPIO_InitStruct->GPIO_Mode == GPIO_Mode_AF)) |
mbed_official | 125:23cc3068a9e4 | 207 | { |
mbed_official | 125:23cc3068a9e4 | 208 | /* Check Speed mode parameters */ |
mbed_official | 125:23cc3068a9e4 | 209 | assert_param(IS_GPIO_SPEED(GPIO_InitStruct->GPIO_Speed)); |
mbed_official | 125:23cc3068a9e4 | 210 | |
mbed_official | 125:23cc3068a9e4 | 211 | /* Speed mode configuration */ |
mbed_official | 125:23cc3068a9e4 | 212 | GPIOx->OSPEEDR &= ~(GPIO_OSPEEDER_OSPEEDR0 << (pinpos * 2)); |
mbed_official | 125:23cc3068a9e4 | 213 | GPIOx->OSPEEDR |= ((uint32_t)(GPIO_InitStruct->GPIO_Speed) << (pinpos * 2)); |
mbed_official | 125:23cc3068a9e4 | 214 | |
mbed_official | 125:23cc3068a9e4 | 215 | /* Check Output mode parameters */ |
mbed_official | 125:23cc3068a9e4 | 216 | assert_param(IS_GPIO_OTYPE(GPIO_InitStruct->GPIO_OType)); |
mbed_official | 125:23cc3068a9e4 | 217 | |
mbed_official | 125:23cc3068a9e4 | 218 | /* Output mode configuration */ |
mbed_official | 125:23cc3068a9e4 | 219 | GPIOx->OTYPER &= ~((GPIO_OTYPER_OT_0) << ((uint16_t)pinpos)); |
mbed_official | 125:23cc3068a9e4 | 220 | GPIOx->OTYPER |= (uint16_t)(((uint16_t)GPIO_InitStruct->GPIO_OType) << ((uint16_t)pinpos)); |
mbed_official | 125:23cc3068a9e4 | 221 | } |
mbed_official | 125:23cc3068a9e4 | 222 | |
mbed_official | 125:23cc3068a9e4 | 223 | GPIOx->MODER &= ~(GPIO_MODER_MODER0 << (pinpos * 2)); |
mbed_official | 125:23cc3068a9e4 | 224 | |
mbed_official | 125:23cc3068a9e4 | 225 | GPIOx->MODER |= (((uint32_t)GPIO_InitStruct->GPIO_Mode) << (pinpos * 2)); |
mbed_official | 125:23cc3068a9e4 | 226 | |
mbed_official | 125:23cc3068a9e4 | 227 | /* Use temporary variable to update PUPDR register configuration, to avoid |
mbed_official | 125:23cc3068a9e4 | 228 | unexpected transition in the GPIO pin configuration. */ |
mbed_official | 125:23cc3068a9e4 | 229 | tmpreg = GPIOx->PUPDR; |
mbed_official | 125:23cc3068a9e4 | 230 | tmpreg &= ~(GPIO_PUPDR_PUPDR0 << ((uint16_t)pinpos * 2)); |
mbed_official | 125:23cc3068a9e4 | 231 | tmpreg |= (((uint32_t)GPIO_InitStruct->GPIO_PuPd) << (pinpos * 2)); |
mbed_official | 125:23cc3068a9e4 | 232 | GPIOx->PUPDR = tmpreg; |
mbed_official | 125:23cc3068a9e4 | 233 | } |
mbed_official | 125:23cc3068a9e4 | 234 | } |
mbed_official | 125:23cc3068a9e4 | 235 | } |
mbed_official | 125:23cc3068a9e4 | 236 | |
mbed_official | 125:23cc3068a9e4 | 237 | /** |
mbed_official | 125:23cc3068a9e4 | 238 | * @brief Fills each GPIO_InitStruct member with its default value. |
mbed_official | 125:23cc3068a9e4 | 239 | * @param GPIO_InitStruct: pointer to a GPIO_InitTypeDef structure which will |
mbed_official | 125:23cc3068a9e4 | 240 | * be initialized. |
mbed_official | 125:23cc3068a9e4 | 241 | * @retval None |
mbed_official | 125:23cc3068a9e4 | 242 | */ |
mbed_official | 125:23cc3068a9e4 | 243 | void GPIO_StructInit(GPIO_InitTypeDef* GPIO_InitStruct) |
mbed_official | 125:23cc3068a9e4 | 244 | { |
mbed_official | 125:23cc3068a9e4 | 245 | /* Reset GPIO init structure parameters values */ |
mbed_official | 125:23cc3068a9e4 | 246 | GPIO_InitStruct->GPIO_Pin = GPIO_Pin_All; |
mbed_official | 125:23cc3068a9e4 | 247 | GPIO_InitStruct->GPIO_Mode = GPIO_Mode_IN; |
mbed_official | 125:23cc3068a9e4 | 248 | GPIO_InitStruct->GPIO_Speed = GPIO_Speed_2MHz; |
mbed_official | 125:23cc3068a9e4 | 249 | GPIO_InitStruct->GPIO_OType = GPIO_OType_PP; |
mbed_official | 125:23cc3068a9e4 | 250 | GPIO_InitStruct->GPIO_PuPd = GPIO_PuPd_NOPULL; |
mbed_official | 125:23cc3068a9e4 | 251 | } |
mbed_official | 125:23cc3068a9e4 | 252 | |
mbed_official | 125:23cc3068a9e4 | 253 | /** |
mbed_official | 125:23cc3068a9e4 | 254 | * @brief Locks GPIO Pins configuration registers. |
mbed_official | 125:23cc3068a9e4 | 255 | * The locked registers are GPIOx_MODER, GPIOx_OTYPER, GPIOx_OSPEEDR, |
mbed_official | 125:23cc3068a9e4 | 256 | * GPIOx_PUPDR, GPIOx_AFRL and GPIOx_AFRH. |
mbed_official | 125:23cc3068a9e4 | 257 | * @note The configuration of the locked GPIO pins can no longer be modified |
mbed_official | 125:23cc3068a9e4 | 258 | * until the next reset. |
mbed_official | 125:23cc3068a9e4 | 259 | * @param GPIOx: where x can be (A or B or D) to select the GPIO peripheral. |
mbed_official | 125:23cc3068a9e4 | 260 | * @param GPIO_Pin: specifies the port bit to be written. |
mbed_official | 125:23cc3068a9e4 | 261 | * This parameter can be any combination of GPIO_Pin_x where x can be (0..15). |
mbed_official | 125:23cc3068a9e4 | 262 | * @retval None |
mbed_official | 125:23cc3068a9e4 | 263 | */ |
mbed_official | 125:23cc3068a9e4 | 264 | void GPIO_PinLockConfig(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin) |
mbed_official | 125:23cc3068a9e4 | 265 | { |
mbed_official | 125:23cc3068a9e4 | 266 | uint32_t tmp = 0x00010000; |
mbed_official | 125:23cc3068a9e4 | 267 | |
mbed_official | 125:23cc3068a9e4 | 268 | /* Check the parameters */ |
mbed_official | 125:23cc3068a9e4 | 269 | assert_param(IS_GPIO_LIST_PERIPH(GPIOx)); |
mbed_official | 125:23cc3068a9e4 | 270 | assert_param(IS_GPIO_PIN(GPIO_Pin)); |
mbed_official | 125:23cc3068a9e4 | 271 | |
mbed_official | 125:23cc3068a9e4 | 272 | tmp |= GPIO_Pin; |
mbed_official | 125:23cc3068a9e4 | 273 | /* Set LCKK bit */ |
mbed_official | 125:23cc3068a9e4 | 274 | GPIOx->LCKR = tmp; |
mbed_official | 125:23cc3068a9e4 | 275 | /* Reset LCKK bit */ |
mbed_official | 125:23cc3068a9e4 | 276 | GPIOx->LCKR = GPIO_Pin; |
mbed_official | 125:23cc3068a9e4 | 277 | /* Set LCKK bit */ |
mbed_official | 125:23cc3068a9e4 | 278 | GPIOx->LCKR = tmp; |
mbed_official | 125:23cc3068a9e4 | 279 | /* Read LCKK bit */ |
mbed_official | 125:23cc3068a9e4 | 280 | tmp = GPIOx->LCKR; |
mbed_official | 125:23cc3068a9e4 | 281 | /* Read LCKK bit */ |
mbed_official | 125:23cc3068a9e4 | 282 | tmp = GPIOx->LCKR; |
mbed_official | 125:23cc3068a9e4 | 283 | } |
mbed_official | 125:23cc3068a9e4 | 284 | |
mbed_official | 125:23cc3068a9e4 | 285 | /** |
mbed_official | 125:23cc3068a9e4 | 286 | * @} |
mbed_official | 125:23cc3068a9e4 | 287 | */ |
mbed_official | 125:23cc3068a9e4 | 288 | |
mbed_official | 125:23cc3068a9e4 | 289 | /** @defgroup GPIO_Group2 GPIO Read and Write |
mbed_official | 125:23cc3068a9e4 | 290 | * @brief GPIO Read and Write |
mbed_official | 125:23cc3068a9e4 | 291 | * |
mbed_official | 125:23cc3068a9e4 | 292 | @verbatim |
mbed_official | 125:23cc3068a9e4 | 293 | =============================================================================== |
mbed_official | 125:23cc3068a9e4 | 294 | ##### GPIO Read and Write ##### |
mbed_official | 125:23cc3068a9e4 | 295 | =============================================================================== |
mbed_official | 125:23cc3068a9e4 | 296 | |
mbed_official | 125:23cc3068a9e4 | 297 | @endverbatim |
mbed_official | 125:23cc3068a9e4 | 298 | * @{ |
mbed_official | 125:23cc3068a9e4 | 299 | */ |
mbed_official | 125:23cc3068a9e4 | 300 | |
mbed_official | 125:23cc3068a9e4 | 301 | /** |
mbed_official | 125:23cc3068a9e4 | 302 | * @brief Reads the specified input port pin. |
mbed_official | 125:23cc3068a9e4 | 303 | * @param GPIOx: where x can be (A, B, C, D, E or F) to select the GPIO peripheral. |
mbed_official | 125:23cc3068a9e4 | 304 | * @param GPIO_Pin: specifies the port bit to read. |
mbed_official | 125:23cc3068a9e4 | 305 | * @note This parameter can be GPIO_Pin_x where x can be : |
mbed_official | 125:23cc3068a9e4 | 306 | * (0..15) for GPIOA, GPIOB, GPIOC, GPIOD or GPIOE; |
mbed_official | 125:23cc3068a9e4 | 307 | * (0..2, 4, 6, 9..10) for GPIOF. |
mbed_official | 125:23cc3068a9e4 | 308 | * @retval The input port pin value. |
mbed_official | 125:23cc3068a9e4 | 309 | */ |
mbed_official | 125:23cc3068a9e4 | 310 | uint8_t GPIO_ReadInputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin) |
mbed_official | 125:23cc3068a9e4 | 311 | { |
mbed_official | 125:23cc3068a9e4 | 312 | uint8_t bitstatus = 0x00; |
mbed_official | 125:23cc3068a9e4 | 313 | |
mbed_official | 125:23cc3068a9e4 | 314 | /* Check the parameters */ |
mbed_official | 125:23cc3068a9e4 | 315 | assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); |
mbed_official | 125:23cc3068a9e4 | 316 | assert_param(IS_GET_GPIO_PIN(GPIO_Pin)); |
mbed_official | 125:23cc3068a9e4 | 317 | |
mbed_official | 125:23cc3068a9e4 | 318 | if ((GPIOx->IDR & GPIO_Pin) != (uint32_t)Bit_RESET) |
mbed_official | 125:23cc3068a9e4 | 319 | { |
mbed_official | 125:23cc3068a9e4 | 320 | bitstatus = (uint8_t)Bit_SET; |
mbed_official | 125:23cc3068a9e4 | 321 | } |
mbed_official | 125:23cc3068a9e4 | 322 | else |
mbed_official | 125:23cc3068a9e4 | 323 | { |
mbed_official | 125:23cc3068a9e4 | 324 | bitstatus = (uint8_t)Bit_RESET; |
mbed_official | 125:23cc3068a9e4 | 325 | } |
mbed_official | 125:23cc3068a9e4 | 326 | return bitstatus; |
mbed_official | 125:23cc3068a9e4 | 327 | } |
mbed_official | 125:23cc3068a9e4 | 328 | |
mbed_official | 125:23cc3068a9e4 | 329 | /** |
mbed_official | 125:23cc3068a9e4 | 330 | * @brief Reads the specified input port pin. |
mbed_official | 125:23cc3068a9e4 | 331 | * @param GPIOx: where x can be (A, B, C, D, E or F) to select the GPIO peripheral. |
mbed_official | 125:23cc3068a9e4 | 332 | * @retval The input port pin value. |
mbed_official | 125:23cc3068a9e4 | 333 | */ |
mbed_official | 125:23cc3068a9e4 | 334 | uint16_t GPIO_ReadInputData(GPIO_TypeDef* GPIOx) |
mbed_official | 125:23cc3068a9e4 | 335 | { |
mbed_official | 125:23cc3068a9e4 | 336 | /* Check the parameters */ |
mbed_official | 125:23cc3068a9e4 | 337 | assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); |
mbed_official | 125:23cc3068a9e4 | 338 | |
mbed_official | 125:23cc3068a9e4 | 339 | return ((uint16_t)GPIOx->IDR); |
mbed_official | 125:23cc3068a9e4 | 340 | } |
mbed_official | 125:23cc3068a9e4 | 341 | |
mbed_official | 125:23cc3068a9e4 | 342 | /** |
mbed_official | 125:23cc3068a9e4 | 343 | * @brief Reads the specified output data port bit. |
mbed_official | 125:23cc3068a9e4 | 344 | * @param GPIOx: where x can be (A, B, C, D, E or F) to select the GPIO peripheral. |
mbed_official | 125:23cc3068a9e4 | 345 | * @param GPIO_Pin: Specifies the port bit to read. |
mbed_official | 125:23cc3068a9e4 | 346 | * @note This parameter can be GPIO_Pin_x where x can be : |
mbed_official | 125:23cc3068a9e4 | 347 | * (0..15) for GPIOA, GPIOB, GPIOC, GPIOD or GPIOE; |
mbed_official | 125:23cc3068a9e4 | 348 | * (0..2, 4, 6, 9..10) for GPIOF. |
mbed_official | 125:23cc3068a9e4 | 349 | * @retval The output port pin value. |
mbed_official | 125:23cc3068a9e4 | 350 | */ |
mbed_official | 125:23cc3068a9e4 | 351 | uint8_t GPIO_ReadOutputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin) |
mbed_official | 125:23cc3068a9e4 | 352 | { |
mbed_official | 125:23cc3068a9e4 | 353 | uint8_t bitstatus = 0x00; |
mbed_official | 125:23cc3068a9e4 | 354 | |
mbed_official | 125:23cc3068a9e4 | 355 | /* Check the parameters */ |
mbed_official | 125:23cc3068a9e4 | 356 | assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); |
mbed_official | 125:23cc3068a9e4 | 357 | assert_param(IS_GET_GPIO_PIN(GPIO_Pin)); |
mbed_official | 125:23cc3068a9e4 | 358 | |
mbed_official | 125:23cc3068a9e4 | 359 | if ((GPIOx->ODR & GPIO_Pin) != (uint32_t)Bit_RESET) |
mbed_official | 125:23cc3068a9e4 | 360 | { |
mbed_official | 125:23cc3068a9e4 | 361 | bitstatus = (uint8_t)Bit_SET; |
mbed_official | 125:23cc3068a9e4 | 362 | } |
mbed_official | 125:23cc3068a9e4 | 363 | else |
mbed_official | 125:23cc3068a9e4 | 364 | { |
mbed_official | 125:23cc3068a9e4 | 365 | bitstatus = (uint8_t)Bit_RESET; |
mbed_official | 125:23cc3068a9e4 | 366 | } |
mbed_official | 125:23cc3068a9e4 | 367 | return bitstatus; |
mbed_official | 125:23cc3068a9e4 | 368 | } |
mbed_official | 125:23cc3068a9e4 | 369 | |
mbed_official | 125:23cc3068a9e4 | 370 | /** |
mbed_official | 125:23cc3068a9e4 | 371 | * @brief Reads the specified GPIO output data port. |
mbed_official | 125:23cc3068a9e4 | 372 | * @param GPIOx: where x can be (A, B, C, D, E or F) to select the GPIO peripheral. |
mbed_official | 125:23cc3068a9e4 | 373 | * @retval GPIO output data port value. |
mbed_official | 125:23cc3068a9e4 | 374 | */ |
mbed_official | 125:23cc3068a9e4 | 375 | uint16_t GPIO_ReadOutputData(GPIO_TypeDef* GPIOx) |
mbed_official | 125:23cc3068a9e4 | 376 | { |
mbed_official | 125:23cc3068a9e4 | 377 | /* Check the parameters */ |
mbed_official | 125:23cc3068a9e4 | 378 | assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); |
mbed_official | 125:23cc3068a9e4 | 379 | |
mbed_official | 125:23cc3068a9e4 | 380 | return ((uint16_t)GPIOx->ODR); |
mbed_official | 125:23cc3068a9e4 | 381 | } |
mbed_official | 125:23cc3068a9e4 | 382 | |
mbed_official | 125:23cc3068a9e4 | 383 | /** |
mbed_official | 125:23cc3068a9e4 | 384 | * @brief Sets the selected data port bits. |
mbed_official | 125:23cc3068a9e4 | 385 | * @param GPIOx: where x can be (A, B, C, D, E or F) to select the GPIO peripheral. |
mbed_official | 125:23cc3068a9e4 | 386 | * @param GPIO_Pin: specifies the port bits to be written. |
mbed_official | 125:23cc3068a9e4 | 387 | * @note This parameter can be GPIO_Pin_x where x can be : |
mbed_official | 125:23cc3068a9e4 | 388 | * (0..15) for GPIOA, GPIOB, GPIOC, GPIOD or GPIOE; |
mbed_official | 125:23cc3068a9e4 | 389 | * (0..2, 4, 6, 9..10) for GPIOF. |
mbed_official | 125:23cc3068a9e4 | 390 | * @retval None |
mbed_official | 125:23cc3068a9e4 | 391 | */ |
mbed_official | 125:23cc3068a9e4 | 392 | void GPIO_SetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin) |
mbed_official | 125:23cc3068a9e4 | 393 | { |
mbed_official | 125:23cc3068a9e4 | 394 | /* Check the parameters */ |
mbed_official | 125:23cc3068a9e4 | 395 | assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); |
mbed_official | 125:23cc3068a9e4 | 396 | assert_param(IS_GPIO_PIN(GPIO_Pin)); |
mbed_official | 125:23cc3068a9e4 | 397 | |
mbed_official | 125:23cc3068a9e4 | 398 | GPIOx->BSRR = GPIO_Pin; |
mbed_official | 125:23cc3068a9e4 | 399 | } |
mbed_official | 125:23cc3068a9e4 | 400 | |
mbed_official | 125:23cc3068a9e4 | 401 | /** |
mbed_official | 125:23cc3068a9e4 | 402 | * @brief Clears the selected data port bits. |
mbed_official | 125:23cc3068a9e4 | 403 | * @param GPIOx: where x can be (A, B, C, D, E or F) to select the GPIO peripheral. |
mbed_official | 125:23cc3068a9e4 | 404 | * @param GPIO_Pin: specifies the port bits to be written. |
mbed_official | 125:23cc3068a9e4 | 405 | * @note This parameter can be GPIO_Pin_x where x can be : |
mbed_official | 125:23cc3068a9e4 | 406 | * (0..15) for GPIOA, GPIOB, GPIOC, GPIOD or GPIOE; |
mbed_official | 125:23cc3068a9e4 | 407 | * (0..2, 4, 6, 9..10) for GPIOF. |
mbed_official | 125:23cc3068a9e4 | 408 | * @retval None |
mbed_official | 125:23cc3068a9e4 | 409 | */ |
mbed_official | 125:23cc3068a9e4 | 410 | void GPIO_ResetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin) |
mbed_official | 125:23cc3068a9e4 | 411 | { |
mbed_official | 125:23cc3068a9e4 | 412 | /* Check the parameters */ |
mbed_official | 125:23cc3068a9e4 | 413 | assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); |
mbed_official | 125:23cc3068a9e4 | 414 | assert_param(IS_GPIO_PIN(GPIO_Pin)); |
mbed_official | 125:23cc3068a9e4 | 415 | |
mbed_official | 125:23cc3068a9e4 | 416 | GPIOx->BRR = GPIO_Pin; |
mbed_official | 125:23cc3068a9e4 | 417 | } |
mbed_official | 125:23cc3068a9e4 | 418 | |
mbed_official | 125:23cc3068a9e4 | 419 | /** |
mbed_official | 125:23cc3068a9e4 | 420 | * @brief Sets or clears the selected data port bit. |
mbed_official | 125:23cc3068a9e4 | 421 | * @param GPIOx: where x can be (A, B, C, D, E or F) to select the GPIO peripheral. |
mbed_official | 125:23cc3068a9e4 | 422 | * @param GPIO_Pin: specifies the port bit to be written. |
mbed_official | 125:23cc3068a9e4 | 423 | * @note This parameter can be GPIO_Pin_x where x can be : |
mbed_official | 125:23cc3068a9e4 | 424 | * (0..15) for GPIOA, GPIOB, GPIOC, GPIOD or GPIOE; |
mbed_official | 125:23cc3068a9e4 | 425 | * (0..2, 4, 6, 9..10) for GPIOF. |
mbed_official | 125:23cc3068a9e4 | 426 | * @param BitVal: specifies the value to be written to the selected bit. |
mbed_official | 125:23cc3068a9e4 | 427 | * This parameter can be one of the BitAction enumeration values: |
mbed_official | 125:23cc3068a9e4 | 428 | * @arg Bit_RESET: to clear the port pin |
mbed_official | 125:23cc3068a9e4 | 429 | * @arg Bit_SET: to set the port pin |
mbed_official | 125:23cc3068a9e4 | 430 | * @retval None |
mbed_official | 125:23cc3068a9e4 | 431 | */ |
mbed_official | 125:23cc3068a9e4 | 432 | void GPIO_WriteBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, BitAction BitVal) |
mbed_official | 125:23cc3068a9e4 | 433 | { |
mbed_official | 125:23cc3068a9e4 | 434 | /* Check the parameters */ |
mbed_official | 125:23cc3068a9e4 | 435 | assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); |
mbed_official | 125:23cc3068a9e4 | 436 | assert_param(IS_GET_GPIO_PIN(GPIO_Pin)); |
mbed_official | 125:23cc3068a9e4 | 437 | assert_param(IS_GPIO_BIT_ACTION(BitVal)); |
mbed_official | 125:23cc3068a9e4 | 438 | |
mbed_official | 125:23cc3068a9e4 | 439 | if (BitVal != Bit_RESET) |
mbed_official | 125:23cc3068a9e4 | 440 | { |
mbed_official | 125:23cc3068a9e4 | 441 | GPIOx->BSRR = GPIO_Pin; |
mbed_official | 125:23cc3068a9e4 | 442 | } |
mbed_official | 125:23cc3068a9e4 | 443 | else |
mbed_official | 125:23cc3068a9e4 | 444 | { |
mbed_official | 125:23cc3068a9e4 | 445 | GPIOx->BRR = GPIO_Pin ; |
mbed_official | 125:23cc3068a9e4 | 446 | } |
mbed_official | 125:23cc3068a9e4 | 447 | } |
mbed_official | 125:23cc3068a9e4 | 448 | |
mbed_official | 125:23cc3068a9e4 | 449 | /** |
mbed_official | 125:23cc3068a9e4 | 450 | * @brief Writes data to the specified GPIO data port. |
mbed_official | 125:23cc3068a9e4 | 451 | * @param GPIOx: where x can be (A, B, C, D, E or F) to select the GPIO peripheral. |
mbed_official | 125:23cc3068a9e4 | 452 | * @param PortVal: specifies the value to be written to the port output data |
mbed_official | 125:23cc3068a9e4 | 453 | * register. |
mbed_official | 125:23cc3068a9e4 | 454 | * @retval None |
mbed_official | 125:23cc3068a9e4 | 455 | */ |
mbed_official | 125:23cc3068a9e4 | 456 | void GPIO_Write(GPIO_TypeDef* GPIOx, uint16_t PortVal) |
mbed_official | 125:23cc3068a9e4 | 457 | { |
mbed_official | 125:23cc3068a9e4 | 458 | /* Check the parameters */ |
mbed_official | 125:23cc3068a9e4 | 459 | assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); |
mbed_official | 125:23cc3068a9e4 | 460 | |
mbed_official | 125:23cc3068a9e4 | 461 | GPIOx->ODR = PortVal; |
mbed_official | 125:23cc3068a9e4 | 462 | } |
mbed_official | 125:23cc3068a9e4 | 463 | |
mbed_official | 125:23cc3068a9e4 | 464 | /** |
mbed_official | 125:23cc3068a9e4 | 465 | * @} |
mbed_official | 125:23cc3068a9e4 | 466 | */ |
mbed_official | 125:23cc3068a9e4 | 467 | |
mbed_official | 125:23cc3068a9e4 | 468 | /** @defgroup GPIO_Group3 GPIO Alternate functions configuration functions |
mbed_official | 125:23cc3068a9e4 | 469 | * @brief GPIO Alternate functions configuration functions |
mbed_official | 125:23cc3068a9e4 | 470 | * |
mbed_official | 125:23cc3068a9e4 | 471 | @verbatim |
mbed_official | 125:23cc3068a9e4 | 472 | =============================================================================== |
mbed_official | 125:23cc3068a9e4 | 473 | ##### GPIO Alternate functions configuration functions ##### |
mbed_official | 125:23cc3068a9e4 | 474 | =============================================================================== |
mbed_official | 125:23cc3068a9e4 | 475 | |
mbed_official | 125:23cc3068a9e4 | 476 | @endverbatim |
mbed_official | 125:23cc3068a9e4 | 477 | * @{ |
mbed_official | 125:23cc3068a9e4 | 478 | */ |
mbed_official | 125:23cc3068a9e4 | 479 | |
mbed_official | 125:23cc3068a9e4 | 480 | /** |
mbed_official | 125:23cc3068a9e4 | 481 | * @brief Writes data to the specified GPIO data port. |
mbed_official | 125:23cc3068a9e4 | 482 | * @param GPIOx: where x can be (A, B, C, D, E or F) to select the GPIO peripheral. |
mbed_official | 125:23cc3068a9e4 | 483 | * @param GPIO_PinSource: specifies the pin for the Alternate function. |
mbed_official | 125:23cc3068a9e4 | 484 | * This parameter can be GPIO_PinSourcex where x can be (0..15). |
mbed_official | 125:23cc3068a9e4 | 485 | * @param GPIO_AF: selects the pin to be used as Alternate function. |
mbed_official | 125:23cc3068a9e4 | 486 | * This parameter can be one of the following value: |
mbed_official | 125:23cc3068a9e4 | 487 | * @arg GPIO_AF_0: JTCK-SWCLK, JTDI, JTDO/TRACESW0, JTMS-SWDAT, MCO, NJTRST, |
mbed_official | 125:23cc3068a9e4 | 488 | * TRACED, TRACECK. |
mbed_official | 125:23cc3068a9e4 | 489 | * @arg GPIO_AF_1: OUT, TIM2, TIM15, TIM16, TIM17. |
mbed_official | 125:23cc3068a9e4 | 490 | * @arg GPIO_AF_2: COMP1_OUT, TIM1, TIM2, TIM3, TIM4, TIM8, TIM15, TIM16. |
mbed_official | 125:23cc3068a9e4 | 491 | * @arg GPIO_AF_3: COMP7_OUT, TIM8, TIM15, Touch, HRTIM. |
mbed_official | 125:23cc3068a9e4 | 492 | * @arg GPIO_AF_4: I2C1, I2C2, TIM1, TIM8, TIM16, TIM17. |
mbed_official | 125:23cc3068a9e4 | 493 | * @arg GPIO_AF_5: IR_OUT, I2S2, I2S3, SPI1, SPI2, TIM8, USART4, USART5 |
mbed_official | 125:23cc3068a9e4 | 494 | * @arg GPIO_AF_6: IR_OUT, I2S2, I2S3, SPI2, SPI3, TIM1, TIM8 |
mbed_official | 125:23cc3068a9e4 | 495 | * @arg GPIO_AF_7: AOP2_OUT, CAN, COMP3_OUT, COMP5_OUT, COMP6_OUT, USART1, |
mbed_official | 125:23cc3068a9e4 | 496 | * USART2, USART3. |
mbed_official | 125:23cc3068a9e4 | 497 | * @arg GPIO_AF_8: COMP1_OUT, COMP2_OUT, COMP3_OUT, COMP4_OUT, COMP5_OUT, |
mbed_official | 125:23cc3068a9e4 | 498 | * COMP6_OUT. |
mbed_official | 125:23cc3068a9e4 | 499 | * @arg GPIO_AF_9: AOP4_OUT, CAN, TIM1, TIM8, TIM15. |
mbed_official | 125:23cc3068a9e4 | 500 | * @arg GPIO_AF_10: AOP1_OUT, AOP3_OUT, TIM2, TIM3, TIM4, TIM8, TIM17. |
mbed_official | 125:23cc3068a9e4 | 501 | * @arg GPIO_AF_11: TIM1, TIM8. |
mbed_official | 125:23cc3068a9e4 | 502 | * @arg GPIO_AF_12: TIM1, HRTIM. |
mbed_official | 125:23cc3068a9e4 | 503 | * @arg GPIO_AF_13: HRTIM, AOP2_OUT. |
mbed_official | 125:23cc3068a9e4 | 504 | * @arg GPIO_AF_14: USBDM, USBDP. |
mbed_official | 125:23cc3068a9e4 | 505 | * @arg GPIO_AF_15: OUT. |
mbed_official | 125:23cc3068a9e4 | 506 | * @note The pin should already been configured in Alternate Function mode(AF) |
mbed_official | 125:23cc3068a9e4 | 507 | * using GPIO_InitStruct->GPIO_Mode = GPIO_Mode_AF |
mbed_official | 125:23cc3068a9e4 | 508 | * @note Refer to the Alternate function mapping table in the device datasheet |
mbed_official | 125:23cc3068a9e4 | 509 | * for the detailed mapping of the system and peripherals alternate |
mbed_official | 125:23cc3068a9e4 | 510 | * function I/O pins. |
mbed_official | 125:23cc3068a9e4 | 511 | * @retval None |
mbed_official | 125:23cc3068a9e4 | 512 | */ |
mbed_official | 125:23cc3068a9e4 | 513 | void GPIO_PinAFConfig(GPIO_TypeDef* GPIOx, uint16_t GPIO_PinSource, uint8_t GPIO_AF) |
mbed_official | 125:23cc3068a9e4 | 514 | { |
mbed_official | 125:23cc3068a9e4 | 515 | uint32_t temp = 0x00; |
mbed_official | 125:23cc3068a9e4 | 516 | uint32_t temp_2 = 0x00; |
mbed_official | 125:23cc3068a9e4 | 517 | |
mbed_official | 125:23cc3068a9e4 | 518 | /* Check the parameters */ |
mbed_official | 125:23cc3068a9e4 | 519 | assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); |
mbed_official | 125:23cc3068a9e4 | 520 | assert_param(IS_GPIO_PIN_SOURCE(GPIO_PinSource)); |
mbed_official | 125:23cc3068a9e4 | 521 | assert_param(IS_GPIO_AF(GPIO_AF)); |
mbed_official | 125:23cc3068a9e4 | 522 | |
mbed_official | 125:23cc3068a9e4 | 523 | temp = ((uint32_t)(GPIO_AF) << ((uint32_t)((uint32_t)GPIO_PinSource & (uint32_t)0x07) * 4)); |
mbed_official | 125:23cc3068a9e4 | 524 | GPIOx->AFR[GPIO_PinSource >> 0x03] &= ~((uint32_t)0xF << ((uint32_t)((uint32_t)GPIO_PinSource & (uint32_t)0x07) * 4)); |
mbed_official | 125:23cc3068a9e4 | 525 | temp_2 = GPIOx->AFR[GPIO_PinSource >> 0x03] | temp; |
mbed_official | 125:23cc3068a9e4 | 526 | GPIOx->AFR[GPIO_PinSource >> 0x03] = temp_2; |
mbed_official | 125:23cc3068a9e4 | 527 | } |
mbed_official | 125:23cc3068a9e4 | 528 | |
mbed_official | 125:23cc3068a9e4 | 529 | /** |
mbed_official | 125:23cc3068a9e4 | 530 | * @} |
mbed_official | 125:23cc3068a9e4 | 531 | */ |
mbed_official | 125:23cc3068a9e4 | 532 | |
mbed_official | 125:23cc3068a9e4 | 533 | /** |
mbed_official | 125:23cc3068a9e4 | 534 | * @} |
mbed_official | 125:23cc3068a9e4 | 535 | */ |
mbed_official | 125:23cc3068a9e4 | 536 | |
mbed_official | 125:23cc3068a9e4 | 537 | /** |
mbed_official | 125:23cc3068a9e4 | 538 | * @} |
mbed_official | 125:23cc3068a9e4 | 539 | */ |
mbed_official | 125:23cc3068a9e4 | 540 | |
mbed_official | 125:23cc3068a9e4 | 541 | /** |
mbed_official | 125:23cc3068a9e4 | 542 | * @} |
mbed_official | 125:23cc3068a9e4 | 543 | */ |
mbed_official | 125:23cc3068a9e4 | 544 | |
mbed_official | 125:23cc3068a9e4 | 545 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |