Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
rt-thread
提交
12b1e74f
R
rt-thread
项目概览
BaiXuePrincess
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / 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,发现更多精彩内容 >>
提交
12b1e74f
编写于
10月 14, 2021
作者:
M
mazhiyuan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
修复STM32串口mask问题
上级
634e5341
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
100 addition
and
6 deletion
+100
-6
bsp/stm32/libraries/HAL_Drivers/drv_usart.c
bsp/stm32/libraries/HAL_Drivers/drv_usart.c
+49
-2
bsp/stm32/libraries/HAL_Drivers/drv_usart_v2.c
bsp/stm32/libraries/HAL_Drivers/drv_usart_v2.c
+49
-2
bsp/stm32/libraries/HAL_Drivers/drv_usart_v2.h
bsp/stm32/libraries/HAL_Drivers/drv_usart_v2.h
+2
-2
未找到文件。
bsp/stm32/libraries/HAL_Drivers/drv_usart.c
浏览文件 @
12b1e74f
...
@@ -251,6 +251,53 @@ static rt_err_t stm32_control(struct rt_serial_device *serial, int cmd, void *ar
...
@@ -251,6 +251,53 @@ static rt_err_t stm32_control(struct rt_serial_device *serial, int cmd, void *ar
return
RT_EOK
;
return
RT_EOK
;
}
}
rt_uint32_t
stm32_uart_get_mask
(
rt_uint32_t
word_length
,
rt_uint32_t
parity
)
{
rt_uint32_t
mask
;
if
(
word_length
==
UART_WORDLENGTH_8B
)
{
if
(
parity
==
UART_PARITY_NONE
)
{
mask
=
0x00FFU
;
}
else
{
mask
=
0x007FU
;
}
}
#ifdef UART_WORDLENGTH_9B
else
if
(
word_length
==
UART_WORDLENGTH_9B
)
{
if
(
parity
==
UART_PARITY_NONE
)
{
mask
=
0x01FFU
;
}
else
{
mask
=
0x00FFU
;
}
}
#endif
#ifdef UART_WORDLENGTH_7B
else
if
(
word_length
==
UART_WORDLENGTH_7B
)
{
if
(
parity
==
UART_PARITY_NONE
)
{
mask
=
0x007FU
;
}
else
{
mask
=
0x003FU
;
}
}
else
{
mask
=
0x0000U
;
}
#endif
return
mask
;
}
static
int
stm32_putc
(
struct
rt_serial_device
*
serial
,
char
c
)
static
int
stm32_putc
(
struct
rt_serial_device
*
serial
,
char
c
)
{
{
struct
stm32_uart
*
uart
;
struct
stm32_uart
*
uart
;
...
@@ -282,9 +329,9 @@ static int stm32_getc(struct rt_serial_device *serial)
...
@@ -282,9 +329,9 @@ static int stm32_getc(struct rt_serial_device *serial)
#if defined(SOC_SERIES_STM32L4) || defined(SOC_SERIES_STM32WL) || defined(SOC_SERIES_STM32F7) || defined(SOC_SERIES_STM32F0) \
#if defined(SOC_SERIES_STM32L4) || defined(SOC_SERIES_STM32WL) || defined(SOC_SERIES_STM32F7) || defined(SOC_SERIES_STM32F0) \
|| defined(SOC_SERIES_STM32L0) || defined(SOC_SERIES_STM32G0) || defined(SOC_SERIES_STM32H7) \
|| defined(SOC_SERIES_STM32L0) || defined(SOC_SERIES_STM32G0) || defined(SOC_SERIES_STM32H7) \
|| defined(SOC_SERIES_STM32G4) || defined(SOC_SERIES_STM32MP1) || defined(SOC_SERIES_STM32WB)|| defined(SOC_SERIES_STM32F3)
|| defined(SOC_SERIES_STM32G4) || defined(SOC_SERIES_STM32MP1) || defined(SOC_SERIES_STM32WB)|| defined(SOC_SERIES_STM32F3)
ch
=
uart
->
handle
.
Instance
->
RDR
&
0xff
;
ch
=
uart
->
handle
.
Instance
->
RDR
&
stm32_uart_get_mask
(
uart
->
handle
.
Init
.
WordLength
,
uart
->
handle
.
Init
.
Parity
)
;
#else
#else
ch
=
uart
->
handle
.
Instance
->
DR
&
0xff
;
ch
=
uart
->
handle
.
Instance
->
DR
&
stm32_uart_get_mask
(
uart
->
handle
.
Init
.
WordLength
,
uart
->
handle
.
Init
.
Parity
)
;
#endif
#endif
}
}
return
ch
;
return
ch
;
...
...
bsp/stm32/libraries/HAL_Drivers/drv_usart_v2.c
浏览文件 @
12b1e74f
...
@@ -302,6 +302,53 @@ static int stm32_putc(struct rt_serial_device *serial, char c)
...
@@ -302,6 +302,53 @@ static int stm32_putc(struct rt_serial_device *serial, char c)
return
1
;
return
1
;
}
}
rt_uint32_t
stm32_uart_get_mask
(
rt_uint32_t
word_length
,
rt_uint32_t
parity
)
{
rt_uint32_t
mask
;
if
(
word_length
==
UART_WORDLENGTH_8B
)
{
if
(
parity
==
UART_PARITY_NONE
)
{
mask
=
0x00FFU
;
}
else
{
mask
=
0x007FU
;
}
}
#ifdef UART_WORDLENGTH_9B
else
if
(
word_length
==
UART_WORDLENGTH_9B
)
{
if
(
parity
==
UART_PARITY_NONE
)
{
mask
=
0x01FFU
;
}
else
{
mask
=
0x00FFU
;
}
}
#endif
#ifdef UART_WORDLENGTH_7B
else
if
(
word_length
==
UART_WORDLENGTH_7B
)
{
if
(
parity
==
UART_PARITY_NONE
)
{
mask
=
0x007FU
;
}
else
{
mask
=
0x003FU
;
}
}
else
{
mask
=
0x0000U
;
}
#endif
return
mask
;
}
static
int
stm32_getc
(
struct
rt_serial_device
*
serial
)
static
int
stm32_getc
(
struct
rt_serial_device
*
serial
)
{
{
int
ch
;
int
ch
;
...
@@ -311,7 +358,7 @@ static int stm32_getc(struct rt_serial_device *serial)
...
@@ -311,7 +358,7 @@ static int stm32_getc(struct rt_serial_device *serial)
ch
=
-
1
;
ch
=
-
1
;
if
(
__HAL_UART_GET_FLAG
(
&
(
uart
->
handle
),
UART_FLAG_RXNE
)
!=
RESET
)
if
(
__HAL_UART_GET_FLAG
(
&
(
uart
->
handle
),
UART_FLAG_RXNE
)
!=
RESET
)
ch
=
UART_GET_RDR
(
&
uart
->
handle
);
ch
=
UART_GET_RDR
(
&
uart
->
handle
,
stm32_uart_get_mask
(
uart
->
handle
.
Init
.
WordLength
,
uart
->
handle
.
Init
.
Parity
)
);
return
ch
;
return
ch
;
}
}
...
@@ -403,7 +450,7 @@ static void uart_isr(struct rt_serial_device *serial)
...
@@ -403,7 +450,7 @@ static void uart_isr(struct rt_serial_device *serial)
rx_fifo
=
(
struct
rt_serial_rx_fifo
*
)
serial
->
serial_rx
;
rx_fifo
=
(
struct
rt_serial_rx_fifo
*
)
serial
->
serial_rx
;
RT_ASSERT
(
rx_fifo
!=
RT_NULL
);
RT_ASSERT
(
rx_fifo
!=
RT_NULL
);
rt_ringbuffer_putchar
(
&
(
rx_fifo
->
rb
),
UART_GET_RDR
(
&
uart
->
handle
));
rt_ringbuffer_putchar
(
&
(
rx_fifo
->
rb
),
UART_GET_RDR
(
&
uart
->
handle
,
stm32_uart_get_mask
(
uart
->
handle
.
Init
.
WordLength
,
uart
->
handle
.
Init
.
Parity
)
));
rt_hw_serial_isr
(
serial
,
RT_SERIAL_EVENT_RX_IND
);
rt_hw_serial_isr
(
serial
,
RT_SERIAL_EVENT_RX_IND
);
}
}
...
...
bsp/stm32/libraries/HAL_Drivers/drv_usart_v2.h
浏览文件 @
12b1e74f
...
@@ -24,11 +24,11 @@ int rt_hw_usart_init(void);
...
@@ -24,11 +24,11 @@ int rt_hw_usart_init(void);
|| defined(SOC_SERIES_STM32L0) || defined(SOC_SERIES_STM32G0) || defined(SOC_SERIES_STM32H7) \
|| defined(SOC_SERIES_STM32L0) || defined(SOC_SERIES_STM32G0) || defined(SOC_SERIES_STM32H7) \
|| defined(SOC_SERIES_STM32G4)
|| defined(SOC_SERIES_STM32G4)
#define UART_SET_TDR(__HANDLE__, __DATA__) ((__HANDLE__)->Instance->TDR = (__DATA__))
#define UART_SET_TDR(__HANDLE__, __DATA__) ((__HANDLE__)->Instance->TDR = (__DATA__))
#define UART_GET_RDR(__HANDLE__
) ((__HANDLE__)->Instance->RDR & 0xFF
)
#define UART_GET_RDR(__HANDLE__
, MASK) ((__HANDLE__)->Instance->RDR & MASK
)
#else
#else
#define UART_SET_TDR(__HANDLE__, __DATA__) ((__HANDLE__)->Instance->DR = (__DATA__))
#define UART_SET_TDR(__HANDLE__, __DATA__) ((__HANDLE__)->Instance->DR = (__DATA__))
#define UART_GET_RDR(__HANDLE__
) ((__HANDLE__)->Instance->DR & 0xFF
)
#define UART_GET_RDR(__HANDLE__
, MASK) ((__HANDLE__)->Instance->DR & MASK
)
#endif
#endif
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录