Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
RT-Thread
rt-thread
提交
131c41d1
R
rt-thread
项目概览
RT-Thread
/
rt-thread
大约 1 年 前同步成功
通知
775
Star
8911
Fork
4735
代码
文件
提交
分支
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,发现更多精彩内容 >>
提交
131c41d1
编写于
1月 31, 2015
作者:
armink_ztl
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[BSP]support 9 data bits and parity config for stm32f10x uart driver.
上级
1213dec3
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
35 addition
and
24 deletion
+35
-24
bsp/stm32f10x/drivers/usart.c
bsp/stm32f10x/drivers/usart.c
+35
-24
未找到文件。
bsp/stm32f10x/drivers/usart.c
浏览文件 @
131c41d1
...
...
@@ -17,23 +17,22 @@
#include "stm32f10x.h"
#include "usart.h"
#include "board.h"
#include <rtdevice.h>
/* USART1 */
#define UART1_GPIO_TX GPIO_Pin_9
#define UART1_GPIO_RX GPIO_Pin_10
#define UART1_GPIO GPIOA
#define UART1_GPIO_TX
GPIO_Pin_9
#define UART1_GPIO_RX
GPIO_Pin_10
#define UART1_GPIO
GPIOA
/* USART2 */
#define UART2_GPIO_TX GPIO_Pin_2
#define UART2_GPIO_RX GPIO_Pin_3
#define UART2_GPIO GPIOA
#define UART2_GPIO_TX
GPIO_Pin_2
#define UART2_GPIO_RX
GPIO_Pin_3
#define UART2_GPIO
GPIOA
/* USART3_REMAP[1:0] = 00 */
#define UART3_GPIO_TX GPIO_Pin_10
#define UART3_GPIO_RX GPIO_Pin_11
#define UART3_GPIO GPIOB
#define UART3_GPIO_TX
GPIO_Pin_10
#define UART3_GPIO_RX
GPIO_Pin_11
#define UART3_GPIO
GPIOB
/* STM32 uart driver */
struct
stm32_uart
...
...
@@ -54,15 +53,26 @@ static rt_err_t stm32_configure(struct rt_serial_device *serial, struct serial_c
USART_InitStructure
.
USART_BaudRate
=
cfg
->
baud_rate
;
if
(
cfg
->
data_bits
==
DATA_BITS_8
)
if
(
cfg
->
data_bits
==
DATA_BITS_8
)
{
USART_InitStructure
.
USART_WordLength
=
USART_WordLength_8b
;
}
else
if
(
cfg
->
data_bits
==
DATA_BITS_9
)
{
USART_InitStructure
.
USART_WordLength
=
USART_WordLength_9b
;
}
if
(
cfg
->
stop_bits
==
STOP_BITS_1
)
if
(
cfg
->
stop_bits
==
STOP_BITS_1
)
{
USART_InitStructure
.
USART_StopBits
=
USART_StopBits_1
;
else
if
(
cfg
->
stop_bits
==
STOP_BITS_2
)
}
else
if
(
cfg
->
stop_bits
==
STOP_BITS_2
){
USART_InitStructure
.
USART_StopBits
=
USART_StopBits_2
;
}
if
(
cfg
->
parity
==
PARITY_NONE
){
USART_InitStructure
.
USART_Parity
=
USART_Parity_No
;
}
else
if
(
cfg
->
parity
==
PARITY_ODD
)
{
USART_InitStructure
.
USART_Parity
=
USART_Parity_Odd
;
}
else
if
(
cfg
->
parity
==
PARITY_EVEN
)
{
USART_InitStructure
.
USART_Parity
=
USART_Parity_Even
;
}
USART_InitStructure
.
USART_Parity
=
USART_Parity_No
;
USART_InitStructure
.
USART_HardwareFlowControl
=
USART_HardwareFlowControl_None
;
USART_InitStructure
.
USART_Mode
=
USART_Mode_Rx
|
USART_Mode_Tx
;
USART_Init
(
uart
->
uart_device
,
&
USART_InitStructure
);
...
...
@@ -162,6 +172,7 @@ void USART1_IRQHandler(void)
/* clear interrupt */
USART_ClearITPendingBit
(
uart
->
uart_device
,
USART_IT_RXNE
);
}
if
(
USART_GetITStatus
(
uart
->
uart_device
,
USART_IT_TC
)
!=
RESET
)
{
/* clear interrupt */
...
...
@@ -254,21 +265,21 @@ void USART3_IRQHandler(void)
static
void
RCC_Configuration
(
void
)
{
#if
def RT_USING_UART1
#if
defined(RT_USING_UART1)
/* Enable UART GPIO clocks */
RCC_APB2PeriphClockCmd
(
RCC_APB2Periph_GPIOA
,
ENABLE
);
/* Enable UART clock */
RCC_APB2PeriphClockCmd
(
RCC_APB2Periph_USART1
,
ENABLE
);
#endif
/* RT_USING_UART1 */
#if
def RT_USING_UART2
#if
defined(RT_USING_UART2)
/* Enable UART GPIO clocks */
RCC_APB2PeriphClockCmd
(
RCC_APB2Periph_GPIOA
,
ENABLE
);
/* Enable UART clock */
RCC_APB1PeriphClockCmd
(
RCC_APB1Periph_USART2
,
ENABLE
);
#endif
/* RT_USING_UART2 */
#if
def RT_USING_UART3
#if
defined(RT_USING_UART3)
/* Enable UART GPIO clocks */
RCC_APB2PeriphClockCmd
(
RCC_APB2Periph_GPIOB
,
ENABLE
);
/* Enable UART clock */
...
...
@@ -282,7 +293,7 @@ static void GPIO_Configuration(void)
GPIO_InitStructure
.
GPIO_Speed
=
GPIO_Speed_2MHz
;
#if
def RT_USING_UART1
#if
defined(RT_USING_UART1)
/* Configure USART Rx/tx PIN */
GPIO_InitStructure
.
GPIO_Mode
=
GPIO_Mode_IN_FLOATING
;
GPIO_InitStructure
.
GPIO_Pin
=
UART1_GPIO_RX
;
...
...
@@ -293,7 +304,7 @@ static void GPIO_Configuration(void)
GPIO_Init
(
UART1_GPIO
,
&
GPIO_InitStructure
);
#endif
/* RT_USING_UART1 */
#if
def RT_USING_UART2
#if
defined(RT_USING_UART2)
/* Configure USART Rx/tx PIN */
GPIO_InitStructure
.
GPIO_Mode
=
GPIO_Mode_IN_FLOATING
;
GPIO_InitStructure
.
GPIO_Pin
=
UART2_GPIO_RX
;
...
...
@@ -304,7 +315,7 @@ static void GPIO_Configuration(void)
GPIO_Init
(
UART2_GPIO
,
&
GPIO_InitStructure
);
#endif
/* RT_USING_UART2 */
#if
def RT_USING_UART3
#if
defined(RT_USING_UART3)
/* Configure USART Rx/tx PIN */
GPIO_InitStructure
.
GPIO_Mode
=
GPIO_Mode_IN_FLOATING
;
GPIO_InitStructure
.
GPIO_Pin
=
UART3_GPIO_RX
;
...
...
@@ -336,7 +347,7 @@ void rt_hw_usart_init(void)
RCC_Configuration
();
GPIO_Configuration
();
#if
def RT_USING_UART1
#if
defined(RT_USING_UART1)
uart
=
&
uart1
;
config
.
baud_rate
=
BAUD_RATE_115200
;
...
...
@@ -347,11 +358,11 @@ void rt_hw_usart_init(void)
/* register UART1 device */
rt_hw_serial_register
(
&
serial1
,
"uart1"
,
RT_DEVICE_FLAG_RDWR
|
RT_DEVICE_FLAG_INT_RX
,
RT_DEVICE_FLAG_RDWR
|
RT_DEVICE_FLAG_INT_RX
,
uart
);
#endif
/* RT_USING_UART1 */
#if
def RT_USING_UART2
#if
defined(RT_USING_UART2)
uart
=
&
uart2
;
config
.
baud_rate
=
BAUD_RATE_115200
;
...
...
@@ -366,7 +377,7 @@ void rt_hw_usart_init(void)
uart
);
#endif
/* RT_USING_UART2 */
#if
def RT_USING_UART3
#if
defined(RT_USING_UART3)
uart
=
&
uart3
;
config
.
baud_rate
=
BAUD_RATE_115200
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录