Cortex Challenge Team / Mbed 2 deprecated DiscoveryF3-LED_and_Button

Dependencies:   mbed

Committer:
Foxnec
Date:
Tue May 12 09:15:11 2015 +0000
Revision:
2:87dc86a7288b
Parent:
1:73d739c64e4c
Changes to comments

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dousape2 1:73d739c64e4c 1 /**********************************************************************************
dousape2 1:73d739c64e4c 2 * @file main.cpp
dousape2 1:73d739c64e4c 3 * @author Name
dousape2 1:73d739c64e4c 4 * @version V0.1
dousape2 1:73d739c64e4c 5 * @date 09-March-2015
dousape2 1:73d739c64e4c 6 * @brief LEDs blinking with ticker.
dousape2 1:73d739c64e4c 7 * With push button pressed, LEDs turn on.
dousape2 1:73d739c64e4c 8 ***********************************************************************************/
dousape2 1:73d739c64e4c 9
dousape2 1:73d739c64e4c 10 /**********************************************************************************/
dousape2 1:73d739c64e4c 11 /* Table of used pins on STM32F3 Discovery kit */
dousape2 1:73d739c64e4c 12 /**********************************************************************************/
dousape2 1:73d739c64e4c 13 /* Discovery pin | ST Nucleo F303RE pin | peripheral */
dousape2 1:73d739c64e4c 14 /* PA_0 | PC_13 | User button */
dousape2 1:73d739c64e4c 15 /* PE_8 to PE_15 | PA_5 | LEDs */
dousape2 1:73d739c64e4c 16 /**********************************************************************************/
dousape2 1:73d739c64e4c 17
dousape2 1:73d739c64e4c 18 /* Includes ----------------------------------------------------------------------*/
dousape2 1:73d739c64e4c 19
dousape2 0:1f39a86b8daa 20 #include "mbed.h"
dousape2 1:73d739c64e4c 21 #include "stm32f3xx_hal_gpio.h" //library necessary to blink LEDs on STM32F3 discovery
dousape2 0:1f39a86b8daa 22
dousape2 1:73d739c64e4c 23 /* Defines -----------------------------------------------------------------------*/
dousape2 1:73d739c64e4c 24
Foxnec 2:87dc86a7288b 25 // In some mbed libraries these defines are not included
Foxnec 2:87dc86a7288b 26 // please uncomment if the example is not working
dousape2 1:73d739c64e4c 27
dousape2 1:73d739c64e4c 28 //#define GPIOE_BASE (AHB2PERIPH_BASE + 0x1000)
dousape2 1:73d739c64e4c 29 //#define GPIOE ((GPIO_TypeDef *) GPIOE_BASE)
dousape2 1:73d739c64e4c 30 //#define RCC_AHBENR_GPIOEEN ((uint32_t)0x00200000)
dousape2 1:73d739c64e4c 31 //#define RCC_AHBPeriph_GPIOE RCC_AHBENR_GPIOEEN
dousape2 1:73d739c64e4c 32
dousape2 1:73d739c64e4c 33
dousape2 1:73d739c64e4c 34 //mbed - initialization of peripherals
Foxnec 2:87dc86a7288b 35 InterruptIn button(PA_0); // initialize button on STM32F3 discovery
Foxnec 2:87dc86a7288b 36 Ticker toggle_ticker; // initialize ticker
dousape2 1:73d739c64e4c 37
dousape2 1:73d739c64e4c 38
dousape2 1:73d739c64e4c 39 /* Functions----------------------------------------------------------------------*/
dousape2 1:73d739c64e4c 40
dousape2 1:73d739c64e4c 41 /*******************************************************************************
dousape2 1:73d739c64e4c 42 * Function Name : toggle.
Foxnec 2:87dc86a7288b 43 * Description : Blinks with 8 LEDs if ticker interval reached.
dousape2 1:73d739c64e4c 44 * Input : None.
Foxnec 2:87dc86a7288b 45 * Output : Blinks with 8 LEDs.
dousape2 1:73d739c64e4c 46 * Return : None.
dousape2 1:73d739c64e4c 47 *******************************************************************************/
dousape2 0:1f39a86b8daa 48
dousape2 0:1f39a86b8daa 49 void toggle()
dousape2 0:1f39a86b8daa 50 {
dousape2 1:73d739c64e4c 51 // Toggle pins PE_15 to PE_8 , where LEDs are attached to
dousape2 1:73d739c64e4c 52 HAL_GPIO_TogglePin(GPIOE,GPIO_PIN_15 | GPIO_PIN_14 | GPIO_PIN_13 | GPIO_PIN_12 | GPIO_PIN_11 | GPIO_PIN_10 | GPIO_PIN_9 | GPIO_PIN_8);
dousape2 0:1f39a86b8daa 53 }
dousape2 0:1f39a86b8daa 54
dousape2 1:73d739c64e4c 55 /*******************************************************************************
dousape2 1:73d739c64e4c 56 * Function Name : pressed.
dousape2 1:73d739c64e4c 57 * Description : Set LEDs on if someone pressed the button.
dousape2 1:73d739c64e4c 58 * Input : None.
dousape2 1:73d739c64e4c 59 * Output : None.
dousape2 1:73d739c64e4c 60 * Return : None.
dousape2 1:73d739c64e4c 61 *******************************************************************************/
dousape2 1:73d739c64e4c 62 void pressed()
dousape2 1:73d739c64e4c 63 {
Foxnec 2:87dc86a7288b 64 // Switch pins PE_15 to PE_8 (LEDs) to high level
dousape2 1:73d739c64e4c 65 HAL_GPIO_WritePin(GPIOE , GPIO_PIN_15 | GPIO_PIN_14 | GPIO_PIN_13 | GPIO_PIN_12 | GPIO_PIN_11 | GPIO_PIN_10 | GPIO_PIN_9 | GPIO_PIN_8 , GPIO_PIN_SET);
dousape2 1:73d739c64e4c 66 }
dousape2 1:73d739c64e4c 67
dousape2 1:73d739c64e4c 68 /***********************************************************************************
dousape2 1:73d739c64e4c 69 * Function Name : main.
dousape2 1:73d739c64e4c 70 * Description : Main routine.
dousape2 1:73d739c64e4c 71 * Input : None.
dousape2 1:73d739c64e4c 72 * Output : None.
dousape2 1:73d739c64e4c 73 * Return : None.
dousape2 1:73d739c64e4c 74 ***********************************************************************************/
dousape2 0:1f39a86b8daa 75
dousape2 0:1f39a86b8daa 76 int main()
dousape2 0:1f39a86b8daa 77 {
Foxnec 2:87dc86a7288b 78 //initialize power (clock source) to port E (GPIOE)
dousape2 0:1f39a86b8daa 79 __GPIOE_CLK_ENABLE();
dousape2 1:73d739c64e4c 80 // RCC->AHBENR |= RCC_AHBPeriph_GPIOE; // if __GPIOE_CLK_ENABLE(); is not defined
dousape2 0:1f39a86b8daa 81
Foxnec 2:87dc86a7288b 82 // initialize pins
Foxnec 2:87dc86a7288b 83 // structure to set GPIO
dousape2 0:1f39a86b8daa 84 GPIO_InitTypeDef GPIO_InitStruct;
Foxnec 2:87dc86a7288b 85 // Specifies the operating mode for the selected pins.
dousape2 1:73d739c64e4c 86 // Output Push Pull Mode
dousape2 0:1f39a86b8daa 87 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
Foxnec 2:87dc86a7288b 88 // Specifies the Pull-up or Pull-Down activation for the selected pins.
Foxnec 2:87dc86a7288b 89 // Pull-up activation
dousape2 0:1f39a86b8daa 90 GPIO_InitStruct.Pull = GPIO_PULLUP;
Foxnec 2:87dc86a7288b 91 // Specifies the speed for the selected pins.
Foxnec 2:87dc86a7288b 92 // High speed
dousape2 0:1f39a86b8daa 93 GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
Foxnec 2:87dc86a7288b 94 // Specifies the GPIO pins to be configured.
Foxnec 2:87dc86a7288b 95 // Pins 15 to 8
dousape2 1:73d739c64e4c 96 GPIO_InitStruct.Pin = GPIO_PIN_15 | GPIO_PIN_14 | GPIO_PIN_13 | GPIO_PIN_12 | GPIO_PIN_11 | GPIO_PIN_10 | GPIO_PIN_9 | GPIO_PIN_8;
dousape2 1:73d739c64e4c 97
Foxnec 2:87dc86a7288b 98 // Initialize pins PE_15 to PE_8
dousape2 0:1f39a86b8daa 99 HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
dousape2 0:1f39a86b8daa 100
Foxnec 2:87dc86a7288b 101 // Button was pressed, call function pressed()
dousape2 1:73d739c64e4c 102 button.fall(&pressed);
dousape2 0:1f39a86b8daa 103
dousape2 1:73d739c64e4c 104 // Init the ticker with the address of the function (toggle) to be attached and the interval (1 s)
dousape2 1:73d739c64e4c 105 toggle_ticker.attach(&toggle, 1);
dousape2 1:73d739c64e4c 106
Foxnec 2:87dc86a7288b 107 // infinite loop
dousape2 0:1f39a86b8daa 108 while (1) {
dousape2 0:1f39a86b8daa 109 }
dousape2 0:1f39a86b8daa 110 }