Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PHPmihuan
rt-thread
提交
ffd34fd3
R
rt-thread
项目概览
PHPmihuan
/
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,发现更多精彩内容 >>
提交
ffd34fd3
编写于
11月 15, 2020
作者:
csnd_nc
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[bsp/nrf5x]support for uarte1
上级
065488e7
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
409 addition
and
15 deletion
+409
-15
bsp/nrf5x/libraries/drivers/SConscript
bsp/nrf5x/libraries/drivers/SConscript
+4
-2
bsp/nrf5x/libraries/drivers/drv_uarte.c
bsp/nrf5x/libraries/drivers/drv_uarte.c
+281
-0
bsp/nrf5x/libraries/drivers/drv_uarte.h
bsp/nrf5x/libraries/drivers/drv_uarte.h
+33
-0
bsp/nrf5x/nrf52832/board/Kconfig
bsp/nrf5x/nrf52832/board/Kconfig
+38
-7
bsp/nrf5x/nrf52840/board/Kconfig
bsp/nrf5x/nrf52840/board/Kconfig
+53
-6
未找到文件。
bsp/nrf5x/libraries/drivers/SConscript
浏览文件 @
ffd34fd3
...
...
@@ -9,8 +9,10 @@ src = Split("""
"""
)
if
GetDepend
([
'BSP_USING_UART'
]):
if
GetDepend
([
'NRFX_USING_UART'
]):
src
+=
[
'drv_uart.c'
]
else
:
src
+=
[
'drv_uarte.c'
]
if
GetDepend
([
'BSP_USING_ON_CHIP_FLASH'
]):
src
+=
[
'drv_flash.c'
]
...
...
bsp/nrf5x/libraries/drivers/drv_uarte.c
0 → 100644
浏览文件 @
ffd34fd3
/*
* 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>
* 2020-10-31 xckhmf Support for UART1
*
*/
#include <rtdevice.h>
#include <nrfx_uarte.h>
#include "drv_uart.h"
#ifdef BSP_USING_UART
#if defined(BSP_USING_UART0) || defined(BSP_USING_UART1)
typedef
struct
{
struct
rt_serial_device
*
serial
;
nrfx_uarte_t
uarte_instance
;
uint8_t
rx_length
;
uint8_t
tx_buffer
[
1
];
uint8_t
rx_buffer
[
1
];
bool
isInit
;
uint32_t
rx_pin
;
uint32_t
tx_pin
;
}
drv_uart_cb_t
;
#ifdef BSP_USING_UART0
static
struct
rt_serial_device
m_serial_0
;
drv_uart_cb_t
m_uarte0_cb
=
{
.
uarte_instance
=
NRFX_UARTE_INSTANCE
(
0
),
.
rx_length
=
0
,
.
rx_pin
=
BSP_UART0_RX_PIN
,
.
tx_pin
=
BSP_UART0_TX_PIN
,
.
isInit
=
false
};
#endif
/* BSP_USING_UART0 */
#ifdef BSP_USING_UART1
static
struct
rt_serial_device
m_serial_1
;
drv_uart_cb_t
m_uarte1_cb
=
{
.
uarte_instance
=
NRFX_UARTE_INSTANCE
(
1
),
.
rx_length
=
0
,
.
rx_pin
=
BSP_UART1_RX_PIN
,
.
tx_pin
=
BSP_UART1_TX_PIN
,
.
isInit
=
false
};
#endif
/* BSP_USING_UART1 */
static
void
uarte_evt_handler
(
nrfx_uarte_event_t
const
*
p_event
,
void
*
p_context
)
{
drv_uart_cb_t
*
p_cb
=
RT_NULL
;
p_cb
=
(
drv_uart_cb_t
*
)
p_context
;
switch
(
p_event
->
type
)
{
case
NRFX_UARTE_EVT_RX_DONE
:
p_cb
->
rx_length
=
p_event
->
data
.
rxtx
.
bytes
;
if
(
p_cb
->
serial
->
parent
.
open_flag
&
RT_DEVICE_FLAG_INT_RX
)
{
rt_hw_serial_isr
(
p_cb
->
serial
,
RT_SERIAL_EVENT_RX_IND
);
}
(
void
)
nrfx_uarte_rx
(
&
(
p_cb
->
uarte_instance
),
p_cb
->
rx_buffer
,
1
);
break
;
case
NRFX_UARTE_EVT_ERROR
:
(
void
)
nrfx_uarte_rx
(
&
(
p_cb
->
uarte_instance
),
p_cb
->
rx_buffer
,
1
);
break
;
case
NRFX_UARTE_EVT_TX_DONE
:
if
(
p_cb
->
serial
->
parent
.
open_flag
&
RT_DEVICE_FLAG_INT_TX
)
{
rt_hw_serial_isr
(
p_cb
->
serial
,
RT_SERIAL_EVENT_TX_DONE
);
}
break
;
default:
break
;
}
}
static
rt_err_t
_uart_cfg
(
struct
rt_serial_device
*
serial
,
struct
serial_configure
*
cfg
)
{
nrfx_uarte_config_t
config
=
NRFX_UARTE_DEFAULT_CONFIG
(
NRF_UARTE_PSEL_DISCONNECTED
,
\
NRF_UARTE_PSEL_DISCONNECTED
);
drv_uart_cb_t
*
p_cb
=
RT_NULL
;
RT_ASSERT
(
serial
!=
RT_NULL
);
RT_ASSERT
(
cfg
!=
RT_NULL
);
if
(
serial
->
parent
.
user_data
==
RT_NULL
)
{
return
-
RT_ERROR
;
}
p_cb
=
(
drv_uart_cb_t
*
)
serial
->
parent
.
user_data
;
if
(
p_cb
->
isInit
)
{
nrfx_uarte_uninit
(
&
(
p_cb
->
uarte_instance
));
p_cb
->
isInit
=
false
;
}
switch
(
cfg
->
baud_rate
)
{
case
BAUD_RATE_2400
:
config
.
baudrate
=
NRF_UARTE_BAUDRATE_2400
;
break
;
case
BAUD_RATE_4800
:
config
.
baudrate
=
NRF_UARTE_BAUDRATE_4800
;
break
;
case
BAUD_RATE_9600
:
config
.
baudrate
=
NRF_UARTE_BAUDRATE_9600
;
break
;
case
BAUD_RATE_19200
:
config
.
baudrate
=
NRF_UARTE_BAUDRATE_19200
;
break
;
case
BAUD_RATE_38400
:
config
.
baudrate
=
NRF_UARTE_BAUDRATE_38400
;
break
;
case
BAUD_RATE_57600
:
config
.
baudrate
=
NRF_UARTE_BAUDRATE_57600
;
break
;
case
BAUD_RATE_115200
:
config
.
baudrate
=
NRF_UARTE_BAUDRATE_115200
;
break
;
case
BAUD_RATE_230400
:
config
.
baudrate
=
NRF_UARTE_BAUDRATE_230400
;
break
;
case
BAUD_RATE_460800
:
config
.
baudrate
=
NRF_UARTE_BAUDRATE_460800
;
break
;
case
BAUD_RATE_921600
:
config
.
baudrate
=
NRF_UARTE_BAUDRATE_921600
;
break
;
case
BAUD_RATE_2000000
:
case
BAUD_RATE_3000000
:
return
-
RT_EINVAL
;
default:
config
.
baudrate
=
NRF_UARTE_BAUDRATE_115200
;
break
;
}
config
.
hal_cfg
.
parity
=
(
cfg
->
parity
==
PARITY_NONE
)
?
\
NRF_UARTE_PARITY_EXCLUDED
:
NRF_UARTE_PARITY_INCLUDED
;
config
.
hal_cfg
.
hwfc
=
NRF_UARTE_HWFC_DISABLED
;
config
.
pselrxd
=
p_cb
->
rx_pin
;
config
.
pseltxd
=
p_cb
->
tx_pin
;
config
.
p_context
=
(
void
*
)
p_cb
;
nrfx_uarte_init
(
&
(
p_cb
->
uarte_instance
),(
nrfx_uarte_config_t
const
*
)
&
config
,
uarte_evt_handler
);
nrfx_uarte_rx
(
&
(
p_cb
->
uarte_instance
),
p_cb
->
rx_buffer
,
1
);
p_cb
->
isInit
=
true
;
return
RT_EOK
;
}
static
rt_err_t
_uart_ctrl
(
struct
rt_serial_device
*
serial
,
int
cmd
,
void
*
arg
)
{
drv_uart_cb_t
*
p_cb
=
RT_NULL
;
RT_ASSERT
(
serial
!=
RT_NULL
);
if
(
serial
->
parent
.
user_data
==
RT_NULL
)
{
return
-
RT_ERROR
;
}
p_cb
=
(
drv_uart_cb_t
*
)
serial
->
parent
.
user_data
;
switch
(
cmd
)
{
/* disable interrupt */
case
RT_DEVICE_CTRL_CLR_INT
:
break
;
/* enable interrupt */
case
RT_DEVICE_CTRL_SET_INT
:
break
;
case
RT_DEVICE_CTRL_CUSTOM
:
if
((
rt_uint32_t
)(
arg
)
==
UART_CONFIG_BAUD_RATE_9600
)
{
p_cb
->
serial
->
config
.
baud_rate
=
9600
;
}
else
if
((
rt_uint32_t
)(
arg
)
==
UART_CONFIG_BAUD_RATE_115200
)
{
p_cb
->
serial
->
config
.
baud_rate
=
115200
;
}
_uart_cfg
(
serial
,
&
(
serial
->
config
));
break
;
case
RT_DEVICE_CTRL_PIN
:
_uart_cfg
(
serial
,
&
(
serial
->
config
));
break
;
case
RT_DEVICE_POWERSAVE
:
if
(
p_cb
->
isInit
)
{
nrfx_uarte_uninit
(
&
(
p_cb
->
uarte_instance
));
p_cb
->
isInit
=
false
;
}
break
;
case
RT_DEVICE_WAKEUP
:
_uart_cfg
(
serial
,
&
(
serial
->
config
));
break
;
default:
return
-
RT_ERROR
;
}
return
RT_EOK
;
}
static
int
_uart_putc
(
struct
rt_serial_device
*
serial
,
char
c
)
{
drv_uart_cb_t
*
p_cb
=
RT_NULL
;
int
rtn
=
-
1
;
RT_ASSERT
(
serial
!=
RT_NULL
);
if
(
serial
->
parent
.
user_data
!=
RT_NULL
)
{
p_cb
=
(
drv_uart_cb_t
*
)
serial
->
parent
.
user_data
;
}
p_cb
->
tx_buffer
[
0
]
=
c
;
nrfx_uarte_tx
(
&
(
p_cb
->
uarte_instance
),
p_cb
->
tx_buffer
,
1
);
if
(
!
(
serial
->
parent
.
open_flag
&
RT_DEVICE_FLAG_INT_TX
))
{
while
(
nrfx_uarte_tx_in_progress
(
&
(
p_cb
->
uarte_instance
)))
{
}
}
return
rtn
;
}
static
int
_uart_getc
(
struct
rt_serial_device
*
serial
)
{
int
ch
=
-
1
;
drv_uart_cb_t
*
p_cb
=
RT_NULL
;
RT_ASSERT
(
serial
!=
RT_NULL
);
if
(
serial
->
parent
.
user_data
!=
RT_NULL
)
{
p_cb
=
(
drv_uart_cb_t
*
)
serial
->
parent
.
user_data
;
}
if
(
p_cb
->
rx_length
)
{
ch
=
p_cb
->
rx_buffer
[
0
];
p_cb
->
rx_length
--
;
}
return
ch
;
}
static
struct
rt_uart_ops
_uart_ops
=
{
_uart_cfg
,
_uart_ctrl
,
_uart_putc
,
_uart_getc
};
void
rt_hw_uart_init
(
void
)
{
struct
serial_configure
config
=
RT_SERIAL_CONFIG_DEFAULT
;
#ifdef BSP_USING_UART0
m_serial_0
.
config
=
config
;
m_serial_0
.
ops
=
&
_uart_ops
;
m_uarte0_cb
.
serial
=
&
m_serial_0
;
rt_hw_serial_register
(
&
m_serial_0
,
"uart0"
,
\
RT_DEVICE_FLAG_RDWR
|
RT_DEVICE_FLAG_INT_RX
,
&
m_uarte0_cb
);
#endif
/* BSP_USING_UART0 */
#ifdef BSP_USING_UART1
m_serial_1
.
config
=
config
;
m_serial_1
.
ops
=
&
_uart_ops
;
m_uarte1_cb
.
serial
=
&
m_serial_1
;
rt_hw_serial_register
(
&
m_serial_1
,
"uart1"
,
\
RT_DEVICE_FLAG_RDWR
|
RT_DEVICE_FLAG_INT_RX
|
RT_DEVICE_FLAG_INT_TX
,
&
m_uarte1_cb
);
#endif
/* BSP_USING_UART1 */
}
#endif
/* defined(BSP_USING_UART0) || defined(BSP_USING_UART1) */
#endif
/* BSP_USING_UART */
bsp/nrf5x/libraries/drivers/drv_uarte.h
0 → 100644
浏览文件 @
ffd34fd3
/*
* 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>
* 2020-10-31 xckhmf Support for UART1
*
*/
#ifndef __DRV_UART_H__
#define __DRV_UART_H__
#ifdef __cplusplus
extern
"C"
{
#endif
#define RT_DEVICE_CTRL_CUSTOM 0x20
#define RT_DEVICE_CTRL_PIN 0x21
#define RT_DEVICE_POWERSAVE 0x22
#define RT_DEVICE_WAKEUP 0x23
#define UART_CONFIG_BAUD_RATE_9600 1
#define UART_CONFIG_BAUD_RATE_115200 2
void
rt_hw_uart_init
(
void
);
#ifdef __cplusplus
}
#endif
#endif
/* __DRV_UART_H__ */
bsp/nrf5x/nrf52832/board/Kconfig
浏览文件 @
ffd34fd3
...
...
@@ -157,12 +157,24 @@ menu "On-chip Peripheral Drivers"
endif
menu
config BSP_USING_UART
config BSP_USING_UART
bool "Enable UART"
default y
select RT_USING_SERIAL
if BSP_USING_UART
choice
prompt "UART or UARTE"
default NRFX_USING_UART
help
Select the UART or UARTE
config NRFX_USING_UART
bool "UART"
config NRFX_USING_UARTE
bool "UARTE"
endchoice
endif
if BSP_USING_UART&&NRFX_USING_UART
config NRFX_UART_ENABLED
int
default 1
...
...
@@ -183,9 +195,28 @@ menu "On-chip Peripheral Drivers"
range 0 31
default 6
endif
config BSP_USING_UART1
bool "Enable UART1"
endif
if BSP_USING_UART&&NRFX_USING_UARTE
config NRFX_UARTE_ENABLED
int
default 1
config BSP_USING_UART0
bool "Enable UARTE0"
default n
if BSP_USING_UART0
config NRFX_UARTE0_ENABLED
int
default 1
config BSP_UART0_RX_PIN
int "uarte0 rx pin number"
range 0 31
default 8
config BSP_UART0_TX_PIN
int "uarte0 tx pin number"
range 0 31
default 6
endif
endif
config BSP_USING_SPI
...
...
bsp/nrf5x/nrf52840/board/Kconfig
浏览文件 @
ffd34fd3
...
...
@@ -194,12 +194,24 @@ menu "On-chip Peripheral Drivers"
endif
menu
config BSP_USING_UART
config BSP_USING_UART
bool "Enable UART"
default y
select RT_USING_SERIAL
if BSP_USING_UART
choice
prompt "UART or UARTE"
default NRFX_USING_UART
help
Select the UART or UARTE
config NRFX_USING_UART
bool "UART"
config NRFX_USING_UARTE
bool "UARTE"
endchoice
endif
if BSP_USING_UART&&NRFX_USING_UART
config NRFX_UART_ENABLED
int
default 1
...
...
@@ -220,9 +232,44 @@ menu "On-chip Peripheral Drivers"
range 0 31
default 6
endif
endif
if BSP_USING_UART&&NRFX_USING_UARTE
config NRFX_UARTE_ENABLED
int
default 1
config BSP_USING_UART0
bool "Enable UARTE0"
default n
if BSP_USING_UART0
config NRFX_UARTE0_ENABLED
int
default 1
config BSP_UART0_RX_PIN
int "uarte0 rx pin number"
range 0 31
default 8
config BSP_UART0_TX_PIN
int "uarte0 tx pin number"
range 0 31
default 6
endif
config BSP_USING_UART1
bool "Enable UART1"
bool "Enable UART
E
1"
default n
if BSP_USING_UART1
config NRFX_UARTE1_ENABLED
int
default 1
config BSP_UART1_RX_PIN
int "uarte1 rx pin number"
range 0 31
default 7
config BSP_UART1_TX_PIN
int "uarte1 tx pin number"
range 0 31
default 5
endif
endif
config BSP_USING_SPI
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录