mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Revision:
630:825f75ca301e
Parent:
441:d2c15dda23c1
--- a/targets/cmsis/TARGET_STM/TARGET_STM32F0/stm32f0xx_hal_gpio.c	Mon Sep 28 10:30:09 2015 +0100
+++ b/targets/cmsis/TARGET_STM/TARGET_STM32F0/stm32f0xx_hal_gpio.c	Mon Sep 28 10:45:10 2015 +0100
@@ -2,8 +2,8 @@
   ******************************************************************************
   * @file    stm32f0xx_hal_gpio.c
   * @author  MCD Application Team
-  * @version V1.2.0
-  * @date    11-December-2014
+  * @version V1.3.0
+  * @date    26-June-2015
   * @brief   GPIO HAL module driver.
   *          This file provides firmware functions to manage the following 
   *          functionalities of the General Purpose Input/Output (GPIO) peripheral:
@@ -15,58 +15,51 @@
                     ##### GPIO Peripheral features #####
   ==============================================================================         
   [..] 
-  Each port bit of the general-purpose I/O (GPIO) ports can be individually 
+    (+) Each port bit of the general-purpose I/O (GPIO) ports can be individually
   configured by software in several modes:
-  (+) Input mode 
-  (+) Analog mode
-  (+) Output mode
-  (+) Alternate function mode
-  (+) External interrupt/event lines
+        (++) Input mode
+        (++) Analog mode
+        (++) Output mode
+        (++) Alternate function mode
+        (++) External interrupt/event lines
  
-  [..]  
-  During and just after reset, the alternate functions and external interrupt  
+    (+) During and just after reset, the alternate functions and external interrupt
   lines are not active and the I/O ports are configured in input floating mode.
   
-  [..]   
-  All GPIO pins have weak internal pull-up and pull-down resistors, which can be 
+    (+) All GPIO pins have weak internal pull-up and pull-down resistors, which can be
   activated or not.
            
-  [..]
-  In Output or Alternate mode, each IO can be configured on open-drain or push-pull
+    (+) In Output or Alternate mode, each IO can be configured on open-drain or push-pull
   type and the IO speed can be selected depending on the VDD value.
        
-  [..]
-  The microcontroller IO pins are connected to onboard peripherals/modules through a 
-  multiplexer that allows only one peripheral s alternate function (AF) connected 
+    (+) The microcontroller IO pins are connected to onboard peripherals/modules through a
+        multiplexer that allows only one peripheral alternate function (AF) connected
   to an IO pin at a time. In this way, there can be no conflict between peripherals 
   sharing the same IO pin. 
   
-  [..]  
-  All ports have external interrupt/event capability. To use external interrupt 
+    (+) All ports have external interrupt/event capability. To use external interrupt
   lines, the port must be configured in input mode. All available GPIO pins are 
   connected to the 16 external interrupt/event lines from EXTI0 to EXTI15.
   
-  [..]  
-  The external interrupt/event controller consists of up to 28 edge detectors 
-  (depending on products 16 lines are connected to GPIO) for generating event/interrupt
-  requests (each input line can be independently configured to select the type 
-  (interrupt or event) and the corresponding trigger event (rising or falling or both). 
-  Each line can also be masked independently. 
+    (+) The external interrupt/event controller consists of up to 28 edge detectors
+        (16 lines are connected to GPIO) for generating event/interrupt requests (each
+        input line can be independently configured to select the type (interrupt or event)
+        and the corresponding trigger event (rising or falling or both). Each line can
+        also be masked independently.
    
             ##### How to use this driver #####
   ==============================================================================  
   [..]
-   (#) Enable the GPIO AHB clock using the following function : __GPIOx_CLK_ENABLE(). 
+   (#) Enable the GPIO AHB clock using the following function : __HAL_RCC_GPIOx_CLK_ENABLE(). 
                                     
    (#) Configure the GPIO pin(s) using HAL_GPIO_Init().
        (++) Configure the IO mode using "Mode" member from GPIO_InitTypeDef structure
        (++) Activate Pull-up, Pull-down resistor using "Pull" member from GPIO_InitTypeDef 
             structure.
        (++) In case of Output or alternate function mode selection: the speed is 
-            configured through "Speed" member from GPIO_InitTypeDef structure, 
-            the speed is configurable: Low, Medium and High.
-       (++) If alternate mode is selected, the alternate function connected to the IO
-            is configured through "Alternate" member from GPIO_InitTypeDef structure
+             configured through "Speed" member from GPIO_InitTypeDef structure.
+        (++) In alternate mode is selection, the alternate function connected to the IO
+             is configured through "Alternate" member from GPIO_InitTypeDef structure.
        (++) Analog mode is required when a pin is to be used as ADC channel 
             or DAC output.
        (++) In case of external interrupt/event selection the "Mode" member from 
@@ -98,14 +91,14 @@
        priority over the GPIO function.
   
    (#) The HSE oscillator pins OSC_IN/OSC_OUT can be used as 
-       general purpose PD0 and PD1, respectively, when the HSE oscillator is off. 
+        general purpose PF0 and PF1, respectively, when the HSE oscillator is off.
        The HSE has priority over the GPIO function.
   
   @endverbatim
   ******************************************************************************
   * @attention
   *
-  * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
+  * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
   *
   * Redistribution and use in source and binary forms, with or without modification,
   * are permitted provided that the following conditions are met:
@@ -139,7 +132,7 @@
   * @{
   */
 
-/** @defgroup GPIO GPIO HAL module driver
+/** @defgroup GPIO GPIO
   * @brief GPIO HAL module driver
   * @{
   */
@@ -147,8 +140,8 @@
 #ifdef HAL_GPIO_MODULE_ENABLED
 
 /* Private typedef -----------------------------------------------------------*/
-/* Private define ------------------------------------------------------------*/
-/** @defgroup GPIO_Private_Define GPIO Private Define
+/* Private defines -----------------------------------------------------------*/
+/** @defgroup GPIO_Private_Defines GPIO Private Defines
   * @{
   */
 #define GPIO_MODE             ((uint32_t)0x00000003)
@@ -160,15 +153,14 @@
 #define GPIO_OUTPUT_TYPE      ((uint32_t)0x00000010)
 
 #define GPIO_NUMBER           ((uint32_t)16)
- 
 /**
   * @}
   */
-  
-/* Private macro -------------------------------------------------------------*/
+
+/* Private macros ------------------------------------------------------------*/
 /* Private variables ---------------------------------------------------------*/
 /* Private function prototypes -----------------------------------------------*/
-/* Exporte functions ---------------------------------------------------------*/
+/* Exported functions --------------------------------------------------------*/
 
 /** @defgroup GPIO_Exported_Functions GPIO Exported Functions
   * @{
@@ -187,10 +179,8 @@
   */
 
 /**
-  * @brief  Initializes the GPIOx peripheral according to the specified parameters in the GPIO_Init.
+  * @brief  Initialize the GPIOx peripheral according to the specified parameters in the GPIO_Init.
   * @param  GPIOx: where x can be (A..F) to select the GPIO peripheral for STM32F0 family
-  *   @note   GPIOD is only available on STM32F05xx, STM32F07xx and STM32F09xx
-  *   @note   GPIOE is only available on STM32F07xx and STM32F09xx
   * @param  GPIO_Init: pointer to a GPIO_InitTypeDef structure that contains
   *         the configuration information for the specified GPIO peripheral.
   * @retval None
@@ -225,15 +215,15 @@
         
         /* Configure Alternate function mapped with the current IO */ 
         temp = GPIOx->AFR[position >> 3];
-        temp &= ~((uint32_t)0xF << ((uint32_t)(position & (uint32_t)0x07) * 4)) ;
-        temp |= ((uint32_t)(GPIO_Init->Alternate) << (((uint32_t)position & (uint32_t)0x07) * 4));
+        CLEAR_BIT(temp, (uint32_t)0xF << ((uint32_t)(position & (uint32_t)0x07) * 4)) ;      
+        SET_BIT(temp, (uint32_t)(GPIO_Init->Alternate) << (((uint32_t)position & (uint32_t)0x07) * 4));       
         GPIOx->AFR[position >> 3] = temp;
       }
 
       /* Configure IO Direction mode (Input, Output, Alternate or Analog) */
       temp = GPIOx->MODER;
-      temp &= ~(GPIO_MODER_MODER0 << (position * 2));
-      temp |= ((GPIO_Init->Mode & GPIO_MODE) << (position * 2));
+      CLEAR_BIT(temp, GPIO_MODER_MODER0 << (position * 2));   
+      SET_BIT(temp, (GPIO_Init->Mode & GPIO_MODE) << (position * 2));
       GPIOx->MODER = temp;
 
       /* In case of Output or Alternate function mode selection */
@@ -244,21 +234,21 @@
         assert_param(IS_GPIO_SPEED(GPIO_Init->Speed));
         /* Configure the IO Speed */
         temp = GPIOx->OSPEEDR; 
-        temp &= ~(GPIO_OSPEEDER_OSPEEDR0 << (position * 2));
-        temp |= (GPIO_Init->Speed << (position * 2));
+        CLEAR_BIT(temp, GPIO_OSPEEDER_OSPEEDR0 << (position * 2));
+        SET_BIT(temp, GPIO_Init->Speed << (position * 2));
         GPIOx->OSPEEDR = temp;
 
         /* Configure the IO Output Type */
         temp = GPIOx->OTYPER;
-        temp &= ~(GPIO_OTYPER_OT_0 << position) ;
-        temp |= (((GPIO_Init->Mode & GPIO_OUTPUT_TYPE) >> 4) << position);
+        CLEAR_BIT(temp, GPIO_OTYPER_OT_0 << position) ;
+        SET_BIT(temp, ((GPIO_Init->Mode & GPIO_OUTPUT_TYPE) >> 4) << position);
         GPIOx->OTYPER = temp;
       }
 
       /* Activate the Pull-up or Pull down resistor for the current IO */
       temp = GPIOx->PUPDR;
-      temp &= ~(GPIO_PUPDR_PUPDR0 << (position * 2));
-      temp |= ((GPIO_Init->Pull) << (position * 2));
+      CLEAR_BIT(temp, GPIO_PUPDR_PUPDR0 << (position * 2));
+      SET_BIT(temp, (GPIO_Init->Pull) << (position * 2));
       GPIOx->PUPDR = temp;
 
       /*--------------------- EXTI Mode Configuration ------------------------*/
@@ -266,44 +256,44 @@
       if((GPIO_Init->Mode & EXTI_MODE) == EXTI_MODE) 
       {
         /* Enable SYSCFG Clock */
-        __SYSCFG_CLK_ENABLE();
+        __HAL_RCC_SYSCFG_CLK_ENABLE();
   
         temp = SYSCFG->EXTICR[position >> 2];
-        temp &= ~(((uint32_t)0x0F) << (4 * (position & 0x03)));
-        temp |= (GPIO_GET_INDEX(GPIOx) << (4 * (position & 0x03)));
+        CLEAR_BIT(temp, ((uint32_t)0x0F) << (4 * (position & 0x03)));
+        SET_BIT(temp, (GPIO_GET_INDEX(GPIOx)) << (4 * (position & 0x03)));
         SYSCFG->EXTICR[position >> 2] = temp;
                   
         /* Clear EXTI line configuration */
         temp = EXTI->IMR;
-        temp &= ~((uint32_t)iocurrent);
+        CLEAR_BIT(temp, (uint32_t)iocurrent);
         if((GPIO_Init->Mode & GPIO_MODE_IT) == GPIO_MODE_IT)
         {
-          temp |= iocurrent;
+          SET_BIT(temp, iocurrent); 
         }
         EXTI->IMR = temp;
 
         temp = EXTI->EMR;
-        temp &= ~((uint32_t)iocurrent);
+        CLEAR_BIT(temp, (uint32_t)iocurrent);      
         if((GPIO_Init->Mode & GPIO_MODE_EVT) == GPIO_MODE_EVT)
         { 
-          temp |= iocurrent;
+          SET_BIT(temp, iocurrent); 
         }
         EXTI->EMR = temp;
   
         /* Clear Rising Falling edge configuration */
         temp = EXTI->RTSR;
-        temp &= ~((uint32_t)iocurrent);
+        CLEAR_BIT(temp, (uint32_t)iocurrent); 
         if((GPIO_Init->Mode & RISING_EDGE) == RISING_EDGE)
         {
-          temp |= iocurrent;
+          SET_BIT(temp, iocurrent); 
         }
         EXTI->RTSR = temp;
 
         temp = EXTI->FTSR;
-        temp &= ~((uint32_t)iocurrent);
+        CLEAR_BIT(temp, (uint32_t)iocurrent); 
         if((GPIO_Init->Mode & FALLING_EDGE) == FALLING_EDGE)
         {
-          temp |= iocurrent;
+          SET_BIT(temp, iocurrent); 
         }
         EXTI->FTSR = temp;
       }
@@ -314,10 +304,8 @@
 }
 
 /**
-  * @brief  De-initializes the GPIOx peripheral registers to their default reset values.
+  * @brief  De-initialize the GPIOx peripheral registers to their default reset values.
   * @param  GPIOx: where x can be (A..F) to select the GPIO peripheral for STM32F0 family
-  *   @note   GPIOD is only available on STM32F05xx, STM32F07xx and STM32F09xx
-  *   @note   GPIOE is only available on STM32F07xx and STM32F09xx
   * @param  GPIO_Pin: specifies the port bit to be written.
   *         This parameter can be one of GPIO_PIN_x where x can be (0..15).
   * @retval None
@@ -342,19 +330,19 @@
     {
       /*------------------------- GPIO Mode Configuration --------------------*/
       /* Configure IO Direction in Input Floting Mode */
-      GPIOx->MODER &= ~(GPIO_MODER_MODER0 << (position * 2));
+      CLEAR_BIT(GPIOx->MODER, GPIO_MODER_MODER0 << (position * 2)); 
   
       /* Configure the default Alternate Function in current IO */ 
-      GPIOx->AFR[position >> 3] &= ~((uint32_t)0xF << ((uint32_t)(position & (uint32_t)0x07) * 4)) ;
+      CLEAR_BIT(GPIOx->AFR[position >> 3], (uint32_t)0xF << ((uint32_t)(position & (uint32_t)0x07) * 4)) ;
   
       /* Configure the default value for IO Speed */
-      GPIOx->OSPEEDR &= ~(GPIO_OSPEEDER_OSPEEDR0 << (position * 2));
+      CLEAR_BIT(GPIOx->OSPEEDR, GPIO_OSPEEDER_OSPEEDR0 << (position * 2));
                   
       /* Configure the default value IO Output Type */
-      GPIOx->OTYPER  &= ~(GPIO_OTYPER_OT_0 << position) ;
+      CLEAR_BIT(GPIOx->OTYPER, GPIO_OTYPER_OT_0 << position) ;
   
       /* Deactivate the Pull-up oand Pull-down resistor for the current IO */
-      GPIOx->PUPDR &= ~(GPIO_PUPDR_PUPDR0 << (position * 2));
+      CLEAR_BIT(GPIOx->PUPDR, GPIO_PUPDR_PUPDR0 << (position * 2));
 
       /*------------------------- EXTI Mode Configuration --------------------*/
       /* Clear the External Interrupt or Event for the current IO */
@@ -364,15 +352,15 @@
       if(tmp == (GPIO_GET_INDEX(GPIOx) << (4 * (position & 0x03))))
       {
         tmp = ((uint32_t)0x0F) << (4 * (position & 0x03));
-        SYSCFG->EXTICR[position >> 2] &= ~tmp;
+        CLEAR_BIT(SYSCFG->EXTICR[position >> 2], tmp);
         
         /* Clear EXTI line configuration */
-        EXTI->IMR &= ~((uint32_t)iocurrent);
-        EXTI->EMR &= ~((uint32_t)iocurrent);
+        CLEAR_BIT(EXTI->IMR, (uint32_t)iocurrent);
+        CLEAR_BIT(EXTI->EMR, (uint32_t)iocurrent);
         
         /* Clear Rising Falling edge configuration */
-        EXTI->RTSR &= ~((uint32_t)iocurrent);
-        EXTI->FTSR &= ~((uint32_t)iocurrent);
+        CLEAR_BIT(EXTI->RTSR, (uint32_t)iocurrent);
+        CLEAR_BIT(EXTI->FTSR, (uint32_t)iocurrent);
       }
     }
     
@@ -397,10 +385,8 @@
   */
 
 /**
-  * @brief  Reads the specified input port pin.
+  * @brief  Read the specified input port pin.
   * @param  GPIOx: where x can be (A..F) to select the GPIO peripheral for STM32F0 family
-  *   @note   GPIOD is only available on STM32F05xx, STM32F07xx and STM32F09xx
-  *   @note   GPIOE is only available on STM32F07xx and STM32F09xx
   * @param  GPIO_Pin: specifies the port bit to read.
   *         This parameter can be GPIO_PIN_x where x can be (0..15).
   * @retval The input port pin value.
@@ -424,13 +410,12 @@
   }
 
 /**
-  * @brief  Sets or clears the selected data port bit.
-  * @note   This function uses GPIOx_BSRR register to allow atomic read/modify 
+  * @brief  Set or clear the selected data port bit.
+  * @note   This function uses GPIOx_BSRR and GPIOx_BRR registers to allow atomic read/modify
   *         accesses. In this way, there is no risk of an IRQ occurring between
   *         the read and the modify access.
-  * @param  GPIOx: where x can be (A..F) to select the GPIO peripheral for STM32F0 family
-  *   @note   GPIOD is only available on STM32F05xx, STM32F07xx and STM32F09xx
-  *   @note   GPIOE is only available on STM32F07xx and STM32F09xx
+  *
+  * @param  GPIOx: where x can be (A..H) to select the GPIO peripheral for STM32F0 family
   * @param  GPIO_Pin: specifies the port bit to be written.
   *          This parameter can be one of GPIO_PIN_x where x can be (0..15).
   * @param  PinState: specifies the value to be written to the selected bit.
@@ -451,16 +436,14 @@
   }
   else
   {
-    GPIOx->BSRR = (uint32_t)GPIO_Pin << 16 ;
+    GPIOx->BRR = (uint32_t)GPIO_Pin;
   }
 }
   
 /**
-  * @brief  Toggles the specified GPIO pin
+  * @brief  Toggle the specified GPIO pin.
   * @param  GPIOx: where x can be (A..F) to select the GPIO peripheral for STM32F0 family
-  *   @note   GPIOD is only available on STM32F05xx, STM32F07xx and STM32F09xx
-  *   @note   GPIOE is only available on STM32F07xx and STM32F09xx
-  * @param  GPIO_Pin: specifies the pins to be toggled.
+  * @param  GPIO_Pin: specifies the pin to be toggled.
   * @retval None
   */
 void HAL_GPIO_TogglePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
@@ -477,10 +460,8 @@
 *         GPIOx_PUPDR, GPIOx_AFRL and GPIOx_AFRH.
 * @note   The configuration of the locked GPIO pins can no longer be modified
 *         until the next reset.
-* @param  GPIOx: where x can be (A..F) to select the GPIO peripheral for STM32F0 family
-*   @note   GPIOD is only available on STM32F05xx, STM32F07xx and STM32F09xx
-*   @note   GPIOE is only available on STM32F07xx and STM32F09xx
-* @param  GPIO_Pin: specifies the port bit to be locked.
+  * @param  GPIOx: where x can be (A..F) to select the GPIO peripheral for STM32F0 family
+  * @param  GPIO_Pin: specifies the port bits to be locked.
 *         This parameter can be any combination of GPIO_Pin_x where x can be (0..15).
 * @retval None
 */
@@ -493,7 +474,7 @@
   assert_param(IS_GPIO_PIN(GPIO_Pin));
 
   /* Apply lock key write sequence */
-  tmp |= GPIO_Pin;
+  SET_BIT(tmp, GPIO_Pin);
   /* Set LCKx bit(s): LCKK='1' + LCK[15-0] */
   GPIOx->LCKR = tmp;
   /* Reset LCKx bit(s): LCKK='0' + LCK[15-0] */
@@ -514,7 +495,7 @@
 }
 
 /**
-  * @brief  This function handles EXTI interrupt request.
+  * @brief  Handle EXTI interrupt request.
   * @param  GPIO_Pin: Specifies the port pin connected to corresponding EXTI line.
   * @retval None
   */
@@ -529,13 +510,13 @@
 }
 
 /**
-  * @brief  EXTI line detection callbacks.
+  * @brief  EXTI line detection callback.
   * @param  GPIO_Pin: Specifies the port pin connected to corresponding EXTI line.
   * @retval None
   */
 __weak void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
 {
-  /* NOTE : This function Should not be modified, when the callback is needed,
+  /* NOTE: This function should not be modified, when the callback is needed,
             the HAL_GPIO_EXTI_Callback could be implemented in the user file
    */ 
 }