mbed library sources
Dependents: frdm_kl05z_gpio_test
Fork of mbed-src by
targets/cmsis/TARGET_STM/TARGET_NUCLEO_F103RB/stm32f10x_gpio.c@323:9e901b0a5aa1, 2014-09-13 (annotated)
- Committer:
- shaoziyang
- Date:
- Sat Sep 13 14:25:46 2014 +0000
- Revision:
- 323:9e901b0a5aa1
- Parent:
- 84:f54042cbc282
test with CLOCK_SETUP = 0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 52:a51c77007319 | 1 | /** |
mbed_official | 52:a51c77007319 | 2 | ****************************************************************************** |
mbed_official | 52:a51c77007319 | 3 | * @file stm32f10x_gpio.c |
mbed_official | 52:a51c77007319 | 4 | * @author MCD Application Team |
mbed_official | 84:f54042cbc282 | 5 | * @version V3.6.1 |
mbed_official | 84:f54042cbc282 | 6 | * @date 05-March-2012 |
mbed_official | 52:a51c77007319 | 7 | * @brief This file provides all the GPIO firmware functions. |
mbed_official | 70:c1fbde68b492 | 8 | ******************************************************************************* |
mbed_official | 70:c1fbde68b492 | 9 | * Copyright (c) 2014, STMicroelectronics |
mbed_official | 70:c1fbde68b492 | 10 | * All rights reserved. |
mbed_official | 70:c1fbde68b492 | 11 | * |
mbed_official | 70:c1fbde68b492 | 12 | * Redistribution and use in source and binary forms, with or without |
mbed_official | 70:c1fbde68b492 | 13 | * modification, are permitted provided that the following conditions are met: |
mbed_official | 70:c1fbde68b492 | 14 | * |
mbed_official | 70:c1fbde68b492 | 15 | * 1. Redistributions of source code must retain the above copyright notice, |
mbed_official | 70:c1fbde68b492 | 16 | * this list of conditions and the following disclaimer. |
mbed_official | 70:c1fbde68b492 | 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
mbed_official | 70:c1fbde68b492 | 18 | * this list of conditions and the following disclaimer in the documentation |
mbed_official | 70:c1fbde68b492 | 19 | * and/or other materials provided with the distribution. |
mbed_official | 70:c1fbde68b492 | 20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
mbed_official | 70:c1fbde68b492 | 21 | * may be used to endorse or promote products derived from this software |
mbed_official | 70:c1fbde68b492 | 22 | * without specific prior written permission. |
mbed_official | 70:c1fbde68b492 | 23 | * |
mbed_official | 70:c1fbde68b492 | 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
mbed_official | 70:c1fbde68b492 | 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
mbed_official | 70:c1fbde68b492 | 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
mbed_official | 70:c1fbde68b492 | 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
mbed_official | 70:c1fbde68b492 | 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
mbed_official | 70:c1fbde68b492 | 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
mbed_official | 70:c1fbde68b492 | 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
mbed_official | 70:c1fbde68b492 | 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
mbed_official | 70:c1fbde68b492 | 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
mbed_official | 70:c1fbde68b492 | 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
mbed_official | 70:c1fbde68b492 | 34 | ******************************************************************************* |
mbed_official | 70:c1fbde68b492 | 35 | */ |
mbed_official | 52:a51c77007319 | 36 | |
mbed_official | 52:a51c77007319 | 37 | /* Includes ------------------------------------------------------------------*/ |
mbed_official | 52:a51c77007319 | 38 | #include "stm32f10x_gpio.h" |
mbed_official | 52:a51c77007319 | 39 | #include "stm32f10x_rcc.h" |
mbed_official | 52:a51c77007319 | 40 | |
mbed_official | 52:a51c77007319 | 41 | /** @addtogroup STM32F10x_StdPeriph_Driver |
mbed_official | 52:a51c77007319 | 42 | * @{ |
mbed_official | 52:a51c77007319 | 43 | */ |
mbed_official | 52:a51c77007319 | 44 | |
mbed_official | 52:a51c77007319 | 45 | /** @defgroup GPIO |
mbed_official | 52:a51c77007319 | 46 | * @brief GPIO driver modules |
mbed_official | 52:a51c77007319 | 47 | * @{ |
mbed_official | 52:a51c77007319 | 48 | */ |
mbed_official | 52:a51c77007319 | 49 | |
mbed_official | 52:a51c77007319 | 50 | /** @defgroup GPIO_Private_TypesDefinitions |
mbed_official | 52:a51c77007319 | 51 | * @{ |
mbed_official | 52:a51c77007319 | 52 | */ |
mbed_official | 52:a51c77007319 | 53 | |
mbed_official | 52:a51c77007319 | 54 | /** |
mbed_official | 52:a51c77007319 | 55 | * @} |
mbed_official | 52:a51c77007319 | 56 | */ |
mbed_official | 52:a51c77007319 | 57 | |
mbed_official | 52:a51c77007319 | 58 | /** @defgroup GPIO_Private_Defines |
mbed_official | 52:a51c77007319 | 59 | * @{ |
mbed_official | 52:a51c77007319 | 60 | */ |
mbed_official | 52:a51c77007319 | 61 | |
mbed_official | 52:a51c77007319 | 62 | /* ------------ RCC registers bit address in the alias region ----------------*/ |
mbed_official | 52:a51c77007319 | 63 | #define AFIO_OFFSET (AFIO_BASE - PERIPH_BASE) |
mbed_official | 52:a51c77007319 | 64 | |
mbed_official | 52:a51c77007319 | 65 | /* --- EVENTCR Register -----*/ |
mbed_official | 52:a51c77007319 | 66 | |
mbed_official | 52:a51c77007319 | 67 | /* Alias word address of EVOE bit */ |
mbed_official | 52:a51c77007319 | 68 | #define EVCR_OFFSET (AFIO_OFFSET + 0x00) |
mbed_official | 52:a51c77007319 | 69 | #define EVOE_BitNumber ((uint8_t)0x07) |
mbed_official | 52:a51c77007319 | 70 | #define EVCR_EVOE_BB (PERIPH_BB_BASE + (EVCR_OFFSET * 32) + (EVOE_BitNumber * 4)) |
mbed_official | 52:a51c77007319 | 71 | |
mbed_official | 52:a51c77007319 | 72 | |
mbed_official | 52:a51c77007319 | 73 | /* --- MAPR Register ---*/ |
mbed_official | 52:a51c77007319 | 74 | /* Alias word address of MII_RMII_SEL bit */ |
mbed_official | 52:a51c77007319 | 75 | #define MAPR_OFFSET (AFIO_OFFSET + 0x04) |
mbed_official | 52:a51c77007319 | 76 | #define MII_RMII_SEL_BitNumber ((u8)0x17) |
mbed_official | 52:a51c77007319 | 77 | #define MAPR_MII_RMII_SEL_BB (PERIPH_BB_BASE + (MAPR_OFFSET * 32) + (MII_RMII_SEL_BitNumber * 4)) |
mbed_official | 52:a51c77007319 | 78 | |
mbed_official | 52:a51c77007319 | 79 | |
mbed_official | 52:a51c77007319 | 80 | #define EVCR_PORTPINCONFIG_MASK ((uint16_t)0xFF80) |
mbed_official | 52:a51c77007319 | 81 | #define LSB_MASK ((uint16_t)0xFFFF) |
mbed_official | 52:a51c77007319 | 82 | #define DBGAFR_POSITION_MASK ((uint32_t)0x000F0000) |
mbed_official | 52:a51c77007319 | 83 | #define DBGAFR_SWJCFG_MASK ((uint32_t)0xF0FFFFFF) |
mbed_official | 52:a51c77007319 | 84 | #define DBGAFR_LOCATION_MASK ((uint32_t)0x00200000) |
mbed_official | 52:a51c77007319 | 85 | #define DBGAFR_NUMBITS_MASK ((uint32_t)0x00100000) |
mbed_official | 52:a51c77007319 | 86 | /** |
mbed_official | 52:a51c77007319 | 87 | * @} |
mbed_official | 52:a51c77007319 | 88 | */ |
mbed_official | 52:a51c77007319 | 89 | |
mbed_official | 52:a51c77007319 | 90 | /** @defgroup GPIO_Private_Macros |
mbed_official | 52:a51c77007319 | 91 | * @{ |
mbed_official | 52:a51c77007319 | 92 | */ |
mbed_official | 52:a51c77007319 | 93 | |
mbed_official | 52:a51c77007319 | 94 | /** |
mbed_official | 52:a51c77007319 | 95 | * @} |
mbed_official | 52:a51c77007319 | 96 | */ |
mbed_official | 52:a51c77007319 | 97 | |
mbed_official | 52:a51c77007319 | 98 | /** @defgroup GPIO_Private_Variables |
mbed_official | 52:a51c77007319 | 99 | * @{ |
mbed_official | 52:a51c77007319 | 100 | */ |
mbed_official | 52:a51c77007319 | 101 | |
mbed_official | 52:a51c77007319 | 102 | /** |
mbed_official | 52:a51c77007319 | 103 | * @} |
mbed_official | 52:a51c77007319 | 104 | */ |
mbed_official | 52:a51c77007319 | 105 | |
mbed_official | 52:a51c77007319 | 106 | /** @defgroup GPIO_Private_FunctionPrototypes |
mbed_official | 52:a51c77007319 | 107 | * @{ |
mbed_official | 52:a51c77007319 | 108 | */ |
mbed_official | 52:a51c77007319 | 109 | |
mbed_official | 52:a51c77007319 | 110 | /** |
mbed_official | 52:a51c77007319 | 111 | * @} |
mbed_official | 52:a51c77007319 | 112 | */ |
mbed_official | 52:a51c77007319 | 113 | |
mbed_official | 52:a51c77007319 | 114 | /** @defgroup GPIO_Private_Functions |
mbed_official | 52:a51c77007319 | 115 | * @{ |
mbed_official | 52:a51c77007319 | 116 | */ |
mbed_official | 52:a51c77007319 | 117 | |
mbed_official | 52:a51c77007319 | 118 | /** |
mbed_official | 52:a51c77007319 | 119 | * @brief Deinitializes the GPIOx peripheral registers to their default reset values. |
mbed_official | 52:a51c77007319 | 120 | * @param GPIOx: where x can be (A..G) to select the GPIO peripheral. |
mbed_official | 52:a51c77007319 | 121 | * @retval None |
mbed_official | 52:a51c77007319 | 122 | */ |
mbed_official | 52:a51c77007319 | 123 | void GPIO_DeInit(GPIO_TypeDef* GPIOx) |
mbed_official | 52:a51c77007319 | 124 | { |
mbed_official | 52:a51c77007319 | 125 | /* Check the parameters */ |
mbed_official | 52:a51c77007319 | 126 | assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); |
mbed_official | 52:a51c77007319 | 127 | |
mbed_official | 52:a51c77007319 | 128 | if (GPIOx == GPIOA) |
mbed_official | 52:a51c77007319 | 129 | { |
mbed_official | 52:a51c77007319 | 130 | RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOA, ENABLE); |
mbed_official | 52:a51c77007319 | 131 | RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOA, DISABLE); |
mbed_official | 52:a51c77007319 | 132 | } |
mbed_official | 52:a51c77007319 | 133 | else if (GPIOx == GPIOB) |
mbed_official | 52:a51c77007319 | 134 | { |
mbed_official | 52:a51c77007319 | 135 | RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOB, ENABLE); |
mbed_official | 52:a51c77007319 | 136 | RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOB, DISABLE); |
mbed_official | 52:a51c77007319 | 137 | } |
mbed_official | 52:a51c77007319 | 138 | else if (GPIOx == GPIOC) |
mbed_official | 52:a51c77007319 | 139 | { |
mbed_official | 52:a51c77007319 | 140 | RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOC, ENABLE); |
mbed_official | 52:a51c77007319 | 141 | RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOC, DISABLE); |
mbed_official | 52:a51c77007319 | 142 | } |
mbed_official | 52:a51c77007319 | 143 | else if (GPIOx == GPIOD) |
mbed_official | 52:a51c77007319 | 144 | { |
mbed_official | 52:a51c77007319 | 145 | RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOD, ENABLE); |
mbed_official | 52:a51c77007319 | 146 | RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOD, DISABLE); |
mbed_official | 52:a51c77007319 | 147 | } |
mbed_official | 52:a51c77007319 | 148 | else if (GPIOx == GPIOE) |
mbed_official | 52:a51c77007319 | 149 | { |
mbed_official | 52:a51c77007319 | 150 | RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOE, ENABLE); |
mbed_official | 52:a51c77007319 | 151 | RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOE, DISABLE); |
mbed_official | 52:a51c77007319 | 152 | } |
mbed_official | 52:a51c77007319 | 153 | else if (GPIOx == GPIOF) |
mbed_official | 52:a51c77007319 | 154 | { |
mbed_official | 52:a51c77007319 | 155 | RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOF, ENABLE); |
mbed_official | 52:a51c77007319 | 156 | RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOF, DISABLE); |
mbed_official | 52:a51c77007319 | 157 | } |
mbed_official | 52:a51c77007319 | 158 | else |
mbed_official | 52:a51c77007319 | 159 | { |
mbed_official | 52:a51c77007319 | 160 | if (GPIOx == GPIOG) |
mbed_official | 52:a51c77007319 | 161 | { |
mbed_official | 52:a51c77007319 | 162 | RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOG, ENABLE); |
mbed_official | 52:a51c77007319 | 163 | RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOG, DISABLE); |
mbed_official | 52:a51c77007319 | 164 | } |
mbed_official | 52:a51c77007319 | 165 | } |
mbed_official | 52:a51c77007319 | 166 | } |
mbed_official | 52:a51c77007319 | 167 | |
mbed_official | 52:a51c77007319 | 168 | /** |
mbed_official | 52:a51c77007319 | 169 | * @brief Deinitializes the Alternate Functions (remap, event control |
mbed_official | 52:a51c77007319 | 170 | * and EXTI configuration) registers to their default reset values. |
mbed_official | 52:a51c77007319 | 171 | * @param None |
mbed_official | 52:a51c77007319 | 172 | * @retval None |
mbed_official | 52:a51c77007319 | 173 | */ |
mbed_official | 52:a51c77007319 | 174 | void GPIO_AFIODeInit(void) |
mbed_official | 52:a51c77007319 | 175 | { |
mbed_official | 52:a51c77007319 | 176 | RCC_APB2PeriphResetCmd(RCC_APB2Periph_AFIO, ENABLE); |
mbed_official | 52:a51c77007319 | 177 | RCC_APB2PeriphResetCmd(RCC_APB2Periph_AFIO, DISABLE); |
mbed_official | 52:a51c77007319 | 178 | } |
mbed_official | 52:a51c77007319 | 179 | |
mbed_official | 52:a51c77007319 | 180 | /** |
mbed_official | 52:a51c77007319 | 181 | * @brief Initializes the GPIOx peripheral according to the specified |
mbed_official | 52:a51c77007319 | 182 | * parameters in the GPIO_InitStruct. |
mbed_official | 52:a51c77007319 | 183 | * @param GPIOx: where x can be (A..G) to select the GPIO peripheral. |
mbed_official | 52:a51c77007319 | 184 | * @param GPIO_InitStruct: pointer to a GPIO_InitTypeDef structure that |
mbed_official | 52:a51c77007319 | 185 | * contains the configuration information for the specified GPIO peripheral. |
mbed_official | 52:a51c77007319 | 186 | * @retval None |
mbed_official | 52:a51c77007319 | 187 | */ |
mbed_official | 52:a51c77007319 | 188 | void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct) |
mbed_official | 52:a51c77007319 | 189 | { |
mbed_official | 52:a51c77007319 | 190 | uint32_t currentmode = 0x00, currentpin = 0x00, pinpos = 0x00, pos = 0x00; |
mbed_official | 52:a51c77007319 | 191 | uint32_t tmpreg = 0x00, pinmask = 0x00; |
mbed_official | 52:a51c77007319 | 192 | /* Check the parameters */ |
mbed_official | 52:a51c77007319 | 193 | assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); |
mbed_official | 52:a51c77007319 | 194 | assert_param(IS_GPIO_MODE(GPIO_InitStruct->GPIO_Mode)); |
mbed_official | 52:a51c77007319 | 195 | assert_param(IS_GPIO_PIN(GPIO_InitStruct->GPIO_Pin)); |
mbed_official | 52:a51c77007319 | 196 | |
mbed_official | 52:a51c77007319 | 197 | /*---------------------------- GPIO Mode Configuration -----------------------*/ |
mbed_official | 52:a51c77007319 | 198 | currentmode = ((uint32_t)GPIO_InitStruct->GPIO_Mode) & ((uint32_t)0x0F); |
mbed_official | 52:a51c77007319 | 199 | if ((((uint32_t)GPIO_InitStruct->GPIO_Mode) & ((uint32_t)0x10)) != 0x00) |
mbed_official | 52:a51c77007319 | 200 | { |
mbed_official | 52:a51c77007319 | 201 | /* Check the parameters */ |
mbed_official | 52:a51c77007319 | 202 | assert_param(IS_GPIO_SPEED(GPIO_InitStruct->GPIO_Speed)); |
mbed_official | 52:a51c77007319 | 203 | /* Output mode */ |
mbed_official | 52:a51c77007319 | 204 | currentmode |= (uint32_t)GPIO_InitStruct->GPIO_Speed; |
mbed_official | 52:a51c77007319 | 205 | } |
mbed_official | 52:a51c77007319 | 206 | /*---------------------------- GPIO CRL Configuration ------------------------*/ |
mbed_official | 52:a51c77007319 | 207 | /* Configure the eight low port pins */ |
mbed_official | 52:a51c77007319 | 208 | if (((uint32_t)GPIO_InitStruct->GPIO_Pin & ((uint32_t)0x00FF)) != 0x00) |
mbed_official | 52:a51c77007319 | 209 | { |
mbed_official | 52:a51c77007319 | 210 | tmpreg = GPIOx->CRL; |
mbed_official | 52:a51c77007319 | 211 | for (pinpos = 0x00; pinpos < 0x08; pinpos++) |
mbed_official | 52:a51c77007319 | 212 | { |
mbed_official | 52:a51c77007319 | 213 | pos = ((uint32_t)0x01) << pinpos; |
mbed_official | 52:a51c77007319 | 214 | /* Get the port pins position */ |
mbed_official | 52:a51c77007319 | 215 | currentpin = (GPIO_InitStruct->GPIO_Pin) & pos; |
mbed_official | 52:a51c77007319 | 216 | if (currentpin == pos) |
mbed_official | 52:a51c77007319 | 217 | { |
mbed_official | 52:a51c77007319 | 218 | pos = pinpos << 2; |
mbed_official | 52:a51c77007319 | 219 | /* Clear the corresponding low control register bits */ |
mbed_official | 52:a51c77007319 | 220 | pinmask = ((uint32_t)0x0F) << pos; |
mbed_official | 52:a51c77007319 | 221 | tmpreg &= ~pinmask; |
mbed_official | 52:a51c77007319 | 222 | /* Write the mode configuration in the corresponding bits */ |
mbed_official | 52:a51c77007319 | 223 | tmpreg |= (currentmode << pos); |
mbed_official | 52:a51c77007319 | 224 | /* Reset the corresponding ODR bit */ |
mbed_official | 52:a51c77007319 | 225 | if (GPIO_InitStruct->GPIO_Mode == GPIO_Mode_IPD) |
mbed_official | 52:a51c77007319 | 226 | { |
mbed_official | 52:a51c77007319 | 227 | GPIOx->BRR = (((uint32_t)0x01) << pinpos); |
mbed_official | 52:a51c77007319 | 228 | } |
mbed_official | 52:a51c77007319 | 229 | else |
mbed_official | 52:a51c77007319 | 230 | { |
mbed_official | 52:a51c77007319 | 231 | /* Set the corresponding ODR bit */ |
mbed_official | 52:a51c77007319 | 232 | if (GPIO_InitStruct->GPIO_Mode == GPIO_Mode_IPU) |
mbed_official | 52:a51c77007319 | 233 | { |
mbed_official | 52:a51c77007319 | 234 | GPIOx->BSRR = (((uint32_t)0x01) << pinpos); |
mbed_official | 52:a51c77007319 | 235 | } |
mbed_official | 52:a51c77007319 | 236 | } |
mbed_official | 52:a51c77007319 | 237 | } |
mbed_official | 52:a51c77007319 | 238 | } |
mbed_official | 52:a51c77007319 | 239 | GPIOx->CRL = tmpreg; |
mbed_official | 52:a51c77007319 | 240 | } |
mbed_official | 52:a51c77007319 | 241 | /*---------------------------- GPIO CRH Configuration ------------------------*/ |
mbed_official | 52:a51c77007319 | 242 | /* Configure the eight high port pins */ |
mbed_official | 52:a51c77007319 | 243 | if (GPIO_InitStruct->GPIO_Pin > 0x00FF) |
mbed_official | 52:a51c77007319 | 244 | { |
mbed_official | 52:a51c77007319 | 245 | tmpreg = GPIOx->CRH; |
mbed_official | 52:a51c77007319 | 246 | for (pinpos = 0x00; pinpos < 0x08; pinpos++) |
mbed_official | 52:a51c77007319 | 247 | { |
mbed_official | 52:a51c77007319 | 248 | pos = (((uint32_t)0x01) << (pinpos + 0x08)); |
mbed_official | 52:a51c77007319 | 249 | /* Get the port pins position */ |
mbed_official | 52:a51c77007319 | 250 | currentpin = ((GPIO_InitStruct->GPIO_Pin) & pos); |
mbed_official | 52:a51c77007319 | 251 | if (currentpin == pos) |
mbed_official | 52:a51c77007319 | 252 | { |
mbed_official | 52:a51c77007319 | 253 | pos = pinpos << 2; |
mbed_official | 52:a51c77007319 | 254 | /* Clear the corresponding high control register bits */ |
mbed_official | 52:a51c77007319 | 255 | pinmask = ((uint32_t)0x0F) << pos; |
mbed_official | 52:a51c77007319 | 256 | tmpreg &= ~pinmask; |
mbed_official | 52:a51c77007319 | 257 | /* Write the mode configuration in the corresponding bits */ |
mbed_official | 52:a51c77007319 | 258 | tmpreg |= (currentmode << pos); |
mbed_official | 52:a51c77007319 | 259 | /* Reset the corresponding ODR bit */ |
mbed_official | 52:a51c77007319 | 260 | if (GPIO_InitStruct->GPIO_Mode == GPIO_Mode_IPD) |
mbed_official | 52:a51c77007319 | 261 | { |
mbed_official | 52:a51c77007319 | 262 | GPIOx->BRR = (((uint32_t)0x01) << (pinpos + 0x08)); |
mbed_official | 52:a51c77007319 | 263 | } |
mbed_official | 52:a51c77007319 | 264 | /* Set the corresponding ODR bit */ |
mbed_official | 52:a51c77007319 | 265 | if (GPIO_InitStruct->GPIO_Mode == GPIO_Mode_IPU) |
mbed_official | 52:a51c77007319 | 266 | { |
mbed_official | 52:a51c77007319 | 267 | GPIOx->BSRR = (((uint32_t)0x01) << (pinpos + 0x08)); |
mbed_official | 52:a51c77007319 | 268 | } |
mbed_official | 52:a51c77007319 | 269 | } |
mbed_official | 52:a51c77007319 | 270 | } |
mbed_official | 52:a51c77007319 | 271 | GPIOx->CRH = tmpreg; |
mbed_official | 52:a51c77007319 | 272 | } |
mbed_official | 52:a51c77007319 | 273 | } |
mbed_official | 52:a51c77007319 | 274 | |
mbed_official | 52:a51c77007319 | 275 | /** |
mbed_official | 52:a51c77007319 | 276 | * @brief Fills each GPIO_InitStruct member with its default value. |
mbed_official | 52:a51c77007319 | 277 | * @param GPIO_InitStruct : pointer to a GPIO_InitTypeDef structure which will |
mbed_official | 52:a51c77007319 | 278 | * be initialized. |
mbed_official | 52:a51c77007319 | 279 | * @retval None |
mbed_official | 52:a51c77007319 | 280 | */ |
mbed_official | 52:a51c77007319 | 281 | void GPIO_StructInit(GPIO_InitTypeDef* GPIO_InitStruct) |
mbed_official | 52:a51c77007319 | 282 | { |
mbed_official | 52:a51c77007319 | 283 | /* Reset GPIO init structure parameters values */ |
mbed_official | 52:a51c77007319 | 284 | GPIO_InitStruct->GPIO_Pin = GPIO_Pin_All; |
mbed_official | 52:a51c77007319 | 285 | GPIO_InitStruct->GPIO_Speed = GPIO_Speed_2MHz; |
mbed_official | 52:a51c77007319 | 286 | GPIO_InitStruct->GPIO_Mode = GPIO_Mode_IN_FLOATING; |
mbed_official | 52:a51c77007319 | 287 | } |
mbed_official | 52:a51c77007319 | 288 | |
mbed_official | 52:a51c77007319 | 289 | /** |
mbed_official | 52:a51c77007319 | 290 | * @brief Reads the specified input port pin. |
mbed_official | 52:a51c77007319 | 291 | * @param GPIOx: where x can be (A..G) to select the GPIO peripheral. |
mbed_official | 52:a51c77007319 | 292 | * @param GPIO_Pin: specifies the port bit to read. |
mbed_official | 52:a51c77007319 | 293 | * This parameter can be GPIO_Pin_x where x can be (0..15). |
mbed_official | 52:a51c77007319 | 294 | * @retval The input port pin value. |
mbed_official | 52:a51c77007319 | 295 | */ |
mbed_official | 52:a51c77007319 | 296 | uint8_t GPIO_ReadInputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin) |
mbed_official | 52:a51c77007319 | 297 | { |
mbed_official | 52:a51c77007319 | 298 | uint8_t bitstatus = 0x00; |
mbed_official | 52:a51c77007319 | 299 | |
mbed_official | 52:a51c77007319 | 300 | /* Check the parameters */ |
mbed_official | 52:a51c77007319 | 301 | assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); |
mbed_official | 52:a51c77007319 | 302 | assert_param(IS_GET_GPIO_PIN(GPIO_Pin)); |
mbed_official | 52:a51c77007319 | 303 | |
mbed_official | 52:a51c77007319 | 304 | if ((GPIOx->IDR & GPIO_Pin) != (uint32_t)Bit_RESET) |
mbed_official | 52:a51c77007319 | 305 | { |
mbed_official | 52:a51c77007319 | 306 | bitstatus = (uint8_t)Bit_SET; |
mbed_official | 52:a51c77007319 | 307 | } |
mbed_official | 52:a51c77007319 | 308 | else |
mbed_official | 52:a51c77007319 | 309 | { |
mbed_official | 52:a51c77007319 | 310 | bitstatus = (uint8_t)Bit_RESET; |
mbed_official | 52:a51c77007319 | 311 | } |
mbed_official | 52:a51c77007319 | 312 | return bitstatus; |
mbed_official | 52:a51c77007319 | 313 | } |
mbed_official | 52:a51c77007319 | 314 | |
mbed_official | 52:a51c77007319 | 315 | /** |
mbed_official | 52:a51c77007319 | 316 | * @brief Reads the specified GPIO input data port. |
mbed_official | 52:a51c77007319 | 317 | * @param GPIOx: where x can be (A..G) to select the GPIO peripheral. |
mbed_official | 52:a51c77007319 | 318 | * @retval GPIO input data port value. |
mbed_official | 52:a51c77007319 | 319 | */ |
mbed_official | 52:a51c77007319 | 320 | uint16_t GPIO_ReadInputData(GPIO_TypeDef* GPIOx) |
mbed_official | 52:a51c77007319 | 321 | { |
mbed_official | 52:a51c77007319 | 322 | /* Check the parameters */ |
mbed_official | 52:a51c77007319 | 323 | assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); |
mbed_official | 52:a51c77007319 | 324 | |
mbed_official | 52:a51c77007319 | 325 | return ((uint16_t)GPIOx->IDR); |
mbed_official | 52:a51c77007319 | 326 | } |
mbed_official | 52:a51c77007319 | 327 | |
mbed_official | 52:a51c77007319 | 328 | /** |
mbed_official | 52:a51c77007319 | 329 | * @brief Reads the specified output data port bit. |
mbed_official | 52:a51c77007319 | 330 | * @param GPIOx: where x can be (A..G) to select the GPIO peripheral. |
mbed_official | 52:a51c77007319 | 331 | * @param GPIO_Pin: specifies the port bit to read. |
mbed_official | 52:a51c77007319 | 332 | * This parameter can be GPIO_Pin_x where x can be (0..15). |
mbed_official | 52:a51c77007319 | 333 | * @retval The output port pin value. |
mbed_official | 52:a51c77007319 | 334 | */ |
mbed_official | 52:a51c77007319 | 335 | uint8_t GPIO_ReadOutputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin) |
mbed_official | 52:a51c77007319 | 336 | { |
mbed_official | 52:a51c77007319 | 337 | uint8_t bitstatus = 0x00; |
mbed_official | 52:a51c77007319 | 338 | /* Check the parameters */ |
mbed_official | 52:a51c77007319 | 339 | assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); |
mbed_official | 52:a51c77007319 | 340 | assert_param(IS_GET_GPIO_PIN(GPIO_Pin)); |
mbed_official | 52:a51c77007319 | 341 | |
mbed_official | 52:a51c77007319 | 342 | if ((GPIOx->ODR & GPIO_Pin) != (uint32_t)Bit_RESET) |
mbed_official | 52:a51c77007319 | 343 | { |
mbed_official | 52:a51c77007319 | 344 | bitstatus = (uint8_t)Bit_SET; |
mbed_official | 52:a51c77007319 | 345 | } |
mbed_official | 52:a51c77007319 | 346 | else |
mbed_official | 52:a51c77007319 | 347 | { |
mbed_official | 52:a51c77007319 | 348 | bitstatus = (uint8_t)Bit_RESET; |
mbed_official | 52:a51c77007319 | 349 | } |
mbed_official | 52:a51c77007319 | 350 | return bitstatus; |
mbed_official | 52:a51c77007319 | 351 | } |
mbed_official | 52:a51c77007319 | 352 | |
mbed_official | 52:a51c77007319 | 353 | /** |
mbed_official | 52:a51c77007319 | 354 | * @brief Reads the specified GPIO output data port. |
mbed_official | 52:a51c77007319 | 355 | * @param GPIOx: where x can be (A..G) to select the GPIO peripheral. |
mbed_official | 52:a51c77007319 | 356 | * @retval GPIO output data port value. |
mbed_official | 52:a51c77007319 | 357 | */ |
mbed_official | 52:a51c77007319 | 358 | uint16_t GPIO_ReadOutputData(GPIO_TypeDef* GPIOx) |
mbed_official | 52:a51c77007319 | 359 | { |
mbed_official | 52:a51c77007319 | 360 | /* Check the parameters */ |
mbed_official | 52:a51c77007319 | 361 | assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); |
mbed_official | 52:a51c77007319 | 362 | |
mbed_official | 52:a51c77007319 | 363 | return ((uint16_t)GPIOx->ODR); |
mbed_official | 52:a51c77007319 | 364 | } |
mbed_official | 52:a51c77007319 | 365 | |
mbed_official | 52:a51c77007319 | 366 | /** |
mbed_official | 52:a51c77007319 | 367 | * @brief Sets the selected data port bits. |
mbed_official | 52:a51c77007319 | 368 | * @param GPIOx: where x can be (A..G) to select the GPIO peripheral. |
mbed_official | 52:a51c77007319 | 369 | * @param GPIO_Pin: specifies the port bits to be written. |
mbed_official | 52:a51c77007319 | 370 | * This parameter can be any combination of GPIO_Pin_x where x can be (0..15). |
mbed_official | 52:a51c77007319 | 371 | * @retval None |
mbed_official | 52:a51c77007319 | 372 | */ |
mbed_official | 52:a51c77007319 | 373 | void GPIO_SetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin) |
mbed_official | 52:a51c77007319 | 374 | { |
mbed_official | 52:a51c77007319 | 375 | /* Check the parameters */ |
mbed_official | 52:a51c77007319 | 376 | assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); |
mbed_official | 52:a51c77007319 | 377 | assert_param(IS_GPIO_PIN(GPIO_Pin)); |
mbed_official | 52:a51c77007319 | 378 | |
mbed_official | 52:a51c77007319 | 379 | GPIOx->BSRR = GPIO_Pin; |
mbed_official | 52:a51c77007319 | 380 | } |
mbed_official | 52:a51c77007319 | 381 | |
mbed_official | 52:a51c77007319 | 382 | /** |
mbed_official | 52:a51c77007319 | 383 | * @brief Clears the selected data port bits. |
mbed_official | 52:a51c77007319 | 384 | * @param GPIOx: where x can be (A..G) to select the GPIO peripheral. |
mbed_official | 52:a51c77007319 | 385 | * @param GPIO_Pin: specifies the port bits to be written. |
mbed_official | 52:a51c77007319 | 386 | * This parameter can be any combination of GPIO_Pin_x where x can be (0..15). |
mbed_official | 52:a51c77007319 | 387 | * @retval None |
mbed_official | 52:a51c77007319 | 388 | */ |
mbed_official | 52:a51c77007319 | 389 | void GPIO_ResetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin) |
mbed_official | 52:a51c77007319 | 390 | { |
mbed_official | 52:a51c77007319 | 391 | /* Check the parameters */ |
mbed_official | 52:a51c77007319 | 392 | assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); |
mbed_official | 52:a51c77007319 | 393 | assert_param(IS_GPIO_PIN(GPIO_Pin)); |
mbed_official | 52:a51c77007319 | 394 | |
mbed_official | 52:a51c77007319 | 395 | GPIOx->BRR = GPIO_Pin; |
mbed_official | 52:a51c77007319 | 396 | } |
mbed_official | 52:a51c77007319 | 397 | |
mbed_official | 52:a51c77007319 | 398 | /** |
mbed_official | 52:a51c77007319 | 399 | * @brief Sets or clears the selected data port bit. |
mbed_official | 52:a51c77007319 | 400 | * @param GPIOx: where x can be (A..G) to select the GPIO peripheral. |
mbed_official | 52:a51c77007319 | 401 | * @param GPIO_Pin: specifies the port bit to be written. |
mbed_official | 52:a51c77007319 | 402 | * This parameter can be one of GPIO_Pin_x where x can be (0..15). |
mbed_official | 52:a51c77007319 | 403 | * @param BitVal: specifies the value to be written to the selected bit. |
mbed_official | 52:a51c77007319 | 404 | * This parameter can be one of the BitAction enum values: |
mbed_official | 52:a51c77007319 | 405 | * @arg Bit_RESET: to clear the port pin |
mbed_official | 52:a51c77007319 | 406 | * @arg Bit_SET: to set the port pin |
mbed_official | 52:a51c77007319 | 407 | * @retval None |
mbed_official | 52:a51c77007319 | 408 | */ |
mbed_official | 52:a51c77007319 | 409 | void GPIO_WriteBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, BitAction BitVal) |
mbed_official | 52:a51c77007319 | 410 | { |
mbed_official | 52:a51c77007319 | 411 | /* Check the parameters */ |
mbed_official | 52:a51c77007319 | 412 | assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); |
mbed_official | 52:a51c77007319 | 413 | assert_param(IS_GET_GPIO_PIN(GPIO_Pin)); |
mbed_official | 52:a51c77007319 | 414 | assert_param(IS_GPIO_BIT_ACTION(BitVal)); |
mbed_official | 52:a51c77007319 | 415 | |
mbed_official | 52:a51c77007319 | 416 | if (BitVal != Bit_RESET) |
mbed_official | 52:a51c77007319 | 417 | { |
mbed_official | 52:a51c77007319 | 418 | GPIOx->BSRR = GPIO_Pin; |
mbed_official | 52:a51c77007319 | 419 | } |
mbed_official | 52:a51c77007319 | 420 | else |
mbed_official | 52:a51c77007319 | 421 | { |
mbed_official | 52:a51c77007319 | 422 | GPIOx->BRR = GPIO_Pin; |
mbed_official | 52:a51c77007319 | 423 | } |
mbed_official | 52:a51c77007319 | 424 | } |
mbed_official | 52:a51c77007319 | 425 | |
mbed_official | 52:a51c77007319 | 426 | /** |
mbed_official | 52:a51c77007319 | 427 | * @brief Writes data to the specified GPIO data port. |
mbed_official | 52:a51c77007319 | 428 | * @param GPIOx: where x can be (A..G) to select the GPIO peripheral. |
mbed_official | 52:a51c77007319 | 429 | * @param PortVal: specifies the value to be written to the port output data register. |
mbed_official | 52:a51c77007319 | 430 | * @retval None |
mbed_official | 52:a51c77007319 | 431 | */ |
mbed_official | 52:a51c77007319 | 432 | void GPIO_Write(GPIO_TypeDef* GPIOx, uint16_t PortVal) |
mbed_official | 52:a51c77007319 | 433 | { |
mbed_official | 52:a51c77007319 | 434 | /* Check the parameters */ |
mbed_official | 52:a51c77007319 | 435 | assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); |
mbed_official | 52:a51c77007319 | 436 | |
mbed_official | 52:a51c77007319 | 437 | GPIOx->ODR = PortVal; |
mbed_official | 52:a51c77007319 | 438 | } |
mbed_official | 52:a51c77007319 | 439 | |
mbed_official | 52:a51c77007319 | 440 | /** |
mbed_official | 52:a51c77007319 | 441 | * @brief Locks GPIO Pins configuration registers. |
mbed_official | 52:a51c77007319 | 442 | * @param GPIOx: where x can be (A..G) to select the GPIO peripheral. |
mbed_official | 52:a51c77007319 | 443 | * @param GPIO_Pin: specifies the port bit to be written. |
mbed_official | 52:a51c77007319 | 444 | * This parameter can be any combination of GPIO_Pin_x where x can be (0..15). |
mbed_official | 52:a51c77007319 | 445 | * @retval None |
mbed_official | 52:a51c77007319 | 446 | */ |
mbed_official | 52:a51c77007319 | 447 | void GPIO_PinLockConfig(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin) |
mbed_official | 52:a51c77007319 | 448 | { |
mbed_official | 52:a51c77007319 | 449 | uint32_t tmp = 0x00010000; |
mbed_official | 52:a51c77007319 | 450 | |
mbed_official | 52:a51c77007319 | 451 | /* Check the parameters */ |
mbed_official | 52:a51c77007319 | 452 | assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); |
mbed_official | 52:a51c77007319 | 453 | assert_param(IS_GPIO_PIN(GPIO_Pin)); |
mbed_official | 52:a51c77007319 | 454 | |
mbed_official | 52:a51c77007319 | 455 | tmp |= GPIO_Pin; |
mbed_official | 52:a51c77007319 | 456 | /* Set LCKK bit */ |
mbed_official | 52:a51c77007319 | 457 | GPIOx->LCKR = tmp; |
mbed_official | 52:a51c77007319 | 458 | /* Reset LCKK bit */ |
mbed_official | 52:a51c77007319 | 459 | GPIOx->LCKR = GPIO_Pin; |
mbed_official | 52:a51c77007319 | 460 | /* Set LCKK bit */ |
mbed_official | 52:a51c77007319 | 461 | GPIOx->LCKR = tmp; |
mbed_official | 52:a51c77007319 | 462 | /* Read LCKK bit*/ |
mbed_official | 52:a51c77007319 | 463 | tmp = GPIOx->LCKR; |
mbed_official | 52:a51c77007319 | 464 | /* Read LCKK bit*/ |
mbed_official | 52:a51c77007319 | 465 | tmp = GPIOx->LCKR; |
mbed_official | 52:a51c77007319 | 466 | } |
mbed_official | 52:a51c77007319 | 467 | |
mbed_official | 52:a51c77007319 | 468 | /** |
mbed_official | 52:a51c77007319 | 469 | * @brief Selects the GPIO pin used as Event output. |
mbed_official | 52:a51c77007319 | 470 | * @param GPIO_PortSource: selects the GPIO port to be used as source |
mbed_official | 52:a51c77007319 | 471 | * for Event output. |
mbed_official | 52:a51c77007319 | 472 | * This parameter can be GPIO_PortSourceGPIOx where x can be (A..E). |
mbed_official | 52:a51c77007319 | 473 | * @param GPIO_PinSource: specifies the pin for the Event output. |
mbed_official | 52:a51c77007319 | 474 | * This parameter can be GPIO_PinSourcex where x can be (0..15). |
mbed_official | 52:a51c77007319 | 475 | * @retval None |
mbed_official | 52:a51c77007319 | 476 | */ |
mbed_official | 52:a51c77007319 | 477 | void GPIO_EventOutputConfig(uint8_t GPIO_PortSource, uint8_t GPIO_PinSource) |
mbed_official | 52:a51c77007319 | 478 | { |
mbed_official | 52:a51c77007319 | 479 | uint32_t tmpreg = 0x00; |
mbed_official | 52:a51c77007319 | 480 | /* Check the parameters */ |
mbed_official | 52:a51c77007319 | 481 | assert_param(IS_GPIO_EVENTOUT_PORT_SOURCE(GPIO_PortSource)); |
mbed_official | 52:a51c77007319 | 482 | assert_param(IS_GPIO_PIN_SOURCE(GPIO_PinSource)); |
mbed_official | 52:a51c77007319 | 483 | |
mbed_official | 52:a51c77007319 | 484 | tmpreg = AFIO->EVCR; |
mbed_official | 52:a51c77007319 | 485 | /* Clear the PORT[6:4] and PIN[3:0] bits */ |
mbed_official | 52:a51c77007319 | 486 | tmpreg &= EVCR_PORTPINCONFIG_MASK; |
mbed_official | 52:a51c77007319 | 487 | tmpreg |= (uint32_t)GPIO_PortSource << 0x04; |
mbed_official | 52:a51c77007319 | 488 | tmpreg |= GPIO_PinSource; |
mbed_official | 52:a51c77007319 | 489 | AFIO->EVCR = tmpreg; |
mbed_official | 52:a51c77007319 | 490 | } |
mbed_official | 52:a51c77007319 | 491 | |
mbed_official | 52:a51c77007319 | 492 | /** |
mbed_official | 52:a51c77007319 | 493 | * @brief Enables or disables the Event Output. |
mbed_official | 52:a51c77007319 | 494 | * @param NewState: new state of the Event output. |
mbed_official | 52:a51c77007319 | 495 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 52:a51c77007319 | 496 | * @retval None |
mbed_official | 52:a51c77007319 | 497 | */ |
mbed_official | 52:a51c77007319 | 498 | void GPIO_EventOutputCmd(FunctionalState NewState) |
mbed_official | 52:a51c77007319 | 499 | { |
mbed_official | 52:a51c77007319 | 500 | /* Check the parameters */ |
mbed_official | 52:a51c77007319 | 501 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 52:a51c77007319 | 502 | |
mbed_official | 52:a51c77007319 | 503 | *(__IO uint32_t *) EVCR_EVOE_BB = (uint32_t)NewState; |
mbed_official | 52:a51c77007319 | 504 | } |
mbed_official | 52:a51c77007319 | 505 | |
mbed_official | 52:a51c77007319 | 506 | /** |
mbed_official | 52:a51c77007319 | 507 | * @brief Changes the mapping of the specified pin. |
mbed_official | 52:a51c77007319 | 508 | * @param GPIO_Remap: selects the pin to remap. |
mbed_official | 52:a51c77007319 | 509 | * This parameter can be one of the following values: |
mbed_official | 52:a51c77007319 | 510 | * @arg GPIO_Remap_SPI1 : SPI1 Alternate Function mapping |
mbed_official | 52:a51c77007319 | 511 | * @arg GPIO_Remap_I2C1 : I2C1 Alternate Function mapping |
mbed_official | 52:a51c77007319 | 512 | * @arg GPIO_Remap_USART1 : USART1 Alternate Function mapping |
mbed_official | 52:a51c77007319 | 513 | * @arg GPIO_Remap_USART2 : USART2 Alternate Function mapping |
mbed_official | 52:a51c77007319 | 514 | * @arg GPIO_PartialRemap_USART3 : USART3 Partial Alternate Function mapping |
mbed_official | 52:a51c77007319 | 515 | * @arg GPIO_FullRemap_USART3 : USART3 Full Alternate Function mapping |
mbed_official | 52:a51c77007319 | 516 | * @arg GPIO_PartialRemap_TIM1 : TIM1 Partial Alternate Function mapping |
mbed_official | 52:a51c77007319 | 517 | * @arg GPIO_FullRemap_TIM1 : TIM1 Full Alternate Function mapping |
mbed_official | 52:a51c77007319 | 518 | * @arg GPIO_PartialRemap1_TIM2 : TIM2 Partial1 Alternate Function mapping |
mbed_official | 52:a51c77007319 | 519 | * @arg GPIO_PartialRemap2_TIM2 : TIM2 Partial2 Alternate Function mapping |
mbed_official | 52:a51c77007319 | 520 | * @arg GPIO_FullRemap_TIM2 : TIM2 Full Alternate Function mapping |
mbed_official | 52:a51c77007319 | 521 | * @arg GPIO_PartialRemap_TIM3 : TIM3 Partial Alternate Function mapping |
mbed_official | 52:a51c77007319 | 522 | * @arg GPIO_FullRemap_TIM3 : TIM3 Full Alternate Function mapping |
mbed_official | 52:a51c77007319 | 523 | * @arg GPIO_Remap_TIM4 : TIM4 Alternate Function mapping |
mbed_official | 52:a51c77007319 | 524 | * @arg GPIO_Remap1_CAN1 : CAN1 Alternate Function mapping |
mbed_official | 52:a51c77007319 | 525 | * @arg GPIO_Remap2_CAN1 : CAN1 Alternate Function mapping |
mbed_official | 52:a51c77007319 | 526 | * @arg GPIO_Remap_PD01 : PD01 Alternate Function mapping |
mbed_official | 52:a51c77007319 | 527 | * @arg GPIO_Remap_TIM5CH4_LSI : LSI connected to TIM5 Channel4 input capture for calibration |
mbed_official | 52:a51c77007319 | 528 | * @arg GPIO_Remap_ADC1_ETRGINJ : ADC1 External Trigger Injected Conversion remapping |
mbed_official | 52:a51c77007319 | 529 | * @arg GPIO_Remap_ADC1_ETRGREG : ADC1 External Trigger Regular Conversion remapping |
mbed_official | 52:a51c77007319 | 530 | * @arg GPIO_Remap_ADC2_ETRGINJ : ADC2 External Trigger Injected Conversion remapping |
mbed_official | 52:a51c77007319 | 531 | * @arg GPIO_Remap_ADC2_ETRGREG : ADC2 External Trigger Regular Conversion remapping |
mbed_official | 52:a51c77007319 | 532 | * @arg GPIO_Remap_ETH : Ethernet remapping (only for Connectivity line devices) |
mbed_official | 52:a51c77007319 | 533 | * @arg GPIO_Remap_CAN2 : CAN2 remapping (only for Connectivity line devices) |
mbed_official | 52:a51c77007319 | 534 | * @arg GPIO_Remap_SWJ_NoJTRST : Full SWJ Enabled (JTAG-DP + SW-DP) but without JTRST |
mbed_official | 52:a51c77007319 | 535 | * @arg GPIO_Remap_SWJ_JTAGDisable : JTAG-DP Disabled and SW-DP Enabled |
mbed_official | 52:a51c77007319 | 536 | * @arg GPIO_Remap_SWJ_Disable : Full SWJ Disabled (JTAG-DP + SW-DP) |
mbed_official | 52:a51c77007319 | 537 | * @arg GPIO_Remap_SPI3 : SPI3/I2S3 Alternate Function mapping (only for Connectivity line devices) |
mbed_official | 52:a51c77007319 | 538 | * When the SPI3/I2S3 is remapped using this function, the SWJ is configured |
mbed_official | 52:a51c77007319 | 539 | * to Full SWJ Enabled (JTAG-DP + SW-DP) but without JTRST. |
mbed_official | 52:a51c77007319 | 540 | * @arg GPIO_Remap_TIM2ITR1_PTP_SOF : Ethernet PTP output or USB OTG SOF (Start of Frame) connected |
mbed_official | 52:a51c77007319 | 541 | * to TIM2 Internal Trigger 1 for calibration (only for Connectivity line devices) |
mbed_official | 52:a51c77007319 | 542 | * If the GPIO_Remap_TIM2ITR1_PTP_SOF is enabled the TIM2 ITR1 is connected to |
mbed_official | 52:a51c77007319 | 543 | * Ethernet PTP output. When Reset TIM2 ITR1 is connected to USB OTG SOF output. |
mbed_official | 52:a51c77007319 | 544 | * @arg GPIO_Remap_PTP_PPS : Ethernet MAC PPS_PTS output on PB05 (only for Connectivity line devices) |
mbed_official | 52:a51c77007319 | 545 | * @arg GPIO_Remap_TIM15 : TIM15 Alternate Function mapping (only for Value line devices) |
mbed_official | 52:a51c77007319 | 546 | * @arg GPIO_Remap_TIM16 : TIM16 Alternate Function mapping (only for Value line devices) |
mbed_official | 52:a51c77007319 | 547 | * @arg GPIO_Remap_TIM17 : TIM17 Alternate Function mapping (only for Value line devices) |
mbed_official | 52:a51c77007319 | 548 | * @arg GPIO_Remap_CEC : CEC Alternate Function mapping (only for Value line devices) |
mbed_official | 52:a51c77007319 | 549 | * @arg GPIO_Remap_TIM1_DMA : TIM1 DMA requests mapping (only for Value line devices) |
mbed_official | 52:a51c77007319 | 550 | * @arg GPIO_Remap_TIM9 : TIM9 Alternate Function mapping (only for XL-density devices) |
mbed_official | 52:a51c77007319 | 551 | * @arg GPIO_Remap_TIM10 : TIM10 Alternate Function mapping (only for XL-density devices) |
mbed_official | 52:a51c77007319 | 552 | * @arg GPIO_Remap_TIM11 : TIM11 Alternate Function mapping (only for XL-density devices) |
mbed_official | 52:a51c77007319 | 553 | * @arg GPIO_Remap_TIM13 : TIM13 Alternate Function mapping (only for High density Value line and XL-density devices) |
mbed_official | 52:a51c77007319 | 554 | * @arg GPIO_Remap_TIM14 : TIM14 Alternate Function mapping (only for High density Value line and XL-density devices) |
mbed_official | 52:a51c77007319 | 555 | * @arg GPIO_Remap_FSMC_NADV : FSMC_NADV Alternate Function mapping (only for High density Value line and XL-density devices) |
mbed_official | 52:a51c77007319 | 556 | * @arg GPIO_Remap_TIM67_DAC_DMA : TIM6/TIM7 and DAC DMA requests remapping (only for High density Value line devices) |
mbed_official | 52:a51c77007319 | 557 | * @arg GPIO_Remap_TIM12 : TIM12 Alternate Function mapping (only for High density Value line devices) |
mbed_official | 52:a51c77007319 | 558 | * @arg GPIO_Remap_MISC : Miscellaneous Remap (DMA2 Channel5 Position and DAC Trigger remapping, |
mbed_official | 52:a51c77007319 | 559 | * only for High density Value line devices) |
mbed_official | 52:a51c77007319 | 560 | * @param NewState: new state of the port pin remapping. |
mbed_official | 52:a51c77007319 | 561 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 52:a51c77007319 | 562 | * @retval None |
mbed_official | 52:a51c77007319 | 563 | */ |
mbed_official | 52:a51c77007319 | 564 | void GPIO_PinRemapConfig(uint32_t GPIO_Remap, FunctionalState NewState) |
mbed_official | 52:a51c77007319 | 565 | { |
mbed_official | 52:a51c77007319 | 566 | uint32_t tmp = 0x00, tmp1 = 0x00, tmpreg = 0x00, tmpmask = 0x00; |
mbed_official | 52:a51c77007319 | 567 | |
mbed_official | 52:a51c77007319 | 568 | /* Check the parameters */ |
mbed_official | 52:a51c77007319 | 569 | assert_param(IS_GPIO_REMAP(GPIO_Remap)); |
mbed_official | 52:a51c77007319 | 570 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 52:a51c77007319 | 571 | |
mbed_official | 52:a51c77007319 | 572 | if((GPIO_Remap & 0x80000000) == 0x80000000) |
mbed_official | 52:a51c77007319 | 573 | { |
mbed_official | 52:a51c77007319 | 574 | tmpreg = AFIO->MAPR2; |
mbed_official | 52:a51c77007319 | 575 | } |
mbed_official | 52:a51c77007319 | 576 | else |
mbed_official | 52:a51c77007319 | 577 | { |
mbed_official | 52:a51c77007319 | 578 | tmpreg = AFIO->MAPR; |
mbed_official | 52:a51c77007319 | 579 | } |
mbed_official | 52:a51c77007319 | 580 | |
mbed_official | 52:a51c77007319 | 581 | tmpmask = (GPIO_Remap & DBGAFR_POSITION_MASK) >> 0x10; |
mbed_official | 52:a51c77007319 | 582 | tmp = GPIO_Remap & LSB_MASK; |
mbed_official | 52:a51c77007319 | 583 | |
mbed_official | 52:a51c77007319 | 584 | if ((GPIO_Remap & (DBGAFR_LOCATION_MASK | DBGAFR_NUMBITS_MASK)) == (DBGAFR_LOCATION_MASK | DBGAFR_NUMBITS_MASK)) |
mbed_official | 52:a51c77007319 | 585 | { |
mbed_official | 52:a51c77007319 | 586 | tmpreg &= DBGAFR_SWJCFG_MASK; |
mbed_official | 52:a51c77007319 | 587 | AFIO->MAPR &= DBGAFR_SWJCFG_MASK; |
mbed_official | 52:a51c77007319 | 588 | } |
mbed_official | 52:a51c77007319 | 589 | else if ((GPIO_Remap & DBGAFR_NUMBITS_MASK) == DBGAFR_NUMBITS_MASK) |
mbed_official | 52:a51c77007319 | 590 | { |
mbed_official | 52:a51c77007319 | 591 | tmp1 = ((uint32_t)0x03) << tmpmask; |
mbed_official | 52:a51c77007319 | 592 | tmpreg &= ~tmp1; |
mbed_official | 52:a51c77007319 | 593 | tmpreg |= ~DBGAFR_SWJCFG_MASK; |
mbed_official | 52:a51c77007319 | 594 | } |
mbed_official | 52:a51c77007319 | 595 | else |
mbed_official | 52:a51c77007319 | 596 | { |
mbed_official | 52:a51c77007319 | 597 | tmpreg &= ~(tmp << ((GPIO_Remap >> 0x15)*0x10)); |
mbed_official | 52:a51c77007319 | 598 | tmpreg |= ~DBGAFR_SWJCFG_MASK; |
mbed_official | 52:a51c77007319 | 599 | } |
mbed_official | 52:a51c77007319 | 600 | |
mbed_official | 52:a51c77007319 | 601 | if (NewState != DISABLE) |
mbed_official | 52:a51c77007319 | 602 | { |
mbed_official | 52:a51c77007319 | 603 | tmpreg |= (tmp << ((GPIO_Remap >> 0x15)*0x10)); |
mbed_official | 52:a51c77007319 | 604 | } |
mbed_official | 52:a51c77007319 | 605 | |
mbed_official | 52:a51c77007319 | 606 | if((GPIO_Remap & 0x80000000) == 0x80000000) |
mbed_official | 52:a51c77007319 | 607 | { |
mbed_official | 52:a51c77007319 | 608 | AFIO->MAPR2 = tmpreg; |
mbed_official | 52:a51c77007319 | 609 | } |
mbed_official | 52:a51c77007319 | 610 | else |
mbed_official | 52:a51c77007319 | 611 | { |
mbed_official | 52:a51c77007319 | 612 | AFIO->MAPR = tmpreg; |
mbed_official | 52:a51c77007319 | 613 | } |
mbed_official | 52:a51c77007319 | 614 | } |
mbed_official | 52:a51c77007319 | 615 | |
mbed_official | 52:a51c77007319 | 616 | /** |
mbed_official | 52:a51c77007319 | 617 | * @brief Selects the GPIO pin used as EXTI Line. |
mbed_official | 52:a51c77007319 | 618 | * @param GPIO_PortSource: selects the GPIO port to be used as source for EXTI lines. |
mbed_official | 52:a51c77007319 | 619 | * This parameter can be GPIO_PortSourceGPIOx where x can be (A..G). |
mbed_official | 52:a51c77007319 | 620 | * @param GPIO_PinSource: specifies the EXTI line to be configured. |
mbed_official | 52:a51c77007319 | 621 | * This parameter can be GPIO_PinSourcex where x can be (0..15). |
mbed_official | 52:a51c77007319 | 622 | * @retval None |
mbed_official | 52:a51c77007319 | 623 | */ |
mbed_official | 52:a51c77007319 | 624 | void GPIO_EXTILineConfig(uint8_t GPIO_PortSource, uint8_t GPIO_PinSource) |
mbed_official | 52:a51c77007319 | 625 | { |
mbed_official | 52:a51c77007319 | 626 | uint32_t tmp = 0x00; |
mbed_official | 52:a51c77007319 | 627 | /* Check the parameters */ |
mbed_official | 52:a51c77007319 | 628 | assert_param(IS_GPIO_EXTI_PORT_SOURCE(GPIO_PortSource)); |
mbed_official | 52:a51c77007319 | 629 | assert_param(IS_GPIO_PIN_SOURCE(GPIO_PinSource)); |
mbed_official | 52:a51c77007319 | 630 | |
mbed_official | 52:a51c77007319 | 631 | tmp = ((uint32_t)0x0F) << (0x04 * (GPIO_PinSource & (uint8_t)0x03)); |
mbed_official | 52:a51c77007319 | 632 | AFIO->EXTICR[GPIO_PinSource >> 0x02] &= ~tmp; |
mbed_official | 52:a51c77007319 | 633 | AFIO->EXTICR[GPIO_PinSource >> 0x02] |= (((uint32_t)GPIO_PortSource) << (0x04 * (GPIO_PinSource & (uint8_t)0x03))); |
mbed_official | 52:a51c77007319 | 634 | } |
mbed_official | 52:a51c77007319 | 635 | |
mbed_official | 52:a51c77007319 | 636 | /** |
mbed_official | 52:a51c77007319 | 637 | * @brief Selects the Ethernet media interface. |
mbed_official | 52:a51c77007319 | 638 | * @note This function applies only to STM32 Connectivity line devices. |
mbed_official | 52:a51c77007319 | 639 | * @param GPIO_ETH_MediaInterface: specifies the Media Interface mode. |
mbed_official | 52:a51c77007319 | 640 | * This parameter can be one of the following values: |
mbed_official | 52:a51c77007319 | 641 | * @arg GPIO_ETH_MediaInterface_MII: MII mode |
mbed_official | 52:a51c77007319 | 642 | * @arg GPIO_ETH_MediaInterface_RMII: RMII mode |
mbed_official | 52:a51c77007319 | 643 | * @retval None |
mbed_official | 52:a51c77007319 | 644 | */ |
mbed_official | 52:a51c77007319 | 645 | void GPIO_ETH_MediaInterfaceConfig(uint32_t GPIO_ETH_MediaInterface) |
mbed_official | 52:a51c77007319 | 646 | { |
mbed_official | 52:a51c77007319 | 647 | assert_param(IS_GPIO_ETH_MEDIA_INTERFACE(GPIO_ETH_MediaInterface)); |
mbed_official | 52:a51c77007319 | 648 | |
mbed_official | 52:a51c77007319 | 649 | /* Configure MII_RMII selection bit */ |
mbed_official | 52:a51c77007319 | 650 | *(__IO uint32_t *) MAPR_MII_RMII_SEL_BB = GPIO_ETH_MediaInterface; |
mbed_official | 52:a51c77007319 | 651 | } |
mbed_official | 52:a51c77007319 | 652 | |
mbed_official | 52:a51c77007319 | 653 | /** |
mbed_official | 52:a51c77007319 | 654 | * @} |
mbed_official | 52:a51c77007319 | 655 | */ |
mbed_official | 52:a51c77007319 | 656 | |
mbed_official | 52:a51c77007319 | 657 | /** |
mbed_official | 52:a51c77007319 | 658 | * @} |
mbed_official | 52:a51c77007319 | 659 | */ |
mbed_official | 52:a51c77007319 | 660 | |
mbed_official | 52:a51c77007319 | 661 | /** |
mbed_official | 52:a51c77007319 | 662 | * @} |
mbed_official | 52:a51c77007319 | 663 | */ |
mbed_official | 52:a51c77007319 | 664 | |
mbed_official | 84:f54042cbc282 | 665 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |