|
|
|
@ -25,10 +25,12 @@ |
|
|
|
|
#include <libopencm3/stm32/rcc.h> // real-time control clock library |
|
|
|
|
#include <libopencm3/stm32/gpio.h> // general purpose input output library |
|
|
|
|
#include <libopencm3/cm3/scb.h> // vector table definition |
|
|
|
|
#include <libopencmsis/core_cm3.h> // Cortex M3 utilities |
|
|
|
|
|
|
|
|
|
/* own libraries */ |
|
|
|
|
#include "main.h" // board definitions |
|
|
|
|
#include "usart.h" // USART utilities |
|
|
|
|
#include "usb_cdcacm.h" // USB CDC ACM utilities |
|
|
|
|
|
|
|
|
|
/* default output (i.e. for printf) */ |
|
|
|
|
int _write(int file, char *ptr, int len) |
|
|
|
@ -39,8 +41,10 @@ int _write(int file, char *ptr, int len) |
|
|
|
|
for (i = 0; i < len; i++) { |
|
|
|
|
if (ptr[i] == '\n') { // add carrier return before line feed. this is recommended for most UART terminals
|
|
|
|
|
usart_putchar_nonblocking('\r'); // a second line feed doesn't break the display
|
|
|
|
|
cdcacm_putchar('\r'); // a second line feed doesn't break the display
|
|
|
|
|
} |
|
|
|
|
usart_putchar_nonblocking(ptr[i]); // send byte over USART
|
|
|
|
|
cdcacm_putchar(ptr[i]); // send byte over USB
|
|
|
|
|
} |
|
|
|
|
return i; |
|
|
|
|
} |
|
|
|
@ -56,8 +60,7 @@ static void clock_setup(void) |
|
|
|
|
|
|
|
|
|
static void gpio_setup(void) |
|
|
|
|
{ |
|
|
|
|
/* set LED pin to 'output push-pull' */ |
|
|
|
|
gpio_set_mode(LED_PORT, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, LED_PIN); |
|
|
|
|
gpio_set_mode(LED_PORT, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, LED_PIN); // set LED pin to 'output push-pull'
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int main(void) |
|
|
|
@ -67,16 +70,24 @@ int main(void) |
|
|
|
|
clock_setup(); // setup main clock
|
|
|
|
|
gpio_setup(); // setup main inputs/ouputs
|
|
|
|
|
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"); |
|
|
|
|
|
|
|
|
|
/* blink the LED with every transmitted character */ |
|
|
|
|
while (1) { |
|
|
|
|
while (usart_received) { // echo every received character
|
|
|
|
|
gpio_toggle(LED_PORT, LED_PIN); // toggle LED
|
|
|
|
|
gpio_toggle(LED_PORT, LED_PIN); // toggle LED
|
|
|
|
|
printf("%c",usart_getchar()); // transmit receive character
|
|
|
|
|
} |
|
|
|
|
__asm__("wfi"); // go to sleep
|
|
|
|
|
while (cdcacm_received) { // echo every received character
|
|
|
|
|
gpio_toggle(LED_PORT, LED_PIN); // toggle LED
|
|
|
|
|
printf("%c",cdcacm_getchar()); // transmit receive character
|
|
|
|
|
} |
|
|
|
|
__WFI(); // go to sleep
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|