From 765fb2e33810f47a830813bc5d0dbd6a134fc5c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?King=20K=C3=A9vin?= Date: Fri, 29 Jan 2016 00:24:49 +0100 Subject: [PATCH] led on/off/togle methods added --- main.c | 45 +++++++++++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/main.c b/main.c index 1e957a2..dc80370 100644 --- a/main.c +++ b/main.c @@ -52,39 +52,60 @@ int _write(int file, char *ptr, int len) return -1; } -static void clock_setup(void) +/* switch on LED */ +void led_on(void) { - rcc_clock_setup_in_hse_8mhz_out_72mhz(); // use 8 MHz high speed external clock to generate 72 MHz internal clock - rcc_periph_clock_enable(LED_RCC); //enable clock for LED +#ifdef SYSTEM_BOARD + gpio_clear(LED_PORT, LED_PIN); +#elif MAPLE_MINI + gpio_set(LED_PORT, LED_PIN); +#endif } -static void gpio_setup(void) +/* switch off LED */ +void led_off(void) { - gpio_set_mode(LED_PORT, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, LED_PIN); // set LED pin to 'output push-pull' +#ifdef SYSTEM_BOARD + gpio_set(LED_PORT, LED_PIN); +#elif MAPLE_MINI + gpio_clear(LED_PORT, LED_PIN); +#endif +} + +/* toggle LED */ +void led_toggle(void) +{ + gpio_toggle(LED_PORT, LED_PIN); } int main(void) { SCB_VTOR = (uint32_t) 0x08002000; // relocate vector table because of the bootloader - clock_setup(); // setup main clock - gpio_setup(); // setup main inputs/ouputs + rcc_clock_setup_in_hse_8mhz_out_72mhz(); // use 8 MHz high speed external clock to generate 72 MHz internal clock + + // setup LED + rcc_periph_clock_enable(LED_RCC); //enable clock for LED + gpio_set_mode(LED_PORT, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, LED_PIN); // set LED pin to 'output push-pull' + led_off(); // switch off LED to indicate setup started + usart_setup(); // setup USART (for printing) cdcacm_setup(); // setup USB CDC ACM (for printing) setbuf(stdout, NULL); // set standard out buffer to NULL to immediately print setbuf(stderr, NULL); // set standard error buffer to NULL to immediately print - printf("welcome to the STM32F1 CuVoodoo example code\n"); + printf("welcome to the STM32F1 CuVoodoo example code\n"); // print welcome message + led_on(); // switch on LED to indicate setup completed - /* blink the LED with every transmitted character */ - while (1) { + /* toggle the LED with every transmitted character */ + while (true) { // infinite loop while (usart_received) { // echo every received character - gpio_toggle(LED_PORT, LED_PIN); // toggle LED + led_toggle(); // toggle LED printf("%c",usart_getchar()); // transmit receive character } while (cdcacm_received) { // echo every received character - gpio_toggle(LED_PORT, LED_PIN); // toggle LED + led_toggle(); // toggle LED printf("%c",cdcacm_getchar()); // transmit receive character } __WFI(); // go to sleep