Electronics > Projects, Designs, and Technical Stuff
Using SFUD(Serial Flash Universal Driver) library to operate SPI Flash devices
(1/1)
Peter9090:
Using SFUD(Serial Flash Universal Driver) library to operate Serial Peripheral Interface (SPI) Flash devices
PS: This article forwarded from RT-Thread IoT OS Community! RT-Thread is an open source embedded IoT operating system.
SFUD is a standard Serial(SPI) Flash Universal Drive Library using JEDEC and which is supported after RT-Thread version 2.1.0. It allows RT-Thread to drive more models of SPI Flash, and using this drive to support multiple Flash object instances at the same time, and it also allows users to drive multiple SPI Flash at the same time. The main methods of use are as follows:
1.Configuration
The following configuration information can be added in rtconfig.h, and the features of each configuration can be found in detail on Github: https://github.com/armink/rt-thread/blob/master/components/drivers/spi/sfud/inc/sfud_cfg.h
--- Code: ---1.
2.#define RT_USING_SFUD // Required
3.#define RT_DEBUG_SFUD 1 //Optional
4.#define RT_SFUD_USING_SFDP //Optional
5.#define RT_SFUD_USING_FLASH_INFO_TABLE //Optional
--- End code ---
`
2. Use Method
The way we used in the past is to simply enter the device name of SPI Flash and its corresponding SPI device name
--- Code: ---1.
2.w25qxx_init("flash", "spi10");
3.
4.dfs_mount("flash", "/", "elm", 0, 0);
--- End code ---
Now the same way could be used, except that the SPI flash object is returned after successful initialization, which is a dynamic SPI flash object that supports the removal of the SPI flash device.
--- Code: ---1. static rt_spi_flash_device_t w25q64, sst25vf016b;
2. /* Create two SPI Flash devices to detect from spi10 and spi30, respectively */
3. w25q64 = rt_sfud_flash_probe("flash0", "spi10");
4. sst25vf016b = rt_sfud_flash_probe("flash1", "spi30")
5.
6. dfs_mount("flash0", "/", "elm", 0, 0);
7.
8.rt_sfud_flash_delete(sst25vf016b);
--- End code ---
3、SP (SPI Flash operation) Test Command
In spi_flash_sfud.c the definition has the SPI Flash operation command, which can be manually operated by the MSH command, as follows:
--- Code: ---1. msh >sf
2. Usage:
3. sf probe [spi_device] - probe and init SPI flash by given 'spi_device'
4. sf read addr size - read 'size' bytes starting at 'addr'
5. sf write addr data1 ... dataN - write some bytes 'data' to flash starting at 'addr'
6. sf erase addr size - erase 'size' bytes starting at 'addr'
7. sf status [<volatile> <status>] - read or write '1:volatile|0:non-volatile' 'status'
8. sf bench - full chip benchmark. DANGER: It will erase full chip!
9.
10. msh >sf probe spi10
11. 8 MB W25Q64 is current selected device.
12.
13. msh >sf read 0 64
14. Read the W25Q64 flash data success. Start from 0x00000000, size is 64. The data is:
15. Offset (h) 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
16. [00000000] 54 00 00 00 90 8F E3 A7 69 61 70 5F 6E 65 65 64
17. [00000010] 5F 63 6F 70 79 5F 61 70 70 3D 30 00 69 61 70 5F
18. [00000020] 63 6F 70 79 5F 61 70 70 5F 73 69 7A 65 3D 30 00
19. [00000030] 73 74 6F 70 5F 69 6E 5F 62 6F 6F 74 6C 6F 61 64
20.
21. msh >sf write 10 1 2 3 4 5
22. Write the W25Q64 flash data success. Start from 0x0000000A, size is 5.
23. Write data: 1 2 3 4 5 .
24.
25. msh >sf erase 0 8192
26. Erase the W25Q64 flash data success. Start from 0x00000000, size is 8192
27.
28. msh >sf status
29. The W25Q64 flash status register current value is 0x00.
30.
31. msh >sf status 1 28
32. Write the W25Q64 flash status register to 0x1C success.
33.
34. msh >sf bench yes
35. Erasing the W25Q64 8388608 bytes data, waiting...
36. Erase benchmark success, total time: 20.591S.
37. Writing the W25Q64 8388608 bytes data, waiting...
38. Write benchmark success, total time: 32.768S.
39. Reading the W25Q64 8388608 bytes data, waiting...
40. Read benchmark success, total time: 16.129S.
--- End code ---
For more information about RT-Thread, you can visit its Github or Twitter.
Github: https://github.com/RT-Thread/rtthread-manual-doc
Twitter: https://twitter.com/rt_thread
Peter9090:
No one need to use this in the development process?
I was expecting we could discuss this together.
Navigation
[0] Message Index
Go to full version