_BSP_User_Manual
|
stm32vl_discovery.c
Go to the documentation of this file.
00001 /** 00002 ****************************************************************************** 00003 * @file stm32vl_discovery.c 00004 * @author MCD Application Team 00005 * @version $VERSION$ 00006 * @date $DATE$ 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>© COPYRIGHT(c) 2014 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 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 (0x00) /*!< [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 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 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 * @retval None 00110 */ 00111 void BSP_LED_Init(Led_TypeDef Led) 00112 { 00113 GPIO_InitTypeDef gpioinitstruct = {0}; 00114 00115 /* Enable the GPIO_LED Clock */ 00116 LEDx_GPIO_CLK_ENABLE(Led); 00117 00118 /* Configure the GPIO_LED pin */ 00119 gpioinitstruct.Pin = LED_PIN[Led]; 00120 gpioinitstruct.Mode = GPIO_MODE_OUTPUT_PP; 00121 gpioinitstruct.Pull = GPIO_NOPULL; 00122 gpioinitstruct.Speed = GPIO_SPEED_HIGH; 00123 HAL_GPIO_Init(LED_PORT[Led], &gpioinitstruct); 00124 00125 /* Reset PIN to switch off the LED */ 00126 HAL_GPIO_WritePin(LED_PORT[Led], LED_PIN[Led], GPIO_PIN_RESET); 00127 } 00128 00129 /** 00130 * @brief Turns selected LED On. 00131 * @param Led: Specifies the Led to be set on. 00132 * This parameter can be one of following parameters: 00133 * @arg LED3 00134 * @arg LED4 00135 * @retval None 00136 */ 00137 void BSP_LED_On(Led_TypeDef Led) 00138 { 00139 HAL_GPIO_WritePin(LED_PORT[Led], LED_PIN[Led], GPIO_PIN_SET); 00140 } 00141 00142 /** 00143 * @brief Turns selected LED Off. 00144 * @param Led: Specifies the Led to be set off. 00145 * This parameter can be one of following parameters: 00146 * @arg LED3 00147 * @arg LED4 00148 * @retval None 00149 */ 00150 void BSP_LED_Off(Led_TypeDef Led) 00151 { 00152 HAL_GPIO_WritePin(LED_PORT[Led], LED_PIN[Led], GPIO_PIN_RESET); 00153 } 00154 00155 /** 00156 * @brief Toggles the selected LED. 00157 * @param Led: Specifies the Led to be toggled. 00158 * This parameter can be one of following parameters: 00159 * @arg LED3 00160 * @arg LED4 00161 * @retval None 00162 */ 00163 void BSP_LED_Toggle(Led_TypeDef Led) 00164 { 00165 HAL_GPIO_TogglePin(LED_PORT[Led], LED_PIN[Led]); 00166 } 00167 00168 /** 00169 * @brief Configures Button GPIO and EXTI Line. 00170 * @param Button: Specifies the Button to be configured. 00171 * This parameter should be: BUTTON_USER 00172 * @param Button_Mode: Specifies Button mode. 00173 * This parameter can be one of following parameters: 00174 * @arg BUTTON_MODE_GPIO: Button will be used as simple IO 00175 * @arg BUTTON_MODE_EXTI: Button will be connected to EXTI line with interrupt 00176 * generation capability 00177 * @retval None 00178 */ 00179 void BSP_PB_Init(Button_TypeDef Button, ButtonMode_TypeDef Button_Mode) 00180 { 00181 GPIO_InitTypeDef gpioinitstruct = {0}; 00182 00183 /* Enable the BUTTON Clock */ 00184 BUTTONx_GPIO_CLK_ENABLE(Button); 00185 00186 gpioinitstruct.Pin = BUTTON_PIN[Button]; 00187 gpioinitstruct.Pull = GPIO_NOPULL; 00188 gpioinitstruct.Speed = GPIO_SPEED_HIGH; 00189 00190 if (Button_Mode == BUTTON_MODE_GPIO) 00191 { 00192 /* Configure Button pin as input */ 00193 gpioinitstruct.Mode = GPIO_MODE_INPUT; 00194 HAL_GPIO_Init(BUTTON_PORT[Button], &gpioinitstruct); 00195 } 00196 else if (Button_Mode == BUTTON_MODE_EXTI) 00197 { 00198 /* Configure Button pin as input with External interrupt */ 00199 gpioinitstruct.Mode = GPIO_MODE_IT_RISING; 00200 HAL_GPIO_Init(BUTTON_PORT[Button], &gpioinitstruct); 00201 00202 /* Enable and set Button EXTI Interrupt to the lowest priority */ 00203 HAL_NVIC_SetPriority((IRQn_Type)(BUTTON_IRQn[Button]), 0x0F, 0); 00204 HAL_NVIC_EnableIRQ((IRQn_Type)(BUTTON_IRQn[Button])); 00205 } 00206 } 00207 00208 /** 00209 * @brief Returns the selected Button state. 00210 * @param Button: Specifies the Button to be checked. 00211 * This parameter should be: BUTTON_USER 00212 * @retval Button state. 00213 */ 00214 uint32_t BSP_PB_GetState(Button_TypeDef Button) 00215 { 00216 return HAL_GPIO_ReadPin(BUTTON_PORT[Button], BUTTON_PIN[Button]); 00217 } 00218 00219 /** 00220 * @} 00221 */ 00222 00223 /** 00224 * @} 00225 */ 00226 00227 /** 00228 * @} 00229 */ 00230 00231 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 00232
Generated on Thu Dec 11 2014 17:12:21 for _BSP_User_Manual by
