Last active
December 24, 2018 16:19
-
-
Save cms-codes/6be0bd39f862bd6bfbd8721e610c317a to your computer and use it in GitHub Desktop.
Toggles all the user LEDs on the STM32F3 Discovery board using libopencm3, arm-none-eabi, and OpenOCD to program
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <libopencm3/stm32/rcc.h> | |
#include <libopencm3/stm32/gpio.h> | |
#define PORT_LED GPIOE | |
#define PIN_LED GPIO9 | |
uint16_t outBits[] = { GPIO9, GPIO10, GPIO11, GPIO12, GPIO13, GPIO14, GPIO15, GPIO8 }; | |
static void gpio_setup(void) | |
{ | |
rcc_periph_clock_enable(RCC_GPIOE); | |
gpio_mode_setup( PORT_LED, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, | |
GPIO9|GPIO8|GPIO10|GPIO15|GPIO11|GPIO14|GPIO12|GPIO13 ); | |
} | |
int main(void) | |
{ | |
volatile int i = 0; | |
volatile int p = 0; | |
gpio_setup(); | |
while (1) | |
{ | |
for ( p = 0; p < 8; p++ ) | |
{ | |
gpio_toggle( PORT_LED, outBits[p] ); | |
for ( i=0; i<100000; i++ ) | |
__asm__("nop"); | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment