Using the SFUD Component to Drive SPI Flash on S32K146 RT-Thread

This article is contributed by andeyqi

4 min readApr 11, 2025

Overview

Building upon the previous implementation of the SPI driver for the S32K146 RT-Thread (https://www.nxpic.org.cn/module/forum/thread-803087-1-1.html), we will now use the SFUD component to drive the SPI Flash. We have already implemented the SPI10 device driver, and we will utilize the SFUD component to interface with the SPI Flash.

SFUD (https://github.com/armink/SFUD) is an open-source universal driver library for serial SPI Flash. As the market for serial Flash expands, the diversity in specifications and commands across different Flash types increases. SFUD is designed to address these variations, enabling our products to support various brands and specifications of Flash, thereby enhancing the software’s reusability and scalability related to Flash functions. It also mitigates risks associated with Flash shortages or discontinuations affecting products.

The SFUD driver library is an open-source project available on GitHub (https://github.com/armink/SFUD), and it is already integrated into the RT-Thread system; we simply need to enable it for use.

Background of the JESD216 SFDP Standard

As the serial Flash market continues to expand, the number of commands, functionalities, and features for serial Flash devices is also increasing. However, the capabilities and characteristics of these devices vary significantly among manufacturers. For instance, while sector erase functionalities may support operations at 4KB, 32KB, and 64KB segments, the commands may differ between manufacturers, resulting in variations in functionality between their devices. Consequently, to accurately conduct compatibility testing or consider capacity upgrades, developers and designers need to meticulously review the product specifications of each serial Flash device. They must ensure pin configurations and definitions are consistent and that the required command functionalities are fully compatible. This can necessitate additional modifications to the underlying device driver software and, in some cases, even hardware changes, thus complicating project design, maintenance, and updates.

Thus, there is an urgent need for a standardized functionality parameter table for serial Flash devices, allowing developers and designers to clearly retrieve the features and characteristics of each serial Flash used. The new JEDEC standard JESD216 SFDP was conceived in such a market environment.

Below is the SFDP header structure software that allows reading of parameter information from the Flash for usage.

Use SFUD to Drive Flash

Enable SFUD in Menuconfig

To begin using SFUD to drive the Flash memory, you first need to enable SFUD in the menu configuration. After the configuration is set up, you can use test commands to probe the SPI Flash, and it should detect the 16MB Flash successfully.

msh />sf probe spi10
[D/SFUD] (D:\work\andeyqi_rtthread\rt-thread\components\drivers\spi\sfud\src\sfud.c:871) The flash device manufacturer ID is 0xC2, memo
[D/SFUD] (D:\work\andeyqi_rtthread\rt-thread\components\drivers\spi\sfud\src\sfud_sfdp.c:132) Check SFDP header is OK. The reversion is
[D/SFUD] (D:\work\andeyqi_rtthread\rt-thread\components\drivers\spi\sfud\src\sfud_sfdp.c:175) Check JEDEC basic flash parameter header
[D/SFUD] (D:\work\andeyqi_rtthread\rt-thread\components\drivers\spi\sfud\src\sfud_sfdp.c:203) JEDEC basic flash parameter table info:
[D/SFUD] (D:\work\andeyqi_rtthread\rt-thread\components\drivers\spi\sfud\src\sfud_sfdp.c:204) MSB-LSB 3 2 1 0
[D/SFUD] (D:\work\andeyqi_rtthread\rt-thread\components\drivers\spi\sfud\src\sfud_sfdp.c:207) [0001] 0xFF 0xF1 0x20 0xE5
[D/SFUD] (D:\work\andeyqi_rtthread\rt-thread\components\drivers\spi\sfud\src\sfud_sfdp.c:207) [0002] 0x07 0xFF 0xFF 0xFF
[D/SFUD] (D:\work\andeyqi_rtthread\rt-thread\components\drivers\spi\sfud\src\sfud_sfdp.c:207) [0003] 0x6B 0x08 0xEB 0x44
[D/SFUD] (D:\work\andeyqi_rtthread\rt-thread\components\drivers\spi\sfud\src\sfud_sfdp.c:207) [0004] 0xBB 0x04 0x3B 0x08
[D/SFUD] (D:\work\andeyqi_rtthread\rt-thread\components\drivers\spi\sfud\src\sfud_sfdp.c:207) [0005] 0xFF 0xFF 0xFF 0xFE
[D/SFUD] (D:\work\andeyqi_rtthread\rt-thread\components\drivers\spi\sfud\src\sfud_sfdp.c:207) [0006] 0xFF 0x00 0xFF 0xFF
[D/SFUD] (D:\work\andeyqi_rtthread\rt-thread\components\drivers\spi\sfud\src\sfud_sfdp.c:207) [0007] 0xEB 0x44 0xFF 0xFF
[D/SFUD] (D:\work\andeyqi_rtthread\rt-thread\components\drivers\spi\sfud\src\sfud_sfdp.c:207) [0008] 0x52 0x0F 0x20 0x0C
[D/SFUD] (D:\work\andeyqi_rtthread\rt-thread\components\drivers\spi\sfud\src\sfud_sfdp.c:207) [0009] 0xFF 0x00 0xD8 0x10
[D/SFUD] (D:\work\andeyqi_rtthread\rt-thread\components\drivers\spi\sfud\src\sfud_sfdp.c:215) 4 KB Erase is supported throughout the de
[D/SFUD] (D:\work\andeyqi_rtthread\rt-thread\components\drivers\spi\sfud\src\sfud_sfdp.c:234) Write granularity is 64 bytes or larger.
[D/SFUD] (D:\work\andeyqi_rtthread\rt-thread\components\drivers\spi\sfud\src\sfud_sfdp.c:245) Target flash status register is non-volat
[D/SFUD] (D:\work\andeyqi_rtthread\rt-thread\components\drivers\spi\sfud\src\sfud_sfdp.c:271) 3-Byte only addressing.
[D/SFUD] (D:\work\andeyqi_rtthread\rt-thread\components\drivers\spi\sfud\src\sfud_sfdp.c:305) Capacity is 16777216 Bytes.
[D/SFUD] (D:\work\andeyqi_rtthread\rt-thread\components\drivers\spi\sfud\src\sfud_sfdp.c:312) Flash device supports 4KB block erase. Co
[D/SFUD] (D:\work\andeyqi_rtthread\rt-thread\components\drivers\spi\sfud\src\sfud_sfdp.c:312) Flash device supports 32KB block erase. C
[D/SFUD] (D:\work\andeyqi_rtthread\rt-thread\components\drivers\spi\sfud\src\sfud_sfdp.c:312) Flash device supports 64KB block erase. C
[I/SFUD] Found a Macronix flash chip. Size is 16777216 bytes.
[D/SFUD] (D:\work\andeyqi_rtthread\rt-thread\components\drivers\spi\sfud\src\sfud.c:849) Flash device reset success.
[I/SFUD] sf_cmd flash device initialized successfully.
[I/SFUD] Probe SPI flash sf_cmd by SPI device spi10 success.

Upon checking the logs, the Parameter Table (0) confirms that the JEDEC Flash Parameter Tables match the descriptions found in the chip manual. This indicates that the SFUD component is correctly interfacing with the Flash memory, and the parameters have been read accurately.

Using test commands, the erase, read, and write operations on the Flash can be performed successfully.

JESD216 SFDP specification document: https://kdocs.cn/l/ce7ApUMAyUE7

--

--

RT-Thread IoT OS
RT-Thread IoT OS

Written by RT-Thread IoT OS

An Open-Source Community-Powered Real-Time Operating System (RTOS) Project! Let’s develop, DIY, create, share, and explore this new IoT World together!

No responses yet