led on/off/togle methods added
This commit is contained in:
parent
32c8f5ae00
commit
765fb2e338
45
main.c
45
main.c
|
@ -52,39 +52,60 @@ int _write(int file, char *ptr, int len)
|
||||||
return -1;
|
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
|
#ifdef SYSTEM_BOARD
|
||||||
rcc_periph_clock_enable(LED_RCC); //enable clock for LED
|
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)
|
int main(void)
|
||||||
{
|
{
|
||||||
SCB_VTOR = (uint32_t) 0x08002000; // relocate vector table because of the bootloader
|
SCB_VTOR = (uint32_t) 0x08002000; // relocate vector table because of the bootloader
|
||||||
|
|
||||||
clock_setup(); // setup main clock
|
rcc_clock_setup_in_hse_8mhz_out_72mhz(); // use 8 MHz high speed external clock to generate 72 MHz internal clock
|
||||||
gpio_setup(); // setup main inputs/ouputs
|
|
||||||
|
// 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)
|
usart_setup(); // setup USART (for printing)
|
||||||
cdcacm_setup(); // setup USB CDC ACM (for printing)
|
cdcacm_setup(); // setup USB CDC ACM (for printing)
|
||||||
|
|
||||||
setbuf(stdout, NULL); // set standard out buffer to NULL to immediately print
|
setbuf(stdout, NULL); // set standard out buffer to NULL to immediately print
|
||||||
setbuf(stderr, NULL); // set standard error 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 */
|
/* toggle the LED with every transmitted character */
|
||||||
while (1) {
|
while (true) { // infinite loop
|
||||||
while (usart_received) { // echo every received character
|
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
|
printf("%c",usart_getchar()); // transmit receive character
|
||||||
}
|
}
|
||||||
while (cdcacm_received) { // echo every received 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
|
printf("%c",cdcacm_getchar()); // transmit receive character
|
||||||
}
|
}
|
||||||
__WFI(); // go to sleep
|
__WFI(); // go to sleep
|
||||||
|
|
Loading…
Reference in New Issue