Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
rt-thread
提交
6a9e081e
R
rt-thread
项目概览
BaiXuePrincess
/
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,发现更多精彩内容 >>
提交
6a9e081e
编写于
6月 13, 2020
作者:
armink_ztl
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[SFUD] Add new probe API (rt_sfud_flash_probe_ext) for using user SPI configuration.
上级
930de790
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
55 addition
and
70 deletion
+55
-70
components/drivers/spi/spi_flash_sfud.c
components/drivers/spi/spi_flash_sfud.c
+42
-70
components/drivers/spi/spi_flash_sfud.h
components/drivers/spi/spi_flash_sfud.h
+13
-0
未找到文件。
components/drivers/spi/spi_flash_sfud.c
浏览文件 @
6a9e081e
...
...
@@ -15,12 +15,6 @@
#ifdef RT_USING_SFUD
#ifdef RT_DEBUG_SFUD
#define DEBUG_TRACE rt_kprintf("[SFUD] "); rt_kprintf
#else
#define DEBUG_TRACE(...)
#endif
/* RT_DEBUG_SFUD */
#ifndef RT_SFUD_DEFAULT_SPI_CFG
#ifndef RT_SFUD_SPI_MAX_HZ
...
...
@@ -34,7 +28,7 @@
.data_width = 8, \
.max_hz = RT_SFUD_SPI_MAX_HZ, \
}
#endif
#endif
/* RT_SFUD_DEFAULT_SPI_CFG */
#ifdef SFUD_USING_QSPI
#define RT_SFUD_DEFAULT_QSPI_CFG \
...
...
@@ -44,11 +38,7 @@
.ddr_mode = 0, \
.qspi_dl_width = 4, \
}
#endif
static
char
log_buf
[
RT_CONSOLEBUF_SIZE
];
void
sfud_log_debug
(
const
char
*
file
,
const
long
line
,
const
char
*
format
,
...);
#endif
/* SFUD_USING_QSPI */
static
rt_err_t
rt_sfud_control
(
rt_device_t
dev
,
int
cmd
,
void
*
args
)
{
RT_ASSERT
(
dev
);
...
...
@@ -259,44 +249,6 @@ static void retry_delay_100us(void) {
rt_thread_delay
((
RT_TICK_PER_SECOND
*
1
+
9999
)
/
10000
);
}
/**
* This function is print debug info.
*
* @param file the file which has call this function
* @param line the line number which has call this function
* @param format output format
* @param ... args
*/
void
sfud_log_debug
(
const
char
*
file
,
const
long
line
,
const
char
*
format
,
...)
{
va_list
args
;
/* args point to the first variable parameter */
va_start
(
args
,
format
);
rt_kprintf
(
"[SFUD] (%s:%ld) "
,
file
,
line
);
/* must use vprintf to print */
rt_vsnprintf
(
log_buf
,
sizeof
(
log_buf
),
format
,
args
);
rt_kprintf
(
"%s
\n
"
,
log_buf
);
va_end
(
args
);
}
/**
* This function is print routine info.
*
* @param format output format
* @param ... args
*/
void
sfud_log_info
(
const
char
*
format
,
...)
{
va_list
args
;
/* args point to the first variable parameter */
va_start
(
args
,
format
);
rt_kprintf
(
"[SFUD] "
);
/* must use vprintf to print */
rt_vsnprintf
(
log_buf
,
sizeof
(
log_buf
),
format
,
args
);
rt_kprintf
(
"%s
\n
"
,
log_buf
);
va_end
(
args
);
}
sfud_err
sfud_spi_port_init
(
sfud_flash
*
flash
)
{
sfud_err
result
=
SFUD_SUCCESS
;
...
...
@@ -311,7 +263,7 @@ sfud_err sfud_spi_port_init(sfud_flash *flash) {
flash
->
spi
.
unlock
=
spi_unlock
;
flash
->
spi
.
user_data
=
flash
;
if
(
RT_TICK_PER_SECOND
<
1000
)
{
rt_kprintf
(
"[SFUD] Warning: The OS tick(%d) is less than 1000. So the flash write will take more time.
\n
"
,
RT_TICK_PER_SECOND
);
LOG_W
(
"[SFUD] Warning: The OS tick(%d) is less than 1000. So the flash write will take more time.
"
,
RT_TICK_PER_SECOND
);
}
/* 100 microsecond delay */
flash
->
retry
.
delay
=
retry_delay_100us
;
...
...
@@ -334,23 +286,23 @@ const static struct rt_device_ops flash_device_ops =
#endif
/**
* Probe SPI flash by SFUD
(Serial Flash Universal Driver) driver library and though SPI device
.
* Probe SPI flash by SFUD
(Serial Flash Universal Driver) driver library and though SPI device by specified configuration
.
*
* @param spi_flash_dev_name the name which will create SPI flash device
* @param spi_dev_name using SPI device name
* @param spi_cfg SPI device configuration
* @param qspi_cfg QSPI device configuration
*
* @return probed SPI flash device, probe failed will return RT_NULL
*/
rt_spi_flash_device_t
rt_sfud_flash_probe
(
const
char
*
spi_flash_dev_name
,
const
char
*
spi_dev_name
)
{
rt_spi_flash_device_t
rt_sfud_flash_probe_ext
(
const
char
*
spi_flash_dev_name
,
const
char
*
spi_dev_name
,
struct
rt_spi_configuration
*
spi_cfg
,
struct
rt_qspi_configuration
*
qspi_cfg
)
{
rt_spi_flash_device_t
rtt_dev
=
RT_NULL
;
sfud_flash
*
sfud_dev
=
RT_NULL
;
char
*
spi_flash_dev_name_bak
=
RT_NULL
,
*
spi_dev_name_bak
=
RT_NULL
;
/* using default flash SPI configuration for initialize SPI Flash
* @note you also can change the SPI to other configuration after initialized finish */
struct
rt_spi_configuration
cfg
=
RT_SFUD_DEFAULT_SPI_CFG
;
extern
sfud_err
sfud_device_init
(
sfud_flash
*
flash
);
#ifdef SFUD_USING_QSPI
struct
rt_qspi_configuration
qspi_cfg
=
RT_SFUD_DEFAULT_QSPI_CFG
;
struct
rt_qspi_device
*
qspi_dev
=
RT_NULL
;
#endif
...
...
@@ -380,7 +332,7 @@ rt_spi_flash_device_t rt_sfud_flash_probe(const char *spi_flash_dev_name, const
/* RT-Thread SPI device initialize */
rtt_dev
->
rt_spi_device
=
(
struct
rt_spi_device
*
)
rt_device_find
(
spi_dev_name
);
if
(
rtt_dev
->
rt_spi_device
==
RT_NULL
||
rtt_dev
->
rt_spi_device
->
parent
.
type
!=
RT_Device_Class_SPIDevice
)
{
rt_kprintf
(
"ERROR: SPI device %s not found!
\n
"
,
spi_dev_name
);
LOG_E
(
"ERROR: SPI device %s not found!
"
,
spi_dev_name
);
goto
error
;
}
sfud_dev
->
spi
.
name
=
spi_dev_name_bak
;
...
...
@@ -389,12 +341,12 @@ rt_spi_flash_device_t rt_sfud_flash_probe(const char *spi_flash_dev_name, const
/* set the qspi line number and configure the QSPI bus */
if
(
rtt_dev
->
rt_spi_device
->
bus
->
mode
&
RT_SPI_BUS_MODE_QSPI
)
{
qspi_dev
=
(
struct
rt_qspi_device
*
)
rtt_dev
->
rt_spi_device
;
qspi_cfg
.
qspi_dl_width
=
qspi_dev
->
config
.
qspi_dl_width
;
rt_qspi_configure
(
qspi_dev
,
&
qspi_cfg
);
qspi_cfg
->
qspi_dl_width
=
qspi_dev
->
config
.
qspi_dl_width
;
rt_qspi_configure
(
qspi_dev
,
qspi_cfg
);
}
else
#endif
rt_spi_configure
(
rtt_dev
->
rt_spi_device
,
&
cfg
);
rt_spi_configure
(
rtt_dev
->
rt_spi_device
,
spi_
cfg
);
}
/* SFUD flash device initialize */
{
...
...
@@ -406,7 +358,7 @@ rt_spi_flash_device_t rt_sfud_flash_probe(const char *spi_flash_dev_name, const
sfud_dev
->
user_data
=
rtt_dev
;
/* initialize SFUD device */
if
(
sfud_device_init
(
sfud_dev
)
!=
SFUD_SUCCESS
)
{
rt_kprintf
(
"ERROR: SPI flash probe failed by SPI device %s.
\n
"
,
spi_dev_name
);
LOG_E
(
"ERROR: SPI flash probe failed by SPI device %s.
"
,
spi_dev_name
);
goto
error
;
}
/* when initialize success, then copy SFUD flash device's geometry to RT-Thread SPI flash device */
...
...
@@ -416,8 +368,8 @@ rt_spi_flash_device_t rt_sfud_flash_probe(const char *spi_flash_dev_name, const
#ifdef SFUD_USING_QSPI
/* reconfigure the QSPI bus for medium size */
if
(
rtt_dev
->
rt_spi_device
->
bus
->
mode
&
RT_SPI_BUS_MODE_QSPI
)
{
qspi_cfg
.
medium_size
=
sfud_dev
->
chip
.
capacity
;
rt_qspi_configure
(
qspi_dev
,
&
qspi_cfg
);
qspi_cfg
->
medium_size
=
sfud_dev
->
chip
.
capacity
;
rt_qspi_configure
(
qspi_dev
,
qspi_cfg
);
if
(
qspi_dev
->
enter_qspi_mode
!=
RT_NULL
)
qspi_dev
->
enter_qspi_mode
(
qspi_dev
);
...
...
@@ -442,10 +394,10 @@ rt_spi_flash_device_t rt_sfud_flash_probe(const char *spi_flash_dev_name, const
rt_device_register
(
&
(
rtt_dev
->
flash_device
),
spi_flash_dev_name
,
RT_DEVICE_FLAG_RDWR
|
RT_DEVICE_FLAG_STANDALONE
);
DEBUG_TRACE
(
"Probe SPI flash %s by SPI device %s success.
\n
"
,
spi_flash_dev_name
,
spi_dev_name
);
LOG_I
(
"Probe SPI flash %s by SPI device %s success.
"
,
spi_flash_dev_name
,
spi_dev_name
);
return
rtt_dev
;
}
else
{
rt_kprintf
(
"ERROR: Low memory.
\n
"
);
LOG_E
(
"ERROR: Low memory.
"
);
goto
error
;
}
...
...
@@ -463,6 +415,26 @@ error:
return
RT_NULL
;
}
/**
* Probe SPI flash by SFUD(Serial Flash Universal Driver) driver library and though SPI device.
*
* @param spi_flash_dev_name the name which will create SPI flash device
* @param spi_dev_name using SPI device name
*
* @return probed SPI flash device, probe failed will return RT_NULL
*/
rt_spi_flash_device_t
rt_sfud_flash_probe
(
const
char
*
spi_flash_dev_name
,
const
char
*
spi_dev_name
)
{
struct
rt_spi_configuration
cfg
=
RT_SFUD_DEFAULT_SPI_CFG
;
#ifndef SFUD_USING_QSPI
return
rt_sfud_flash_probe_ext
(
spi_flash_dev_name
,
spi_dev_name
,
&
cfg
,
RT_NULL
);
#else
struct
rt_qspi_configuration
qspi_cfg
=
RT_SFUD_DEFAULT_QSPI_CFG
;
return
rt_sfud_flash_probe_ext
(
spi_flash_dev_name
,
spi_dev_name
,
&
cfg
,
&
qspi_cfg
);
#endif
}
/**
* Delete SPI flash device
*
...
...
@@ -496,7 +468,7 @@ sfud_flash_t rt_sfud_flash_find(const char *spi_dev_name)
rt_spi_device
=
(
struct
rt_spi_device
*
)
rt_device_find
(
spi_dev_name
);
if
(
rt_spi_device
==
RT_NULL
||
rt_spi_device
->
parent
.
type
!=
RT_Device_Class_SPIDevice
)
{
rt_kprintf
(
"ERROR: SPI device %s not found!
\n
"
,
spi_dev_name
);
LOG_E
(
"ERROR: SPI device %s not found!
"
,
spi_dev_name
);
goto
__error
;
}
...
...
@@ -505,7 +477,7 @@ sfud_flash_t rt_sfud_flash_find(const char *spi_dev_name)
sfud_dev
=
(
sfud_flash_t
)
(
rtt_dev
->
user_data
);
return
sfud_dev
;
}
else
{
rt_kprintf
(
"ERROR: SFUD flash device not found!
\n
"
);
LOG_E
(
"ERROR: SFUD flash device not found!
"
);
goto
__error
;
}
...
...
@@ -520,7 +492,7 @@ sfud_flash_t rt_sfud_flash_find_by_dev_name(const char *flash_dev_name)
rtt_dev
=
(
rt_spi_flash_device_t
)
rt_device_find
(
flash_dev_name
);
if
(
rtt_dev
==
RT_NULL
||
rtt_dev
->
flash_device
.
type
!=
RT_Device_Class_Block
)
{
rt_kprintf
(
"ERROR: Flash device %s not found!
\n
"
,
flash_dev_name
);
LOG_E
(
"ERROR: Flash device %s not found!
"
,
flash_dev_name
);
goto
__error
;
}
...
...
@@ -528,7 +500,7 @@ sfud_flash_t rt_sfud_flash_find_by_dev_name(const char *flash_dev_name)
sfud_dev
=
(
sfud_flash_t
)
(
rtt_dev
->
user_data
);
return
sfud_dev
;
}
else
{
rt_kprintf
(
"ERROR: SFUD flash device not found!
\n
"
);
LOG_E
(
"ERROR: SFUD flash device not found!
"
);
goto
__error
;
}
...
...
components/drivers/spi/spi_flash_sfud.h
浏览文件 @
6a9e081e
...
...
@@ -26,6 +26,19 @@
*/
rt_spi_flash_device_t
rt_sfud_flash_probe
(
const
char
*
spi_flash_dev_name
,
const
char
*
spi_dev_name
);
/**
* Probe SPI flash by SFUD (Serial Flash Universal Driver) driver library and though SPI device by specified configuration.
*
* @param spi_flash_dev_name the name which will create SPI flash device
* @param spi_dev_name using SPI device name
* @param spi_cfg SPI device configuration
* @param qspi_cfg QSPI device configuration
*
* @return probed SPI flash device, probe failed will return RT_NULL
*/
rt_spi_flash_device_t
rt_sfud_flash_probe_ext
(
const
char
*
spi_flash_dev_name
,
const
char
*
spi_dev_name
,
struct
rt_spi_configuration
*
spi_cfg
,
struct
rt_qspi_configuration
*
qspi_cfg
);
/**
* Delete SPI flash device
*
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录