stm32f30x_gpio.c
Go to the documentation of this file.
1 
76 /* Includes ------------------------------------------------------------------*/
77 #include "stm32f30x_gpio.h"
78 #include "stm32f30x_rcc.h"
79 
90 /* Private typedef -----------------------------------------------------------*/
91 /* Private define ------------------------------------------------------------*/
92 
93 
94 /* Private macro -------------------------------------------------------------*/
95 /* Private variables ---------------------------------------------------------*/
96 /* Private function prototypes -----------------------------------------------*/
97 /* Private functions ---------------------------------------------------------*/
98 
121 void GPIO_DeInit(GPIO_TypeDef* GPIOx)
122 {
123  /* Check the parameters */
125 
126  if(GPIOx == GPIOA)
127  {
130  }
131  else if(GPIOx == GPIOB)
132  {
135  }
136  else if(GPIOx == GPIOC)
137  {
140  }
141  else if(GPIOx == GPIOD)
142  {
145  }
146  else if(GPIOx == GPIOE)
147  {
150  }
151  else
152  {
153  if(GPIOx == GPIOF)
154  {
157  }
158  }
159 }
160 
174 void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct)
175 {
176  uint32_t pinpos = 0x00, pos = 0x00 , currentpin = 0x00;
177  uint32_t tmpreg = 0x00;
178 
179  /* Check the parameters */
181  assert_param(IS_GPIO_PIN(GPIO_InitStruct->GPIO_Pin));
182  assert_param(IS_GPIO_MODE(GPIO_InitStruct->GPIO_Mode));
183  assert_param(IS_GPIO_PUPD(GPIO_InitStruct->GPIO_PuPd));
184 
185  /*-------------------------- Configure the port pins -----------------------*/
186  /*-- GPIO Mode Configuration --*/
187  for (pinpos = 0x00; pinpos < 0x10; pinpos++)
188  {
189  pos = ((uint32_t)0x01) << pinpos;
190 
191  /* Get the port pins position */
192  currentpin = (GPIO_InitStruct->GPIO_Pin) & pos;
193 
194  if (currentpin == pos)
195  {
196  if ((GPIO_InitStruct->GPIO_Mode == GPIO_Mode_OUT) || (GPIO_InitStruct->GPIO_Mode == GPIO_Mode_AF))
197  {
198  /* Check Speed mode parameters */
199  assert_param(IS_GPIO_SPEED(GPIO_InitStruct->GPIO_Speed));
200 
201  /* Speed mode configuration */
202  GPIOx->OSPEEDR &= ~(GPIO_OSPEEDER_OSPEEDR0 << (pinpos * 2));
203  GPIOx->OSPEEDR |= ((uint32_t)(GPIO_InitStruct->GPIO_Speed) << (pinpos * 2));
204 
205  /* Check Output mode parameters */
206  assert_param(IS_GPIO_OTYPE(GPIO_InitStruct->GPIO_OType));
207 
208  /* Output mode configuration */
209  GPIOx->OTYPER &= ~((GPIO_OTYPER_OT_0) << ((uint16_t)pinpos));
210  GPIOx->OTYPER |= (uint16_t)(((uint16_t)GPIO_InitStruct->GPIO_OType) << ((uint16_t)pinpos));
211  }
212 
213  GPIOx->MODER &= ~(GPIO_MODER_MODER0 << (pinpos * 2));
214 
215  GPIOx->MODER |= (((uint32_t)GPIO_InitStruct->GPIO_Mode) << (pinpos * 2));
216 
217  /* Use temporary variable to update PUPDR register configuration, to avoid
218  unexpected transition in the GPIO pin configuration. */
219  tmpreg = GPIOx->PUPDR;
220  tmpreg &= ~(GPIO_PUPDR_PUPDR0 << ((uint16_t)pinpos * 2));
221  tmpreg |= (((uint32_t)GPIO_InitStruct->GPIO_PuPd) << (pinpos * 2));
222  GPIOx->PUPDR = tmpreg;
223  }
224  }
225 }
226 
233 void GPIO_StructInit(GPIO_InitTypeDef* GPIO_InitStruct)
234 {
235  /* Reset GPIO init structure parameters values */
236  GPIO_InitStruct->GPIO_Pin = GPIO_Pin_All;
237  GPIO_InitStruct->GPIO_Mode = GPIO_Mode_IN;
238  GPIO_InitStruct->GPIO_Speed = GPIO_Speed_2MHz;
239  GPIO_InitStruct->GPIO_OType = GPIO_OType_PP;
240  GPIO_InitStruct->GPIO_PuPd = GPIO_PuPd_NOPULL;
241 }
242 
254 void GPIO_PinLockConfig(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
255 {
256  uint32_t tmp = 0x00010000;
257 
258  /* Check the parameters */
260  assert_param(IS_GPIO_PIN(GPIO_Pin));
261 
262  tmp |= GPIO_Pin;
263  /* Set LCKK bit */
264  GPIOx->LCKR = tmp;
265  /* Reset LCKK bit */
266  GPIOx->LCKR = GPIO_Pin;
267  /* Set LCKK bit */
268  GPIOx->LCKR = tmp;
269  /* Read LCKK bit */
270  tmp = GPIOx->LCKR;
271  /* Read LCKK bit */
272  tmp = GPIOx->LCKR;
273 }
274 
300 uint8_t GPIO_ReadInputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
301 {
302  uint8_t bitstatus = 0x00;
303 
304  /* Check the parameters */
306  assert_param(IS_GET_GPIO_PIN(GPIO_Pin));
307 
308  if ((GPIOx->IDR & GPIO_Pin) != (uint32_t)Bit_RESET)
309  {
310  bitstatus = (uint8_t)Bit_SET;
311  }
312  else
313  {
314  bitstatus = (uint8_t)Bit_RESET;
315  }
316  return bitstatus;
317 }
318 
324 uint16_t GPIO_ReadInputData(GPIO_TypeDef* GPIOx)
325 {
326  /* Check the parameters */
328 
329  return ((uint16_t)GPIOx->IDR);
330 }
331 
341 uint8_t GPIO_ReadOutputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
342 {
343  uint8_t bitstatus = 0x00;
344 
345  /* Check the parameters */
347  assert_param(IS_GET_GPIO_PIN(GPIO_Pin));
348 
349  if ((GPIOx->ODR & GPIO_Pin) != (uint32_t)Bit_RESET)
350  {
351  bitstatus = (uint8_t)Bit_SET;
352  }
353  else
354  {
355  bitstatus = (uint8_t)Bit_RESET;
356  }
357  return bitstatus;
358 }
359 
365 uint16_t GPIO_ReadOutputData(GPIO_TypeDef* GPIOx)
366 {
367  /* Check the parameters */
369 
370  return ((uint16_t)GPIOx->ODR);
371 }
372 
382 void GPIO_SetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
383 {
384  /* Check the parameters */
386  assert_param(IS_GPIO_PIN(GPIO_Pin));
387 
388  GPIOx->BSRR = GPIO_Pin;
389 }
390 
400 void GPIO_ResetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
401 {
402  /* Check the parameters */
404  assert_param(IS_GPIO_PIN(GPIO_Pin));
405 
406  GPIOx->BRR = GPIO_Pin;
407 }
408 
422 void GPIO_WriteBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, BitAction BitVal)
423 {
424  /* Check the parameters */
426  assert_param(IS_GET_GPIO_PIN(GPIO_Pin));
428 
429  if (BitVal != Bit_RESET)
430  {
431  GPIOx->BSRR = GPIO_Pin;
432  }
433  else
434  {
435  GPIOx->BRR = GPIO_Pin ;
436  }
437 }
438 
446 void GPIO_Write(GPIO_TypeDef* GPIOx, uint16_t PortVal)
447 {
448  /* Check the parameters */
450 
451  GPIOx->ODR = PortVal;
452 }
453 
503 void GPIO_PinAFConfig(GPIO_TypeDef* GPIOx, uint16_t GPIO_PinSource, uint8_t GPIO_AF)
504 {
505  uint32_t temp = 0x00;
506  uint32_t temp_2 = 0x00;
507 
508  /* Check the parameters */
510  assert_param(IS_GPIO_PIN_SOURCE(GPIO_PinSource));
511  assert_param(IS_GPIO_AF(GPIO_AF));
512 
513  temp = ((uint32_t)(GPIO_AF) << ((uint32_t)((uint32_t)GPIO_PinSource & (uint32_t)0x07) * 4));
514  GPIOx->AFR[GPIO_PinSource >> 0x03] &= ~((uint32_t)0xF << ((uint32_t)((uint32_t)GPIO_PinSource & (uint32_t)0x07) * 4));
515  temp_2 = GPIOx->AFR[GPIO_PinSource >> 0x03] | temp;
516  GPIOx->AFR[GPIO_PinSource >> 0x03] = temp_2;
517 }
518 
535 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
void GPIO_PinAFConfig(GPIO_TypeDef *GPIOx, uint16_t GPIO_PinSource, uint8_t GPIO_AF)
Changes the mapping of the specified pin.
__IO uint32_t ODR
Definition: stm32f4xx.h:1288
#define GPIOA
Definition: stm32f4xx.h:2110
uint8_t GPIO_ReadInputDataBit(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
Reads the specified input port pin.
BitAction
GPIO Bit SET and Bit RESET enumeration.
#define RCC_AHBPeriph_GPIOF
#define RCC_AHBPeriph_GPIOB
#define GPIOB
Definition: stm32f4xx.h:2111
void assert_param(int val)
#define GPIOC
Definition: stm32f4xx.h:2112
__IO uint32_t MODER
Definition: stm32f4xx.h:1283
void GPIO_Init(GPIO_TypeDef *GPIOx, GPIO_InitTypeDef *GPIO_InitStruct)
Initializes the GPIOx peripheral according to the specified parameters in the GPIO_InitStruct.
#define GPIO_OSPEEDER_OSPEEDR0
Definition: stm32f4xx.h:6507
#define RCC_AHBPeriph_GPIOC
void GPIO_StructInit(GPIO_InitTypeDef *GPIO_InitStruct)
Fills each GPIO_InitStruct member with its default value.
void GPIO_Write(GPIO_TypeDef *GPIOx, uint16_t PortVal)
Writes data to the specified GPIO data port.
#define GPIO_MODER_MODER0
Definition: stm32f4xx.h:6424
This file contains all the functions prototypes for the GPIO firmware library.
__IO uint32_t PUPDR
Definition: stm32f4xx.h:1286
This file contains all the functions prototypes for the RCC firmware library.
General Purpose I/O.
Definition: stm32f4xx.h:1281
#define GPIOD
Definition: stm32f4xx.h:2113
#define GPIO_OTYPER_OT_0
Definition: stm32f4xx.h:6489
GPIO_Pin
Definition: drv_gpio.h:41
void GPIO_WriteBit(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, BitAction BitVal)
Sets or clears the selected data port bit.
static volatile int16_t temp
Definition: drv_mpu6050.c:278
#define RCC_AHBPeriph_GPIOD
#define GPIO_PUPDR_PUPDR0
Definition: stm32f4xx.h:6572
void GPIO_PinLockConfig(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
Locks GPIO Pins configuration registers.
#define GPIOF
Definition: stm32f4xx.h:2115
#define RCC_AHBPeriph_GPIOE
#define GPIOE
Definition: stm32f4xx.h:2114
uint16_t GPIO_ReadInputData(GPIO_TypeDef *GPIOx)
Reads the specified GPIO input data port.
void GPIO_DeInit(GPIO_TypeDef *GPIOx)
De-initializes the GPIOx peripheral registers to their default reset values.
__IO uint32_t LCKR
Definition: stm32f4xx.h:1291
uint16_t GPIO_ReadOutputData(GPIO_TypeDef *GPIOx)
Reads the specified GPIO output data port.
void GPIO_ResetBits(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
Clears the selected data port bits.
#define RCC_AHBPeriph_GPIOA
void GPIO_SetBits(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
Sets the selected data port bits.
__IO uint32_t BSRR
Definition: stm32f10x.h:1007
__IO uint32_t BRR
Definition: stm32f10x.h:1008
__IO uint32_t IDR
Definition: stm32f4xx.h:1287
uint8_t GPIO_ReadOutputDataBit(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
Reads the specified output data port bit.
__IO uint32_t OTYPER
Definition: stm32f4xx.h:1284
#define IS_GPIO_LIST_PERIPH(PERIPH)
__IO uint32_t AFR[2]
Definition: stm32f4xx.h:1292
__IO uint32_t OSPEEDR
Definition: stm32f4xx.h:1285
void RCC_AHBPeriphResetCmd(uint32_t RCC_AHBPeriph, FunctionalState NewState)
Forces or releases AHB peripheral reset.


rosflight_firmware
Author(s): Daniel Koch , James Jackson
autogenerated on Thu Apr 15 2021 05:07:48