[STM32F407VG Discovery] Toggle LED
by JungWook_libopencm3
라이브러리를 사용하겠습니다.
Datasheet의 STM32 pin description versus board functions
부분을 보면 LED는 PA9
, PD5
, PD12
, PD13
, PD14
, PD15
의 핀에 연결되어 있습니다. 그 중 PA9
과 PD5
에 연결되어 있는 LED는 다른 용도로 사용하는 LED이므로 나머지 LED를 사용하겠습니다.
아래는 LED 4개가 점멸하는 코드입니다.
#include <libopencm3/stm32/rcc.h>
#include <libopencm3/stm32/gpio.h>
#define RCCLEDPORT (RCC_GPIOD)
#define LEDPORT (GPIOD)
#define LED_GREEN_PIN (GPIO12)
#define LED_ORANGE_PIN (GPIO13)
#define LED_RED_PIN (GPIO14)
#define LED_BLUE_PIN (GPIO15)
static void gpio_setup(void)
{
/* Enable GPIO clock. */
/* Using API functions: */
rcc_periph_clock_enable(RCCLEDPORT);
/* Set pin to 'output push-pull'. */
/* Using API functions: */
gpio_mode_setup(LEDPORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, LED_GREEN_PIN | LED_ORANGE_PIN | LED_RED_PIN | LED_BLUE_PIN);
}
int main(void)
{
int i;
gpio_setup();
/* Blink the LED on the board. */
while (1) {
/* Using API function gpio_toggle(): */
gpio_toggle(LEDPORT, LED_GREEN_PIN); /* LED on/off */
gpio_toggle(LEDPORT, LED_ORANGE_PIN); /* LED on/off */
gpio_toggle(LEDPORT, LED_RED_PIN); /* LED on/off */
gpio_toggle(LEDPORT, LED_BLUE_PIN); /* LED on/off */
for (i = 0; i < 1000000; i++) { /* Wait a bit. */
__asm__("nop");
}
}
return 0;
}
'Embedded' 카테고리의 다른 글
[STM32F407VG Discovery] External Interrupt (0) | 2021.02.22 |
---|---|
[STM32F407VG Discovery] Push Button (0) | 2021.02.18 |
[STM32F407VG Discovery] PlatformIO 사용 (0) | 2021.02.18 |
[Sensor] TFMini Plus on Arduino Leonardo (0) | 2019.11.28 |
[Verilog] 반가산기 (0) | 2018.05.31 |
블로그의 정보
hongmono
JungWook_