2017-01-16 23:08:35 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								Storage API
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								***** ***** *
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-09-06 19:12:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								:link_to_translation:`zh_CN:[中文]` 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-10-14 03:55:41 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								This section contains reference of the high-level storage APIs. They are based on low-level drivers such as SPI flash, SD/MMC.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-11-23 16:48:17 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-10-14 03:55:41 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								-  :doc: `Partitions API <partition>`  allow block based access to SPI flash according to the :doc: `/api-guides/partition-tables` .
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								-  :doc: `Non-Volatile Storage library (NVS) <nvs_flash>`  implements a fault-tolerant wear-levelled key-value storage in SPI NOR flash.
  
						 
					
						
							
								
									
										
										
										
											2022-11-23 16:48:17 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								-  :doc: `Virtual File System (VFS) <vfs>`  library provides an interface for registration of file system drivers. SPIFFS, FAT and various other file system libraries are based on the VFS.
  
						 
					
						
							
								
									
										
										
										
											2023-10-14 03:55:41 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								-  :doc: `SPIFFS <spiffs>`  is a wear-levelled file system optimized for SPI NOR flash, well suited for small partition sizes and low throughput
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								-  :doc: `FAT <fatfs>`  is a standard file system which can be used in SPI flash or on SD/MMC cards
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								-  :doc: `Wear Levelling <wear-levelling>`  library implements a flash translation layer (FTL) suitable for SPI NOR flash. It is used as a container for FAT partitions in flash.
  
						 
					
						
							
								
									
										
										
										
											2022-11-23 16:48:17 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-12-06 17:25:58 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Topics related to :doc: `Storage Security <storage-security>`  are described in separate section.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-11-23 16:48:17 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								..  note :: 
  
						 
					
						
							
								
									
										
										
										
											2023-07-18 17:16:41 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-10-14 03:55:41 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    It is suggested to use high-level APIs (`` esp_partition ``  or file system) instead of low-level driver APIs to access the SPI NOR flash.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-11-23 16:48:17 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-10-14 03:55:41 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    Due to the restriction of NOR flash and ESP hardware, accessing the main flash will affect the performance of the whole system. See :doc: `/api-reference/peripherals/spi_flash/index`  to learn more about the limitations.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-11-23 16:48:17 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-01-16 23:08:35 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								..  toctree :: 
  
						 
					
						
							
								
									
										
										
										
											2019-08-13 16:01:50 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    :maxdepth:  1 
 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-16 23:08:35 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-12-30 18:50:55 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    fatfs
 
							 
						 
					
						
							
								
									
										
										
										
											2024-05-07 23:54:05 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    fatfsgen
 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-30 18:50:55 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    mass_mfg.rst
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    nvs_flash
 
							 
						 
					
						
							
								
									
										
										
										
											2023-04-18 18:09:38 +05:30 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    nvs_encryption
 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-30 18:50:55 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    nvs_partition_gen.rst
 
							 
						 
					
						
							
								
									
										
										
										
											2022-04-14 12:08:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    nvs_partition_parse.rst
 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-30 18:50:55 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    sdmmc
 
							 
						 
					
						
							
								
									
										
										
										
											2022-11-23 16:48:17 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    partition
 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-30 18:50:55 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    spiffs
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    vfs
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    wear-levelling
 
							 
						 
					
						
							
								
									
										
										
										
											2023-12-06 17:25:58 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    storage-security.rst
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								..  list-table ::  Code examples for this API section
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    :widths:  25 75 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    :header-rows:  0 
 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-03 16:06:02 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-12-06 17:25:58 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    *  - **Link** 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      -  **Description** 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    *  - :doc: `FAT <fatfs>` 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      -
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    *  - :example: `<wear_levelling <storage/wear_levelling>` 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      -  Demonstrates using FATFS over wear leveling on internal flash.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    *  - :example: `ext_flash_fatfs <storage/ext_flash_fatfs>` 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      -  Demonstrates using FATFS over wear leveling on external flash.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    *  - :example: `fatfsgen <storage/fatfsgen>` 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      -  Demonstrates the capabilities of Python-based tooling for FATFS images available on host computers.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    *  - :doc: `Non-Volatile Storage library (NVS) <nvs_flash>` 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      -
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    *  - :example: `nvs_rw_blob <storage/nvs_rw_blob>` 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      -  Shows the use of the C-style API to read and write blob data types in NVS flash.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    *  - :example: `nvs_rw_value <storage/nvs_rw_value>` 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      -  Shows the use of the C-style API to read and write integer data types in NVS flash.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    *  - :example: `nvs_rw_value_cxx <storage/nvs_rw_value_cxx>` 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      -  Shows the use of the C++-style API to read and write integer data types in NVS flash.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    *  - :example: `nvsgen <storage/nvsgen>` 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      -  Demonstrates how to use the Python-based NVS image generation tool to create an NVS partition image from the contents of a CSV file.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    *  - :doc: `SPIFFS <spiffs>` 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      -
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    *  - :example: `spiffs <storage/spiffs>` 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      -  Shows the use of the SPIFFS API to initialize the filesystem and work with files using POSIX functions.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    *  - :example: `spiffsgen <storage/spiffsgen>` 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      -  Demonstrates the capabilities of Python-based tooling for SPIFFS images available on host computers.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    *  - :doc: `Partitions API <partition>` 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      -
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    *  - :example: `partition_api <storage/partition_api>` 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      -  Provides an overview of API functions to look up particular partitions, perform basic I/O operations, and use partitions via CPU memory mapping.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    *  - :example: `parttool <storage/parttool>` 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      -  Demonstrates the capabilities of Python-based tooling for partition images available on host computers.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    *  - :doc: `Virtual File System (VFS) <vfs>` 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      -
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    *  - :example: `littlefs <storage/littlefs>` 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      -  Shows the use of the LittleFS component to initialize the filesystem and work with a file using POSIX functions.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    *  - :example: `semihost_vfs <storage/semihost_vfs>` 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      -  Demonstrates the use of the VFS API to let an ESP-based device access a file on a JTAG-connected host using POSIX functions.