Toggle navigation
首页
问答
文章
积分商城
专家
专区
更多专区...
文档中心
返回主站
搜索
提问
会员
中心
登录
注册
SPI
rt_spi_configure配置相关问题
发布于 2025-03-14 17:53:24 浏览:97
订阅该版
在使用rt_spi_configure配置过程中,函数内必要要求`device->bus->owner == device`? 系统刚开始配置的时候,此处应该就是不相等的,为什么不能判断为不相等时,执行后续配置工作? 不然每次系统初始配置时,都执行不到后续配置,必须要到读写操作时,才能执行配置操作。 ```c rt_err_t rt_spi_bus_configure(struct rt_spi_device *device) { rt_err_t result = -RT_ERROR; if (device->bus != RT_NULL) { result = rt_mutex_take(&(device->bus->lock), RT_WAITING_FOREVER); if (result == RT_EOK) { if (device->bus->owner == device) // 此处配置为什么要相等?每次初始配置时,都执行不到后续配置操作 { /* current device is using, re-configure SPI bus */ result = device->bus->ops->configure(device, &device->config); if (result != RT_EOK) { /* configure SPI bus failed */ LOG_E("SPI device %s configuration failed", device->parent.parent.name); } } else { /* RT_EBUSY is not an error condition and * the configuration will take effect once the device has the bus */ result = -RT_EBUSY; } /* release lock */ rt_mutex_release(&(device->bus->lock)); } } else { result = RT_EOK; } return result; } ``` ```c rt_err_t rt_spi_configure(struct rt_spi_device *device, struct rt_spi_configuration *cfg) { RT_ASSERT(device != RT_NULL); RT_ASSERT(cfg != RT_NULL); /* reset the CS pin */ if (device->cs_pin != PIN_NONE) { rt_err_t result = rt_mutex_take(&(device->bus->lock), RT_WAITING_FOREVER); if (result == RT_EOK) { if (cfg->mode & RT_SPI_CS_HIGH) { rt_pin_write(device->cs_pin, PIN_LOW); } else { rt_pin_write(device->cs_pin, PIN_HIGH); } rt_mutex_release(&(device->bus->lock)); } else { return result; } } /* If the configurations are the same, we don't need to set again. */ if (device->config.data_width == cfg->data_width && device->config.mode == (cfg->mode & RT_SPI_MODE_MASK) && device->config.max_hz == cfg->max_hz) { return RT_EOK; } /* set configuration */ device->config.data_width = cfg->data_width; device->config.mode = cfg->mode & RT_SPI_MODE_MASK; device->config.max_hz = cfg->max_hz; return rt_spi_bus_configure(device); } ```
查看更多
三世执戟
2025-03-14
这家伙很懒,什么也没写!
CS配好了就行,后面真正读写时再配置也没问题吧。这里要提前配置是有什么特殊需求吗? 另外看到github上面好像有修改这部分,改为及时配置了。
1
个回答
默认排序
按发布时间排序
撰写答案
登录
注册新账号
关注者
0
被浏览
97
关于作者
admin_wt
这家伙很懒,什么也没写!
提问
4
回答
1
被采纳
0
关注TA
发私信
相关问题
1
BBB的SPI驱动
2
求个SPI上挂两个或多个设备的使用例子
3
SPI设备有个bug
4
spi flash 的fatfs使用一段时间后读写文件出现故障
5
SPI驱动
6
请教rt_spi_configure函数理解
7
SPI FLASH挂载的问题
8
SPI-FLASH 文件系统 SPIFFS
9
求助一个完整的 spi flash 驱动
10
关于同时使用文件系统与SPI FLASH的问题
推荐文章
1
RT-Thread应用项目汇总
2
玩转RT-Thread系列教程
3
国产MCU移植系列教程汇总,欢迎查看!
4
机器人操作系统 (ROS2) 和 RT-Thread 通信
5
五分钟玩转RT-Thread新社区
6
【技术三千问】之《玩转ART-Pi》,看这篇就够了!干货汇总
7
关于STM32H7开发板上使用SDIO接口驱动SD卡挂载文件系统的问题总结
8
STM32的“GPU”——DMA2D实例详解
9
RT-Thread隐藏的宝藏之completion
10
【ART-PI】RT-Thread 开启RTC 与 Alarm组件
最新文章
1
RT-Thread离线包制作
2
RT-Thread 屏蔽在线软件包的方法
3
RT-Thread OS应用开发实战线上师资培训通知
4
【ci】【github】【bsp】RT-Thread仓库的CI自动编译测试
5
免费解锁MCU超能力!4月AIoT实战培训三城巡演
热门标签
RT-Thread Studio
串口
Env
LWIP
SPI
AT
Bootloader
Hardfault
CAN总线
FinSH
ART-Pi
DMA
USB
文件系统
RT-Thread
SCons
RT-Thread Nano
线程
MQTT
STM32
RTC
rt-smart
FAL
I2C_IIC
cubemx
ESP8266
WIZnet_W5500
UART
ota在线升级
PWM
BSP
flash
freemodbus
packages_软件包
潘多拉开发板_Pandora
GD32
定时器
ADC
flashDB
编译报错
socket
中断
rt_mq_消息队列_msg_queue
keil_MDK
Debug
SFUD
msh
ulog
C++_cpp
at_device
本月问答贡献
聚散无由
5
个答案
4
次被采纳
RTT_逍遥
4
个答案
2
次被采纳
踩姑娘的小蘑菇
6
个答案
1
次被采纳
a1012112796
4
个答案
1
次被采纳
YZRD
3
个答案
1
次被采纳
本月文章贡献
出出啊
1
篇文章
2
次点赞
小小李sunny
1
篇文章
1
次点赞
张世争
1
篇文章
7
次点赞
crystal266
2
篇文章
1
次点赞
whj467467222
2
篇文章
1
次点赞
回到
顶部
发布
问题
分享
好友
手机
浏览
扫码手机浏览
投诉
建议
回到
底部