Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PHPmihuan
rt-thread
提交
7c05d851
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,发现更多精彩内容 >>
未验证
提交
7c05d851
编写于
1月 08, 2023
作者:
L
liYangYang
提交者:
GitHub
1月 07, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[STM32][SPI]解决挂载函数里面不同bsp对uaer_data的滥用 (#6819)
* [spi]attach 片选引脚依赖pin框架 * 修改attach函数
上级
98a997c5
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
16 addition
and
29 deletion
+16
-29
bsp/stm32/libraries/HAL_Drivers/drv_spi.c
bsp/stm32/libraries/HAL_Drivers/drv_spi.c
+12
-22
bsp/stm32/libraries/HAL_Drivers/drv_spi.h
bsp/stm32/libraries/HAL_Drivers/drv_spi.h
+1
-7
components/drivers/include/drivers/spi.h
components/drivers/include/drivers/spi.h
+2
-0
components/drivers/spi/spi_core.c
components/drivers/spi/spi_core.c
+1
-0
未找到文件。
bsp/stm32/libraries/HAL_Drivers/drv_spi.c
浏览文件 @
7c05d851
...
...
@@ -85,6 +85,9 @@ static rt_err_t stm32_spi_init(struct stm32_spi *spi_drv, struct rt_spi_configur
RT_ASSERT
(
spi_drv
!=
RT_NULL
);
RT_ASSERT
(
cfg
!=
RT_NULL
);
rt_pin_mode
(
cfg
->
cs_pin
,
PIN_MODE_OUTPUT
);
rt_pin_write
(
cfg
->
cs_pin
,
PIN_HIGH
);
SPI_HandleTypeDef
*
spi_handle
=
&
spi_drv
->
handle
;
if
(
cfg
->
mode
&
RT_SPI_SLAVE
)
...
...
@@ -291,19 +294,17 @@ static rt_uint32_t spixfer(struct rt_spi_device *device, struct rt_spi_message *
RT_ASSERT
(
device
!=
RT_NULL
);
RT_ASSERT
(
device
->
bus
!=
RT_NULL
);
RT_ASSERT
(
device
->
bus
->
parent
.
user_data
!=
RT_NULL
);
RT_ASSERT
(
message
!=
RT_NULL
);
struct
stm32_spi
*
spi_drv
=
rt_container_of
(
device
->
bus
,
struct
stm32_spi
,
spi_bus
);
SPI_HandleTypeDef
*
spi_handle
=
&
spi_drv
->
handle
;
struct
stm32_hw_spi_cs
*
cs
=
device
->
parent
.
user_data
;
if
(
message
->
cs_take
&&
!
(
device
->
config
.
mode
&
RT_SPI_NO_CS
))
{
if
(
device
->
config
.
mode
&
RT_SPI_CS_HIGH
)
HAL_GPIO_WritePin
(
cs
->
GPIOx
,
cs
->
GPIO_Pin
,
GPIO_PIN_SET
);
rt_pin_write
(
device
->
config
.
cs_pin
,
PIN_HIGH
);
else
HAL_GPIO_WritePin
(
cs
->
GPIOx
,
cs
->
GPIO_Pin
,
GPIO_PIN_RESET
);
rt_pin_write
(
device
->
config
.
cs_pin
,
PIN_LOW
);
}
LOG_D
(
"%s transfer prepare and start"
,
spi_drv
->
config
->
bus_name
);
...
...
@@ -435,9 +436,9 @@ static rt_uint32_t spixfer(struct rt_spi_device *device, struct rt_spi_message *
if
(
message
->
cs_release
&&
!
(
device
->
config
.
mode
&
RT_SPI_NO_CS
))
{
if
(
device
->
config
.
mode
&
RT_SPI_CS_HIGH
)
HAL_GPIO_WritePin
(
cs
->
GPIOx
,
cs
->
GPIO_Pin
,
GPIO_PIN_RESET
);
rt_pin_write
(
device
->
config
.
cs_pin
,
PIN_LOW
);
else
HAL_GPIO_WritePin
(
cs
->
GPIOx
,
cs
->
GPIO_Pin
,
GPIO_PIN_SET
);
rt_pin_write
(
device
->
config
.
cs_pin
,
PIN_HIGH
);
}
return
message
->
length
;
...
...
@@ -570,33 +571,22 @@ static int rt_hw_spi_bus_init(void)
/**
* Attach the spi device to SPI bus, this function must be used after initialization.
*/
rt_err_t
rt_hw_spi_device_attach
(
const
char
*
bus_name
,
const
char
*
device_name
,
GPIO_TypeDef
*
cs_gpiox
,
uint16_t
cs_gpio_pin
)
rt_err_t
rt_hw_spi_device_attach
(
const
char
*
bus_name
,
const
char
*
device_name
,
struct
rt_spi_configuration
*
cfg
)
{
RT_ASSERT
(
bus_name
!=
RT_NULL
);
RT_ASSERT
(
device_name
!=
RT_NULL
);
rt_err_t
result
;
struct
rt_spi_device
*
spi_device
;
struct
stm32_hw_spi_cs
*
cs_pin
;
/* initialize the cs pin && select the slave*/
GPIO_InitTypeDef
GPIO_Initure
;
GPIO_Initure
.
Pin
=
cs_gpio_pin
;
GPIO_Initure
.
Mode
=
GPIO_MODE_OUTPUT_PP
;
GPIO_Initure
.
Pull
=
GPIO_PULLUP
;
GPIO_Initure
.
Speed
=
GPIO_SPEED_FREQ_HIGH
;
HAL_GPIO_Init
(
cs_gpiox
,
&
GPIO_Initure
);
HAL_GPIO_WritePin
(
cs_gpiox
,
cs_gpio_pin
,
GPIO_PIN_SET
);
/* attach the device to spi bus*/
spi_device
=
(
struct
rt_spi_device
*
)
rt_malloc
(
sizeof
(
struct
rt_spi_device
));
RT_ASSERT
(
spi_device
!=
RT_NULL
);
cs_pin
=
(
struct
stm32_hw_spi_cs
*
)
rt_malloc
(
sizeof
(
struct
stm32_hw_spi_cs
));
RT_ASSERT
(
cs_pin
!=
RT_NULL
);
cs_pin
->
GPIOx
=
cs_gpiox
;
cs_pin
->
GPIO_Pin
=
cs_gpio_pin
;
result
=
rt_spi_bus_attach_device
(
spi_device
,
device_name
,
bus_name
,
(
void
*
)
cs_pin
);
result
=
rt_spi_bus_attach_device
(
spi_device
,
device_name
,
bus_name
,
RT_NULL
);
result
=
rt_spi_configure
(
spi_device
,
cfg
);
if
(
result
!=
RT_EOK
)
{
LOG_E
(
"%s attach to %s faild, %d
\n
"
,
device_name
,
bus_name
,
result
);
...
...
bsp/stm32/libraries/HAL_Drivers/drv_spi.h
浏览文件 @
7c05d851
...
...
@@ -22,18 +22,12 @@
extern
"C"
{
#endif
rt_err_t
rt_hw_spi_device_attach
(
const
char
*
bus_name
,
const
char
*
device_name
,
GPIO_TypeDef
*
cs_gpiox
,
uint16_t
cs_gpio_pin
);
rt_err_t
rt_hw_spi_device_attach
(
const
char
*
bus_name
,
const
char
*
device_name
,
struct
rt_spi_configuration
*
cfg
);
#ifdef __cplusplus
}
#endif
struct
stm32_hw_spi_cs
{
GPIO_TypeDef
*
GPIOx
;
uint16_t
GPIO_Pin
;
};
struct
stm32_spi_config
{
SPI_TypeDef
*
Instance
;
...
...
components/drivers/include/drivers/spi.h
浏览文件 @
7c05d851
...
...
@@ -15,6 +15,7 @@
#include <stdlib.h>
#include <rtthread.h>
#include <rtdevice.h>
#ifdef __cplusplus
extern
"C"
{
...
...
@@ -78,6 +79,7 @@ struct rt_spi_configuration
rt_uint8_t
mode
;
rt_uint8_t
data_width
;
rt_uint16_t
reserved
;
rt_base_t
cs_pin
;
rt_uint32_t
max_hz
;
};
...
...
components/drivers/spi/spi_core.c
浏览文件 @
7c05d851
...
...
@@ -80,6 +80,7 @@ rt_err_t rt_spi_configure(struct rt_spi_device *device,
device
->
config
.
data_width
=
cfg
->
data_width
;
device
->
config
.
mode
=
cfg
->
mode
&
RT_SPI_MODE_MASK
;
device
->
config
.
max_hz
=
cfg
->
max_hz
;
device
->
config
.
cs_pin
=
cfg
->
cs_pin
;
if
(
device
->
bus
!=
RT_NULL
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录