Universal Driver Library for Serial SPI Flash: SFUD Application Example

Universal Driver Library for Serial SPI Flash: SFUD Application Example

SFUD (Serial Flash Universal Driver) is an open-source universal driver library for serial SPI Flash.

It aims to address the command differences among various brands and specifications of serial Flash, achieving cross-hardware compatibility through a unified interface, thereby reducing the complexity of embedded system development and enhancing software reusability and scalability. It also mitigates the risks associated with Flash shortages or discontinuation for products.

The LuatOS platform provides developers with convenient SFUD core library API interfaces:

  • Supports direct operations on Flash storage units through the native SFUD interface, and also allows Flash devices to be mounted as an SFUD LFS file system for standardized file management, simplifying embedded storage management and improving development efficiency;

  • Supports setting the offset and size of the mounted file system, providing more flexible configuration options suitable for various application scenarios such as IoT smart devices and industrial control.

This article will take the Air780EHM core board as an example to share an SFUD application example; this example is also applicable to the Air780EHV and Air780EGH series products.

1

Preparation Work

  • Air780EHM core board kit

  • SPI Flash module

    Note: A SPI Flash module that supports the SFUD standard is required; this article uses the W25Q32 for demonstration.

  • Type-C USB data cable

  • PC with Windows 10 or above

Universal Driver Library for Serial SPI Flash: SFUD Application Example

Universal Driver Library for Serial SPI Flash: SFUD Application Example

The Air780EHM core board is connected to the computer via a Type-C USB data cable; it supports USB power supply, and please switch the power switch next to the USB to the ON position during use.

Universal Driver Library for Serial SPI Flash: SFUD Application Example

The Air780EHM core board is connected to the SPI Flash module via Dupont wires, with the corresponding pin connection method shown in the diagram below:

Universal Driver Library for Serial SPI Flash: SFUD Application Example

2

Latest Source Code Download

The latest demo has been uploaded to the source code repository:https://gitee.com/openLuat/LuatOS/tree/master/module/Air780EHM_Air780EHV_Air780EGH/demo/sfud

The sfud_test.lua code is shown in the diagram below; for the complete demo, please refer to the source code repository.

Universal Driver Library for Serial SPI Flash: SFUD Application Example

Related Notes:

In sfud_test.lua, the variables test_sfud_raw and test_sfud_mount control whether to read and write Flash through the SFUD interface or to mount it as an SFUD LFS file system and operate on files in the SFUD LFS file system through related file system interfaces.

Both methods can be used simultaneously, but care must be taken to design the addresses for direct writing via SFUD and the offsets when mounting SFUD LFS to avoid conflicts (note that the offset must be a multiple of 64k).

3

Example Run Results

The Air780EHM core board is programmed with the kernel firmware and demo script code via LuaTools. After successful programming, it runs on startup, and the run results can be viewed through the LuaTools log.

3.1 Directly Operate Flash via SFUD Native Interface:

  • Write string:luatos-sfud1234567890123456789012345678901234567890

  • Then read the first 4 bytes of data.

The result is shown in the diagram below:

Universal Driver Library for Serial SPI Flash: SFUD Application Example

3.2 Mount Flash Device as SFUD LFS File System:

After successfully mounting the Flash device as an SFUD LFS file system, we verified the entire process through standardized file management interfaces.

Universal Driver Library for Serial SPI Flash: SFUD Application Example

The log output shows that the file system mounting process was completed smoothly, and core operations such as file read/write, content append, and file deletion were all executed stably, with no abnormal error messages during the entire interaction process, fully validating the functional integrity of the SFUD LFS file system in embedded storage scenarios.

Universal Driver Library for Serial SPI Flash: SFUD Application Example

That’s all for today’s content! If you have any questions regarding IoT development selection, feel free to join the technical discussion group or contact the person in charge for further discussion.

For more of the latest development materials, please refer to the Hezhuo Resource Center:

—— docs.openluat.com

Universal Driver Library for Serial SPI Flash: SFUD Application Example

▼ Learn More About Hezhuo ▼

4G+ positioning + WiFi + Bluetooth, Air8000 complete development boardNew products: Air8101 core board + accessory board

Hezhuo low-power 4G module, adding 4 more hardcore new products

Universal Driver Library for Serial SPI Flash: SFUD Application Example

Leave a Comment