STM32VL-Discovery BSP User Manual: stm32vl_discovery.c Source File

STM32VL Discovery BSP

stm32vl_discovery.c
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32vl_discovery.c
00004   * @author  MCD Application Team
00005   * @version V1.0.1
00006   * @date    18-December-2015
00007   * @brief   This file provides
00008   *            - set of firmware functions to manage Led and push-button
00009   *          available on STM32VL-Discovery board from STMicroelectronics.  
00010   ******************************************************************************
00011   * @attention
00012   *
00013   * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
00014   *
00015   * Redistribution and use in source and binary forms, with or without modification,
00016   * are permitted provided that the following conditions are met:
00017   *   1. Redistributions of source code must retain the above copyright notice,
00018   *      this list of conditions and the following disclaimer.
00019   *   2. Redistributions in binary form must reproduce the above copyright notice,
00020   *      this list of conditions and the following disclaimer in the documentation
00021   *      and/or other materials provided with the distribution.
00022   *   3. Neither the name of STMicroelectronics nor the names of its contributors
00023   *      may be used to endorse or promote products derived from this software
00024   *      without specific prior written permission.
00025   *
00026   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00027   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00028   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00029   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00030   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00031   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00032   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00033   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00034   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00035   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036   *
00037   ******************************************************************************
00038   */
00039 /* Includes ------------------------------------------------------------------*/
00040 #include "stm32vl_discovery.h"
00041 
00042 /** @addtogroup BSP
00043   * @{
00044   */
00045 
00046 /** @defgroup STM32VL_DISCOVERY STM32VL Discovery
00047   * @brief This file provides firmware functions to manage Leds and push-buttons
00048   *        available on STM32VL discovery board from STMicroelectronics.
00049   * @{
00050   */ 
00051 
00052 /** @defgroup STM32VL_DISCOVERY_Private_Defines STM32VL DISCOVERY Private Defines
00053   * @{
00054   */ 
00055   
00056 /**
00057 * @brief STM32VL-Discovery BSP Driver version number
00058 */
00059 #define __STM32VL_DISCO_BSP_VERSION_MAIN   (0x01) /*!< [31:24] main version */
00060 #define __STM32VL_DISCO_BSP_VERSION_SUB1   (0x00) /*!< [23:16] sub1 version */
00061 #define __STM32VL_DISCO_BSP_VERSION_SUB2   (0x01) /*!< [15:8]  sub2 version */
00062 #define __STM32VL_DISCO_BSP_VERSION_RC     (0x00) /*!< [7:0]  release candidate */ 
00063 #define __STM32VL_DISCO_BSP_VERSION        ((__STM32VL_DISCO_BSP_VERSION_MAIN << 24)\
00064                                            |(__STM32VL_DISCO_BSP_VERSION_SUB1 << 16)\
00065                                            |(__STM32VL_DISCO_BSP_VERSION_SUB2 << 8 )\
00066                                            |(__STM32VL_DISCO_BSP_VERSION_RC)) 
00067 /**
00068   * @}
00069   */ 
00070 
00071 /** @defgroup STM32VL_DISCOVERY_Private_Variables STM32VL DISCOVERY Private Variables
00072   * @{
00073   */ 
00074 GPIO_TypeDef*   LED_PORT[LEDn] = {LED3_GPIO_PORT,
00075                                   LED4_GPIO_PORT};
00076 
00077 const uint16_t  LED_PIN[LEDn]  = {LED3_PIN,
00078                                   LED4_PIN};
00079 
00080 
00081 GPIO_TypeDef*   BUTTON_PORT[BUTTONn]  = {USER_BUTTON_GPIO_PORT};
00082 const uint16_t  BUTTON_PIN[BUTTONn]   = {USER_BUTTON_PIN};
00083 const uint8_t   BUTTON_IRQn[BUTTONn]  = {USER_BUTTON_EXTI_IRQn};
00084 
00085 /**
00086   * @}
00087   */ 
00088 
00089 
00090 /** @defgroup STM32VL_DISCOVERY_Exported_Functions STM32VL DISCOVERY Exported Functions
00091   * @{
00092   */ 
00093 
00094 /**
00095   * @brief  This method returns the STM32VL-Discovery BSP Driver version
00096   * @retval version : 0xXYZR (8bits for each decimal, R for RC)
00097   */
00098 uint32_t BSP_GetVersion(void)
00099 {
00100   return __STM32VL_DISCO_BSP_VERSION;
00101 }
00102 
00103 /**
00104   * @brief  Configures LED GPIO.
00105   * @param  Led: Specifies the Led to be configured. 
00106   *   This parameter can be one of following parameters:
00107   *     @arg LED3
00108   *     @arg LED4
00109   */
00110 void BSP_LED_Init(Led_TypeDef Led)
00111 {
00112   GPIO_InitTypeDef  gpioinitstruct = {0};
00113   
00114   /* Enable the GPIO_LED Clock */
00115   LEDx_GPIO_CLK_ENABLE(Led);
00116 
00117   /* Configure the GPIO_LED pin */
00118   gpioinitstruct.Pin    = LED_PIN[Led];
00119   gpioinitstruct.Mode   = GPIO_MODE_OUTPUT_PP;
00120   gpioinitstruct.Pull   = GPIO_NOPULL;
00121   gpioinitstruct.Speed  = GPIO_SPEED_FREQ_HIGH;
00122   HAL_GPIO_Init(LED_PORT[Led], &gpioinitstruct);
00123 
00124   /* Reset PIN to switch off the LED */
00125   HAL_GPIO_WritePin(LED_PORT[Led], LED_PIN[Led], GPIO_PIN_RESET);
00126 }
00127 
00128 /**
00129   * @brief  Turns selected LED On.
00130   * @param  Led: Specifies the Led to be set on. 
00131   *   This parameter can be one of following parameters:
00132   *     @arg LED3
00133   *     @arg LED4
00134   */
00135 void BSP_LED_On(Led_TypeDef Led)
00136 {
00137   HAL_GPIO_WritePin(LED_PORT[Led], LED_PIN[Led], GPIO_PIN_SET);
00138 }
00139 
00140 /**
00141   * @brief  Turns selected LED Off.
00142   * @param  Led: Specifies the Led to be set off. 
00143   *   This parameter can be one of following parameters:
00144   *     @arg LED3
00145   *     @arg LED4
00146   */
00147 void BSP_LED_Off(Led_TypeDef Led)
00148 {
00149   HAL_GPIO_WritePin(LED_PORT[Led], LED_PIN[Led], GPIO_PIN_RESET);
00150 }
00151 
00152 /**
00153   * @brief  Toggles the selected LED.
00154   * @param  Led: Specifies the Led to be toggled. 
00155   *   This parameter can be one of following parameters:
00156   *     @arg LED3
00157   *     @arg LED4
00158   */
00159 void BSP_LED_Toggle(Led_TypeDef Led)
00160 {
00161   HAL_GPIO_TogglePin(LED_PORT[Led], LED_PIN[Led]);
00162 }
00163 
00164 /**
00165   * @brief  Configures Button GPIO and EXTI Line.
00166   * @param  Button: Specifies the Button to be configured.
00167   *   This parameter should be: BUTTON_USER
00168   * @param  Button_Mode: Specifies Button mode.
00169   *   This parameter can be one of following parameters:   
00170   *     @arg BUTTON_MODE_GPIO: Button will be used as simple IO 
00171   *     @arg BUTTON_MODE_EXTI: Button will be connected to EXTI line with interrupt
00172   *                     generation capability  
00173   */
00174 void BSP_PB_Init(Button_TypeDef Button, ButtonMode_TypeDef Button_Mode)
00175 {
00176   GPIO_InitTypeDef gpioinitstruct = {0};
00177 
00178   /* Enable the BUTTON Clock */
00179   BUTTONx_GPIO_CLK_ENABLE(Button);
00180 
00181   gpioinitstruct.Pin    = BUTTON_PIN[Button];
00182   gpioinitstruct.Pull   = GPIO_NOPULL;
00183   gpioinitstruct.Speed  = GPIO_SPEED_FREQ_HIGH;
00184 
00185   if (Button_Mode == BUTTON_MODE_GPIO)
00186   {
00187     /* Configure Button pin as input */
00188     gpioinitstruct.Mode = GPIO_MODE_INPUT;
00189     HAL_GPIO_Init(BUTTON_PORT[Button], &gpioinitstruct);
00190   }
00191   else if (Button_Mode == BUTTON_MODE_EXTI)
00192   {
00193     /* Configure Button pin as input with External interrupt */
00194     gpioinitstruct.Mode = GPIO_MODE_IT_RISING;
00195     HAL_GPIO_Init(BUTTON_PORT[Button], &gpioinitstruct);
00196 
00197     /* Enable and set Button EXTI Interrupt to the lowest priority */
00198     HAL_NVIC_SetPriority((IRQn_Type)(BUTTON_IRQn[Button]), 0x0F, 0);
00199     HAL_NVIC_EnableIRQ((IRQn_Type)(BUTTON_IRQn[Button]));
00200   }
00201 }
00202 
00203 /**
00204   * @brief  Returns the selected Button state.
00205   * @param  Button: Specifies the Button to be checked.
00206   *   This parameter should be: BUTTON_USER  
00207   * @retval Button state.
00208   */
00209 uint32_t BSP_PB_GetState(Button_TypeDef Button)
00210 {
00211   return HAL_GPIO_ReadPin(BUTTON_PORT[Button], BUTTON_PIN[Button]);
00212 }
00213 
00214 /**
00215   * @}
00216   */ 
00217 
00218 /**
00219   * @}
00220   */ 
00221 
00222 /**
00223   * @}
00224   */
00225     
00226 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
00227 
Generated on Fri Mar 3 2017 19:32:58 for STM32VL-Discovery BSP User Manual by   doxygen 1.7.6.1