2 ******************************************************************************
3 * @file stm32f4_discovery.c
4 * @author MCD Application Team
6 * @date 19-September-2011
7 * @brief This file provides set of firmware functions to manage Leds and
8 * push-button available on STM32F4-Discovery Kit from STMicroelectronics.
9 ******************************************************************************
12 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
13 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
14 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
15 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
16 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
17 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
19 * <h2><center>© COPYRIGHT 2011 STMicroelectronics</center></h2>
20 ******************************************************************************
23 /* Includes ------------------------------------------------------------------*/
24 #include "stm32f4_discovery.h"
26 //ADDED BY ME!!!!!!!!!!!!!!!!!!!!
27 #include "stm32f4xx_conf.h"
30 /** @addtogroup Utilities
34 /** @addtogroup STM32F4_DISCOVERY
38 /** @defgroup STM32F4_DISCOVERY_LOW_LEVEL
39 * @brief This file provides set of firmware functions to manage Leds and push-button
40 * available on STM32F4-Discovery Kit from STMicroelectronics.
44 /** @defgroup STM32F4_DISCOVERY_LOW_LEVEL_Private_TypesDefinitions
52 /** @defgroup STM32F4_DISCOVERY_LOW_LEVEL_Private_Defines
60 /** @defgroup STM32F4_DISCOVERY_LOW_LEVEL_Private_Macros
68 /** @defgroup STM32F4_DISCOVERY_LOW_LEVEL_Private_Variables
71 GPIO_TypeDef* GPIO_PORT[LEDn] = {LED4_GPIO_PORT, LED3_GPIO_PORT, LED5_GPIO_PORT,
73 const uint16_t GPIO_PIN[LEDn] = {LED4_PIN, LED3_PIN, LED5_PIN,
75 const uint32_t GPIO_CLK[LEDn] = {LED4_GPIO_CLK, LED3_GPIO_CLK, LED5_GPIO_CLK,
78 GPIO_TypeDef* BUTTON_PORT[BUTTONn] = {USER_BUTTON_GPIO_PORT };
80 const uint16_t BUTTON_PIN[BUTTONn] = {USER_BUTTON_PIN };
82 const uint32_t BUTTON_CLK[BUTTONn] = {USER_BUTTON_GPIO_CLK };
84 const uint16_t BUTTON_EXTI_LINE[BUTTONn] = {USER_BUTTON_EXTI_LINE };
86 const uint8_t BUTTON_PORT_SOURCE[BUTTONn] = {USER_BUTTON_EXTI_PORT_SOURCE};
88 const uint8_t BUTTON_PIN_SOURCE[BUTTONn] = {USER_BUTTON_EXTI_PIN_SOURCE };
89 const uint8_t BUTTON_IRQn[BUTTONn] = {USER_BUTTON_EXTI_IRQn };
91 NVIC_InitTypeDef NVIC_InitStructure;
98 /** @defgroup STM32F4_DISCOVERY_LOW_LEVEL_Private_FunctionPrototypes
106 /** @defgroup STM32F4_DISCOVERY_LOW_LEVEL_Private_Functions
111 * @brief Configures LED GPIO.
112 * @param Led: Specifies the Led to be configured.
113 * This parameter can be one of following parameters:
120 void STM_EVAL_LEDInit(Led_TypeDef Led)
122 GPIO_InitTypeDef GPIO_InitStructure;
124 /* Enable the GPIO_LED Clock */
125 RCC_AHB1PeriphClockCmd(GPIO_CLK[Led], ENABLE);
127 /* Configure the GPIO_LED pin */
128 GPIO_InitStructure.GPIO_Pin = GPIO_PIN[Led];
129 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
130 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
131 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
132 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
133 GPIO_Init(GPIO_PORT[Led], &GPIO_InitStructure);
137 * @brief Turns selected LED On.
138 * @param Led: Specifies the Led to be set on.
139 * This parameter can be one of following parameters:
146 void STM_EVAL_LEDOn(Led_TypeDef Led)
148 GPIO_PORT[Led]->BSRRL = GPIO_PIN[Led];
152 * @brief Turns selected LED Off.
153 * @param Led: Specifies the Led to be set off.
154 * This parameter can be one of following parameters:
161 void STM_EVAL_LEDOff(Led_TypeDef Led)
163 GPIO_PORT[Led]->BSRRH = GPIO_PIN[Led];
167 * @brief Toggles the selected LED.
168 * @param Led: Specifies the Led to be toggled.
169 * This parameter can be one of following parameters:
176 void STM_EVAL_LEDToggle(Led_TypeDef Led)
178 GPIO_PORT[Led]->ODR ^= GPIO_PIN[Led];
182 * @brief Configures Button GPIO and EXTI Line.
183 * @param Button: Specifies the Button to be configured.
184 * This parameter should be: BUTTON_USER
185 * @param Button_Mode: Specifies Button mode.
186 * This parameter can be one of following parameters:
187 * @arg BUTTON_MODE_GPIO: Button will be used as simple IO
188 * @arg BUTTON_MODE_EXTI: Button will be connected to EXTI line with interrupt
189 * generation capability
192 void STM_EVAL_PBInit(Button_TypeDef Button, ButtonMode_TypeDef Button_Mode)
194 GPIO_InitTypeDef GPIO_InitStructure;
195 EXTI_InitTypeDef EXTI_InitStructure;
196 NVIC_InitTypeDef NVIC_InitStructure;
198 /* Enable the BUTTON Clock */
199 RCC_AHB1PeriphClockCmd(BUTTON_CLK[Button], ENABLE);
200 RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
202 /* Configure Button pin as input */
203 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
204 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
205 GPIO_InitStructure.GPIO_Pin = BUTTON_PIN[Button];
206 GPIO_Init(BUTTON_PORT[Button], &GPIO_InitStructure);
208 if (Button_Mode == BUTTON_MODE_EXTI)
210 /* Connect Button EXTI Line to Button GPIO Pin */
211 SYSCFG_EXTILineConfig(BUTTON_PORT_SOURCE[Button], BUTTON_PIN_SOURCE[Button]);
213 /* Configure Button EXTI line */
214 EXTI_InitStructure.EXTI_Line = BUTTON_EXTI_LINE[Button];
215 EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
216 EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
217 EXTI_InitStructure.EXTI_LineCmd = ENABLE;
218 EXTI_Init(&EXTI_InitStructure);
220 /* Enable and set Button EXTI Interrupt to the lowest priority */
221 NVIC_InitStructure.NVIC_IRQChannel = BUTTON_IRQn[Button];
222 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;
223 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;
224 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
226 NVIC_Init(&NVIC_InitStructure);
231 * @brief Returns the selected Button state.
232 * @param Button: Specifies the Button to be checked.
233 * This parameter should be: BUTTON_USER
234 * @retval The Button GPIO pin value.
236 uint32_t STM_EVAL_PBGetState(Button_TypeDef Button)
238 return GPIO_ReadInputDataBit(BUTTON_PORT[Button], BUTTON_PIN[Button]);
257 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/