How to use the SFUD library to operate SPI Flash devices?

Created at 2020-12-10 17:00:10

Forwarded from RT-Thread Community Developer Armink

SFUD is a serial (SPI) Flash universal drive library that uses the JEDEC SFDP standard and is supported with RT-Thread v2.1.0 and the after. This allows RT-Thread to drive more models of SPI Flash. Using this driver to support multiple Flash object instances at the same time enables users to drive multiple SPI Flash. The main methods of use are as follows:

  1. Configuration
    The following configuration information can be added at rtconfig.h, for more details please refer to rt-thread/components/drivers/spi/sfud/inc/sfud_cfg.h
#define RT_USING_SFUD                      //Required
#define RT_DEBUG_SFUD               1   //Optional
#define RT_SFUD_USING_SFDP           //Optional
#define RT_SFUD_USING_FLASH_INFO_TABLE     //Optional
  1. Use
    In the past, you only had to enter the device name of SPI Flash and the corresponding SPI device name
w25qxx_init("flash", "spi10");

dfs_mount("flash", "/", "elm", 0, 0);

The method is now similar, except that after the initialization is successful, the SPI flash object is returned, which is a dynamic SPI flash object that supports the removal of the SPI flash device.

static rt_spi_flash_device_t w25q64, sst25vf016b;
/* Create two SPI Flash devices, probed from spi10 and spi30, respectively */
w25q64 = rt_sfud_flash_probe("flash0", "spi10");
sst25vf016b = rt_sfud_flash_probe("flash1", "spi30");

dfs_mount("flash0", "/", "elm", 0, 0);

rt_sfud_flash_delete(sst25vf016b);
  1. sf (SPI Flash Operation) Test command
    In spi_flash_sfud.c, there is an SPI Flash action command defined, which allows you to manually manipulate SPI Flash with the MSH command, as follows:
msh >sf
Usage:
sf probe [spi_device]           - probe and init SPI flash by given 'spi_device'
sf read addr size               - read 'size' bytes starting at 'addr'
sf write addr data1 ... dataN   - write some bytes 'data' to flash starting at 'addr'
sf erase addr size              - erase 'size' bytes starting at 'addr'
sf status [ ] - read or write '1:volatile|0:non-volatile' 'status'
sf bench                        - full chip benchmark. DANGER: It will erase full chip!

msh >sf probe spi10
8 MB W25Q64 is current selected device.

msh >sf read 0 64
Read the W25Q64 flash data success. Start from 0x00000000, size is 64. The data is:
Offset (h) 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
[00000000] 54 00 00 00 90 8F E3 A7 69 61 70 5F 6E 65 65 64 
[00000010] 5F 63 6F 70 79 5F 61 70 70 3D 30 00 69 61 70 5F 
[00000020] 63 6F 70 79 5F 61 70 70 5F 73 69 7A 65 3D 30 00 
[00000030] 73 74 6F 70 5F 69 6E 5F 62 6F 6F 74 6C 6F 61 64 

msh >sf write 10 1 2 3 4 5
Write the W25Q64 flash data success. Start from 0x0000000A, size is 5.
Write data: 1 2 3 4 5 .

msh >sf erase 0 8192
Erase the W25Q64 flash data success. Start from 0x00000000, size is 8192

msh >sf status
The W25Q64 flash status register current value is 0x00.

msh >sf status 1 28
Write the W25Q64 flash status register to 0x1C success.

msh >sf bench yes
Erasing the W25Q64 8388608 bytes data, waiting...
Erase benchmark success, total time: 20.591S.
Writing the W25Q64 8388608 bytes data, waiting...
Write benchmark success, total time: 32.768S.
Reading the W25Q64 8388608 bytes data, waiting...
Read benchmark success, total time: 16.129S.

更多

Follower
0
Views
2.1k
1 Answer
aozima
aozima 2020-12-10

Thanks for share!

Write Your Answer

Log in to publish your answer,Click here to log in.

Create
Post

Share