[BSP] Fix a bug on stm32f4xx uart rx DMA driver when first receive data filled the FIFO.

This commit is contained in:
armink 2017-05-24 09:09:55 +08:00
parent 9b7d2023bb
commit 98c830f3de
1 changed files with 8 additions and 24 deletions

View File

@ -242,15 +242,7 @@ static void dma_uart_rx_idle_isr(struct rt_serial_device *serial) {
level = rt_hw_interrupt_disable();
recv_total_index = uart->dma.setting_recv_len - DMA_GetCurrDataCounter(uart->dma.rx_stream);
if (recv_total_index >= uart->dma.last_recv_index)
{
recv_len = recv_total_index - uart->dma.last_recv_index;
}
else
{
recv_len = uart->dma.setting_recv_len - uart->dma.last_recv_index + recv_total_index;
}
recv_len = recv_total_index - uart->dma.last_recv_index;
uart->dma.last_recv_index = recv_total_index;
/* enable interrupt */
rt_hw_interrupt_enable(level);
@ -269,7 +261,7 @@ static void dma_uart_rx_idle_isr(struct rt_serial_device *serial) {
static void dma_rx_done_isr(struct rt_serial_device *serial)
{
struct stm32_uart *uart = (struct stm32_uart *) serial->parent.user_data;
rt_size_t recv_total_index, recv_len;
rt_size_t recv_len;
rt_base_t level;
if (DMA_GetFlagStatus(uart->dma.rx_stream, uart->dma.rx_flag) != RESET)
@ -277,17 +269,9 @@ static void dma_rx_done_isr(struct rt_serial_device *serial)
/* disable interrupt */
level = rt_hw_interrupt_disable();
recv_total_index = uart->dma.setting_recv_len - DMA_GetCurrDataCounter(uart->dma.rx_stream);
if (recv_total_index >= uart->dma.last_recv_index)
{
recv_len = recv_total_index - uart->dma.last_recv_index;
}
else
{
recv_len = uart->dma.setting_recv_len - uart->dma.last_recv_index + recv_total_index;
}
uart->dma.last_recv_index = recv_total_index;
recv_len = uart->dma.setting_recv_len - uart->dma.last_recv_index;
/* reset last recv index */
uart->dma.last_recv_index = 0;
/* enable interrupt */
rt_hw_interrupt_enable(level);
@ -639,8 +623,8 @@ static void NVIC_Configuration(struct stm32_uart *uart)
/* Enable the USART1 Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = uart->irq;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
@ -668,7 +652,7 @@ static void DMA_Configuration(struct rt_serial_device *serial) {
/* rx dma interrupt config */
NVIC_InitStructure.NVIC_IRQChannel = uart->dma.rx_irq_ch;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}