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-format

Related SDK API#

lfs_format in lfs.h

Pre-conditions#

None

Parameters#

None

Response#

  • OK on success

  • ERROR <error code> in case of failure. Possible error codes are the same as those returned by the lfs_format API in lfs.h.

Notes#

  • The sl_si91x_littlefs_qspi_init API in sl_si91x_littlefs_hal.h initializes the file system when the first fs- command is invoked.

  • The SL_SI91X_EXT_TCP_IP_SSL_16K_RECORD bit in sl_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
OK

fs-mount#

Mount the file system on the SiWx91x device.

Command Format#

at+fs-mount

Related SDK API#

lfs_mount in lfs.h

Pre-conditions#

None

Parameters#

None

Response#

  • OK on success

  • ERROR <error code> in case of failure. Possible error codes are the same as those returned by the lfs_mount API in lfs.h.

Notes#

  • The sl_si91x_littlefs_qspi_init API in sl_si91x_littlefs_hal.h initializes the file system when the first fs- command is invoked.

  • The SL_SI91X_EXT_TCP_IP_SSL_16K_RECORD bit in sl_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
OK

fs-unmount#

Unmount the file system and release allocated resources.

Command Format#

at+fs-unmount

Related SDK API#

lfs_unmount in lfs.h

Pre-conditions#

fs-mount

Parameters#

None

Response#

  • OK on success

  • ERROR <error code> in case of failure. Possible error codes are the same as those returned by the lfs_unmount API 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
OK

fs-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#

fs-mount

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, where N = <entry-count>

    • <is-dir1> through <is-dirN> indicates whether each entry is a directory (1) or file (0)

  • OK 0 when the directory is empty (no entries)

  • ERROR <error code> in case of failure. Possible error codes are the same as those returned by the sl_si91x_littefs_dir_list API 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 0

fs-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 file

  • ERROR <error code> in case of failure. Possible error codes are the same as those returned by the lfs_file_open API in lfs.h.

Notes#

  • The sl_si91x_littlefs_qspi_init API in sl_si91x_littlefs_hal.h initializes the file system when the first fs- command is invoked.

  • The SL_SI91X_EXT_TCP_IP_SSL_16K_RECORD bit in sl_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 1

fs-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#

fs-fopen

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 beginning

  • ERROR <error code> in case of failure. Possible error codes are the same as those returned by the lfs_file_seek API in lfs.h.

Notes#

  • The whence parameter 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 the whence parameter specifies an offset relative 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 100

fs-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#

fs-fopen

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 bytes

  • ERROR <error code> in case of failure. Possible error codes are the same as those returned by the lfs_file_size API 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 1024

fs-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#

fs-fopen

Parameters#

file-id#

The unique identifier of the file to rewind, returned by a previous fs-fopen command.

Response#

  • OK on success

  • ERROR <error code> in case of failure. Possible error codes are the same as those returned by the lfs_file_rewind API 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
OK

fs-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#

fs-fopen

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 a CR-LF (carriage return-line feed) sequence but instead contains exactly bytes-read number of characters.

  • ERROR <error code> in case of failure. Possible error codes are the same as those returned by the lfs_file_read API 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 file

fs-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#

fs-fopen

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 1 on failing to enter data mode.

  • OK on successfully entering data mode.

    • On receiving this response, you must transmit size number 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 file

      • ERROR <error code> in case of failure. Possible error codes are the same as those returned by the lfs_file_write API 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 written

fs-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#

fs-fopen

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#

  • OK on success

  • ERROR <error code> in case of failure. Possible error codes are the same as those returned by the lfs_file_truncate API in lfs.h.

Examples#

at+fs-ftrunc=1,100        # Truncate file with ID 1 to 100 bytes
OK

fs-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#

fs-fopen

Parameters#

file-id#

The unique identifier of the file to close, returned by a previous fs-fopen command.

Response#

  • OK on success

  • ERROR <error code> in case of failure. Possible error codes are the same as those returned by the lfs_file_close API in lfs.h.

Notes#

  • Any pending writes are automatically written out to storage as though fs-fsync had 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
OK

fs-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#

fs-mount

Parameters#

path#

A string specifying the path of the file or directory to remove.

Response#

  • OK on success

  • ERROR <error code> in case of failure. Possible error codes are the same as those returned by the lfs_remove API in lfs.h.

Notes#

  • The sl_si91x_littlefs_qspi_init API in sl_si91x_littlefs_hal.h initializes the file system when the first fs- command is invoked.

  • The SL_SI91X_EXT_TCP_IP_SSL_16K_RECORD bit in sl_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