Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
逝缘~
rt-thread
提交
284c6ffc
R
rt-thread
项目概览
逝缘~
/
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,发现更多精彩内容 >>
提交
284c6ffc
编写于
9月 05, 2021
作者:
kai.RD
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
解决 代码格式问题
添加联系人
上级
c55c964b
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
116 addition
and
108 deletion
+116
-108
bsp/apm32/apm32f103xe-minibroard/README.md
bsp/apm32/apm32f103xe-minibroard/README.md
+1
-1
bsp/apm32/apm32f103xe-minibroard/project.uvprojx
bsp/apm32/apm32f103xe-minibroard/project.uvprojx
+1
-1
bsp/apm32/libraries/Drivers/Kconfig
bsp/apm32/libraries/Drivers/Kconfig
+0
-0
bsp/apm32/libraries/Drivers/drv_gpio.c
bsp/apm32/libraries/Drivers/drv_gpio.c
+73
-73
bsp/apm32/libraries/Drivers/drv_usart.c
bsp/apm32/libraries/Drivers/drv_usart.c
+41
-33
未找到文件。
bsp/apm32/apm32f103xe-minibroard/README.md
浏览文件 @
284c6ffc
...
...
@@ -81,4 +81,4 @@ msh >
## 联系人信息
-
\ No newline at end of file
-
[
abbbcc
](
https://gitee.com/abbbcc
)
\ No newline at end of file
bsp/apm32/apm32f103xe-minibroard/project.uvprojx
浏览文件 @
284c6ffc
...
...
@@ -10,7 +10,7 @@
<TargetName>
rt-thread
</TargetName>
<ToolsetNumber>
0x4
</ToolsetNumber>
<ToolsetName>
ARM-ADS
</ToolsetName>
<pCCUsed>
5060
750::V5.06 update 6 (build 750)::
ARMCC
</pCCUsed>
<pCCUsed>
5060
960::V5.06 update 7 (build 960)::.\
ARMCC
</pCCUsed>
<uAC6>
0
</uAC6>
<TargetOption>
<TargetCommonOption>
...
...
bsp/apm32/libraries/Drivers/Kconfig
已删除
100644 → 0
浏览文件 @
c55c964b
bsp/apm32/libraries/Drivers/drv_gpio.c
浏览文件 @
284c6ffc
...
...
@@ -17,40 +17,40 @@
#define PIN_PORT(pin) ((uint8_t)(((pin) >> 4) & 0xFu))
#define PIN_NO(pin) ((uint8_t)((pin) & 0xFu))
#define PIN_
ST
PORT(pin) ((GPIO_T *)(GPIOA_BASE + (0x400u * PIN_PORT(pin))))
#define PIN_
APM
PORT(pin) ((GPIO_T *)(GPIOA_BASE + (0x400u * PIN_PORT(pin))))
#define PIN_
ST
PIN(pin) ((uint16_t)(1u << PIN_NO(pin)))
#define PIN_
APM
PIN(pin) ((uint16_t)(1u << PIN_NO(pin)))
#if defined(GPIOZ)
#define __APM32_PORT_MAX 12u
#define __APM32_PORT_MAX 12u
#elif defined(GPIOK)
#define __APM32_PORT_MAX 11u
#define __APM32_PORT_MAX 11u
#elif defined(GPIOJ)
#define __APM32_PORT_MAX 10u
#define __APM32_PORT_MAX 10u
#elif defined(GPIOI)
#define __APM32_PORT_MAX 9u
#define __APM32_PORT_MAX 9u
#elif defined(GPIOH)
#define __APM32_PORT_MAX 8u
#define __APM32_PORT_MAX 8u
#elif defined(GPIOG)
#define __APM32_PORT_MAX 7u
#define __APM32_PORT_MAX 7u
#elif defined(GPIOF)
#define __APM32_PORT_MAX 6u
#define __APM32_PORT_MAX 6u
#elif defined(GPIOE)
#define __APM32_PORT_MAX 5u
#define __APM32_PORT_MAX 5u
#elif defined(GPIOD)
#define __APM32_PORT_MAX 4u
#define __APM32_PORT_MAX 4u
#elif defined(GPIOC)
#define __APM32_PORT_MAX 3u
#define __APM32_PORT_MAX 3u
#elif defined(GPIOB)
#define __APM32_PORT_MAX 2u
#define __APM32_PORT_MAX 2u
#elif defined(GPIOA)
#define __APM32_PORT_MAX 1u
#define __APM32_PORT_MAX 1u
#else
#define __APM32_PORT_MAX 0u
#error Unsupported APM32 GPIO peripheral.
#define __APM32_PORT_MAX 0u
#error Unsupported APM32 GPIO peripheral.
#endif
#define PIN_
ST
PORT_MAX __APM32_PORT_MAX
#define PIN_
APM
PORT_MAX __APM32_PORT_MAX
static
const
struct
pin_irq_map
pin_irq_map
[]
=
{
...
...
@@ -95,7 +95,7 @@ static uint32_t pin_irq_enable_mask = 0;
#define ITEM_NUM(items) sizeof(items) / sizeof(items[0])
static
rt_base_t
apm32
_pin_get
(
const
char
*
name
)
static
rt_base_t
_pin_get
(
const
char
*
name
)
{
rt_base_t
pin
=
0
;
int
hw_port_num
,
hw_pin_num
=
0
;
...
...
@@ -132,47 +132,47 @@ static rt_base_t apm32_pin_get(const char *name)
return
pin
;
}
static
void
apm32
_pin_write
(
rt_device_t
dev
,
rt_base_t
pin
,
rt_base_t
value
)
static
void
_pin_write
(
rt_device_t
dev
,
rt_base_t
pin
,
rt_base_t
value
)
{
GPIO_T
*
gpio_port
;
uint16_t
gpio_pin
;
if
(
PIN_PORT
(
pin
)
<
PIN_
ST
PORT_MAX
)
if
(
PIN_PORT
(
pin
)
<
PIN_
APM
PORT_MAX
)
{
gpio_port
=
PIN_
ST
PORT
(
pin
);
gpio_pin
=
PIN_
ST
PIN
(
pin
);
gpio_port
=
PIN_
APM
PORT
(
pin
);
gpio_pin
=
PIN_
APM
PIN
(
pin
);
GPIO_WriteBitValue
(
gpio_port
,
gpio_pin
,
(
uint8_t
)
value
);
}
}
static
int
apm32
_pin_read
(
rt_device_t
dev
,
rt_base_t
pin
)
static
int
_pin_read
(
rt_device_t
dev
,
rt_base_t
pin
)
{
GPIO_T
*
gpio_port
;
uint16_t
gpio_pin
;
int
value
=
PIN_LOW
;
if
(
PIN_PORT
(
pin
)
<
PIN_
ST
PORT_MAX
)
if
(
PIN_PORT
(
pin
)
<
PIN_
APM
PORT_MAX
)
{
gpio_port
=
PIN_
ST
PORT
(
pin
);
gpio_pin
=
PIN_
ST
PIN
(
pin
);
gpio_port
=
PIN_
APM
PORT
(
pin
);
gpio_pin
=
PIN_
APM
PIN
(
pin
);
value
=
GPIO_ReadInputBit
(
gpio_port
,
gpio_pin
);
}
return
value
;
}
static
void
apm32
_pin_mode
(
rt_device_t
dev
,
rt_base_t
pin
,
rt_base_t
mode
)
static
void
_pin_mode
(
rt_device_t
dev
,
rt_base_t
pin
,
rt_base_t
mode
)
{
GPIO_Config_T
gpioConfig
;
if
(
PIN_PORT
(
pin
)
>=
PIN_
ST
PORT_MAX
)
if
(
PIN_PORT
(
pin
)
>=
PIN_
APM
PORT_MAX
)
{
return
;
}
/* Configure gpioConfigure */
gpioConfig
.
pin
=
PIN_
ST
PIN
(
pin
);
gpioConfig
.
pin
=
PIN_
APM
PIN
(
pin
);
gpioConfig
.
mode
=
GPIO_MODE_OUT_PP
;
gpioConfig
.
speed
=
GPIO_SPEED_50MHz
;
...
...
@@ -202,7 +202,7 @@ static void apm32_pin_mode(rt_device_t dev, rt_base_t pin, rt_base_t mode)
gpioConfig
.
mode
=
GPIO_MODE_OUT_OD
;
}
GPIO_Config
(
PIN_
ST
PORT
(
pin
),
&
gpioConfig
);
GPIO_Config
(
PIN_
APM
PORT
(
pin
),
&
gpioConfig
);
}
rt_inline
rt_int32_t
bit2bitno
(
rt_uint32_t
bit
)
...
...
@@ -228,18 +228,18 @@ rt_inline const struct pin_irq_map *get_pin_irq_map(uint32_t pinbit)
return
&
pin_irq_map
[
mapindex
];
};
static
rt_err_t
apm32
_pin_attach_irq
(
struct
rt_device
*
device
,
rt_int32_t
pin
,
rt_uint32_t
mode
,
void
(
*
hdr
)(
void
*
args
),
void
*
args
)
static
rt_err_t
_pin_attach_irq
(
struct
rt_device
*
device
,
rt_int32_t
pin
,
rt_uint32_t
mode
,
void
(
*
hdr
)(
void
*
args
),
void
*
args
)
{
rt_base_t
level
;
rt_int32_t
irqindex
=
-
1
;
if
(
PIN_PORT
(
pin
)
>=
PIN_
ST
PORT_MAX
)
if
(
PIN_PORT
(
pin
)
>=
PIN_
APM
PORT_MAX
)
{
return
-
RT_ENOSYS
;
}
irqindex
=
bit2bitno
(
PIN_
ST
PIN
(
pin
));
irqindex
=
bit2bitno
(
PIN_
APM
PIN
(
pin
));
if
(
irqindex
<
0
||
irqindex
>=
ITEM_NUM
(
pin_irq_map
))
{
return
RT_ENOSYS
;
...
...
@@ -247,9 +247,9 @@ static rt_err_t apm32_pin_attach_irq(struct rt_device *device, rt_int32_t pin,
level
=
rt_hw_interrupt_disable
();
if
(
pin_irq_hdr_tab
[
irqindex
].
pin
==
pin
&&
pin_irq_hdr_tab
[
irqindex
].
hdr
==
hdr
&&
pin_irq_hdr_tab
[
irqindex
].
mode
==
mode
&&
pin_irq_hdr_tab
[
irqindex
].
args
==
args
)
pin_irq_hdr_tab
[
irqindex
].
hdr
==
hdr
&&
pin_irq_hdr_tab
[
irqindex
].
mode
==
mode
&&
pin_irq_hdr_tab
[
irqindex
].
args
==
args
)
{
rt_hw_interrupt_enable
(
level
);
return
RT_EOK
;
...
...
@@ -268,17 +268,17 @@ static rt_err_t apm32_pin_attach_irq(struct rt_device *device, rt_int32_t pin,
return
RT_EOK
;
}
static
rt_err_t
apm32
_pin_dettach_irq
(
struct
rt_device
*
device
,
rt_int32_t
pin
)
static
rt_err_t
_pin_dettach_irq
(
struct
rt_device
*
device
,
rt_int32_t
pin
)
{
rt_base_t
level
;
rt_int32_t
irqindex
=
-
1
;
if
(
PIN_PORT
(
pin
)
>=
PIN_
ST
PORT_MAX
)
if
(
PIN_PORT
(
pin
)
>=
PIN_
APM
PORT_MAX
)
{
return
-
RT_ENOSYS
;
}
irqindex
=
bit2bitno
(
PIN_
ST
PIN
(
pin
));
irqindex
=
bit2bitno
(
PIN_
APM
PIN
(
pin
));
if
(
irqindex
<
0
||
irqindex
>=
ITEM_NUM
(
pin_irq_map
))
{
return
RT_ENOSYS
;
...
...
@@ -299,22 +299,22 @@ static rt_err_t apm32_pin_dettach_irq(struct rt_device *device, rt_int32_t pin)
return
RT_EOK
;
}
static
rt_err_t
apm32
_pin_irq_enable
(
struct
rt_device
*
device
,
rt_base_t
pin
,
rt_uint32_t
enabled
)
static
rt_err_t
_pin_irq_enable
(
struct
rt_device
*
device
,
rt_base_t
pin
,
rt_uint32_t
enabled
)
{
const
struct
pin_irq_map
*
irqmap
;
rt_base_t
level
;
rt_int32_t
irqindex
=
-
1
;
GPIO_Config_T
gpioConfig
;
if
(
PIN_PORT
(
pin
)
>=
PIN_
ST
PORT_MAX
)
if
(
PIN_PORT
(
pin
)
>=
PIN_
APM
PORT_MAX
)
{
return
-
RT_ENOSYS
;
}
if
(
enabled
==
PIN_IRQ_ENABLE
)
{
irqindex
=
bit2bitno
(
PIN_
ST
PIN
(
pin
));
irqindex
=
bit2bitno
(
PIN_
APM
PIN
(
pin
));
if
(
irqindex
<
0
||
irqindex
>=
ITEM_NUM
(
pin_irq_map
))
{
return
RT_ENOSYS
;
...
...
@@ -331,7 +331,7 @@ static rt_err_t apm32_pin_irq_enable(struct rt_device *device, rt_base_t pin,
irqmap
=
&
pin_irq_map
[
irqindex
];
/* Configure gpioConfigure */
gpioConfig
.
pin
=
PIN_
ST
PIN
(
pin
);
gpioConfig
.
pin
=
PIN_
APM
PIN
(
pin
);
gpioConfig
.
speed
=
GPIO_SPEED_50MHz
;
switch
(
pin_irq_hdr_tab
[
irqindex
].
mode
)
{
...
...
@@ -345,7 +345,7 @@ static rt_err_t apm32_pin_irq_enable(struct rt_device *device, rt_base_t pin,
gpioConfig
.
mode
=
GPIO_MODE_IN_FLOATING
;
break
;
}
GPIO_Config
(
PIN_
ST
PORT
(
pin
),
&
gpioConfig
);
GPIO_Config
(
PIN_
APM
PORT
(
pin
),
&
gpioConfig
);
NVIC_EnableIRQRequest
(
irqmap
->
irqno
,
5
,
0
);
pin_irq_enable_mask
|=
irqmap
->
pinbit
;
...
...
@@ -354,14 +354,14 @@ static rt_err_t apm32_pin_irq_enable(struct rt_device *device, rt_base_t pin,
}
else
if
(
enabled
==
PIN_IRQ_DISABLE
)
{
irqmap
=
get_pin_irq_map
(
PIN_
ST
PIN
(
pin
));
irqmap
=
get_pin_irq_map
(
PIN_
APM
PIN
(
pin
));
if
(
irqmap
==
RT_NULL
)
{
return
RT_ENOSYS
;
}
level
=
rt_hw_interrupt_disable
();
pin_irq_enable_mask
&=
~
irqmap
->
pinbit
;
if
((
irqmap
->
pinbit
>=
GPIO_PIN_5
)
&&
(
irqmap
->
pinbit
<=
GPIO_PIN_9
))
...
...
@@ -393,13 +393,13 @@ static rt_err_t apm32_pin_irq_enable(struct rt_device *device, rt_base_t pin,
}
const
static
struct
rt_pin_ops
_apm32_pin_ops
=
{
apm32
_pin_mode
,
apm32
_pin_write
,
apm32
_pin_read
,
apm32
_pin_attach_irq
,
apm32
_pin_dettach_irq
,
apm32
_pin_irq_enable
,
apm32
_pin_get
,
_pin_mode
,
_pin_write
,
_pin_read
,
_pin_attach_irq
,
_pin_dettach_irq
,
_pin_irq_enable
,
_pin_get
,
};
rt_inline
void
pin_irq_hdr
(
int
irqno
)
...
...
@@ -420,20 +420,20 @@ void GPIO_EXTI_IRQHandler(uint16_t GPIO_Pin)
void
EINT0_IRQHandler
(
void
)
{
rt_interrupt_enter
();
if
(
EINT_ReadIntFlag
(
EINT_LINE_0
))
if
(
EINT_ReadIntFlag
(
EINT_LINE_0
))
{
EINT_ClearIntFlag
(
EINT_LINE_0
);
GPIO_EXTI_IRQHandler
(
GPIO_PIN_0
);
}
rt_interrupt_leave
();
}
void
EINT1_IRQHandler
(
void
)
{
rt_interrupt_enter
();
if
(
EINT_ReadIntFlag
(
EINT_LINE_1
))
if
(
EINT_ReadIntFlag
(
EINT_LINE_1
))
{
EINT_ClearIntFlag
(
EINT_LINE_1
);
GPIO_EXTI_IRQHandler
(
GPIO_PIN_1
);
...
...
@@ -444,7 +444,7 @@ void EINT1_IRQHandler(void)
void
EINT2_IRQHandler
(
void
)
{
rt_interrupt_enter
();
if
(
EINT_ReadIntFlag
(
EINT_LINE_2
))
if
(
EINT_ReadIntFlag
(
EINT_LINE_2
))
{
EINT_ClearIntFlag
(
EINT_LINE_2
);
GPIO_EXTI_IRQHandler
(
GPIO_PIN_2
);
...
...
@@ -455,7 +455,7 @@ void EINT2_IRQHandler(void)
void
EINT3_IRQHandler
(
void
)
{
rt_interrupt_enter
();
if
(
EINT_ReadIntFlag
(
EINT_LINE_3
))
if
(
EINT_ReadIntFlag
(
EINT_LINE_3
))
{
EINT_ClearIntFlag
(
EINT_LINE_3
);
GPIO_EXTI_IRQHandler
(
GPIO_PIN_3
);
...
...
@@ -466,7 +466,7 @@ void EINT3_IRQHandler(void)
void
EINT4_IRQHandler
(
void
)
{
rt_interrupt_enter
();
if
(
EINT_ReadIntFlag
(
EINT_LINE_4
))
if
(
EINT_ReadIntFlag
(
EINT_LINE_4
))
{
EINT_ClearIntFlag
(
EINT_LINE_4
);
GPIO_EXTI_IRQHandler
(
GPIO_PIN_4
);
...
...
@@ -477,27 +477,27 @@ void EINT4_IRQHandler(void)
void
EINT9_5_IRQHandler
(
void
)
{
rt_interrupt_enter
();
if
(
EINT_ReadIntFlag
(
EINT_LINE_5
))
if
(
EINT_ReadIntFlag
(
EINT_LINE_5
))
{
EINT_ClearIntFlag
(
EINT_LINE_5
);
GPIO_EXTI_IRQHandler
(
GPIO_PIN_5
);
}
if
(
EINT_ReadIntFlag
(
EINT_LINE_6
))
if
(
EINT_ReadIntFlag
(
EINT_LINE_6
))
{
EINT_ClearIntFlag
(
EINT_LINE_6
);
GPIO_EXTI_IRQHandler
(
GPIO_PIN_6
);
}
if
(
EINT_ReadIntFlag
(
EINT_LINE_7
))
if
(
EINT_ReadIntFlag
(
EINT_LINE_7
))
{
EINT_ClearIntFlag
(
EINT_LINE_7
);
GPIO_EXTI_IRQHandler
(
GPIO_PIN_7
);
}
if
(
EINT_ReadIntFlag
(
EINT_LINE_8
))
if
(
EINT_ReadIntFlag
(
EINT_LINE_8
))
{
EINT_ClearIntFlag
(
EINT_LINE_8
);
GPIO_EXTI_IRQHandler
(
GPIO_PIN_8
);
}
if
(
EINT_ReadIntFlag
(
EINT_LINE_9
))
if
(
EINT_ReadIntFlag
(
EINT_LINE_9
))
{
EINT_ClearIntFlag
(
EINT_LINE_9
);
GPIO_EXTI_IRQHandler
(
GPIO_PIN_9
);
...
...
@@ -508,32 +508,32 @@ void EINT9_5_IRQHandler(void)
void
EINT15_10_IRQHandler
(
void
)
{
rt_interrupt_enter
();
if
(
EINT_ReadIntFlag
(
EINT_LINE_10
))
if
(
EINT_ReadIntFlag
(
EINT_LINE_10
))
{
EINT_ClearIntFlag
(
EINT_LINE_10
);
GPIO_EXTI_IRQHandler
(
GPIO_PIN_10
);
}
if
(
EINT_ReadIntFlag
(
EINT_LINE_11
))
if
(
EINT_ReadIntFlag
(
EINT_LINE_11
))
{
EINT_ClearIntFlag
(
EINT_LINE_11
);
GPIO_EXTI_IRQHandler
(
GPIO_PIN_11
);
}
if
(
EINT_ReadIntFlag
(
EINT_LINE_12
))
if
(
EINT_ReadIntFlag
(
EINT_LINE_12
))
{
EINT_ClearIntFlag
(
EINT_LINE_12
);
GPIO_EXTI_IRQHandler
(
GPIO_PIN_12
);
}
if
(
EINT_ReadIntFlag
(
EINT_LINE_13
))
if
(
EINT_ReadIntFlag
(
EINT_LINE_13
))
{
EINT_ClearIntFlag
(
EINT_LINE_13
);
GPIO_EXTI_IRQHandler
(
GPIO_PIN_13
);
}
if
(
EINT_ReadIntFlag
(
EINT_LINE_14
))
if
(
EINT_ReadIntFlag
(
EINT_LINE_14
))
{
EINT_ClearIntFlag
(
EINT_LINE_14
);
GPIO_EXTI_IRQHandler
(
GPIO_PIN_14
);
}
if
(
EINT_ReadIntFlag
(
EINT_LINE_15
))
if
(
EINT_ReadIntFlag
(
EINT_LINE_15
))
{
EINT_ClearIntFlag
(
EINT_LINE_15
);
GPIO_EXTI_IRQHandler
(
GPIO_PIN_15
);
...
...
bsp/apm32/libraries/Drivers/drv_usart.c
浏览文件 @
284c6ffc
...
...
@@ -14,8 +14,8 @@
#ifdef RT_USING_SERIAL
#if !defined(BSP_USING_UART1) && !defined(BSP_USING_UART2)
#error "Please define at least one BSP_USING_UARTx"
/* this driver can be disabled at menuconfig -> RT-Thread Components -> Device Drivers */
#error "Please define at least one BSP_USING_UARTx"
/* this driver can be disabled at menuconfig -> RT-Thread Components -> Device Drivers */
#endif
/* stm32 config class */
...
...
@@ -40,18 +40,22 @@ enum
static
struct
apm32_usart
usart_config
[]
=
{
#ifdef BSP_USING_UART1
{
"uart1"
,
{
"uart1"
,
USART1
,
USART1_IRQn
,
},
USART1_IRQn
,
},
#endif
#ifdef BSP_USING_UART2
{
"uart2"
,
{
"uart2"
,
USART2
,
USART2_IRQn
,
},
USART2_IRQn
,
},
#endif
};
static
rt_err_t
apm32
_configure
(
struct
rt_serial_device
*
serial
,
struct
serial_configure
*
cfg
)
static
rt_err_t
_uart
_configure
(
struct
rt_serial_device
*
serial
,
struct
serial_configure
*
cfg
)
{
USART_Config_T
USART_ConfigStruct
;
RT_ASSERT
(
serial
!=
RT_NULL
);
...
...
@@ -60,7 +64,7 @@ static rt_err_t apm32_configure(struct rt_serial_device *serial, struct serial_c
struct
apm32_usart
*
usart_instance
=
(
struct
apm32_usart
*
)
serial
->
parent
.
user_data
;
apm32_usart_init
();
USART_ConfigStruct
.
baudRate
=
cfg
->
baud_rate
;;
USART_ConfigStruct
.
hardwareFlow
=
USART_HARDWARE_FLOW_NONE
;
USART_ConfigStruct
.
mode
=
USART_MODE_TX_RX
;
...
...
@@ -113,14 +117,14 @@ static rt_err_t apm32_configure(struct rt_serial_device *serial, struct serial_c
USART_Config
(
usart_instance
->
usartx
,
&
USART_ConfigStruct
);
USART_Enable
(
usart_instance
->
usartx
);
return
RT_EOK
;
}
static
rt_err_t
apm32
_control
(
struct
rt_serial_device
*
serial
,
int
cmd
,
void
*
arg
)
static
rt_err_t
_uart
_control
(
struct
rt_serial_device
*
serial
,
int
cmd
,
void
*
arg
)
{
struct
apm32_usart
*
usart
;
RT_ASSERT
(
serial
!=
RT_NULL
);
usart
=
(
struct
apm32_usart
*
)
serial
->
parent
.
user_data
;
...
...
@@ -130,10 +134,10 @@ static rt_err_t apm32_control(struct rt_serial_device *serial, int cmd, void *ar
{
/* disable interrupt */
case
RT_DEVICE_CTRL_CLR_INT
:
/* disable rx irq */
NVIC_DisableIRQRequest
(
usart
->
irq_type
);
/* disable interrupt */
USART_DisableInterrupt
(
usart
->
usartx
,
USART_INT_RXBNE
);
...
...
@@ -143,7 +147,7 @@ static rt_err_t apm32_control(struct rt_serial_device *serial, int cmd, void *ar
case
RT_DEVICE_CTRL_SET_INT
:
/* enable rx irq */
NVIC_EnableIRQRequest
(
usart
->
irq_type
,
1
,
0
);
/* enable interrupt */
USART_EnableInterrupt
(
usart
->
usartx
,
USART_INT_RXBNE
);
break
;
...
...
@@ -152,29 +156,29 @@ static rt_err_t apm32_control(struct rt_serial_device *serial, int cmd, void *ar
return
RT_EOK
;
}
static
int
apm32
_putc
(
struct
rt_serial_device
*
serial
,
char
c
)
static
int
_uart
_putc
(
struct
rt_serial_device
*
serial
,
char
c
)
{
struct
apm32_usart
*
usart
;
RT_ASSERT
(
serial
!=
RT_NULL
);
usart
=
(
struct
apm32_usart
*
)
serial
->
parent
.
user_data
;
RT_ASSERT
(
usart
!=
RT_NULL
);
USART_TxData
(
usart
->
usartx
,
(
uint8_t
)
c
);
while
(
USART_ReadStatusFlag
(
usart
->
usartx
,
USART_FLAG_TXC
)
==
RESET
);
return
1
;
}
static
int
apm32
_getc
(
struct
rt_serial_device
*
serial
)
static
int
_uart
_getc
(
struct
rt_serial_device
*
serial
)
{
int
ch
;
struct
apm32_usart
*
usart
;
RT_ASSERT
(
serial
!=
RT_NULL
);
usart
=
(
struct
apm32_usart
*
)
serial
->
parent
.
user_data
;
RT_ASSERT
(
usart
!=
RT_NULL
);
ch
=
-
1
;
...
...
@@ -197,7 +201,7 @@ static void usart_isr(struct rt_serial_device *serial)
RT_ASSERT
(
serial
!=
RT_NULL
);
RT_ASSERT
(
serial
!=
RT_NULL
);
usart
=
(
struct
apm32_usart
*
)
serial
->
parent
.
user_data
;
RT_ASSERT
(
usart
!=
RT_NULL
);
/* UART in mode Receiver -------------------------------------------------*/
...
...
@@ -211,15 +215,18 @@ static void usart_isr(struct rt_serial_device *serial)
else
{
if
(
USART_ReadStatusFlag
(
usart
->
usartx
,
USART_FLAG_CTS
)
!=
RESET
)
{
if
(
USART_ReadStatusFlag
(
usart
->
usartx
,
USART_FLAG_CTS
)
!=
RESET
)
{
USART_ClearStatusFlag
(
usart
->
usartx
,
USART_FLAG_CTS
);
}
if
(
USART_ReadStatusFlag
(
usart
->
usartx
,
USART_FLAG_LBD
)
!=
RESET
)
{
if
(
USART_ReadStatusFlag
(
usart
->
usartx
,
USART_FLAG_LBD
)
!=
RESET
)
{
USART_ClearStatusFlag
(
usart
->
usartx
,
USART_FLAG_LBD
);
}
if
(
USART_ReadStatusFlag
(
usart
->
usartx
,
USART_FLAG_TXBE
)
!=
RESET
)
{
if
(
USART_ReadStatusFlag
(
usart
->
usartx
,
USART_FLAG_TXBE
)
!=
RESET
)
{
USART_ClearStatusFlag
(
usart
->
usartx
,
USART_FLAG_TXBE
);
}
}
...
...
@@ -258,10 +265,10 @@ void USART2_IRQHandler(void)
static
const
struct
rt_uart_ops
apm32_usart_ops
=
{
.
configure
=
apm32
_configure
,
.
control
=
apm32
_control
,
.
putc
=
apm32
_putc
,
.
getc
=
apm32
_getc
,
.
configure
=
_uart
_configure
,
.
control
=
_uart
_control
,
.
putc
=
_uart
_putc
,
.
getc
=
_uart
_getc
,
.
dma_transmit
=
RT_NULL
};
...
...
@@ -274,15 +281,16 @@ int rt_hw_usart_init(void)
struct
serial_configure
config
=
RT_SERIAL_CONFIG_DEFAULT
;
rt_err_t
result
=
0
;
for
(
index
=
0
;
index
<
obj_num
;
index
++
)
{
for
(
index
=
0
;
index
<
obj_num
;
index
++
)
{
usart_config
[
index
].
serial
.
ops
=
&
apm32_usart_ops
;
usart_config
[
index
].
serial
.
config
=
config
;
/* register USART device */
result
=
rt_hw_serial_register
(
&
usart_config
[
index
].
serial
,
usart_config
[
index
].
name
,
RT_DEVICE_FLAG_RDWR
|
RT_DEVICE_FLAG_INT_RX
|
RT_DEVICE_FLAG_INT_TX
,
&
usart_config
[
index
]);
usart_config
[
index
].
name
,
RT_DEVICE_FLAG_RDWR
|
RT_DEVICE_FLAG_INT_RX
|
RT_DEVICE_FLAG_INT_TX
,
&
usart_config
[
index
]);
RT_ASSERT
(
result
==
RT_EOK
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录