Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
红岛
rt-thread
提交
86358d08
R
rt-thread
项目概览
红岛
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rt-thread
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
86358d08
编写于
1月 21, 2015
作者:
B
Bernard Xiong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[BSP] code cleanup for usart and gpio driver in STM32F4
上级
756f2c67
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
38 addition
and
38 deletion
+38
-38
bsp/stm32f40x/drivers/gpio.c
bsp/stm32f40x/drivers/gpio.c
+13
-13
bsp/stm32f40x/drivers/usart.c
bsp/stm32f40x/drivers/usart.c
+25
-25
未找到文件。
bsp/stm32f40x/drivers/gpio.c
浏览文件 @
86358d08
...
...
@@ -88,12 +88,12 @@ static const struct pin_index pins[] =
{
53
,
RCC_AHB1Periph_GPIOA
,
GPIOA
,
GPIO_Pin_4
},
};
#define ITEM_NUM(items)
sizeof(items)/sizeof(items[0])
const
struct
pin_index
*
get_pin
(
uint8_t
pin
)
#define ITEM_NUM(items)
sizeof(items)/sizeof(items[0])
const
struct
pin_index
*
get_pin
(
uint8_t
pin
)
{
const
struct
pin_index
*
index
;
const
struct
pin_index
*
index
;
if
(
pin
<
ITEM_NUM
(
pins
))
if
(
pin
<
ITEM_NUM
(
pins
))
{
index
=
&
pins
[
pin
];
}
...
...
@@ -110,12 +110,12 @@ void stm32_pin_write(rt_device_t dev, rt_base_t pin, rt_base_t value)
const
struct
pin_index
*
index
;
index
=
get_pin
(
pin
);
if
(
index
==
RT_NULL
)
if
(
index
==
RT_NULL
)
{
return
;
}
if
(
value
==
PIN_LOW
)
if
(
value
==
PIN_LOW
)
{
GPIO_ResetBits
(
index
->
gpio
,
index
->
pin
);
}
...
...
@@ -133,12 +133,12 @@ int stm32_pin_read(rt_device_t dev, rt_base_t pin)
value
=
PIN_LOW
;
index
=
get_pin
(
pin
);
if
(
index
==
RT_NULL
)
if
(
index
==
RT_NULL
)
{
return
value
;
}
if
(
GPIO_ReadInputDataBit
(
index
->
gpio
,
index
->
pin
)
==
Bit_RESET
)
if
(
GPIO_ReadInputDataBit
(
index
->
gpio
,
index
->
pin
)
==
Bit_RESET
)
{
value
=
PIN_LOW
;
}
...
...
@@ -156,7 +156,7 @@ void stm32_pin_mode(rt_device_t dev, rt_base_t pin, rt_base_t mode)
GPIO_InitTypeDef
GPIO_InitStructure
;
index
=
get_pin
(
pin
);
if
(
index
==
RT_NULL
)
if
(
index
==
RT_NULL
)
{
return
;
}
...
...
@@ -169,19 +169,19 @@ void stm32_pin_mode(rt_device_t dev, rt_base_t pin, rt_base_t mode)
GPIO_InitStructure
.
GPIO_OType
=
GPIO_OType_PP
;
GPIO_InitStructure
.
GPIO_Speed
=
GPIO_Speed_100MHz
;
if
(
mode
==
PIN_MODE_OUTPUT
)
if
(
mode
==
PIN_MODE_OUTPUT
)
{
/* output setting */
GPIO_InitStructure
.
GPIO_Mode
=
GPIO_Mode_OUT
;
GPIO_InitStructure
.
GPIO_PuPd
=
GPIO_PuPd_NOPULL
;
}
else
if
(
mode
==
PIN_MODE_INPUT
)
else
if
(
mode
==
PIN_MODE_INPUT
)
{
/* input setting: not pull. */
GPIO_InitStructure
.
GPIO_Mode
=
GPIO_Mode_IN
;
GPIO_InitStructure
.
GPIO_PuPd
=
GPIO_PuPd_NOPULL
;
}
else
if
(
mode
==
PIN_MODE_INPUT_PULLUP
)
else
if
(
mode
==
PIN_MODE_INPUT_PULLUP
)
{
/* input setting: pull up. */
GPIO_InitStructure
.
GPIO_Mode
=
GPIO_Mode_IN
;
...
...
@@ -196,7 +196,7 @@ void stm32_pin_mode(rt_device_t dev, rt_base_t pin, rt_base_t mode)
GPIO_Init
(
index
->
gpio
,
&
GPIO_InitStructure
);
}
const
static
struct
rt_pin_ops
_stm32_pin_ops
=
const
static
struct
rt_pin_ops
_stm32_pin_ops
=
{
stm32_pin_mode
,
stm32_pin_write
,
...
...
bsp/stm32f40x/drivers/usart.c
浏览文件 @
86358d08
...
...
@@ -22,25 +22,25 @@
#include <rtdevice.h>
/* UART GPIO define. */
#define UART1_GPIO_TX
GPIO_Pin_6
#define UART1_GPIO_TX
GPIO_Pin_6
#define UART1_TX_PIN_SOURCE GPIO_PinSource6
#define UART1_GPIO_RX
GPIO_Pin_7
#define UART1_GPIO_RX
GPIO_Pin_7
#define UART1_RX_PIN_SOURCE GPIO_PinSource7
#define UART1_GPIO
GPIOB
#define UART1_GPIO
GPIOB
#define UART1_GPIO_RCC RCC_AHB1Periph_GPIOB
#define RCC_APBPeriph_UART1
RCC_APB2Periph_USART1
#define UART1_TX_DMA
DMA1_Channel4
#define UART1_RX_DMA
DMA1_Channel5
#define RCC_APBPeriph_UART1
RCC_APB2Periph_USART1
#define UART1_TX_DMA
DMA1_Channel4
#define UART1_RX_DMA
DMA1_Channel5
#define UART2_GPIO_TX
GPIO_Pin_2
#define UART2_GPIO_TX
GPIO_Pin_2
#define UART2_TX_PIN_SOURCE GPIO_PinSource2
#define UART2_GPIO_RX
GPIO_Pin_3
#define UART2_GPIO_RX
GPIO_Pin_3
#define UART2_RX_PIN_SOURCE GPIO_PinSource3
#define UART2_GPIO
GPIOA
#define UART2_GPIO
GPIOA
#define UART2_GPIO_RCC RCC_AHB1Periph_GPIOA
#define RCC_APBPeriph_UART2
RCC_APB1Periph_USART2
#define UART2_TX_DMA
DMA1_Channel4
#define UART2_RX_DMA
DMA1_Channel5
#define RCC_APBPeriph_UART2
RCC_APB1Periph_USART2
#define UART2_TX_DMA
DMA1_Channel4
#define UART2_RX_DMA
DMA1_Channel5
#define UART3_GPIO_TX GPIO_Pin_8
#define UART3_TX_PIN_SOURCE GPIO_PinSource8
...
...
@@ -55,13 +55,13 @@
/* STM32 uart driver */
struct
stm32_uart
{
USART_TypeDef
*
uart_device
;
USART_TypeDef
*
uart_device
;
IRQn_Type
irq
;
};
static
rt_err_t
stm32_configure
(
struct
rt_serial_device
*
serial
,
struct
serial_configure
*
cfg
)
{
struct
stm32_uart
*
uart
;
struct
stm32_uart
*
uart
;
USART_InitTypeDef
USART_InitStructure
;
RT_ASSERT
(
serial
!=
RT_NULL
);
...
...
@@ -97,7 +97,7 @@ static rt_err_t stm32_configure(struct rt_serial_device *serial, struct serial_c
static
rt_err_t
stm32_control
(
struct
rt_serial_device
*
serial
,
int
cmd
,
void
*
arg
)
{
struct
stm32_uart
*
uart
;
struct
stm32_uart
*
uart
;
RT_ASSERT
(
serial
!=
RT_NULL
);
uart
=
(
struct
stm32_uart
*
)
serial
->
parent
.
user_data
;
...
...
@@ -119,7 +119,7 @@ static rt_err_t stm32_control(struct rt_serial_device *serial, int cmd, void *ar
static
int
stm32_putc
(
struct
rt_serial_device
*
serial
,
char
c
)
{
struct
stm32_uart
*
uart
;
struct
stm32_uart
*
uart
;
RT_ASSERT
(
serial
!=
RT_NULL
);
uart
=
(
struct
stm32_uart
*
)
serial
->
parent
.
user_data
;
...
...
@@ -133,7 +133,7 @@ static int stm32_putc(struct rt_serial_device *serial, char c)
static
int
stm32_getc
(
struct
rt_serial_device
*
serial
)
{
int
ch
;
struct
stm32_uart
*
uart
;
struct
stm32_uart
*
uart
;
RT_ASSERT
(
serial
!=
RT_NULL
);
uart
=
(
struct
stm32_uart
*
)
serial
->
parent
.
user_data
;
...
...
@@ -166,13 +166,13 @@ struct rt_serial_device serial1;
void
USART1_IRQHandler
(
void
)
{
struct
stm32_uart
*
uart
;
struct
stm32_uart
*
uart
;
uart
=
&
uart1
;
/* enter interrupt */
rt_interrupt_enter
();
if
(
USART_GetITStatus
(
uart
->
uart_device
,
USART_IT_RXNE
)
!=
RESET
)
if
(
USART_GetITStatus
(
uart
->
uart_device
,
USART_IT_RXNE
)
!=
RESET
)
{
rt_hw_serial_isr
(
&
serial1
,
RT_SERIAL_EVENT_RX_IND
);
/* clear interrupt */
...
...
@@ -200,13 +200,13 @@ struct rt_serial_device serial2;
void
USART2_IRQHandler
(
void
)
{
struct
stm32_uart
*
uart
;
struct
stm32_uart
*
uart
;
uart
=
&
uart2
;
/* enter interrupt */
rt_interrupt_enter
();
if
(
USART_GetITStatus
(
uart
->
uart_device
,
USART_IT_RXNE
)
!=
RESET
)
if
(
USART_GetITStatus
(
uart
->
uart_device
,
USART_IT_RXNE
)
!=
RESET
)
{
rt_hw_serial_isr
(
&
serial2
,
RT_SERIAL_EVENT_RX_IND
);
/* clear interrupt */
...
...
@@ -234,13 +234,13 @@ struct rt_serial_device serial3;
void
USART3_IRQHandler
(
void
)
{
struct
stm32_uart
*
uart
;
struct
stm32_uart
*
uart
;
uart
=
&
uart3
;
/* enter interrupt */
rt_interrupt_enter
();
if
(
USART_GetITStatus
(
uart
->
uart_device
,
USART_IT_RXNE
)
!=
RESET
)
if
(
USART_GetITStatus
(
uart
->
uart_device
,
USART_IT_RXNE
)
!=
RESET
)
{
rt_hw_serial_isr
(
&
serial3
,
RT_SERIAL_EVENT_RX_IND
);
/* clear interrupt */
...
...
@@ -321,7 +321,7 @@ static void GPIO_Configuration(void)
#endif
/* RT_USING_UART3 */
}
static
void
NVIC_Configuration
(
struct
stm32_uart
*
uart
)
static
void
NVIC_Configuration
(
struct
stm32_uart
*
uart
)
{
NVIC_InitTypeDef
NVIC_InitStructure
;
...
...
@@ -335,7 +335,7 @@ static void NVIC_Configuration(struct stm32_uart* uart)
int
stm32_hw_usart_init
(
void
)
{
struct
stm32_uart
*
uart
;
struct
stm32_uart
*
uart
;
struct
serial_configure
config
=
RT_SERIAL_CONFIG_DEFAULT
;
RCC_Configuration
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录