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