Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
逆着光、寻觅
rt-thread
提交
fa693c51
R
rt-thread
项目概览
逆着光、寻觅
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
1
Star
1
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,发现更多精彩内容 >>
未验证
提交
fa693c51
编写于
3月 03, 2018
作者:
B
Bernard Xiong
提交者:
GitHub
3月 03, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1246 from TanekLiang/fvp-uart-update
[bsp] update uart driver and fixed typo
上级
78c83b36
dc4fde20
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
96 addition
and
232 deletion
+96
-232
bsp/v2m-mps2/README.md
bsp/v2m-mps2/README.md
+2
-2
bsp/v2m-mps2/drivers/drv_uart.c
bsp/v2m-mps2/drivers/drv_uart.c
+93
-212
bsp/v2m-mps2/project.uvoptx
bsp/v2m-mps2/project.uvoptx
+1
-18
未找到文件。
bsp/v2m-mps2/README.md
浏览文件 @
fa693c51
...
...
@@ -24,7 +24,7 @@ V2M-MPS2板级包支持MDK5(已测试MDK5.23~MDK5.25)
-
[
Windows 7: Enabling Telnet Client
](
https://social.technet.microsoft.com/wiki/contents/articles/910.windows-7-enabling-telnet-client.aspx
)
-
[
Windows 10: Enabling Telnet Client
](
https://social.technet.microsoft.com/wiki/contents/articles/38433.windows-10-enabling-telnet-client.aspx
)
打开project.uvprojx,编译,点击Debug->Start/Stop Se
cc
ion就可以进入仿真了。
打开project.uvprojx,编译,点击Debug->Start/Stop Se
ss
ion就可以进入仿真了。
### 3.2 如何选择其他内核
...
...
@@ -54,7 +54,7 @@ finsh />
| 驱动 | 支持情况 | 备注 |
| ------ | ---- | :------: |
| UART | 支持 | UART0/1/2
/3
|
| UART | 支持 | UART0/1/2 |
| GPIO | 未支持 | |
| LED | 未支持 | |
| BUTTOM | 未支持 | |
...
...
bsp/v2m-mps2/drivers/drv_uart.c
浏览文件 @
fa693c51
...
...
@@ -31,16 +31,14 @@
#ifndef RT_USING_DEVICE
#error "you must define RT_USING_DEVICE with uart device"
#endif
#ifndef RT_UART_RX_BUFFER_SIZE
#define RT_UART_RX_BUFFER_SIZE 16
#else
#include <rtdevice.h>
#endif
/* uart driver */
struct
fvp
_uart
struct
v2m
_uart
{
struct
rt_
device
parent
;
struct
rt_
serial_device
serial
;
CMSDK_UART_TypeDef
*
uart_base
;
CMSDK_GPIO_TypeDef
*
rx_pingpio
;
// Pin GPIO
...
...
@@ -49,62 +47,34 @@ struct fvp_uart
uint8_t
tx_pinnum
;
IRQn_Type
uart_irq_rx
;
IRQn_Type
uart_irq_tx
;
//
IRQn_Type uart_irq_tx;
/* buffer for reception */
rt_uint8_t
read_index
,
save_index
;
rt_uint8_t
rx_buffer
[
RT_UART_RX_BUFFER_SIZE
];
};
#ifdef RT_USING_UART0
struct
fvp
_uart
uart0_device
;
struct
v2m
_uart
uart0_device
;
#endif
#ifdef RT_USING_UART1
struct
fvp
_uart
uart1_device
;
struct
v2m
_uart
uart1_device
;
#endif
#ifdef RT_USING_UART2
struct
fvp_uart
uart2_device
;
#endif
#ifdef RT_USING_UART3
struct
fvp_uart
uart3_device
;
struct
v2m_uart
uart2_device
;
#endif
static
void
uart_irq_handler
(
struct
fvp_uart
*
uart
)
static
void
uart_irq_handler
(
struct
rt_serial_device
*
serial
)
{
rt_ubase_t
level
;
uint32_t
status
;
uint8_t
data
;
struct
v2m_uart
*
uart
;
status
=
uart
->
uart_base
->
INTSTATUS
;
data
=
uart
->
uart_base
->
DATA
;
uart
=
(
struct
v2m_uart
*
)
serial
->
parent
.
user_data
;
/* enter interrupt */
rt_interrupt_enter
();
level
=
rt_hw_interrupt_disable
();
uart
->
rx_buffer
[
uart
->
save_index
]
=
data
;
uart
->
save_index
++
;
if
(
uart
->
save_index
>=
RT_UART_RX_BUFFER_SIZE
)
{
uart
->
save_index
=
0
;
}
rt_hw_interrupt_enable
(
level
);
/* invoke callback */
if
(
uart
->
parent
.
rx_indicate
!=
RT_NULL
)
{
rt_size_t
length
;
if
(
uart
->
read_index
>
uart
->
save_index
)
length
=
RT_UART_RX_BUFFER_SIZE
-
uart
->
read_index
+
uart
->
save_index
;
else
length
=
uart
->
save_index
-
uart
->
read_index
;
uart
->
parent
.
rx_indicate
(
&
uart
->
parent
,
length
);
}
status
=
uart
->
uart_base
->
INTSTATUS
;
rt_hw_serial_isr
(
serial
,
RT_SERIAL_EVENT_RX_IND
);
uart
->
uart_base
->
INTCLEAR
=
status
;
/* leave interrupt */
...
...
@@ -114,223 +84,144 @@ static void uart_irq_handler(struct fvp_uart* uart)
#ifdef RT_USING_UART0
void
UART0RX_Handler
(
void
)
{
uart_irq_handler
(
&
uart0_device
);
uart_irq_handler
(
&
uart0_device
.
serial
);
}
#endif
#ifdef RT_USING_UART1
void
UART1RX_Handler
(
void
)
{
uart_irq_handler
(
&
uart1_device
);
uart_irq_handler
(
&
uart1_device
.
serial
);
}
#endif
#ifdef RT_USING_UART2
void
UART2RX_Handler
(
void
)
{
uart_irq_handler
(
&
uart2_device
);
uart_irq_handler
(
&
uart2_device
.
serial
);
}
#endif
#ifdef RT_USING_UART3
void
UART3RX_Handler
(
void
)
static
rt_err_t
v2m_configure
(
struct
rt_serial_device
*
serial
,
struct
serial_configure
*
cfg
)
{
uart_irq_handler
(
&
uart3_device
);
}
#endif
struct
v2m_uart
*
uart
;
static
rt_err_t
rt_uart_init
(
rt_device_t
dev
)
{
struct
fvp_uart
*
uart
;
RT_ASSERT
(
dev
!=
RT_NULL
);
uart
=
(
struct
fvp_uart
*
)
dev
;
RT_ASSERT
(
serial
!=
RT_NULL
);
RT_ASSERT
(
cfg
!=
RT_NULL
);
uart
->
rx_pingpio
->
ALTFUNCSET
|=
(
1u
<<
uart
->
rx_pinnum
);
uart
->
tx_pingpio
->
ALTFUNCSET
|=
(
1u
<<
uart
->
tx_pinnum
);
uart
=
(
struct
v2m_uart
*
)
serial
->
parent
.
user_data
;
uart
->
uart_base
->
BAUDDIV
=
SystemCoreClock
/
cfg
->
baud_rate
;
uart
->
uart_base
->
CTRL
=
CMSDK_UART_CTRL_TXEN_Msk
|
CMSDK_UART_CTRL_RXEN_Msk
|
CMSDK_UART_CTRL_RXIRQEN_Msk
;
uart
->
uart_base
->
BAUDDIV
=
SystemCoreClock
/
115200
;
uart
->
rx_pingpio
->
ALTFUNCSET
|=
(
1u
<<
uart
->
rx_pinnum
);
uart
->
tx_pingpio
->
ALTFUNCSET
|=
(
1u
<<
uart
->
tx_pinnum
);
return
RT_EOK
;
}
static
rt_err_t
rt_uart_open
(
rt_device_t
dev
,
rt_uint16_t
ofla
g
)
static
rt_err_t
v2m_control
(
struct
rt_serial_device
*
serial
,
int
cmd
,
void
*
ar
g
)
{
struct
fvp_uart
*
uart
;
RT_ASSERT
(
dev
!=
RT_NULL
);
uart
=
(
struct
fvp_uart
*
)
dev
;
if
(
dev
->
flag
&
RT_DEVICE_FLAG_INT_RX
)
{
/* Enable the UART Interrupt */
NVIC_EnableIRQ
(
uart
->
uart_irq_rx
);
}
return
RT_EOK
;
struct
v2m_uart
*
uart
;
RT_ASSERT
(
serial
!=
RT_NULL
);
uart
=
(
struct
v2m_uart
*
)
serial
->
parent
.
user_data
;
switch
(
cmd
)
{
case
RT_DEVICE_CTRL_CLR_INT
:
/* disable rx irq */
NVIC_DisableIRQ
(
uart
->
uart_irq_rx
);
break
;
case
RT_DEVICE_CTRL_SET_INT
:
/* enable rx irq */
NVIC_EnableIRQ
(
uart
->
uart_irq_rx
);
break
;
}
return
RT_EOK
;
}
static
rt_err_t
rt_uart_close
(
rt_device_t
dev
)
static
int
v2m_putc
(
struct
rt_serial_device
*
serial
,
char
c
)
{
struct
fvp_uart
*
uart
;
RT_ASSERT
(
dev
!=
RT_NULL
);
uart
=
(
struct
fvp_uart
*
)
dev
;
if
(
dev
->
flag
&
RT_DEVICE_FLAG_INT_RX
)
{
/* Disable the UART Interrupt */
NVIC_DisableIRQ
(
uart
->
uart_irq_rx
);
}
return
RT_EOK
;
struct
v2m_uart
*
uart
;
RT_ASSERT
(
serial
!=
RT_NULL
);
uart
=
(
struct
v2m_uart
*
)
serial
->
parent
.
user_data
;
while
(
uart
->
uart_base
->
STATE
&
CMSDK_UART_STATE_TXBF_Msk
);
uart
->
uart_base
->
DATA
=
c
;
return
1
;
}
static
rt_size_t
rt_uart_read
(
rt_device_t
dev
,
rt_off_t
pos
,
void
*
buffer
,
rt_size_t
size
)
static
int
v2m_getc
(
struct
rt_serial_device
*
serial
)
{
struct
fvp_uart
*
uart
=
(
struct
fvp_uart
*
)
dev
;
rt_uint8_t
*
ptr
;
rt_size_t
length
;
RT_ASSERT
(
dev
!=
RT_NULL
);
RT_ASSERT
(
buffer
!=
RT_NULL
);
int
ch
;
struct
v2m_uart
*
uart
;
ptr
=
(
rt_uint8_t
*
)
buffer
;
while
(
size
)
{
/* interrupt receive */
rt_base_t
level
;
/* disable interrupt */
level
=
rt_hw_interrupt_disable
();
if
(
uart
->
read_index
!=
uart
->
save_index
)
{
*
ptr
=
uart
->
rx_buffer
[
uart
->
read_index
];
uart
->
read_index
++
;
if
(
uart
->
read_index
>=
RT_UART_RX_BUFFER_SIZE
)
uart
->
read_index
=
0
;
}
else
{
/* no data in rx buffer */
/* enable interrupt */
rt_hw_interrupt_enable
(
level
);
break
;
}
/* enable interrupt */
rt_hw_interrupt_enable
(
level
);
ptr
++
;
size
--
;
}
RT_ASSERT
(
serial
!=
RT_NULL
);
uart
=
(
struct
v2m_uart
*
)
serial
->
parent
.
user_data
;
length
=
(
rt_uint32_t
)
ptr
-
(
rt_uint32_t
)
buffer
;
return
length
;
ch
=
-
1
;
if
(
uart
->
uart_base
->
STATE
&
CMSDK_UART_STATE_RXBF_Msk
)
ch
=
uart
->
uart_base
->
DATA
&
0xff
;
return
ch
;
}
static
rt_size_t
rt_uart_write
(
rt_device_t
dev
,
rt_off_t
pos
,
const
void
*
buffer
,
rt_size_t
size
)
static
const
struct
rt_uart_ops
v2m_uart_ops
=
{
char
*
ptr
=
(
char
*
)
buffer
;
struct
fvp_uart
*
uart
=
(
struct
fvp_uart
*
)
dev
;
RT_ASSERT
(
dev
!=
RT_NULL
);
RT_ASSERT
(
buffer
!=
RT_NULL
);
if
(
dev
->
open_flag
&
RT_DEVICE_FLAG_STREAM
)
{
/* stream mode */
while
(
size
)
{
if
(
*
ptr
==
'\n'
)
{
while
(
uart
->
uart_base
->
STATE
&
CMSDK_UART_STATE_TXBF_Msk
);
uart
->
uart_base
->
DATA
=
'\r'
;
}
while
(
uart
->
uart_base
->
STATE
&
CMSDK_UART_STATE_TXBF_Msk
);
uart
->
uart_base
->
DATA
=
*
ptr
;
ptr
++
;
size
--
;
}
}
else
{
while
(
size
)
{
while
(
uart
->
uart_base
->
STATE
&
CMSDK_UART_STATE_TXBF_Msk
);
uart
->
uart_base
->
DATA
=
*
ptr
;
ptr
++
;
size
--
;
}
}
return
(
rt_size_t
)
ptr
-
(
rt_size_t
)
buffer
;
}
v2m_configure
,
v2m_control
,
v2m_putc
,
v2m_getc
,
};
int
rt_hw_usart_init
(
void
)
{
struct
serial_configure
config
=
RT_SERIAL_CONFIG_DEFAULT
;
#ifdef RT_USING_UART0
{
struct
fvp
_uart
*
uart
;
struct
v2m
_uart
*
uart
;
/* get uart device */
uart
=
&
uart0_device
;
/* device initialization */
uart
->
parent
.
type
=
RT_Device_Class_Char
;
uart
->
uart_base
=
CMSDK_UART0
;
uart
->
uart_irq_rx
=
UART0RX_IRQn
;
uart
->
read_index
=
0
;
uart
->
save_index
=
0
;
rt_memset
(
uart
->
rx_buffer
,
0
,
sizeof
(
uart
->
rx_buffer
));
/* device interface */
uart
->
parent
.
init
=
rt_uart_init
;
uart
->
parent
.
open
=
rt_uart_open
;
uart
->
parent
.
close
=
rt_uart_close
;
uart
->
parent
.
read
=
rt_uart_read
;
uart
->
parent
.
write
=
rt_uart_write
;
uart
->
parent
.
control
=
RT_NULL
;
uart
->
parent
.
user_data
=
RT_NULL
;
rt_device_register
(
&
uart
->
parent
,
"uart0"
,
RT_DEVICE_FLAG_RDWR
|
RT_DEVICE_FLAG_INT_RX
);
uart
->
serial
.
ops
=
&
v2m_uart_ops
;
uart
->
serial
.
config
=
config
;
rt_hw_serial_register
(
&
uart
->
serial
,
"uart0"
,
RT_DEVICE_FLAG_RDWR
|
RT_DEVICE_FLAG_INT_RX
,
uart
);
}
#endif
/* RT_USING_UART
1
*/
#endif
/* RT_USING_UART
0
*/
#ifdef RT_USING_UART1
{
struct
fvp
_uart
*
uart
;
struct
v2m
_uart
*
uart
;
/* get uart device */
uart
=
&
uart1_device
;
/* device initialization */
uart
->
parent
.
type
=
RT_Device_Class_Char
;
uart
->
uart_base
=
CMSDK_UART1
;
uart
->
uart_irq_rx
=
UART1RX_IRQn
;
uart
->
read_index
=
0
;
uart
->
save_index
=
0
;
rt_memset
(
uart
->
rx_buffer
,
0
,
sizeof
(
uart
->
rx_buffer
));
/* device interface */
uart
->
parent
.
init
=
rt_uart_init
;
uart
->
parent
.
open
=
rt_uart_open
;
uart
->
parent
.
close
=
rt_uart_close
;
uart
->
parent
.
read
=
rt_uart_read
;
uart
->
parent
.
write
=
rt_uart_write
;
uart
->
parent
.
control
=
RT_NULL
;
uart
->
parent
.
user_data
=
RT_NULL
;
rt_device_register
(
&
uart
->
parent
,
"uart1"
,
RT_DEVICE_FLAG_RDWR
|
RT_DEVICE_FLAG_INT_RX
);
rt_hw_serial_register
(
&
uart
->
serial
,
"uart1"
,
RT_DEVICE_FLAG_RDWR
|
RT_DEVICE_FLAG_INT_RX
,
uart
);
}
#endif
/* RT_USING_UART1 */
#ifdef RT_USING_UART2
{
struct
fvp
_uart
*
uart
;
struct
v2m
_uart
*
uart
;
/* get uart device */
uart
=
&
uart2_device
;
...
...
@@ -338,21 +229,11 @@ int rt_hw_usart_init(void)
/* device initialization */
uart
->
uart_base
=
CMSDK_UART2
;
uart
->
uart_irq_rx
=
UART2RX_IRQn
;
uart
->
read_index
=
0
;
uart
->
save_index
=
0
;
rt_memset
(
uart
->
rx_buffer
,
0
,
sizeof
(
uart
->
rx_buffer
));
/* device interface */
uart
->
parent
.
type
=
RT_Device_Class_Char
;
uart
->
parent
.
init
=
rt_uart_init
;
uart
->
parent
.
open
=
rt_uart_open
;
uart
->
parent
.
close
=
rt_uart_close
;
uart
->
parent
.
read
=
rt_uart_read
;
uart
->
parent
.
write
=
rt_uart_write
;
uart
->
parent
.
control
=
RT_NULL
;
uart
->
parent
.
user_data
=
RT_NULL
;
rt_device_register
(
&
uart
->
parent
,
"uart2"
,
RT_DEVICE_FLAG_RDWR
|
RT_DEVICE_FLAG_INT_RX
);
rt_hw_serial_register
(
&
uart
->
serial
,
"uart2"
,
RT_DEVICE_FLAG_RDWR
|
RT_DEVICE_FLAG_INT_RX
,
uart
);
}
#endif
/* RT_USING_UART2 */
return
0
;
...
...
bsp/v2m-mps2/project.uvoptx
浏览文件 @
fa693c51
...
...
@@ -148,24 +148,7 @@
<Name>
UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000)
</Name>
</SetRegEntry>
</TargetDriverDllRegistry>
<Breakpoint>
<Bp>
<Number>
0
</Number>
<Type>
0
</Type>
<LineNumber>
150
</LineNumber>
<EnabledFlag>
1
</EnabledFlag>
<Address>
2206
</Address>
<ByteObject>
0
</ByteObject>
<HtxType>
0
</HtxType>
<ManyObjects>
0
</ManyObjects>
<SizeOfObject>
0
</SizeOfObject>
<BreakByAccess>
0
</BreakByAccess>
<BreakIfRCount>
1
</BreakIfRCount>
<Filename>
..\..\src\components.c
</Filename>
<ExecCommand></ExecCommand>
<Expression>
\\rtthread_v2m_mps2\../../src/components.c\150
</Expression>
</Bp>
</Breakpoint>
<Breakpoint/>
<Tracepoint>
<THDelay>
0
</THDelay>
</Tracepoint>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录