Get rid of separate debug uart driver.

Conflicts:
	platform/stm32f1xx/debug.c
	platform/stm32f1xx/newlib_stubs.c
This commit is contained in:
Kent Ryhorchuk
2012-07-11 15:20:01 -07:00
committed by Travis Geiselbrecht
parent c5ccb192b2
commit fb577c443e
4 changed files with 26 additions and 71 deletions

View File

@@ -38,72 +38,21 @@ static cbuf_t debug_rx_buf;
void stm32_debug_early_init(void)
{
// XXX move this into usart driver
if (DEBUG_UART == USART1) {
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
} else if (DEBUG_UART == USART2) {
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
} else if (DEBUG_UART == USART3) {
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
}
USART_InitTypeDef init;
init.USART_BaudRate = 115200;
init.USART_WordLength = USART_WordLength_8b;
init.USART_StopBits = USART_StopBits_1;
init.USART_Parity = USART_Parity_No;
init.USART_Mode = USART_Mode_Tx|USART_Mode_Rx;
init.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_Init(DEBUG_UART, &init);
USART_ITConfig(DEBUG_UART, USART_IT_RXNE, DISABLE);
NVIC_DisableIRQ(DEBUG_UART_IRQ);
USART_Cmd(DEBUG_UART, ENABLE);
uart_init_early();
}
/* later in the init process */
void stm32_debug_init(void)
{
cbuf_initialize(&debug_rx_buf, 16);
USART_ITConfig(DEBUG_UART, USART_IT_RXNE, ENABLE);
NVIC_EnableIRQ(DEBUG_UART_IRQ);
}
void DEBUG_UART_IRQ_HANDLER(void)
{
inc_critical_section();
while (USART_GetFlagStatus(DEBUG_UART, USART_FLAG_RXNE)) {
char c = USART_ReceiveData(DEBUG_UART);
cbuf_write(&debug_rx_buf, &c, 1, false);
}
USART_ClearFlag(DEBUG_UART, USART_IT_RXNE);
cm3_trigger_preempt();
dec_critical_section();
uart_init();
}
void _dputc(char c)
{
if (c == '\n') {
_dputc('\r');
}
while (USART_GetFlagStatus(DEBUG_UART, USART_FLAG_TXE) == 0)
;
USART_SendData(DEBUG_UART, c);
while (USART_GetFlagStatus(DEBUG_UART, USART_FLAG_TC) == 0)
;
}
int dgetc(char *c, bool wait)
{
return cbuf_read(&debug_rx_buf, c, 1, wait);
}
void platform_halt(void)
@@ -111,4 +60,3 @@ void platform_halt(void)
dprintf(ALWAYS, "HALT: spinning forever...\n");
for(;;);
}

View File

@@ -37,7 +37,5 @@ void platform_early_init(void)
void platform_init(void)
{
uart_init();
stm32_timer_init();
}

View File

@@ -52,7 +52,7 @@ cbuf_t uart3_rx_buf;
#ifdef ENABLE_UART3
#endif
static void usart_init1(USART_TypeDef *usart, int irqn, cbuf_t *rxbuf)
static void usart_init1_early(USART_TypeDef *usart, int irqn, cbuf_t *rxbuf)
{
USART_InitTypeDef init;
@@ -63,17 +63,22 @@ static void usart_init1(USART_TypeDef *usart, int irqn, cbuf_t *rxbuf)
init.USART_Mode = USART_Mode_Tx|USART_Mode_Rx;
init.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
cbuf_initialize(rxbuf, 16);
USART_Init(usart, &init);
USART_ITConfig(usart, USART_IT_RXNE, ENABLE);
NVIC_EnableIRQ(irqn);
USART_ITConfig(usart, USART_IT_RXNE, DISABLE);
NVIC_DisableIRQ(irqn);
USART_Cmd(usart, ENABLE);
}
void uart_init(void)
static void usart_init1(USART_TypeDef *usart, int irqn, cbuf_t *rxbuf)
{
cbuf_initialize(rxbuf, 16);
USART_ITConfig(usart, USART_IT_RXNE, ENABLE);
NVIC_EnableIRQ(irqn);
USART_Cmd(usart, ENABLE);
}
void uart_init_early(void)
{
#ifdef ENABLE_UART1
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
#endif
@@ -84,17 +89,19 @@ void uart_init(void)
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
#endif
#if (ENABLE_UART1 | ENABLE_UART2 | ENABLE_UART3)
USART_InitTypeDef init;
init.USART_BaudRate = 115200;
init.USART_WordLength = USART_WordLength_8b;
init.USART_StopBits = USART_StopBits_1;
init.USART_Parity = USART_Parity_No;
init.USART_Mode = USART_Mode_Tx|USART_Mode_Rx;
init.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
#ifdef ENABLE_UART1
usart_init1_early(USART1, USART1_IRQn, &uart1_rx_buf);
#endif
#ifdef ENABLE_UART2
usart_init1_early(USART2, USART2_IRQn, &uart2_rx_buf);
#endif
#ifdef ENABLE_UART3
usart_init1_early(USART3, USART3_IRQn, &uart3_rx_buf);
#endif
}
void uart_init(void)
{
#ifdef ENABLE_UART1
usart_init1(USART1, USART1_IRQn, &uart1_rx_buf);
#endif

View File

@@ -4,6 +4,8 @@ STM32_CHIP := stm32f103_md
PLATFORM := stm32f1xx
DEFINES += ENABLE_UART1=1
INCLUDES += -I$(LOCAL_DIR)/include
OBJS += \