Filesystem AT Commands#
This section describes AT commands for file system operations on the SiWx91x device using the LittleFS file system.
Commands#
fs-format#
Format the file system on the SiWx91x device.
Command Format#
at+fs-formatRelated SDK API
lfs_format in lfs.h
Pre-conditions#
None
Parameters#
None
Response#
OKon successERROR <error code>in case of failure. Possible error codes are the same as those returned by thelfs_formatAPI in lfs.h.
Notes#
The
sl_si91x_littlefs_qspi_initAPI in sl_si91x_littlefs_hal.h initializes the file system when the firstfs-command is invoked.The
SL_SI91X_EXT_TCP_IP_SSL_16K_RECORDbit insl_wifi_system_boot_configuration_t::boot_config.ext_tcp_ip_feature_bit_map is set to 1 in the device configuration structure used by the net-init command to allow large data HTTPS downloads.
Examples#
at+fs-format # Format the file system
OKfs-mount#
Mount the file system on the SiWx91x device.
Command Format#
at+fs-mountRelated SDK API
lfs_mount in lfs.h
Pre-conditions#
None
Parameters#
None
Response#
OKon successERROR <error code>in case of failure. Possible error codes are the same as those returned by thelfs_mountAPI in lfs.h.
Notes#
The
sl_si91x_littlefs_qspi_initAPI in sl_si91x_littlefs_hal.h initializes the file system when the firstfs-command is invoked.The
SL_SI91X_EXT_TCP_IP_SSL_16K_RECORDbit insl_wifi_system_boot_configuration_t::boot_config.ext_tcp_ip_feature_bit_map is set to 1 in the device configuration structure used by the net-init command to allow large data HTTPS downloads.
Examples#
at+fs-mount # Mount the filesystem
OKfs-unmount#
Unmount the file system and release allocated resources.
Command Format#
at+fs-unmountRelated SDK API
lfs_unmount in lfs.h
Pre-conditions#
Parameters#
None
Response#
OKon successERROR <error code>in case of failure. Possible error codes are the same as those returned by thelfs_unmountAPI in lfs.h.
Notes#
This command unmounts the file system and releases any allocated resources.
The file system becomes unavailable for file operations after unmounting.
Use when shutting down or when file system access is no longer needed.
Examples#
at+fs-unmount # Unmount the file system
OKfs-ls#
List files in a directory.
Command Format#
at+fs-ls=<path>Related SDK API
sl_si91x_littefs_dir_list in sl_si91x_littlefs_hal.h
Pre-conditions#
Parameters#
path#
A string specifying the path of the directory to list.
Response#
OK <entry-count> <entry-name1> <is-dir1> <entry-name2> <is-dir2> ... <entry-nameN> <is-dirN>on success, where:<entry-count>is the number of file/directory entries in the directory<entry-name1>through<entry-nameN>are the names of the file/directory entries in the directory, whereN=<entry-count><is-dir1>through<is-dirN>indicates whether each entry is a directory (1) or file (0)
OK 0when the directory is empty (no entries)ERROR <error code>in case of failure. Possible error codes are the same as those returned by thesl_si91x_littefs_dir_listAPI in sl_si91x_littlefs_hal.h.
Examples#
at+fs-ls="/config" # List entries in "/config" directory
OK 2 config.txt 0 backup.txt 0
at+fs-ls="/" # List entries in root directory
OK 3 config 1 logs 1 temp.txt 0
at+fs-ls="/empty" # List entries in empty directory
OK 0fs-fopen#
Open a file on the SiWx91x device file system.
Command Format#
at+fs-fopen=<path>,<flags>Related SDK API
lfs_file_open in lfs.h
Pre-conditions#
None
Parameters#
path#
A string specifying the path of the file to open.
flags#
File open flags that determine the mode in which the file is opened. These flags are values from the lfs_open_flags enum in lfs.h that are bitwise-ORed together to specify the desired file access mode.
Response#
OK <file-id>on success, where<file-id>is a unique identifier for the opened fileERROR <error code>in case of failure. Possible error codes are the same as those returned by thelfs_file_openAPI in lfs.h.
Notes#
The
sl_si91x_littlefs_qspi_initAPI in sl_si91x_littlefs_hal.h initializes the file system when the firstfs-command is invoked.The
SL_SI91X_EXT_TCP_IP_SSL_16K_RECORDbit insl_wifi_system_boot_configuration_t::boot_config.ext_tcp_ip_feature_bit_map is set to 1 in the device configuration structure used by the net-init command to allow large data HTTPS downloads.Use the file ID returned by this command for all subsequent file system operations on the same file.
The file remains open until you explicitly close it using the appropriate close command.
You can open multiple files simultaneously, each with a unique file ID.
Examples#
at+fs-fopen="/config.txt",1 # Open file "/config.txt" for reading, returns file ID
OK 1fs-fseek#
Change the position of an open file to a specified offset.
Command Format#
at+fs-fseek=<file-id>,<offset>,<whence>Related SDK API
lfs_file_seek in lfs.h
Pre-conditions#
Parameters#
file-id#
The unique identifier of the file to seek within, returned by a previous fs-fopen command.
offset#
The number of bytes to offset from the position specified by the whence parameter.
whence#
The reference point for the offset. Contains a numeric value that corresponds to one of the values of the lfs_whence_flags enum in lfs.h.
Response#
OK <position>on success, where<position>is the new position of the file relative to the beginningERROR <error code>in case of failure. Possible error codes are the same as those returned by thelfs_file_seekAPI in lfs.h.
Notes#
The
whenceparameter determines how the offset is interpreted relative to the current file position.The returned
<position>is always relative to the beginning of the file, even when thewhenceparameter specifies anoffsetrelative to a position other than the beginning of the file.
Examples#
at+fs-fseek=1,100,0 # Seek to position 100 from the beginning of file with ID 1
OK 100fs-fsize#
Get the size of an open file.
Command Format#
at+fs-fsize=<file-id>Related SDK API
lfs_file_size in lfs.h
Pre-conditions#
Parameters#
file-id#
The unique identifier of the file to query, returned by a previous fs-fopen command.
Response#
OK <size>on success, where<size>is the size of the file in bytesERROR <error code>in case of failure. Possible error codes are the same as those returned by thelfs_file_sizeAPI in lfs.h.
Notes#
The size is equivalent to fs-fseek with position 0 from the end of the file.
The file size may change if another operation writes to the file.
Examples#
at+fs-fsize=1 # Get size of file with ID 1
OK 1024fs-frewind#
Change the position of an open file to the beginning.
Command Format#
at+fs-frewind=<file-id>Related SDK API
lfs_file_rewind in lfs.h
Pre-conditions#
Parameters#
file-id#
The unique identifier of the file to rewind, returned by a previous fs-fopen command.
Response#
OKon successERROR <error code>in case of failure. Possible error codes are the same as those returned by thelfs_file_rewindAPI in lfs.h.
Notes#
This command is equivalent to fs-fseek with position 0 from the beginning of the file.
Examples#
at+fs-frewind=1 # Rewind file with ID 1 to the beginning
OKfs-fread#
Read data from an open file on the SiWx91x device file system.
Command Format#
at+fs-fread=<file-id>,<size>Related SDK API
lfs_file_read in lfs.h
Pre-conditions#
Parameters#
file-id#
The unique identifier of the file to read from, returned by a previous fs-fopen command.
size#
The number of bytes to read from the file.
Response#
OK <bytes-read> <buffer>on success, where<bytes-read>is the number of bytes read from the file and<buffer>contains the data read from the file.<buffer>is not terminated by aCR-LF(carriage return-line feed) sequence but instead contains exactlybytes-readnumber of characters.ERROR <error code>in case of failure. Possible error codes are the same as those returned by thelfs_file_readAPI in lfs.h.
Notes#
The actual number of bytes read may be less than the requested size if the end of file is reached.
Reading from a file advances the file position by the number of bytes read.
Examples#
at+fs-fread=1,512 # Read 512 bytes from file with ID 1
OK 34 Hello World! This is the content of the filefs-fwrite#
Write data to an open file on the SiWx91x device file system.
Command Format#
at+fs-fwrite=<file-id>,<size>Related SDK API
lfs_file_write in lfs.h
Pre-conditions#
Parameters#
file-id#
The unique identifier of the file to write to, returned by a previous fs-fopen command.
size#
The number of bytes to write to the file.
Response#
ERROR 1on failing to enter data mode.OKon successfully entering data mode.On receiving this response, you must transmit
sizenumber of characters.As soon as the specified number of characters is transmitted, the data is written and one of the following responses is returned:
OK <bytes-written>on success, where<bytes-written>is the number of bytes actually written to the fileERROR <error code>in case of failure. Possible error codes are the same as those returned by thelfs_file_writeAPI in lfs.h.
Notes#
The file is not updated on the storage until either
fs-fsync(not currently supported) or fs-fclose is called.The actual number of bytes written may be less than the requested size.
Writing to a file advances the file position by the number of bytes written.
Examples#
at+fs-fwrite=1,23 # Write 23 bytes to file with ID 1
OK # Successfully entered data mode
<transmit 23 characters> # Transmit exactly 23 characters as the data to write
OK 23 # Data successfully written, 23 bytes writtenfs-ftrunc#
Truncate the size of an open file to the specified size.
Command Format#
at+fs-ftrunc=<file-id>,<size>Related SDK API
lfs_file_truncate in lfs.h
Pre-conditions#
Parameters#
file-id#
The unique identifier of the file to truncate, returned by a previous fs-fopen command.
size#
The new size in bytes to which the file should be truncated.
Response#
OKon successERROR <error code>in case of failure. Possible error codes are the same as those returned by thelfs_file_truncateAPI in lfs.h.
Examples#
at+fs-ftrunc=1,100 # Truncate file with ID 1 to 100 bytes
OKfs-fclose#
Close an open file and release allocated resources.
Command Format#
at+fs-fclose=<file-id>Related SDK API
lfs_file_close in lfs.h
Pre-conditions#
Parameters#
file-id#
The unique identifier of the file to close, returned by a previous fs-fopen command.
Response#
OKon successERROR <error code>in case of failure. Possible error codes are the same as those returned by thelfs_file_closeAPI in lfs.h.
Notes#
Any pending writes are automatically written out to storage as though
fs-fsynchad been called.All allocated resources for the file are released.
The file ID becomes invalid after closing and cannot be used for subsequent operations.
Examples#
at+fs-fclose=1 # Close file with ID 1
OKfs-fremove#
Remove a file or directory from the file system.
Command Format#
at+fs-fremove=<path>Related SDK API
lfs_remove in lfs.h
Pre-conditions#
Parameters#
path#
A string specifying the path of the file or directory to remove.
Response#
OKon successERROR <error code>in case of failure. Possible error codes are the same as those returned by thelfs_removeAPI in lfs.h.
Notes#
The
sl_si91x_littlefs_qspi_initAPI in sl_si91x_littlefs_hal.h initializes the file system when the firstfs-command is invoked.The
SL_SI91X_EXT_TCP_IP_SSL_16K_RECORDbit insl_wifi_system_boot_configuration_t::boot_config.ext_tcp_ip_feature_bit_map is set to 1 in the device configuration structure used by the net-init command to allow large data HTTPS downloads.If removing a directory, it must be empty (no files or subdirectories).
The operation is irreversible - removed items cannot be recovered.
Examples#
at+fs-fremove="/config.txt" # Remove file "/config.txt"
OK
at+fs-fremove="/temp" # Remove empty directory "/temp"
OK