|
| 1 | +/* |
| 2 | + * This file is part of the libopencm3 project. |
| 3 | + * |
| 4 | + * Copyright (C) 2009 Uwe Hermann <[email protected]> |
| 5 | + * Copyright (C) 2011 Stephen Caudle <[email protected]> |
| 6 | + * Copyright (C) 2012 Karl Palsson <[email protected]> |
| 7 | + * |
| 8 | + * This library is free software: you can redistribute it and/or modify |
| 9 | + * it under the terms of the GNU Lesser General Public License as published by |
| 10 | + * the Free Software Foundation, either version 3 of the License, or |
| 11 | + * (at your option) any later version. |
| 12 | + * |
| 13 | + * This library is distributed in the hope that it will be useful, |
| 14 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | + * GNU Lesser General Public License for more details. |
| 17 | + * |
| 18 | + * You should have received a copy of the GNU Lesser General Public License |
| 19 | + * along with this library. If not, see <http://www.gnu.org/licenses/>. |
| 20 | + */ |
| 21 | + |
| 22 | +#include <libopencm3/stm32/rcc.h> |
| 23 | +#include <libopencm3/stm32/gpio.h> |
| 24 | + |
| 25 | +static void gpio_setup(void) |
| 26 | +{ |
| 27 | + /* Enable GPIOA clock. */ |
| 28 | + /* Manually: */ |
| 29 | + //RCC_AHB2ENR |= RCC_AHB2ENR_GPIOAEN; |
| 30 | + /* Using API functions: */ |
| 31 | + rcc_periph_clock_enable(RCC_GPIOA); |
| 32 | + |
| 33 | + /* Set GPIO5 (in GPIO port A) to 'output push-pull'. */ |
| 34 | + /* Using API functions: */ |
| 35 | + gpio_mode_setup(GPIOA, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO5); |
| 36 | +} |
| 37 | + |
| 38 | +int main(void) |
| 39 | +{ |
| 40 | + int i; |
| 41 | + |
| 42 | + gpio_setup(); |
| 43 | + |
| 44 | + /* Blink the LED (PA5) on the board. */ |
| 45 | + while (1) { |
| 46 | + /* Manually: */ |
| 47 | + // GPIOA_BSRR = (GPIO5 << 16); /* LED off */ |
| 48 | + // for (i = 0; i < 1000000; i++) /* Wait a bit. */ |
| 49 | + // __asm__("nop"); |
| 50 | + // GPIOB_BRR = GPIO5; /* LED on */ |
| 51 | + // for (i = 0; i < 1000000; i++) /* Wait a bit. */ |
| 52 | + // __asm__("nop"); |
| 53 | + |
| 54 | + /* Using API functions gpio_set()/gpio_clear(): */ |
| 55 | + // gpio_set(GPIOA, GPIO5); /* LED off */ |
| 56 | + // for (i = 0; i < 1000000; i++) /* Wait a bit. */ |
| 57 | + // __asm__("nop"); |
| 58 | + // gpio_clear(GPIOA, GPIO5); /* LED on */ |
| 59 | + // for (i = 0; i < 1000000; i++) /* Wait a bit. */ |
| 60 | + // __asm__("nop"); |
| 61 | + |
| 62 | + /* Using API function gpio_toggle(): */ |
| 63 | + gpio_toggle(GPIOA, GPIO5); /* LED on/off */ |
| 64 | + for (i = 0; i < 1000000; i++) { /* Wait a bit. */ |
| 65 | + __asm__("nop"); |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | + return 0; |
| 70 | +} |
0 commit comments