|
|
|
@ -1,7 +1,11 @@ |
|
|
|
|
#define _GNU_SOURCE |
|
|
|
|
#include <stdint.h> |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
#include <libopencm3/stm32/usart.h> |
|
|
|
|
#include <libopencm3/cm3/nvic.h> |
|
|
|
|
#include <libopencm3/cm3/scb.h> |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
#include <ctype.h> |
|
|
|
|
#include <stdarg.h> |
|
|
|
@ -30,6 +34,7 @@ struct usart_console { |
|
|
|
|
|
|
|
|
|
static struct usart_console usart[2]; |
|
|
|
|
|
|
|
|
|
#if 0 |
|
|
|
|
#ifdef STM32F0 |
|
|
|
|
#define USART_STOPBITS_1 USART_CR2_STOP_1_0BIT |
|
|
|
|
#endif |
|
|
|
@ -37,9 +42,15 @@ static struct usart_console usart[2]; |
|
|
|
|
#ifdef STM32F1 |
|
|
|
|
#define USART_ISR_RXNE USART_SR_RXNE |
|
|
|
|
#endif |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
void usart_send_blocking(uint32_t dev, char c) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void usart_isr(struct usart_console *console) |
|
|
|
|
{ |
|
|
|
|
#if 0 |
|
|
|
|
size_t i; |
|
|
|
|
|
|
|
|
|
if (!console) |
|
|
|
@ -53,6 +64,7 @@ static void usart_isr(struct usart_console *console) |
|
|
|
|
if (i != console->cur) |
|
|
|
|
console->next = i; |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void usart1_isr(void) |
|
|
|
@ -192,17 +204,20 @@ static int usart_get_irq_no(unsigned *irq_no, unsigned dev) |
|
|
|
|
if (!irq_no) |
|
|
|
|
return -1; |
|
|
|
|
|
|
|
|
|
#if 0 |
|
|
|
|
switch (dev) { |
|
|
|
|
case USART1: *irq_no = NVIC_USART1_IRQ; break; |
|
|
|
|
case USART2: *irq_no = NVIC_USART2_IRQ; break; |
|
|
|
|
default: return -1; |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static int usart_init(struct usart_console *console) |
|
|
|
|
{ |
|
|
|
|
#if 0 |
|
|
|
|
if (usart_get_irq_no(&console->irq_no, console->dev) < 0) |
|
|
|
|
return -1; |
|
|
|
|
|
|
|
|
@ -216,6 +231,7 @@ static int usart_init(struct usart_console *console) |
|
|
|
|
nvic_enable_irq(console->irq_no); |
|
|
|
|
usart_enable(console->dev); |
|
|
|
|
usart_enable_rx_interrupt(console->dev); |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
@ -232,11 +248,13 @@ struct console *console_init(unsigned dev_id) |
|
|
|
|
|
|
|
|
|
console = usart + dev_id; |
|
|
|
|
|
|
|
|
|
#if 0 |
|
|
|
|
switch (dev_id) { |
|
|
|
|
case 0: console->dev = USART1; break; |
|
|
|
|
case 1: console->dev = USART2; break; |
|
|
|
|
default: return NULL; |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
console->cur = 0; |
|
|
|
|
console->next = 0; |
|
|
|
|