Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_46254178
rt-thread
提交
65d94a4e
R
rt-thread
项目概览
weixin_46254178
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
1
Star
1
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,发现更多精彩内容 >>
提交
65d94a4e
编写于
2月 20, 2019
作者:
armink_ztl
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[DeviceDriver] Add rt_sfud_flash_find_by_dev_name function to SFUD porting file.
上级
1d1f272f
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
104 addition
and
37 deletion
+104
-37
components/drivers/spi/spi_flash_sfud.c
components/drivers/spi/spi_flash_sfud.c
+94
-36
components/drivers/spi/spi_flash_sfud.h
components/drivers/spi/spi_flash_sfud.h
+10
-1
未找到文件。
components/drivers/spi/spi_flash_sfud.c
浏览文件 @
65d94a4e
...
...
@@ -46,7 +46,7 @@ static char log_buf[RT_CONSOLEBUF_SIZE];
void
sfud_log_debug
(
const
char
*
file
,
const
long
line
,
const
char
*
format
,
...);
static
rt_err_t
rt_sfud_control
(
rt_device_t
dev
,
int
cmd
,
void
*
args
)
{
RT_ASSERT
(
dev
!=
RT_NULL
);
RT_ASSERT
(
dev
);
switch
(
cmd
)
{
case
RT_DEVICE_CTRL_BLK_GETGEOME
:
{
...
...
@@ -93,6 +93,10 @@ static rt_err_t rt_sfud_control(rt_device_t dev, int cmd, void *args) {
static
rt_size_t
rt_sfud_read
(
rt_device_t
dev
,
rt_off_t
pos
,
void
*
buffer
,
rt_size_t
size
)
{
struct
spi_flash_device
*
rtt_dev
=
(
struct
spi_flash_device
*
)
(
dev
->
user_data
);
sfud_flash
*
sfud_dev
=
(
sfud_flash
*
)
(
rtt_dev
->
user_data
);
RT_ASSERT
(
dev
);
RT_ASSERT
(
rtt_dev
);
RT_ASSERT
(
sfud_dev
);
/* change the block device's logic address to physical address */
rt_off_t
phy_pos
=
pos
*
rtt_dev
->
geometry
.
bytes_per_sector
;
rt_size_t
phy_size
=
size
*
rtt_dev
->
geometry
.
bytes_per_sector
;
...
...
@@ -107,6 +111,10 @@ static rt_size_t rt_sfud_read(rt_device_t dev, rt_off_t pos, void* buffer, rt_si
static
rt_size_t
rt_sfud_write
(
rt_device_t
dev
,
rt_off_t
pos
,
const
void
*
buffer
,
rt_size_t
size
)
{
struct
spi_flash_device
*
rtt_dev
=
(
struct
spi_flash_device
*
)
(
dev
->
user_data
);
sfud_flash
*
sfud_dev
=
(
sfud_flash
*
)
(
rtt_dev
->
user_data
);
RT_ASSERT
(
dev
);
RT_ASSERT
(
rtt_dev
);
RT_ASSERT
(
sfud_dev
);
/* change the block device's logic address to physical address */
rt_off_t
phy_pos
=
pos
*
rtt_dev
->
geometry
.
bytes_per_sector
;
rt_size_t
phy_size
=
size
*
rtt_dev
->
geometry
.
bytes_per_sector
;
...
...
@@ -126,6 +134,10 @@ static sfud_err spi_write_read(const sfud_spi *spi, const uint8_t *write_buf, si
sfud_err
result
=
SFUD_SUCCESS
;
sfud_flash
*
sfud_dev
=
(
sfud_flash
*
)
(
spi
->
user_data
);
struct
spi_flash_device
*
rtt_dev
=
(
struct
spi_flash_device
*
)
(
sfud_dev
->
user_data
);
RT_ASSERT
(
spi
);
RT_ASSERT
(
sfud_dev
);
RT_ASSERT
(
rtt_dev
);
#ifdef SFUD_USING_QSPI
struct
rt_qspi_device
*
qspi_dev
=
RT_NULL
;
#endif
...
...
@@ -180,7 +192,12 @@ static sfud_err qspi_read(const struct __sfud_spi *spi, uint32_t addr, sfud_qspi
sfud_flash
*
sfud_dev
=
(
sfud_flash
*
)
(
spi
->
user_data
);
struct
spi_flash_device
*
rtt_dev
=
(
struct
spi_flash_device
*
)
(
sfud_dev
->
user_data
);
struct
rt_qspi_device
*
qspi_dev
=
(
struct
rt_qspi_device
*
)
(
rtt_dev
->
rt_spi_device
);
RT_ASSERT
(
spi
);
RT_ASSERT
(
sfud_dev
);
RT_ASSERT
(
rtt_dev
);
RT_ASSERT
(
qspi_dev
);
/* set message struct */
message
.
instruction
.
content
=
qspi_read_cmd_format
->
instruction
;
message
.
instruction
.
qspi_lines
=
qspi_read_cmd_format
->
instruction_lines
;
...
...
@@ -201,11 +218,11 @@ static sfud_err qspi_read(const struct __sfud_spi *spi, uint32_t addr, sfud_qspi
message
.
parent
.
cs_release
=
1
;
message
.
parent
.
cs_take
=
1
;
message
.
qspi_data_lines
=
qspi_read_cmd_format
->
data_lines
;
if
(
rt_qspi_transfer_message
(
qspi_dev
,
&
message
)
!=
read_size
)
{
result
=
SFUD_ERR_TIMEOUT
;
}
return
result
;
}
#endif
...
...
@@ -214,6 +231,10 @@ static void spi_lock(const sfud_spi *spi) {
sfud_flash
*
sfud_dev
=
(
sfud_flash
*
)
(
spi
->
user_data
);
struct
spi_flash_device
*
rtt_dev
=
(
struct
spi_flash_device
*
)
(
sfud_dev
->
user_data
);
RT_ASSERT
(
spi
);
RT_ASSERT
(
sfud_dev
);
RT_ASSERT
(
rtt_dev
);
rt_mutex_take
(
&
(
rtt_dev
->
lock
),
RT_WAITING_FOREVER
);
}
...
...
@@ -221,6 +242,10 @@ static void spi_unlock(const sfud_spi *spi) {
sfud_flash
*
sfud_dev
=
(
sfud_flash
*
)
(
spi
->
user_data
);
struct
spi_flash_device
*
rtt_dev
=
(
struct
spi_flash_device
*
)
(
sfud_dev
->
user_data
);
RT_ASSERT
(
spi
);
RT_ASSERT
(
sfud_dev
);
RT_ASSERT
(
rtt_dev
);
rt_mutex_release
(
&
(
rtt_dev
->
lock
));
}
...
...
@@ -270,6 +295,8 @@ void sfud_log_info(const char *format, ...) {
sfud_err
sfud_spi_port_init
(
sfud_flash
*
flash
)
{
sfud_err
result
=
SFUD_SUCCESS
;
RT_ASSERT
(
flash
);
/* port SPI device interface */
flash
->
spi
.
wr
=
spi_write_read
;
#ifdef SFUD_USING_QSPI
...
...
@@ -285,7 +312,7 @@ sfud_err sfud_spi_port_init(sfud_flash *flash) {
flash
->
retry
.
delay
=
retry_delay_100us
;
/* 60 seconds timeout */
flash
->
retry
.
times
=
60
*
10000
;
return
result
;
}
...
...
@@ -361,7 +388,7 @@ rt_spi_flash_device_t rt_sfud_flash_probe(const char *spi_flash_dev_name, const
rt_qspi_configure
(
qspi_dev
,
&
qspi_cfg
);
}
else
#endif
#endif
rt_spi_configure
(
rtt_dev
->
rt_spi_device
,
&
cfg
);
}
/* SFUD flash device initialize */
...
...
@@ -461,27 +488,46 @@ sfud_flash_t rt_sfud_flash_find(const char *spi_dev_name)
rt_spi_flash_device_t
rtt_dev
=
RT_NULL
;
struct
rt_spi_device
*
rt_spi_device
=
RT_NULL
;
sfud_flash_t
sfud_dev
=
RT_NULL
;
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
)
{
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
);
goto
error
;
goto
__
error
;
}
rtt_dev
=
(
rt_spi_flash_device_t
)(
rt_spi_device
->
user_data
);
if
(
rtt_dev
&&
rtt_dev
->
user_data
)
{
sfud_dev
=
(
sfud_flash_t
)(
rtt_dev
->
user_data
);
rtt_dev
=
(
rt_spi_flash_device_t
)
(
rt_spi_device
->
user_data
);
if
(
rtt_dev
&&
rtt_dev
->
user_data
)
{
sfud_dev
=
(
sfud_flash_t
)
(
rtt_dev
->
user_data
);
return
sfud_dev
;
}
else
{
rt_kprintf
(
"ERROR: SFUD flash device not found!
\n
"
);
goto
__error
;
}
else
{
__error:
return
RT_NULL
;
}
sfud_flash_t
rt_sfud_flash_find_by_dev_name
(
const
char
*
flash_dev_name
)
{
rt_spi_flash_device_t
rtt_dev
=
RT_NULL
;
sfud_flash_t
sfud_dev
=
RT_NULL
;
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
);
goto
__error
;
}
if
(
rtt_dev
->
user_data
)
{
sfud_dev
=
(
sfud_flash_t
)
(
rtt_dev
->
user_data
);
return
sfud_dev
;
}
else
{
rt_kprintf
(
"ERROR: SFUD flash device not found!
\n
"
);
goto
error
;
goto
__
error
;
}
error:
__
error:
return
RT_NULL
;
}
...
...
@@ -491,6 +537,8 @@ error:
static
void
sf
(
uint8_t
argc
,
char
**
argv
)
{
#define __is_print(ch) ((unsigned int)((ch) - ' ') < 127u - ' ')
#define HEXDUMP_WIDTH 16
#define CMD_PROBE_INDEX 0
#define CMD_READ_INDEX 1
#define CMD_WRITE_INDEX 2
...
...
@@ -501,7 +549,7 @@ static void sf(uint8_t argc, char **argv) {
sfud_err
result
=
SFUD_SUCCESS
;
static
const
sfud_flash
*
sfud_dev
=
NULL
;
static
rt_spi_flash_device_t
rtt_dev
=
NULL
,
rtt_dev_bak
=
NULL
;
size_t
i
=
0
;
size_t
i
=
0
,
j
=
0
;
const
char
*
sf_help_info
[]
=
{
[
CMD_PROBE_INDEX
]
=
"sf probe [spi_device] - probe and init SPI flash by given 'spi_device'"
,
...
...
@@ -528,12 +576,12 @@ static void sf(uint8_t argc, char **argv) {
}
else
{
char
*
spi_dev_name
=
argv
[
2
];
rtt_dev_bak
=
rtt_dev
;
/* delete the old SPI flash device */
if
(
rtt_dev_bak
)
{
rt_sfud_flash_delete
(
rtt_dev_bak
);
}
rtt_dev
=
rt_sfud_flash_probe
(
"sf_cmd"
,
spi_dev_name
);
if
(
!
rtt_dev
)
{
return
;
...
...
@@ -557,8 +605,8 @@ static void sf(uint8_t argc, char **argv) {
rt_kprintf
(
"Usage: %s.
\n
"
,
sf_help_info
[
CMD_READ_INDEX
]);
return
;
}
else
{
addr
=
atol
(
argv
[
2
]
);
size
=
atol
(
argv
[
3
]
);
addr
=
strtol
(
argv
[
2
],
NULL
,
0
);
size
=
strtol
(
argv
[
3
],
NULL
,
0
);
uint8_t
*
data
=
rt_malloc
(
size
);
if
(
data
)
{
result
=
sfud_read
(
sfud_dev
,
addr
,
size
,
data
);
...
...
@@ -566,14 +614,24 @@ static void sf(uint8_t argc, char **argv) {
rt_kprintf
(
"Read the %s flash data success. Start from 0x%08X, size is %ld. The data is:
\n
"
,
sfud_dev
->
name
,
addr
,
size
);
rt_kprintf
(
"Offset (h) 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
\n
"
);
for
(
i
=
0
;
i
<
size
;
i
++
)
{
if
(
i
%
16
==
0
)
{
rt_kprintf
(
"[%08X] "
,
addr
+
i
);
for
(
i
=
0
;
i
<
size
;
i
+=
HEXDUMP_WIDTH
)
{
rt_kprintf
(
"[%08X] "
,
addr
+
i
);
/* dump hex */
for
(
j
=
0
;
j
<
HEXDUMP_WIDTH
;
j
++
)
{
if
(
i
+
j
<
size
)
{
rt_kprintf
(
"%02X "
,
data
[
i
+
j
]);
}
else
{
rt_kprintf
(
" "
);
}
}
rt_kprintf
(
"%02X "
,
data
[
i
]);
if
(((
i
+
1
)
%
16
==
0
)
||
i
==
size
-
1
)
{
rt_kprintf
(
"
\n
"
);
/* dump char for hex */
for
(
j
=
0
;
j
<
HEXDUMP_WIDTH
;
j
++
)
{
if
(
i
+
j
<
size
)
{
rt_kprintf
(
"%c"
,
__is_print
(
data
[
i
+
j
])
?
data
[
i
+
j
]
:
'.'
);
}
}
rt_kprintf
(
"
\n
"
);
}
rt_kprintf
(
"
\n
"
);
}
...
...
@@ -587,12 +645,12 @@ static void sf(uint8_t argc, char **argv) {
rt_kprintf
(
"Usage: %s.
\n
"
,
sf_help_info
[
CMD_WRITE_INDEX
]);
return
;
}
else
{
addr
=
atol
(
argv
[
2
]
);
addr
=
strtol
(
argv
[
2
],
NULL
,
0
);
size
=
argc
-
3
;
uint8_t
*
data
=
rt_malloc
(
size
);
if
(
data
)
{
for
(
i
=
0
;
i
<
size
;
i
++
)
{
data
[
i
]
=
atoi
(
argv
[
3
+
i
]
);
data
[
i
]
=
strtol
(
argv
[
3
+
i
],
NULL
,
0
);
}
result
=
sfud_write
(
sfud_dev
,
addr
,
size
,
data
);
if
(
result
==
SFUD_SUCCESS
)
{
...
...
@@ -614,8 +672,8 @@ static void sf(uint8_t argc, char **argv) {
rt_kprintf
(
"Usage: %s.
\n
"
,
sf_help_info
[
CMD_ERASE_INDEX
]);
return
;
}
else
{
addr
=
atol
(
argv
[
2
]
);
size
=
atol
(
argv
[
3
]
);
addr
=
strtol
(
argv
[
2
],
NULL
,
0
);
size
=
strtol
(
argv
[
3
],
NULL
,
0
);
result
=
sfud_erase
(
sfud_dev
,
addr
,
size
);
if
(
result
==
SFUD_SUCCESS
)
{
rt_kprintf
(
"Erase the %s flash data success. Start from 0x%08X, size is %ld.
\n
"
,
sfud_dev
->
name
,
...
...
@@ -630,8 +688,8 @@ static void sf(uint8_t argc, char **argv) {
rt_kprintf
(
"The %s flash status register current value is 0x%02X.
\n
"
,
sfud_dev
->
name
,
status
);
}
}
else
if
(
argc
==
4
)
{
bool
is_volatile
=
atoi
(
argv
[
2
]
);
uint8_t
status
=
atoi
(
argv
[
3
]
);
bool
is_volatile
=
strtol
(
argv
[
2
],
NULL
,
0
);
uint8_t
status
=
strtol
(
argv
[
3
],
NULL
,
0
);
result
=
sfud_write_status
(
sfud_dev
,
is_volatile
,
status
);
if
(
result
==
SFUD_SUCCESS
)
{
rt_kprintf
(
"Write the %s flash status register to 0x%02X success.
\n
"
,
sfud_dev
->
name
,
status
);
...
...
@@ -696,7 +754,7 @@ static void sf(uint8_t argc, char **argv) {
rt_kprintf
(
"Data check ERROR! Please check you flash by other command.
\n
"
);
result
=
SFUD_ERR_READ
;
}
if
(
result
!=
SFUD_SUCCESS
)
{
break
;
}
...
...
components/drivers/spi/spi_flash_sfud.h
浏览文件 @
65d94a4e
...
...
@@ -36,7 +36,7 @@ rt_spi_flash_device_t rt_sfud_flash_probe(const char *spi_flash_dev_name, const
rt_err_t
rt_sfud_flash_delete
(
rt_spi_flash_device_t
spi_flash_dev
);
/**
* Find sfud flash device
* Find sfud flash device
by SPI device name
*
* @param spi_dev_name using SPI device name
*
...
...
@@ -44,4 +44,13 @@ rt_err_t rt_sfud_flash_delete(rt_spi_flash_device_t spi_flash_dev);
*/
sfud_flash_t
rt_sfud_flash_find
(
const
char
*
spi_dev_name
);
/**
* Find sfud flash device by flash device name
*
* @param flash_dev_name using flash device name
*
* @return sfud flash device if success, otherwise return RT_NULL
*/
sfud_flash_t
rt_sfud_flash_find_by_dev_name
(
const
char
*
flash_dev_name
);
#endif
/* _SPI_FLASH_SFUD_H_ */
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录