Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
dgr6878
rt-thread
提交
79b44d29
R
rt-thread
项目概览
dgr6878
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
5
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rt-thread
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
79b44d29
编写于
4月 28, 2020
作者:
csnd_nc
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[bsp\nrf5x]Support BSP UART0
上级
252b9aa0
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
89 addition
and
60 deletion
+89
-60
bsp/nrf5x/libraries/drivers/drv_uart.c
bsp/nrf5x/libraries/drivers/drv_uart.c
+73
-56
bsp/nrf5x/nrf52840/board/Kconfig
bsp/nrf5x/nrf52840/board/Kconfig
+13
-4
bsp/nrf5x/nrf52840/rtconfig.h
bsp/nrf5x/nrf52840/rtconfig.h
+3
-0
未找到文件。
bsp/nrf5x/libraries/drivers/drv_uart.c
浏览文件 @
79b44d29
/*
* Copyright (c) 2006-2020, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2020-04-28 xckhmf Modify for <nrfx>
*
*/
#include <rtdevice.h>
#include <nrfx_uart.h>
#include "drv_uart.h"
static
struct
rt_serial_device
_serial0_0
;
static
void
uart_event_hander
(
nrfx_uart_event_t
const
*
p_event
,
void
*
p_context
);
#ifdef BSP_USING_UART
typedef
struct
{
struct
rt_serial_device
*
serial
;
nrfx_uart_t
uart
;
uint8_t
rx_byte
;
uint16_t
rx_length
;
uint32_t
rx_pin
;
uint32_t
tx_pin
;
nrfx_uart_event_handler_t
event_handler
;
}
UART_CFG_T
;
}
drv_uart_cfg_t
;
UART_CFG_T
uart0
=
{
#ifdef BSP_USING_UART0
static
struct
rt_serial_device
_serial_0
;
static
void
uart0_event_hander
(
nrfx_uart_event_t
const
*
p_event
,
void
*
p_context
);
drv_uart_cfg_t
m_uart0_cfg
=
{
.
uart
=
NRFX_UART_INSTANCE
(
0
),
#ifdef RT_USING_CONSOLE
.
rx_pin
=
8
,
.
tx_pin
=
6
,
.
event_handler
=
uart_event_hander
,
#else
.
rx_pin
=
19
,
.
tx_pin
=
20
#endif
.
rx_byte
=
0
,
.
rx_length
=
0
,
.
rx_pin
=
BSP_UART0_RX_PIN
,
.
tx_pin
=
BSP_UART0_TX_PIN
,
.
event_handler
=
uart0_event_hander
};
UART_CFG_T
*
working_cfg
=
RT_NULL
;
#endif
/* BSP_USING_UART0 */
static
void
uart_event_hander
(
nrfx_uart_event_t
const
*
p_event
,
void
*
p_context
)
{
#ifdef BSP_USING_UART1
#error <nrfx_uart> not support UART1. Use UART0 instead.
#endif
/* BSP_USING_UART1 */
#ifdef BSP_USING_UART0
static
void
uart0_event_hander
(
nrfx_uart_event_t
const
*
p_event
,
void
*
p_context
)
{
if
(
p_event
->
type
==
NRFX_UART_EVT_RX_DONE
)
{
rt_hw_serial_isr
(
working_cfg
->
serial
,
RT_SERIAL_EVENT_RX_IND
);
if
(
p_event
->
data
.
rxtx
.
bytes
==
1
)
{
m_uart0_cfg
.
rx_length
=
p_event
->
data
.
rxtx
.
bytes
;
/* rx_byte equal p_data */
//m_uart0_cfg.rx_byte = *(p_event->data.rxtx.p_data);
rt_hw_serial_isr
(
m_uart0_cfg
.
serial
,
RT_SERIAL_EVENT_RX_IND
);
}
nrfx_uart_rx
(
&
(
m_uart0_cfg
.
uart
),
&
m_uart0_cfg
.
rx_byte
,
1
);
}
if
(
p_event
->
type
==
NRFX_UART_EVT_TX_DONE
)
{
/* @TODO:[RT_DEVICE_FLAG_INT_TX]*/
}
}
#endif
/* BSP_USING_UART0 */
static
rt_err_t
_uart_cfg
(
struct
rt_serial_device
*
serial
,
struct
serial_configure
*
cfg
)
{
nrfx_uart_config_t
config
=
NRFX_UART_DEFAULT_CONFIG
(
uart0
.
tx_pin
,
uart0
.
rx_pin
);
UART_CFG_T
*
instance
=
&
uart0
;
nrfx_uart_config_t
config
=
NRFX_UART_DEFAULT_CONFIG
(
BSP_UART0_TX_PIN
,
BSP_UART0_RX_PIN
);
drv_uart_cfg_t
*
instance
=
RT_NULL
;
RT_ASSERT
(
serial
!=
RT_NULL
);
RT_ASSERT
(
cfg
!=
RT_NULL
);
if
(
serial
->
parent
.
user_data
!
=
RT_NULL
)
if
(
serial
->
parent
.
user_data
=
=
RT_NULL
)
{
instance
=
(
UART_CFG_T
*
)
serial
->
parent
.
user_data
;
return
-
RT_ERROR
;
}
instance
=
(
drv_uart_cfg_t
*
)
serial
->
parent
.
user_data
;
nrfx_uart_uninit
(
&
(
instance
->
uart
));
switch
(
cfg
->
baud_rate
)
...
...
@@ -83,28 +107,23 @@ static rt_err_t _uart_cfg(struct rt_serial_device *serial, struct serial_configu
config
.
hal_cfg
.
hwfc
=
NRF_UART_HWFC_DISABLED
;
config
.
pselrxd
=
instance
->
rx_pin
;
config
.
pseltxd
=
instance
->
tx_pin
;
nrfx_uart_init
(
&
(
instance
->
uart
),
&
config
,
instance
->
event_handler
);
nrf_uart_int_enable
(
instance
->
uart
.
p_reg
,
NRF_UART_INT_MASK_RXDRDY
|
NRF_UART_INT_MASK_RXTO
|
NRF_UART_INT_MASK_ERROR
);
nrfx_uart_init
(
&
(
instance
->
uart
),
&
config
,
instance
->
event_handler
);
nrfx_uart_rx
(
&
(
instance
->
uart
),
&
(
instance
->
rx_byte
),
1
);
nrf_uart_int_disable
(
instance
->
uart
.
p_reg
,
NRF_UART_INT_MASK_TXDRDY
);
nrfx_uart_rx_enable
(
&
(
instance
->
uart
));
working_cfg
=
instance
;
return
RT_EOK
;
}
static
rt_err_t
_uart_ctrl
(
struct
rt_serial_device
*
serial
,
int
cmd
,
void
*
arg
)
{
UART_CFG_T
*
instance
=
working_cfg
;
drv_uart_cfg_t
*
instance
=
NULL
;
RT_ASSERT
(
serial
!=
RT_NULL
);
if
(
serial
->
parent
.
user_data
!
=
RT_NULL
)
if
(
serial
->
parent
.
user_data
=
=
RT_NULL
)
{
instance
=
(
UART_CFG_T
*
)
serial
->
parent
.
user_data
;
return
-
RT_ERROR
;
}
instance
=
(
drv_uart_cfg_t
*
)
serial
->
parent
.
user_data
;
switch
(
cmd
)
{
...
...
@@ -129,10 +148,7 @@ static rt_err_t _uart_ctrl(struct rt_serial_device *serial, int cmd, void *arg)
break
;
case
RT_DEVICE_CTRL_PIN
:
if
(
working_cfg
!=
instance
)
{
_uart_cfg
(
instance
->
serial
,
&
(
instance
->
serial
->
config
));
}
_uart_cfg
(
instance
->
serial
,
&
(
instance
->
serial
->
config
));
break
;
case
RT_DEVICE_POWERSAVE
:
...
...
@@ -152,13 +168,13 @@ static rt_err_t _uart_ctrl(struct rt_serial_device *serial, int cmd, void *arg)
static
int
_uart_putc
(
struct
rt_serial_device
*
serial
,
char
c
)
{
UART_CFG_T
*
instance
=
working_cfg
;
drv_uart_cfg_t
*
instance
=
NULL
;
int
rtn
=
1
;
RT_ASSERT
(
serial
!=
RT_NULL
);
if
(
serial
->
parent
.
user_data
!=
RT_NULL
)
{
instance
=
(
UART_CFG_T
*
)
serial
->
parent
.
user_data
;
instance
=
(
drv_uart_cfg_t
*
)
serial
->
parent
.
user_data
;
}
nrf_uart_event_clear
(
instance
->
uart
.
p_reg
,
NRF_UART_EVENT_TXDRDY
);
...
...
@@ -171,23 +187,21 @@ static int _uart_putc(struct rt_serial_device *serial, char c)
return
rtn
;
}
/*
@note: this function is invaild ,the cause of the problem is [nrfx_uart.c - line 340]
*/
static
int
_uart_getc
(
struct
rt_serial_device
*
serial
)
{
int
ch
=
-
1
;
UART_CFG_T
*
instance
=
working_cfg
;
drv_uart_cfg_t
*
instance
=
NULL
;
RT_ASSERT
(
serial
!=
RT_NULL
);
if
(
serial
->
parent
.
user_data
!=
RT_NULL
)
{
instance
=
(
UART_CFG_T
*
)
serial
->
parent
.
user_data
;
instance
=
(
drv_uart_cfg_t
*
)
serial
->
parent
.
user_data
;
}
if
(
instance
->
rx_length
)
{
ch
=
instance
->
rx_byte
;
instance
->
rx_length
--
;
}
ch
=
(
int
)(
nrf_uart_rxd_get
(
instance
->
uart
.
p_reg
));
return
ch
;
}
...
...
@@ -202,11 +216,14 @@ void rt_hw_uart_init(void)
{
struct
serial_configure
config
=
RT_SERIAL_CONFIG_DEFAULT
;
config
.
bufsz
=
RT_SERIAL_RB_BUFSZ
;
_serial0_0
.
config
=
config
;
_serial0_0
.
ops
=
&
_uart_ops
;
uart0
.
serial
=
&
_serial0_0
;
#ifdef BSP_USING_UART0
_serial_0
.
config
=
config
;
_serial_0
.
ops
=
&
_uart_ops
;
m_uart0_cfg
.
serial
=
&
_serial_0
;
rt_hw_serial_register
(
&
_serial_0
,
"uart0"
,
\
RT_DEVICE_FLAG_RDWR
|
RT_DEVICE_FLAG_INT_RX
,
&
m_uart0_cfg
);
#endif
/* BSP_USING_UART0 */
rt_hw_serial_register
(
&
_serial0_0
,
"uart0"
,
RT_DEVICE_FLAG_RDWR
|
RT_DEVICE_FLAG_INT_RX
,
&
uart0
);
}
#endif
/* BSP_USING_UART */
bsp/nrf5x/nrf52840/board/Kconfig
浏览文件 @
79b44d29
...
...
@@ -2,14 +2,14 @@ menu "Hardware Drivers Config"
config SOC_NRF52840
bool
config SOC_NRF52840
config SOC_NRF52840
select RT_USING_COMPONENTS_INIT
select RT_USING_USER_MAIN
default y
menu "Onboard Peripheral Drivers"
config BSP_USING_JLINK_TO_USART
bool "Enable JLINK TO USART (uart0)"
bool "Enable JLINK TO USART (uart0
|RX_PIN:8|TX_PIN:6
)"
select BSP_USING_UART
select BSP_USING_UART0
default y
...
...
@@ -30,11 +30,20 @@ menu "On-chip Peripheral Drivers"
config BSP_USING_UART0
bool "Enable UART0"
default y
if BSP_USING_UART0
config BSP_UART0_RX_PIN
int "uart0 rx pin number"
range 0 31
default 8
config BSP_UART0_TX_PIN
int "uart0 tx pin number"
range 0 31
default 6
endif
config BSP_USING_UART1
bool "Enable UART1"
default n
endif
endif
endmenu
endmenu
bsp/nrf5x/nrf52840/rtconfig.h
浏览文件 @
79b44d29
...
...
@@ -155,10 +155,13 @@
/* Onboard Peripheral Drivers */
#define BSP_USING_JLINK_TO_USART
/* On-chip Peripheral Drivers */
#define BSP_USING_UART
#define BSP_USING_UART0
#define BSP_UART0_RX_PIN 8
#define BSP_UART0_TX_PIN 6
#endif
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录