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