Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
stm32f3348_discovery.c
00001 /** 00002 ****************************************************************************** 00003 * @file stm32f3348_discovery.c 00004 * @author MCD Application Team 00005 * @version V1.0.0 00006 * @date 20-June-2014 00007 * @brief This file provides set of firmware functions to manage Leds, 00008 * push-button for STM32F3348 DISCO. 00009 ****************************************************************************** 00010 * @attention 00011 * 00012 * <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2> 00013 * 00014 * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 00015 * You may not use this file except in compliance with the License. 00016 * You may obtain a copy of the License at: 00017 * 00018 * http://www.st.com/software_license_agreement_liberty_v2 00019 * 00020 * Unless required by applicable law or agreed to in writing, software 00021 * distributed under the License is distributed on an "AS IS" BASIS, 00022 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00023 * See the License for the specific language governing permissions and 00024 * limitations under the License. 00025 * 00026 ****************************************************************************** 00027 */ 00028 00029 /* Includes ------------------------------------------------------------------*/ 00030 #include "stm32f3348_discovery.h" 00031 00032 /** @addtogroup Utilities 00033 * @{ 00034 */ 00035 00036 /** @addtogroup STM32F3348_DISCOVERY 00037 * @{ 00038 */ 00039 00040 /** @defgroup STM32F3348_DISCOVERY_LOW_LEVEL 00041 * @brief This file provides firmware functions to manage Leds and push-button 00042 * available on STM32F3348-DISCO board from STMicroelectronics. 00043 * @{ 00044 */ 00045 00046 00047 /* Private typedef -----------------------------------------------------------*/ 00048 /* Private define ------------------------------------------------------------*/ 00049 /* Private macro -------------------------------------------------------------*/ 00050 /* Private variables ---------------------------------------------------------*/ 00051 00052 GPIO_TypeDef* GPIO_PORT[LEDn] = {LED3_GPIO_PORT, LED4_GPIO_PORT, 00053 LED5_GPIO_PORT, LED6_GPIO_PORT}; 00054 00055 const uint16_t GPIO_PIN[LEDn] = {LED3_PIN, LED4_PIN, 00056 LED5_PIN, LED6_PIN}; 00057 00058 const uint32_t GPIO_CLK[LEDn] = {LED3_GPIO_CLK, LED4_GPIO_CLK, 00059 LED5_GPIO_CLK, LED6_GPIO_CLK}; 00060 00061 GPIO_TypeDef* BUTTON_PORT[BUTTONn] = {USER_BUTTON_GPIO_PORT}; 00062 00063 const uint16_t BUTTON_PIN[BUTTONn] = {USER_BUTTON_PIN}; 00064 00065 const uint32_t BUTTON_CLK[BUTTONn] = {USER_BUTTON_GPIO_CLK}; 00066 00067 const uint16_t BUTTON_EXTI_LINE[BUTTONn] = {USER_BUTTON_EXTI_LINE}; 00068 00069 const uint8_t BUTTON_PORT_SOURCE[BUTTONn] = {USER_BUTTON_EXTI_PORT_SOURCE}; 00070 00071 const uint8_t BUTTON_PIN_SOURCE[BUTTONn] = {USER_BUTTON_EXTI_PIN_SOURCE}; 00072 00073 const uint8_t BUTTON_IRQn[BUTTONn] = {USER_BUTTON_EXTI_IRQn}; 00074 00075 00076 /* Private function prototypes -----------------------------------------------*/ 00077 00078 /** 00079 * @brief Configures LED GPIO. 00080 * @param Led: Specifies the Led to be configured. 00081 * This parameter can be one of following parameters: 00082 * @arg LED3 00083 * @arg LED4 00084 * @arg LED5 00085 * @arg LED6 00086 * @retval None 00087 */ 00088 void STM_EVAL_LEDInit(Led_TypeDef Led) 00089 { 00090 GPIO_InitTypeDef GPIO_InitStructure; 00091 00092 /* Enable the GPIO_LED Clock */ 00093 RCC_AHBPeriphClockCmd(GPIO_CLK[Led], ENABLE); 00094 00095 /* Configure the GPIO_LED pin */ 00096 GPIO_InitStructure.GPIO_Pin = GPIO_PIN[Led]; 00097 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; 00098 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; 00099 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; 00100 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 00101 GPIO_Init(GPIO_PORT[Led], &GPIO_InitStructure); 00102 } 00103 00104 /** 00105 * @brief Turns selected LED On. 00106 * @param Led: Specifies the Led to be set on. 00107 * This parameter can be one of following parameters: 00108 * @arg LED3 00109 * @arg LED4 00110 * @arg LED5 00111 * @arg LED6 00112 * @retval None 00113 */ 00114 void STM_EVAL_LEDOn(Led_TypeDef Led) 00115 { 00116 GPIO_PORT[Led]->BSRR = GPIO_PIN[Led]; 00117 } 00118 00119 /** 00120 * @brief Turns selected LED Off. 00121 * @param Led: Specifies the Led to be set off. 00122 * This parameter can be one of following parameters: 00123 * @arg LED3 00124 * @arg LED4 00125 * @arg LED5 00126 * @arg LED6 00127 * @retval None 00128 */ 00129 void STM_EVAL_LEDOff(Led_TypeDef Led) 00130 { 00131 GPIO_PORT[Led]->BRR = GPIO_PIN[Led]; 00132 } 00133 00134 /** 00135 * @brief Toggles the selected LED. 00136 * @param Led: Specifies the Led to be toggled. 00137 * This parameter can be one of following parameters: 00138 * @arg LED3 00139 * @arg LED4 00140 * @arg LED5 00141 * @arg LED6 00142 * @retval None 00143 */ 00144 void STM_EVAL_LEDToggle(Led_TypeDef Led) 00145 { 00146 GPIO_PORT[Led]->ODR ^= GPIO_PIN[Led]; 00147 } 00148 00149 /** 00150 * @brief Configures Button GPIO and EXTI Line. 00151 * @param Button: Specifies the Button to be configured. 00152 * This parameter should be: BUTTON_USER 00153 * @param Button_Mode: Specifies Button mode. 00154 * This parameter can be one of following parameters: 00155 * @arg BUTTON_MODE_GPIO: Button will be used as simple IO 00156 * @arg BUTTON_MODE_EXTI: Button will be connected to EXTI line with interrupt 00157 * generation capability 00158 * @retval None 00159 */ 00160 void STM_EVAL_PBInit(Button_TypeDef Button, ButtonMode_TypeDef Button_Mode) 00161 { 00162 GPIO_InitTypeDef GPIO_InitStructure; 00163 EXTI_InitTypeDef EXTI_InitStructure; 00164 NVIC_InitTypeDef NVIC_InitStructure; 00165 00166 /* Enable the BUTTON Clock */ 00167 RCC_AHBPeriphClockCmd(BUTTON_CLK[Button], ENABLE); 00168 RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE); 00169 00170 /* Configure Button pin as input */ 00171 GPIO_InitStructure.GPIO_Pin = BUTTON_PIN[Button]; 00172 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; 00173 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN; 00174 00175 GPIO_Init(BUTTON_PORT[Button], &GPIO_InitStructure); 00176 00177 if (Button_Mode == BUTTON_MODE_EXTI) 00178 { 00179 /* Connect Button EXTI Line to Button GPIO Pin */ 00180 SYSCFG_EXTILineConfig(BUTTON_PORT_SOURCE[Button], BUTTON_PIN_SOURCE[Button]); 00181 00182 /* Configure Button EXTI line */ 00183 EXTI_InitStructure.EXTI_Line = BUTTON_EXTI_LINE[Button]; 00184 EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; 00185 EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; 00186 EXTI_InitStructure.EXTI_LineCmd = ENABLE; 00187 EXTI_Init(&EXTI_InitStructure); 00188 00189 /* Enable and set Button EXTI Interrupt to the lowest priority */ 00190 NVIC_InitStructure.NVIC_IRQChannel = BUTTON_IRQn[Button]; 00191 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F; 00192 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F; 00193 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; 00194 00195 NVIC_Init(&NVIC_InitStructure); 00196 00197 } 00198 } 00199 00200 /** 00201 * @brief Returns the selected Button state. 00202 * @param Button: Specifies the Button to be checked. 00203 * This parameter should be: BUTTON_USER 00204 * @retval The Button GPIO pin value. 00205 */ 00206 uint32_t STM_EVAL_PBGetState(Button_TypeDef Button) 00207 { 00208 return GPIO_ReadInputDataBit(BUTTON_PORT[Button], BUTTON_PIN[Button]); 00209 } 00210 00211 /** 00212 * @} 00213 */ 00214 00215 /** 00216 * @} 00217 */ 00218 00219 /** 00220 * @} 00221 */ 00222 00223 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Wed Jul 13 2022 03:44:51 by
1.7.2