Using SFUD(Serial Flash Universal Driver) library to operate SPI Flash devices - Page 1
Forum section: electronics / projects

author: Peter9090
author_rank: Contributor
timestamp: February 17, 2020, 10:27:53 am
content: Using SFUD(Serial Flash Universal Driver) library to operate Serial Peripheral Interface (SPI) Flash devicesPS: 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.ConfigurationThe 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.hCode:1.2.#define RT_USING_SFUD // Required3.#define RT_DEBUG_SFUD 1 //Optional4.#define RT_SFUD_USING_SFDP //Optional5.#define RT_SFUD_USING_FLASH_INFO_TABLE //Optional`2. Use MethodThe way we used in the past is to simply enter the device name of SPI Flash and its corresponding SPI device nameCode:1.2.w25qxx_init("flash", "spi10");3.4.dfs_mount("flash", "/", "elm", 0, 0);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);3、SP (SPI Flash operation) Test CommandIn 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 >sf2. Usage:3. sf probe  - 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 spi1011. 8 MB W25Q64 is current selected device.12.13. msh >sf read 0 6414. 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 0F16.  54 00 00 00 90 8F E3 A7 69 61 70 5F 6E 65 65 6417.  5F 63 6F 70 79 5F 61 70 70 3D 30 00 69 61 70 5F18.  63 6F 70 79 5F 61 70 70 5F 73 69 7A 65 3D 30 0019.  73 74 6F 70 5F 69 6E 5F 62 6F 6F 74 6C 6F 61 6420.21. msh >sf write 10 1 2 3 4 522. 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 819226. Erase the W25Q64 flash data success. Start from 0x00000000, size is 819227.28. msh >sf status29. The W25Q64 flash status register current value is 0x00.30.31. msh >sf status 1 2832. Write the W25Q64 flash status register to 0x1C success.33.34. msh >sf bench yes35. 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.For more information about RT-Thread, you can visit its Github or Twitter.Github:https://github.com/RT-Thread/rtthread-manual-docTwitter:https://twitter.com/rt_thread

author: Peter9090
author_rank: Contributor
timestamp: February 20, 2020, 08:27:13 am
content: No one need to use this in the development process?I was expecting we could discuss this together.