Robotique FIP / Mbed 2 deprecated FIP_REV1

Dependencies:   HC_SR04_Ultrasonic_Library Servo mbed

Fork of FIP_REV1 by Robotique FIP

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers stm32f4xx_nucleo.c Source File

stm32f4xx_nucleo.c

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32f4xx_nucleo.c
00004   * @author  MCD Application Team
00005   * @version V1.0.0
00006   * @date    18-February-2014
00007   * @brief   This file provides set of firmware functions to manage Leds and
00008   *          push-button available on STM32F4xx-Nucleo Kit from STMicroelectronics.
00009   ******************************************************************************
00010   * @attention
00011   *
00012   * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
00013   *
00014   * Redistribution and use in source and binary forms, with or without modification,
00015   * are permitted provided that the following conditions are met:
00016   *   1. Redistributions of source code must retain the above copyright notice,
00017   *      this list of conditions and the following disclaimer.
00018   *   2. Redistributions in binary form must reproduce the above copyright notice,
00019   *      this list of conditions and the following disclaimer in the documentation
00020   *      and/or other materials provided with the distribution.
00021   *   3. Neither the name of STMicroelectronics nor the names of its contributors
00022   *      may be used to endorse or promote products derived from this software
00023   *      without specific prior written permission.
00024   *
00025   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00026   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00028   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00029   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00030   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00031   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00032   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00033   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00034   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00035   *
00036   ******************************************************************************
00037   */ 
00038   
00039 /* Includes ------------------------------------------------------------------*/
00040 #include "stm32f4xx_nucleo.h"
00041 
00042 /** @addtogroup BSP
00043   * @{
00044   */ 
00045 
00046 /** @addtogroup STM32F4XX_NUCLEO
00047   * @{
00048   */   
00049     
00050 /** @addtogroup STM32F4XX_NUCLEO_LOW_LEVEL 
00051   * @brief This file provides set of firmware functions to manage Leds and push-button
00052   *        available on STM32F4xx-Nucleo Kit from STMicroelectronics.
00053   * @{
00054   */ 
00055 
00056 /** @defgroup STM32F4XX_NUCLEO_LOW_LEVEL_Private_TypesDefinitions STM32F4XX_NUCLEO_LOW_LEVEL_Private_TypesDefinitions
00057   * @{
00058   */ 
00059 /**
00060   * @}
00061   */ 
00062 
00063 
00064 /** @defgroup STM32F4XX_NUCLEO_LOW_LEVEL_Private_Defines STM32F4XX_NUCLEO_LOW_LEVEL_Private_Defines
00065   * @{
00066   */ 
00067 
00068 /**
00069   * @brief STM32F4xx NUCLEO BSP Driver version number V1.0.0
00070   */
00071 #define __STM32F4xx_NUCLEO_BSP_VERSION_MAIN   (0x01) /*!< [31:24] main version */
00072 #define __STM32F4xx_NUCLEO_BSP_VERSION_SUB1   (0x00) /*!< [23:16] sub1 version */
00073 #define __STM32F4xx_NUCLEO_BSP_VERSION_SUB2   (0x00) /*!< [15:8]  sub2 version */
00074 #define __STM32F4xx_NUCLEO_BSP_VERSION_RC     (0x00) /*!< [7:0]  release candidate */ 
00075 #define __STM32F4xx_NUCLEO_BSP_VERSION        ((__STM32F4xx_NUCLEO_BSP_VERSION_MAIN << 24)\
00076                                              |(__STM32F4xx_NUCLEO_BSP_VERSION_SUB1 << 16)\
00077                                              |(__STM32F4xx_NUCLEO_BSP_VERSION_SUB2 << 8 )\
00078                                              |(__STM32F4xx_NUCLEO_BSP_VERSION_RC))   
00079   
00080 /**
00081   * @}
00082   */ 
00083 
00084 
00085 /** @defgroup STM32F4XX_NUCLEO_LOW_LEVEL_Private_Macros STM32F4XX_NUCLEO_LOW_LEVEL_Private_Macros
00086   * @{
00087   */ 
00088 /**
00089   * @}
00090   */ 
00091 
00092 
00093 /** @defgroup STM32F4XX_NUCLEO_LOW_LEVEL_Private_Variables STM32F4XX_NUCLEO_LOW_LEVEL_Private_Variables
00094   * @{
00095   */ 
00096 GPIO_TypeDef* GPIO_PORT[LEDn] = {LED2_GPIO_PORT};
00097 const uint16_t GPIO_PIN[LEDn] = {LED2_PIN};
00098 
00099 GPIO_TypeDef* BUTTON_PORT[BUTTONn] = {KEY_BUTTON_GPIO_PORT }; 
00100 const uint16_t BUTTON_PIN[BUTTONn] = {KEY_BUTTON_PIN }; 
00101 const uint8_t BUTTON_IRQn[BUTTONn] = {KEY_BUTTON_EXTI_IRQn };
00102 
00103 /**
00104   * @}
00105   */ 
00106 
00107 
00108 /** @defgroup STM32F4XX_NUCLEO_LOW_LEVEL_Private_FunctionPrototypes STM32F4XX_NUCLEO_LOW_LEVEL_Private_FunctionPrototypes
00109   * @{
00110   */ 
00111 
00112 /**
00113   * @}
00114   */ 
00115 
00116 /** @defgroup STM32F4XX_NUCLEO_LOW_LEVEL_Private_Functions STM32F4XX_NUCLEO_LOW_LEVEL_Private_Functions
00117   * @{
00118   */ 
00119 
00120 /**
00121   * @brief  This method returns the STM32F4xx NUCLEO BSP Driver revision
00122   * @param  None
00123   * @retval version : 0xXYZR (8bits for each decimal, R for RC)
00124   */
00125 uint32_t BSP_GetVersion(void)
00126 {
00127   return __STM32F4xx_NUCLEO_BSP_VERSION;
00128 }
00129 
00130 /**
00131   * @brief  Configures LED GPIO.
00132   * @param  Led: Specifies the Led to be configured. 
00133   *   This parameter can be one of following parameters:
00134   *     @arg LED2
00135   * @retval None
00136   */
00137 void BSP_LED_Init(Led_TypeDef Led)
00138 {
00139   GPIO_InitTypeDef  GPIO_InitStruct;
00140   
00141   /* Enable the GPIO_LED Clock */
00142   LEDx_GPIO_CLK_ENABLE(Led);
00143 
00144   /* Configure the GPIO_LED pin */
00145   GPIO_InitStruct.Pin = GPIO_PIN[Led];
00146   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
00147   GPIO_InitStruct.Pull = GPIO_PULLUP;
00148   GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
00149   
00150   HAL_GPIO_Init(GPIO_PORT[Led], &GPIO_InitStruct);
00151   
00152   HAL_GPIO_WritePin(GPIO_PORT[Led], GPIO_PIN[Led], GPIO_PIN_RESET); 
00153 }
00154 
00155 /**
00156   * @brief  Turns selected LED On.
00157   * @param  Led: Specifies the Led to be set on. 
00158   *   This parameter can be one of following parameters:
00159   *     @arg LED2
00160   * @retval None
00161   */
00162 void BSP_LED_On(Led_TypeDef Led)
00163 {
00164   HAL_GPIO_WritePin(GPIO_PORT[Led], GPIO_PIN[Led], GPIO_PIN_RESET); 
00165 }
00166 
00167 /**
00168   * @brief  Turns selected LED Off.
00169   * @param  Led: Specifies the Led to be set off. 
00170   *   This parameter can be one of following parameters:
00171   *     @arg LED2
00172   * @retval None
00173   */
00174 void BSP_LED_Off(Led_TypeDef Led)
00175 {
00176   HAL_GPIO_WritePin(GPIO_PORT[Led], GPIO_PIN[Led], GPIO_PIN_SET); 
00177 }
00178 
00179 /**
00180   * @brief  Toggles the selected LED.
00181   * @param  Led: Specifies the Led to be toggled. 
00182   *   This parameter can be one of following parameters:
00183   *     @arg LED2  
00184   * @retval None
00185   */
00186 void BSP_LED_Toggle(Led_TypeDef Led)
00187 {
00188   HAL_GPIO_TogglePin(GPIO_PORT[Led], GPIO_PIN[Led]);
00189 }
00190 
00191 /**
00192   * @brief  Configures Button GPIO and EXTI Line.
00193   * @param  Button: Specifies the Button to be configured.
00194   *   This parameter should be: BUTTON_KEY
00195   * @param  ButtonMode: Specifies Button mode.
00196   *   This parameter can be one of following parameters:   
00197   *     @arg BUTTON_MODE_GPIO: Button will be used as simple IO 
00198   *     @arg BUTTON_MODE_EXTI: Button will be connected to EXTI line with interrupt
00199   *                            generation capability  
00200   * @retval None
00201   */
00202 void BSP_PB_Init(Button_TypeDef Button, ButtonMode_TypeDef ButtonMode)
00203 {
00204   GPIO_InitTypeDef GPIO_InitStruct;
00205 
00206   /* Enable the BUTTON Clock */
00207   BUTTONx_GPIO_CLK_ENABLE(Button);
00208   __SYSCFG_CLK_ENABLE();
00209 
00210   if(ButtonMode == BUTTON_MODE_GPIO)
00211   {
00212   /* Configure Button pin as input */
00213     GPIO_InitStruct.Pin = BUTTON_PIN[Button];
00214     GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
00215     GPIO_InitStruct.Pull = GPIO_PULLDOWN;
00216     GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
00217     HAL_GPIO_Init(BUTTON_PORT[Button], &GPIO_InitStruct);
00218   }
00219  
00220   if(ButtonMode == BUTTON_MODE_EXTI)
00221   {
00222      /* Configure Button pin as input with External interrupt */
00223     GPIO_InitStruct.Pin = BUTTON_PIN[Button];
00224     GPIO_InitStruct.Pull = GPIO_NOPULL;
00225     GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING; 
00226     HAL_GPIO_Init(BUTTON_PORT[Button], &GPIO_InitStruct);
00227 
00228     /* Enable and set Button EXTI Interrupt to the lowest priority */
00229     HAL_NVIC_SetPriority((IRQn_Type)(BUTTON_IRQn[Button]), 0x0F, 0x00);
00230     HAL_NVIC_EnableIRQ((IRQn_Type)(BUTTON_IRQn[Button]));
00231   }
00232 }
00233 
00234 /**
00235   * @brief  Returns the selected Button state.
00236   * @param  Button: Specifies the Button to be checked.
00237   *   This parameter should be: BUTTON_KEY  
00238   * @retval The Button GPIO pin value.
00239   */
00240 uint32_t BSP_PB_GetState(Button_TypeDef Button)
00241 {
00242   return HAL_GPIO_ReadPin(BUTTON_PORT[Button], BUTTON_PIN[Button]);
00243 }
00244 
00245 
00246 /******************************************************************************
00247                             BUS OPERATIONS
00248 *******************************************************************************/
00249 
00250 /******************************************************************************
00251                             LINK OPERATIONS
00252 *******************************************************************************/
00253 
00254 /**
00255   * @}
00256   */ 
00257 
00258 /**
00259   * @}
00260   */ 
00261 
00262 /**
00263   * @}
00264   */ 
00265 
00266 /**
00267   * @}
00268   */   
00269 
00270 /******************* (C) COPYRIGHT 2013 STMicroelectronics *****END OF FILE****/