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.
Dependencies: mbed
Diff: main.cpp
- Revision:
- 1:73d739c64e4c
- Parent:
- 0:1f39a86b8daa
- Child:
- 2:87dc86a7288b
--- a/main.cpp Tue Mar 10 21:22:07 2015 +0000 +++ b/main.cpp Sat Mar 21 11:21:32 2015 +0000 @@ -1,33 +1,109 @@ +/********************************************************************************** +* @file main.cpp +* @author Name +* @version V0.1 +* @date 09-March-2015 +* @brief LEDs blinking with ticker. +* With push button pressed, LEDs turn on. +***********************************************************************************/ + +/**********************************************************************************/ +/* Table of used pins on STM32F3 Discovery kit */ +/**********************************************************************************/ +/* Discovery pin | ST Nucleo F303RE pin | peripheral */ +/* PA_0 | PC_13 | User button */ +/* PE_8 to PE_15 | PA_5 | LEDs */ +/**********************************************************************************/ + +/* Includes ----------------------------------------------------------------------*/ + #include "mbed.h" -#include "stm32f3xx_hal_gpio.h" +#include "stm32f3xx_hal_gpio.h" //library necessary to blink LEDs on STM32F3 discovery -//DigitalOut my_led(LED1); -DigitalOut out_1(D7); -Ticker toggle_ticker; +/* Defines -----------------------------------------------------------------------*/ + +// In some mbed libraries are not included these definines + +//#define GPIOE_BASE (AHB2PERIPH_BASE + 0x1000) +//#define GPIOE ((GPIO_TypeDef *) GPIOE_BASE) +//#define RCC_AHBENR_GPIOEEN ((uint32_t)0x00200000) +//#define RCC_AHBPeriph_GPIOE RCC_AHBENR_GPIOEEN + + +//mbed - initialization of peripherals +InterruptIn button(PA_0); // inicialize button on STM32F3 discovery +Ticker toggle_ticker; // inicialize ticker + + +/* Functions----------------------------------------------------------------------*/ + +/******************************************************************************* +* Function Name : toggle. +* Description : Blinks whit 8 LEDs if ticker interval reached. +* Input : None. +* Output : Blinks whit 8 LEDs. +* Return : None. +*******************************************************************************/ void toggle() { - HAL_GPIO_TogglePin(GPIOE,GPIO_PIN_14 | GPIO_PIN_15 | GPIO_PIN_13 | GPIO_PIN_12 | GPIO_PIN_11 | GPIO_PIN_10 | GPIO_PIN_9 | GPIO_PIN_8); - //my_led = !my_led; + // Toggle pins PE_15 to PE_8 , where LEDs are attached to + 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); } +/******************************************************************************* +* Function Name : pressed. +* Description : Set LEDs on if someone pressed the button. +* Input : None. +* Output : None. +* Return : None. +*******************************************************************************/ +void pressed() +{ + // Switch pins PE_15 to PE_8 to log. 1 , where LEDs are attached to + 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); +} + +/*********************************************************************************** +* Function Name : main. +* Description : Main routine. +* Input : None. +* Output : None. +* Return : None. +***********************************************************************************/ int main() { //inicialize power (clock source) to port E (GPIOE) __GPIOE_CLK_ENABLE(); + // RCC->AHBENR |= RCC_AHBPeriph_GPIOE; // if __GPIOE_CLK_ENABLE(); is not defined //inicialize pins + // atructure to set GPIO GPIO_InitTypeDef GPIO_InitStruct; + //Specifies the operating mode for the selected pins. + // Output Push Pull Mode GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + //Specifies the Pull-up or Pull-Down activation for the selected pins. + //Pull-up activation GPIO_InitStruct.Pull = GPIO_PULLUP; + //Specifies the speed for the selected pins. + //High speed GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; - GPIO_InitStruct.Pin = GPIO_PIN_14 | GPIO_PIN_15 | GPIO_PIN_13 | GPIO_PIN_12 | GPIO_PIN_11 | GPIO_PIN_10 | GPIO_PIN_9 | GPIO_PIN_8; + //Specifies the GPIO pins to be configured. + //Pins 15 to 8 + 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; + + //Inicialize pins PE_15 to PE_8 HAL_GPIO_Init(GPIOE, &GPIO_InitStruct); - // Init the ticker with the address of the function (toggle) to be attached and the interval (100 ms) + // button was pressed, call function pressed + button.fall(&pressed); - toggle_ticker.attach(&toggle, 0.1); + // Init the ticker with the address of the function (toggle) to be attached and the interval (1 s) + toggle_ticker.attach(&toggle, 1); + + // infinity loop while (1) { } }