Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
混口饭吃,
rt-thread
提交
6ae6ba14
R
rt-thread
项目概览
混口饭吃,
/
rt-thread
与 Fork 源项目一致
Fork自
Mr_Pangza / rt-thread
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rt-thread
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
6ae6ba14
编写于
1月 03, 2019
作者:
C
chenchaoqun@rt-thread.com
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[bsp][stm32f10x][adapt] to serial frame about dma
上级
7563849a
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
33 addition
and
2 deletion
+33
-2
bsp/stm32f10x/drivers/usart.c
bsp/stm32f10x/drivers/usart.c
+33
-2
未找到文件。
bsp/stm32f10x/drivers/usart.c
浏览文件 @
6ae6ba14
...
@@ -45,6 +45,7 @@ struct stm32_uart
...
@@ -45,6 +45,7 @@ struct stm32_uart
{
{
USART_TypeDef
*
uart_device
;
USART_TypeDef
*
uart_device
;
IRQn_Type
irq
;
IRQn_Type
irq
;
#ifdef RT_SERIAL_USING_DMA
struct
stm32_uart_dma
struct
stm32_uart_dma
{
{
/* dma channel */
/* dma channel */
...
@@ -58,9 +59,12 @@ struct stm32_uart
...
@@ -58,9 +59,12 @@ struct stm32_uart
/* last receive index */
/* last receive index */
rt_size_t
last_recv_index
;
rt_size_t
last_recv_index
;
}
dma
;
}
dma
;
#endif
/* RT_SERIAL_USING_DMA */
};
};
#ifdef RT_SERIAL_USING_DMA
static
void
DMA_Configuration
(
struct
rt_serial_device
*
serial
);
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
)
static
rt_err_t
stm32_configure
(
struct
rt_serial_device
*
serial
,
struct
serial_configure
*
cfg
)
{
{
...
@@ -107,7 +111,6 @@ static rt_err_t stm32_configure(struct rt_serial_device *serial, struct serial_c
...
@@ -107,7 +111,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
)
static
rt_err_t
stm32_control
(
struct
rt_serial_device
*
serial
,
int
cmd
,
void
*
arg
)
{
{
struct
stm32_uart
*
uart
;
struct
stm32_uart
*
uart
;
rt_uint32_t
ctrl_arg
=
(
rt_uint32_t
)(
arg
);
RT_ASSERT
(
serial
!=
RT_NULL
);
RT_ASSERT
(
serial
!=
RT_NULL
);
uart
=
(
struct
stm32_uart
*
)
serial
->
parent
.
user_data
;
uart
=
(
struct
stm32_uart
*
)
serial
->
parent
.
user_data
;
...
@@ -128,12 +131,14 @@ static rt_err_t stm32_control(struct rt_serial_device *serial, int cmd, void *ar
...
@@ -128,12 +131,14 @@ static rt_err_t stm32_control(struct rt_serial_device *serial, int cmd, void *ar
/* enable interrupt */
/* enable interrupt */
USART_ITConfig
(
uart
->
uart_device
,
USART_IT_RXNE
,
ENABLE
);
USART_ITConfig
(
uart
->
uart_device
,
USART_IT_RXNE
,
ENABLE
);
break
;
break
;
#ifdef RT_SERIAL_USING_DMA
/* USART config */
/* USART config */
case
RT_DEVICE_CTRL_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
);
DMA_Configuration
(
serial
);
}
}
break
;
break
;
#endif
/* RT_SERIAL_USING_DMA */
}
}
return
RT_EOK
;
return
RT_EOK
;
}
}
...
@@ -182,6 +187,7 @@ static int stm32_getc(struct rt_serial_device *serial)
...
@@ -182,6 +187,7 @@ static int stm32_getc(struct rt_serial_device *serial)
return
ch
;
return
ch
;
}
}
#ifdef RT_SERIAL_USING_DMA
/**
/**
* Serial port receive idle process. This need add to uart idle ISR.
* Serial port receive idle process. This need add to uart idle ISR.
*
*
...
@@ -231,6 +237,7 @@ static void dma_rx_done_isr(struct rt_serial_device *serial) {
...
@@ -231,6 +237,7 @@ static void dma_rx_done_isr(struct rt_serial_device *serial) {
DMA_ClearFlag
(
uart
->
dma
.
rx_gl_flag
);
DMA_ClearFlag
(
uart
->
dma
.
rx_gl_flag
);
}
}
#endif
/* RT_SERIAL_USING_DMA */
/**
/**
* Uart common interrupt process. This need add to uart ISR.
* Uart common interrupt process. This need add to uart ISR.
...
@@ -251,10 +258,12 @@ static void uart_isr(struct rt_serial_device *serial) {
...
@@ -251,10 +258,12 @@ static void uart_isr(struct rt_serial_device *serial) {
/* clear interrupt */
/* clear interrupt */
USART_ClearITPendingBit
(
uart
->
uart_device
,
USART_IT_RXNE
);
USART_ClearITPendingBit
(
uart
->
uart_device
,
USART_IT_RXNE
);
}
}
#ifdef RT_SERIAL_USING_DMA
if
(
USART_GetITStatus
(
uart
->
uart_device
,
USART_IT_IDLE
)
!=
RESET
)
if
(
USART_GetITStatus
(
uart
->
uart_device
,
USART_IT_IDLE
)
!=
RESET
)
{
{
dma_uart_rx_idle_isr
(
serial
);
dma_uart_rx_idle_isr
(
serial
);
}
}
#endif
/* RT_SERIAL_USING_DMA */
if
(
USART_GetITStatus
(
uart
->
uart_device
,
USART_IT_TC
)
!=
RESET
)
if
(
USART_GetITStatus
(
uart
->
uart_device
,
USART_IT_TC
)
!=
RESET
)
{
{
/* clear interrupt */
/* clear interrupt */
...
@@ -284,6 +293,7 @@ static const struct rt_uart_ops stm32_uart_ops =
...
@@ -284,6 +293,7 @@ static const struct rt_uart_ops stm32_uart_ops =
struct
stm32_uart
uart1
=
struct
stm32_uart
uart1
=
{
{
USART1
,
USART1
,
#ifdef RT_SERIAL_USING_DMA
USART1_IRQn
,
USART1_IRQn
,
{
{
DMA1_Channel5
,
DMA1_Channel5
,
...
@@ -291,6 +301,7 @@ struct stm32_uart uart1 =
...
@@ -291,6 +301,7 @@ struct stm32_uart uart1 =
DMA1_Channel5_IRQn
,
DMA1_Channel5_IRQn
,
0
,
0
,
},
},
#endif
/* RT_SERIAL_USING_DMA */
};
};
struct
rt_serial_device
serial1
;
struct
rt_serial_device
serial1
;
...
@@ -305,6 +316,7 @@ void USART1_IRQHandler(void)
...
@@ -305,6 +316,7 @@ void USART1_IRQHandler(void)
rt_interrupt_leave
();
rt_interrupt_leave
();
}
}
#ifdef RT_SERIAL_USING_DMA
void
DMA1_Channel5_IRQHandler
(
void
)
{
void
DMA1_Channel5_IRQHandler
(
void
)
{
/* enter interrupt */
/* enter interrupt */
rt_interrupt_enter
();
rt_interrupt_enter
();
...
@@ -314,6 +326,8 @@ void DMA1_Channel5_IRQHandler(void) {
...
@@ -314,6 +326,8 @@ void DMA1_Channel5_IRQHandler(void) {
/* leave interrupt */
/* leave interrupt */
rt_interrupt_leave
();
rt_interrupt_leave
();
}
}
#endif
/* RT_SERIAL_USING_DMA */
#endif
/* RT_USING_UART1 */
#endif
/* RT_USING_UART1 */
#if defined(RT_USING_UART2)
#if defined(RT_USING_UART2)
...
@@ -321,6 +335,7 @@ void DMA1_Channel5_IRQHandler(void) {
...
@@ -321,6 +335,7 @@ void DMA1_Channel5_IRQHandler(void) {
struct
stm32_uart
uart2
=
struct
stm32_uart
uart2
=
{
{
USART2
,
USART2
,
#ifdef RT_SERIAL_USING_DMA
USART2_IRQn
,
USART2_IRQn
,
{
{
DMA1_Channel6
,
DMA1_Channel6
,
...
@@ -328,6 +343,7 @@ struct stm32_uart uart2 =
...
@@ -328,6 +343,7 @@ struct stm32_uart uart2 =
DMA1_Channel6_IRQn
,
DMA1_Channel6_IRQn
,
0
,
0
,
},
},
#endif
/* RT_SERIAL_USING_DMA */
};
};
struct
rt_serial_device
serial2
;
struct
rt_serial_device
serial2
;
...
@@ -342,6 +358,7 @@ void USART2_IRQHandler(void)
...
@@ -342,6 +358,7 @@ void USART2_IRQHandler(void)
rt_interrupt_leave
();
rt_interrupt_leave
();
}
}
#ifdef RT_SERIAL_USING_DMA
void
DMA1_Channel6_IRQHandler
(
void
)
{
void
DMA1_Channel6_IRQHandler
(
void
)
{
/* enter interrupt */
/* enter interrupt */
rt_interrupt_enter
();
rt_interrupt_enter
();
...
@@ -351,6 +368,8 @@ void DMA1_Channel6_IRQHandler(void) {
...
@@ -351,6 +368,8 @@ void DMA1_Channel6_IRQHandler(void) {
/* leave interrupt */
/* leave interrupt */
rt_interrupt_leave
();
rt_interrupt_leave
();
}
}
#endif
/* RT_SERIAL_USING_DMA */
#endif
/* RT_USING_UART2 */
#endif
/* RT_USING_UART2 */
#if defined(RT_USING_UART3)
#if defined(RT_USING_UART3)
...
@@ -358,6 +377,7 @@ void DMA1_Channel6_IRQHandler(void) {
...
@@ -358,6 +377,7 @@ void DMA1_Channel6_IRQHandler(void) {
struct
stm32_uart
uart3
=
struct
stm32_uart
uart3
=
{
{
USART3
,
USART3
,
#ifdef RT_SERIAL_USING_DMA
USART3_IRQn
,
USART3_IRQn
,
{
{
DMA1_Channel3
,
DMA1_Channel3
,
...
@@ -365,6 +385,7 @@ struct stm32_uart uart3 =
...
@@ -365,6 +385,7 @@ struct stm32_uart uart3 =
DMA1_Channel3_IRQn
,
DMA1_Channel3_IRQn
,
0
,
0
,
},
},
#endif
/* RT_SERIAL_USING_DMA */
};
};
struct
rt_serial_device
serial3
;
struct
rt_serial_device
serial3
;
...
@@ -379,6 +400,7 @@ void USART3_IRQHandler(void)
...
@@ -379,6 +400,7 @@ void USART3_IRQHandler(void)
rt_interrupt_leave
();
rt_interrupt_leave
();
}
}
#ifdef RT_SERIAL_USING_DMA
void
DMA1_Channel3_IRQHandler
(
void
)
{
void
DMA1_Channel3_IRQHandler
(
void
)
{
/* enter interrupt */
/* enter interrupt */
rt_interrupt_enter
();
rt_interrupt_enter
();
...
@@ -388,6 +410,8 @@ void DMA1_Channel3_IRQHandler(void) {
...
@@ -388,6 +410,8 @@ void DMA1_Channel3_IRQHandler(void) {
/* leave interrupt */
/* leave interrupt */
rt_interrupt_leave
();
rt_interrupt_leave
();
}
}
#endif
/* RT_SERIAL_USING_DMA */
#endif
/* RT_USING_UART3 */
#endif
/* RT_USING_UART3 */
#if defined(RT_USING_UART4)
#if defined(RT_USING_UART4)
...
@@ -395,6 +419,7 @@ void DMA1_Channel3_IRQHandler(void) {
...
@@ -395,6 +419,7 @@ void DMA1_Channel3_IRQHandler(void) {
struct
stm32_uart
uart4
=
struct
stm32_uart
uart4
=
{
{
UART4
,
UART4
,
#ifdef RT_SERIAL_USING_DMA
UART4_IRQn
,
UART4_IRQn
,
{
{
DMA2_Channel3
,
DMA2_Channel3
,
...
@@ -402,6 +427,7 @@ struct stm32_uart uart4 =
...
@@ -402,6 +427,7 @@ struct stm32_uart uart4 =
DMA2_Channel3_IRQn
,
DMA2_Channel3_IRQn
,
0
,
0
,
},
},
#endif
/* RT_SERIAL_USING_DMA */
};
};
struct
rt_serial_device
serial4
;
struct
rt_serial_device
serial4
;
...
@@ -416,6 +442,7 @@ void UART4_IRQHandler(void)
...
@@ -416,6 +442,7 @@ void UART4_IRQHandler(void)
rt_interrupt_leave
();
rt_interrupt_leave
();
}
}
#ifdef RT_SERIAL_USING_DMA
void
DMA2_Channel3_IRQHandler
(
void
)
{
void
DMA2_Channel3_IRQHandler
(
void
)
{
/* enter interrupt */
/* enter interrupt */
rt_interrupt_enter
();
rt_interrupt_enter
();
...
@@ -425,6 +452,8 @@ void DMA2_Channel3_IRQHandler(void) {
...
@@ -425,6 +452,8 @@ void DMA2_Channel3_IRQHandler(void) {
/* leave interrupt */
/* leave interrupt */
rt_interrupt_leave
();
rt_interrupt_leave
();
}
}
#endif
/* RT_SERIAL_USING_DMA */
#endif
/* RT_USING_UART4 */
#endif
/* RT_USING_UART4 */
static
void
RCC_Configuration
(
void
)
static
void
RCC_Configuration
(
void
)
...
@@ -521,6 +550,7 @@ static void NVIC_Configuration(struct stm32_uart* uart)
...
@@ -521,6 +550,7 @@ static void NVIC_Configuration(struct stm32_uart* uart)
NVIC_Init
(
&
NVIC_InitStructure
);
NVIC_Init
(
&
NVIC_InitStructure
);
}
}
#ifdef RT_SERIAL_USING_DMA
static
void
DMA_Configuration
(
struct
rt_serial_device
*
serial
)
{
static
void
DMA_Configuration
(
struct
rt_serial_device
*
serial
)
{
struct
stm32_uart
*
uart
=
(
struct
stm32_uart
*
)
serial
->
parent
.
user_data
;
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
;
struct
rt_serial_rx_fifo
*
rx_fifo
=
(
struct
rt_serial_rx_fifo
*
)
serial
->
serial_rx
;
...
@@ -562,6 +592,7 @@ static void DMA_Configuration(struct rt_serial_device *serial) {
...
@@ -562,6 +592,7 @@ static void DMA_Configuration(struct rt_serial_device *serial) {
NVIC_InitStructure
.
NVIC_IRQChannelCmd
=
ENABLE
;
NVIC_InitStructure
.
NVIC_IRQChannelCmd
=
ENABLE
;
NVIC_Init
(
&
NVIC_InitStructure
);
NVIC_Init
(
&
NVIC_InitStructure
);
}
}
#endif
/* RT_SERIAL_USING_DMA */
void
rt_hw_usart_init
(
void
)
void
rt_hw_usart_init
(
void
)
{
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录