21 #include <libopencm3/stm32/rcc.h>
22 #include <libopencm3/stm32/gpio.h>
23 #include <libopencm3/stm32/usart.h>
24 #include <libopencm3/cm3/nvic.h>
25 #include <libopencm3/cm3/systick.h>
30 int _write(
int file,
char *ptr,
int len);
32 static uint8_t outbuf[1024];
42 rcc_periph_clock_enable(RCC_GPIOA);
43 rcc_periph_clock_enable(RCC_AFIO);
44 rcc_periph_clock_enable(RCC_USART1);
47 nvic_enable_irq(NVIC_USART1_IRQ);
50 gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ,
51 GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_USART1_TX);
54 gpio_set_mode(GPIOA, GPIO_MODE_INPUT,
55 GPIO_CNF_INPUT_FLOAT, GPIO_USART1_RX);
58 usart_set_baudrate(USART1, 38400);
59 usart_set_databits(USART1, 8);
60 usart_set_stopbits(USART1, USART_STOPBITS_1);
61 usart_set_parity(USART1, USART_PARITY_NONE);
62 usart_set_flow_control(USART1, USART_FLOWCONTROL_NONE);
63 usart_set_mode(USART1, USART_MODE_TX_RX);
66 USART_CR1(USART1) |= USART_CR1_RXNEIE;
75 if (((USART_CR1(USART1) & USART_CR1_RXNEIE) != 0) &&
76 ((USART_SR(USART1) & USART_SR_RXNE) != 0)) {
77 uint16_t
c = usart_recv(USART1);
85 USART_CR1(USART1) |= USART_CR1_TXEIE;
87 #ifdef CONFIG_CONSOLE_FROM_ISR
95 if (((USART_CR1(USART1) & USART_CR1_TXEIE) != 0) &&
96 ((USART_SR(USART1) & USART_SR_TXE) != 0)) {
101 USART_CR1(USART1) &= ~USART_CR1_TXEIE;
104 usart_send(USART1, data);
111 if (file == 1 || file == 2) {
112 for (
int i=0; i<len; i++) {
116 USART_CR1(USART1) |= USART_CR1_TXEIE;
#define RINGBUF_VAR_INIT(bufp, buf_len)
Static initializer for a ring buffer descriptor.
void console_hwinit(console_t *c)
Platform dependant function that will be called during console_init().
void console_putchar(console_t *c, char d)
Asynchronously send a character to the command processor.
int ringbuf_get(ringbuf_t *rb)
Extract a byte from the ring buffer.
void console_process(console_t *c, char d)
Synchronous console function for use in threaded environments.
bool ringbuf_put(ringbuf_t *rb, uint8_t d)
Insert a byte into the ring buffer.
int _write(int file, char *ptr, int len)