[bsp][stm32f40x][adapt] to serial frame about dma

This commit is contained in:
chenchaoqun@rt-thread.com 2019-01-03 09:57:48 +08:00
parent d9a3cc9a03
commit 7563849add
1 changed files with 39 additions and 3 deletions

View File

@ -66,6 +66,7 @@ struct stm32_uart
{
USART_TypeDef *uart_device;
IRQn_Type irq;
#ifdef RT_SERIAL_USING_DMA
struct stm32_uart_dma
{
/* dma stream */
@ -81,9 +82,12 @@ struct stm32_uart
/* last receive index */
rt_size_t last_recv_index;
} dma;
#endif /* RT_SERIAL_USING_DMA */
};
#ifdef RT_SERIAL_USING_DMA
static void DMA_Configuration(struct rt_serial_device *serial);
#endif /* RT_SERIAL_USING_DMA */
static rt_err_t stm32_configure(struct rt_serial_device *serial, struct serial_configure *cfg)
{
@ -130,7 +134,6 @@ static rt_err_t stm32_configure(struct rt_serial_device *serial, struct serial_c
static rt_err_t stm32_control(struct rt_serial_device *serial, int cmd, void *arg)
{
struct stm32_uart* uart;
rt_uint32_t ctrl_arg = (rt_uint32_t)(arg);
RT_ASSERT(serial != RT_NULL);
uart = (struct stm32_uart *)serial->parent.user_data;
@ -149,11 +152,13 @@ static rt_err_t stm32_control(struct rt_serial_device *serial, int cmd, void *ar
/* enable interrupt */
USART_ITConfig(uart->uart_device, USART_IT_RXNE, ENABLE);
break;
#ifdef RT_SERIAL_USING_DMA
/* USART config */
case RT_DEVICE_CTRL_CONFIG :
if (ctrl_arg == RT_DEVICE_FLAG_DMA_RX) {
if ((rt_uint32_t)(arg) == RT_DEVICE_FLAG_DMA_RX) {
DMA_Configuration(serial);
}
#endif /* RT_SERIAL_USING_DMA */
}
return RT_EOK;
@ -190,6 +195,7 @@ static int stm32_getc(struct rt_serial_device *serial)
return ch;
}
#ifdef RT_SERIAL_USING_DMA
/**
* DMA initialize by DMA_InitStruct structure
*
@ -278,6 +284,7 @@ static void dma_rx_done_isr(struct rt_serial_device *serial)
DMA_ClearFlag(uart->dma.rx_stream, uart->dma.rx_flag);
}
}
#endif /* RT_SERIAL_USING_DMA */
/**
* Uart common interrupt process. This need add to uart ISR.
@ -296,10 +303,12 @@ static void uart_isr(struct rt_serial_device *serial)
/* clear interrupt */
USART_ClearITPendingBit(uart->uart_device, USART_IT_RXNE);
}
#ifdef RT_SERIAL_USING_DMA
if(USART_GetITStatus(uart->uart_device, USART_IT_IDLE) != RESET)
{
dma_uart_rx_idle_isr(serial);
}
#endif /* RT_SERIAL_USING_DMA */
if (USART_GetITStatus(uart->uart_device, USART_IT_TC) != RESET)
{
/* clear interrupt */
@ -325,6 +334,7 @@ static const struct rt_uart_ops stm32_uart_ops =
struct stm32_uart uart1 =
{
USART1,
#ifdef RT_SERIAL_USING_DMA
USART1_IRQn,
{
DMA2_Stream5,
@ -333,6 +343,7 @@ struct stm32_uart uart1 =
DMA2_Stream5_IRQn,
0,
},
#endif /* RT_SERIAL_USING_DMA */
};
struct rt_serial_device serial1;
@ -347,6 +358,7 @@ void USART1_IRQHandler(void)
rt_interrupt_leave();
}
#ifdef RT_SERIAL_USING_DMA
void DMA2_Stream5_IRQHandler(void) {
/* enter interrupt */
rt_interrupt_enter();
@ -356,6 +368,8 @@ void DMA2_Stream5_IRQHandler(void) {
/* leave interrupt */
rt_interrupt_leave();
}
#endif /* RT_SERIAL_USING_DMA */
#endif /* RT_USING_UART1 */
#if defined(RT_USING_UART2)
@ -363,6 +377,7 @@ void DMA2_Stream5_IRQHandler(void) {
struct stm32_uart uart2 =
{
USART2,
#ifdef RT_SERIAL_USING_DMA
USART2_IRQn,
{
DMA1_Stream5,
@ -372,6 +387,7 @@ struct stm32_uart uart2 =
0,
0,
},
#endif /* RT_SERIAL_USING_DMA */
};
struct rt_serial_device serial2;
@ -386,6 +402,7 @@ void USART2_IRQHandler(void)
rt_interrupt_leave();
}
#ifdef RT_SERIAL_USING_DMA
void DMA1_Stream5_IRQHandler(void) {
/* enter interrupt */
rt_interrupt_enter();
@ -395,6 +412,8 @@ void DMA1_Stream5_IRQHandler(void) {
/* leave interrupt */
rt_interrupt_leave();
}
#endif /* RT_SERIAL_USING_DMA */
#endif /* RT_USING_UART2 */
#if defined(RT_USING_UART3)
@ -402,6 +421,7 @@ void DMA1_Stream5_IRQHandler(void) {
struct stm32_uart uart3 =
{
USART3,
#ifdef RT_SERIAL_USING_DMA
USART3_IRQn,
{
DMA1_Stream1,
@ -411,6 +431,7 @@ struct stm32_uart uart3 =
0,
0,
},
#endif /* RT_SERIAL_USING_DMA */
};
struct rt_serial_device serial3;
@ -425,6 +446,7 @@ void USART3_IRQHandler(void)
rt_interrupt_leave();
}
#ifdef RT_SERIAL_USING_DMA
void DMA1_Stream1_IRQHandler(void) {
/* enter interrupt */
rt_interrupt_enter();
@ -434,6 +456,8 @@ void DMA1_Stream1_IRQHandler(void) {
/* leave interrupt */
rt_interrupt_leave();
}
#endif /* RT_SERIAL_USING_DMA */
#endif /* RT_USING_UART3 */
#if defined(RT_USING_UART4)
@ -441,6 +465,7 @@ void DMA1_Stream1_IRQHandler(void) {
struct stm32_uart uart4 =
{
UART4,
#ifdef RT_SERIAL_USING_DMA
UART4_IRQn,
{
DMA1_Stream2,
@ -450,6 +475,7 @@ struct stm32_uart uart4 =
0,
0,
},
#endif /* RT_SERIAL_USING_DMA */
};
struct rt_serial_device serial4;
@ -464,6 +490,7 @@ void UART4_IRQHandler(void)
rt_interrupt_leave();
}
#ifdef RT_SERIAL_USING_DMA
void DMA1_Stream2_IRQHandler(void) {
/* enter interrupt */
rt_interrupt_enter();
@ -473,6 +500,8 @@ void DMA1_Stream2_IRQHandler(void) {
/* leave interrupt */
rt_interrupt_leave();
}
#endif /* RT_SERIAL_USING_DMA */
#endif /* RT_USING_UART4 */
#if defined(RT_USING_UART5)
@ -480,6 +509,7 @@ void DMA1_Stream2_IRQHandler(void) {
struct stm32_uart uart5 =
{
UART5,
#ifdef RT_SERIAL_USING_DMA
UART5_IRQn,
{
DMA1_Stream0,
@ -489,6 +519,7 @@ struct stm32_uart uart5 =
0,
0,
},
#endif /* RT_SERIAL_USING_DMA */
};
struct rt_serial_device serial5;
@ -503,6 +534,7 @@ void UART5_IRQHandler(void)
rt_interrupt_leave();
}
#ifdef RT_SERIAL_USING_DMA
void DMA1_Stream0_IRQHandler(void) {
/* enter interrupt */
rt_interrupt_enter();
@ -512,6 +544,8 @@ void DMA1_Stream0_IRQHandler(void) {
/* leave interrupt */
rt_interrupt_leave();
}
#endif /* RT_SERIAL_USING_DMA */
#endif /* RT_USING_UART5 */
static void RCC_Configuration(void)
@ -626,6 +660,7 @@ static void NVIC_Configuration(struct stm32_uart *uart)
NVIC_Init(&NVIC_InitStructure);
}
#ifdef RT_SERIAL_USING_DMA
static void DMA_Configuration(struct rt_serial_device *serial) {
struct stm32_uart *uart = (struct stm32_uart *) serial->parent.user_data;
struct rt_serial_rx_fifo *rx_fifo = (struct rt_serial_rx_fifo *)serial->serial_rx;
@ -653,6 +688,7 @@ static void DMA_Configuration(struct rt_serial_device *serial) {
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
#endif /* RT_SERIAL_USING_DMA */
int stm32_hw_usart_init(void)
{