mbed library sources modified for open wear

Dependents:   openwear-lifelogger-example

Fork of mbed-src by mbed official

Revision:
226:b062af740e40
Parent:
106:ced8cbb51063
diff -r 2af4c5d0160c -r b062af740e40 targets/cmsis/TARGET_STM/TARGET_NUCLEO_F401RE/stm32f4xx_hal_gpio.c
--- a/targets/cmsis/TARGET_STM/TARGET_NUCLEO_F401RE/stm32f4xx_hal_gpio.c	Wed Jun 11 09:30:07 2014 +0100
+++ b/targets/cmsis/TARGET_STM/TARGET_NUCLEO_F401RE/stm32f4xx_hal_gpio.c	Wed Jun 11 09:45:09 2014 +0100
@@ -2,18 +2,18 @@
   ******************************************************************************
   * @file    stm32f4xx_hal_gpio.c
   * @author  MCD Application Team
-  * @version V1.0.0
-  * @date    18-February-2014
+  * @version V1.1.0RC2
+  * @date    14-May-2014
   * @brief   GPIO HAL module driver.
   *          This file provides firmware functions to manage the following 
   *          functionalities of the General Purpose Input/Output (GPIO) peripheral:
   *           + Initialization and de-initialization functions
   *           + IO operation functions
-  *         
+  *
   @verbatim
   ==============================================================================
                     ##### GPIO Peripheral features #####
-  ==============================================================================         
+  ==============================================================================
   [..] 
     (+) Each port bit of the general-purpose I/O (GPIO) ports can be individually 
         configured by software in several modes:
@@ -22,7 +22,7 @@
         (++) Output mode
         (++) Alternate function mode
         (++) External interrupt/event lines
-   
+
     (+) 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.
      
@@ -31,27 +31,27 @@
 
     (+) 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 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 
         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 23 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(). 
-             
+
     (#) 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 
@@ -65,7 +65,7 @@
         (++) In case of external interrupt/event selection the "Mode" member from 
              GPIO_InitTypeDef structure select the type (interrupt or event) and 
              the corresponding trigger event (rising or falling or both).
-   
+
     (#) In case of external interrupt/event mode selection, configure NVIC IRQ priority 
         mapped to the EXTI line using HAL_NVIC_SetPriority() and enable it using
         HAL_NVIC_EnableIRQ().
@@ -213,14 +213,17 @@
         /* Check the Alternate function parameter */
         assert_param(IS_GPIO_AF(GPIO_Init->Alternate));
         /* Configure Alternate function mapped with the current IO */
-        temp = ((uint32_t)(GPIO_Init->Alternate) << (((uint32_t)position & (uint32_t)0x07) * 4)) ;
-        GPIOx->AFR[position >> 3] &= ~((uint32_t)0xF << ((uint32_t)(position & (uint32_t)0x07) * 4)) ;
-        GPIOx->AFR[position >> 3] |= temp;
+        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));
+        GPIOx->AFR[position >> 3] = temp;
       }
 
       /* Configure IO Direction mode (Input, Output, Alternate or Analog) */
-      GPIOx->MODER &= ~(GPIO_MODER_MODER0 << (position * 2));
-      GPIOx->MODER |= ((GPIO_Init->Mode & GPIO_MODE) << (position * 2));
+      temp = GPIOx->MODER;
+      temp &= ~(GPIO_MODER_MODER0 << (position * 2));
+      temp |= ((GPIO_Init->Mode & GPIO_MODE) << (position * 2));
+      GPIOx->MODER = temp;
 
       /* In case of Output or Alternate function mode selection */
       if((GPIO_Init->Mode == GPIO_MODE_OUTPUT_PP) || (GPIO_Init->Mode == GPIO_MODE_AF_PP) ||
@@ -229,18 +232,23 @@
         /* Check the Speed parameter */
         assert_param(IS_GPIO_SPEED(GPIO_Init->Speed));
         /* Configure the IO Speed */
-        GPIOx->OSPEEDR &= ~(GPIO_OSPEEDER_OSPEEDR0 << (position * 2));
-        GPIOx->OSPEEDR |= (GPIO_Init->Speed << (position * 2));
+        temp = GPIOx->OSPEEDR; 
+        temp &= ~(GPIO_OSPEEDER_OSPEEDR0 << (position * 2));
+        temp |= (GPIO_Init->Speed << (position * 2));
+        GPIOx->OSPEEDR = temp;
 
         /* Configure the IO Output Type */
-        GPIOx->OTYPER  &= ~(GPIO_OTYPER_OT_0 << position) ;
-        GPIOx->OTYPER |= (((GPIO_Init->Mode & GPIO_OUTPUT_TYPE) >> 4) << position);
+        temp = GPIOx->OTYPER;
+        temp &= ~(GPIO_OTYPER_OT_0 << position) ;
+        temp |= (((GPIO_Init->Mode & GPIO_OUTPUT_TYPE) >> 4) << position);
+        GPIOx->OTYPER = temp;
       }
 
       /* Activate the Pull-up or Pull down resistor for the current IO */
-      GPIOx->PUPDR &= ~(GPIO_PUPDR_PUPDR0 << (position * 2));
-      GPIOx->PUPDR |= ((GPIO_Init->Pull) << (position * 2));
-
+      temp = GPIOx->PUPDR;
+      temp &= ~(GPIO_PUPDR_PUPDR0 << (position * 2));
+      temp |= ((GPIO_Init->Pull) << (position * 2));
+      GPIOx->PUPDR = temp;
 
       /*--------------------- EXTI Mode Configuration ------------------------*/
       /* Configure the External Interrupt or event for the current IO */
@@ -249,35 +257,44 @@
         /* Enable SYSCFG Clock */
         __SYSCFG_CLK_ENABLE();
 
-        temp = ((uint32_t)0x0F) << (4 * (position & 0x03));
-        SYSCFG->EXTICR[position >> 2] &= ~temp;
-        SYSCFG->EXTICR[position >> 2] |= ((uint32_t)(__HAL_GET_GPIO_SOURCE(GPIOx)) << (4 * (position & 0x03)));
-        
+        temp = SYSCFG->EXTICR[position >> 2];
+        temp &= ~(((uint32_t)0x0F) << (4 * (position & 0x03)));
+        temp |= ((uint32_t)(__HAL_GET_GPIO_SOURCE(GPIOx)) << (4 * (position & 0x03)));
+        SYSCFG->EXTICR[position >> 2] = temp;
+
         /* Clear EXTI line configuration */
-        EXTI->IMR &= ~((uint32_t)iocurrent);
-        EXTI->EMR &= ~((uint32_t)iocurrent);
-
+        temp = EXTI->IMR;
+        temp &= ~((uint32_t)iocurrent);
         if((GPIO_Init->Mode & GPIO_MODE_IT) == GPIO_MODE_IT)
         {
-          EXTI->IMR |= iocurrent;
+          temp |= iocurrent;
         }
+        EXTI->IMR = temp;
+
+        temp = EXTI->EMR;
+        temp &= ~((uint32_t)iocurrent);
         if((GPIO_Init->Mode & GPIO_MODE_EVT) == GPIO_MODE_EVT)
         {
-          EXTI->EMR |= iocurrent;
+          temp |= iocurrent;
         }
+        EXTI->EMR = temp;
 
         /* Clear Rising Falling edge configuration */
-        EXTI->RTSR &= ~((uint32_t)iocurrent);
-        EXTI->FTSR &= ~((uint32_t)iocurrent);
-
+        temp = EXTI->RTSR;
+        temp &= ~((uint32_t)iocurrent);
         if((GPIO_Init->Mode & RISING_EDGE) == RISING_EDGE)
         {
-          EXTI->RTSR |= iocurrent;
+          temp |= iocurrent;
         }
+        EXTI->RTSR = temp;
+
+        temp = EXTI->FTSR;
+        temp &= ~((uint32_t)iocurrent);
         if((GPIO_Init->Mode & FALLING_EDGE) == FALLING_EDGE)
         {
-          EXTI->FTSR |= iocurrent;
+          temp |= iocurrent;
         }
+        EXTI->FTSR = temp;
       }
     }
   }
@@ -324,7 +341,6 @@
       /* Deactivate the Pull-up oand Pull-down resistor for the current IO */
       GPIOx->PUPDR &= ~(GPIO_PUPDR_PUPDR0 << (position * 2));
 
-
       /*------------------------- EXTI Mode Configuration --------------------*/
       /* Configure the External Interrupt or event for the current IO */
       tmp = ((uint32_t)0x0F) << (4 * (position & 0x03));
@@ -396,8 +412,8 @@
   *          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.
   *          This parameter can be one of the GPIO_PinState enum values:
-  *            @arg GPIO_BIT_RESET: to clear the port pin
-  *            @arg GPIO_BIT_SET: to set the port pin
+  *            @arg GPIO_PIN_RESET: to clear the port pin
+  *            @arg GPIO_PIN_SET: to set the port pin
   * @retval None
   */
 void HAL_GPIO_WritePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState)
@@ -432,6 +448,45 @@
 }
 
 /**
+  * @brief  Locks GPIO Pins configuration registers.
+  * @note   The locked registers are GPIOx_MODER, GPIOx_OTYPER, GPIOx_OSPEEDR,
+  *         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 STM32F4 family
+  * @param  GPIO_Pin: specifies the port bit to be locked.
+  *         This parameter can be any combination of GPIO_PIN_x where x can be (0..15).
+  * @retval None
+  */
+HAL_StatusTypeDef HAL_GPIO_LockPin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
+{
+  __IO uint32_t tmp = GPIO_LCKR_LCKK;
+
+  /* Check the parameters */
+  assert_param(IS_GPIO_PIN(GPIO_Pin));
+
+  /* Apply lock key write sequence */
+  tmp |= GPIO_Pin;
+  /* Set LCKx bit(s): LCKK='1' + LCK[15-0] */
+  GPIOx->LCKR = tmp;
+  /* Reset LCKx bit(s): LCKK='0' + LCK[15-0] */
+  GPIOx->LCKR = GPIO_Pin;
+  /* Set LCKx bit(s): LCKK='1' + LCK[15-0] */
+  GPIOx->LCKR = tmp;
+  /* Read LCKK bit*/
+  tmp = GPIOx->LCKR;
+
+  if(GPIOx->LCKR & GPIO_LCKR_LCKK)
+  {
+    return HAL_OK;
+  }
+  else
+  {
+    return HAL_ERROR;
+  }
+}
+
+/**
   * @brief  This function handles EXTI interrupt request.
   * @param  GPIO_Pin: Specifies the pins connected EXTI line
   * @retval None