example code now also uses USB CDC ACM
This commit is contained in:
parent
4a149d6a80
commit
2eff94979e
19
main.c
19
main.c
|
@ -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;
|
||||
|
|
2
main.h
2
main.h
|
@ -15,9 +15,9 @@
|
|||
/* Copyright (c) 2016 King Kévin <kingkevin@cuvoodoo.info> */
|
||||
|
||||
/* LED is on pin 11/PA1 */
|
||||
#define LED_RCC RCC_GPIOA
|
||||
#define LED_PORT GPIOA
|
||||
#define LED_PIN GPIO1
|
||||
#define LED_RCC RCC_GPIOA
|
||||
|
||||
/* default output (i.e. for printf) */
|
||||
int _write(int file, char *ptr, int len);
|
||||
|
|
Loading…
Reference in New Issue