Synergy Software Package User's Manual
FileX on Block Media

FileX On Block Media Framework Module Introduction

The FileX Port on Media Framework module supports the Azure RTOS FileX system, a complete FAT and exFAT format media and a file management system for deeply embedded applications. FileX is highly optimized for both size and performance.

FileX On Block Media Framework Module Features

Single Partition (Uses total available memory size):

  • Supports FAT32, FAT16, FAT12 and exFAT filesystems
  • Supports single FAT and exFAT partition operations in all SSP block media, that is, sf_block_media_lx_nor, sf_block_media_sdmmc, sf_block_media_qspi and sf_block_media_ram.
  • Multiple FileX objects (that is, media, directories, and files, only limited by available memory)
  • Dynamic FileX object creation/deletion
  • Flexible memory usage
  • Size scales automatically
  • Small footprint
  • Complete integration with ThreadX

Multi Partition:

  • Supports FAT32, FAT16 and exFAT filesystem.
  • Supports the creation of any number of partition on single physical media,  and supports all other fileX operations on them, for underlying block media sf_block_media_lx_nor and sf_block_media_sdmmc.
  • MBR/EBR support with visibility of partitions under Windows OS environment.
  • Each partition can be operated-on independently of other partitions.
  • Provides following operations on synergy platform for FAT and exFAT filesystem:
    1. Format/re-format
    2. open
    3. close
    4. write
    5. read
fx_bm_BD.png
FileX On Block Media Framework Module Block Diagram

FileX On Block Media Framework Module APIs Overview

The FileX On Block Media Framework provides access to all the FileX APIs used to create the file system, access files and directories and manage the file system. The full set of FileX API functions, their parameters, operation and example use can be found in the FileX User's Manual. Some examples are shown below to provide some background for better understanding the rest of the descriptions of the FileX on Block media framework module.

FileX On Block Media Framework Module API Summary (Selected Examples Only)

Function Name Example API Call and Description
fx_directory_attributes_read fx_directory_attributes_read(&my_media, "mydir", &attributes);
Reads the directory's attributes from the specified media.
fx_file_open fx_file_open(&my_media, &my_file, "myfile.txt", FX_OPEN_FOR_READ);
Open "myfile.txt" file for read.
fx_file_create fx_file_create(&my_media, "myfile.txt");
Create file with name "myfile.txt"
fx_media_read fx_media_read(&my_media, 22, my_buffer);
Read the logic sector (in this example from sector 22) from media specified by &my_media, and places it into the buffer my_buffer.
Note
For more complete descriptions refer to the FileX User's Manual available as described in the Reference Section later in this document.

FileX On Block Media Framework Module Operational Overview

  • FileX is a complete File Allocation Table (FAT) and exFAT format media and file management system for deeply embedded applications.
  • FileX supports an unlimited number of media devices at the same time, like sdmmc, FLASH managers, RAM disks & Multiple other physical devices
  • FileX is highly optimized for both size and performance.
  • FileX provides support to following media & file operations for single and multiple partitions on the synergy platform:  Format/re-format, open, close, write, read
  • The user will able to view the SSP created FAT and exFAT partitions and files in windows OS environment.
  • In fileX, when the exFAT support is enabled, the FAT functionalities would still be available

For single partition:

  • FileX supports contiguous file allocation and FAT12, FAT16 FAT32 & exFAT formats.
  • All underlying ssp block media ie sf_block_media_lx_nor, sf_block_media_sdmmc sf_block_media_qspi & sf_block_media_ram are supported

For multiple partitions:

  • FileX supports the creation of any number of partition on given single physical media
  • FileX supports only FAT16, FAT32 and exFAT formats.
  • The following underlying block medias are supported:  sf_block_media_lx_nor & sf_block_media_sdmmc.

FileX On Block Media Framework Module Important Operational Notes and Limitations

FileX On Block Media Framework Module Operational Notes

For Single Partition (Uses total available memory size):

The media must be formatted to either a FAT12, FAT16, FAT32 or exFAT file system before it can be opened, And media Format can be done prior to inserting the media (ie in a windows OS environment) or at project run time (using the "Format media" option in fileX properties in configurator).

For multi-partition:

  • The following media partition format are supported: FAT16, FAT32 or exFAT file system, and the multiple partition must be created in synergy platform first before it can be used in windows environment.
  • MBR sector i.e. sector 0 of the media must be erased (to erase all the existing partitions in the media), before creating new partitions in the media.
  • At least one sector must be left before each EBR partition offset to accommodate the EBR sector, and at least one sector must be left before the first partition to accommodate the MBR sector.
  • The auto-initialization for all the partitions must be disabled, and the partitions must be formatted and opened in the main entry function in application.

FileX On Block Media Framework Module Limitations

For Single partition:

  • The exFAT file system is not supported on the sf_block_media_qspi framework (note: the user can use the sf_block_media_lx_nor instead to use the same qspi flash memory)
  • For certain "total sectors" values in fileX properties, the media format in SSP application returns success, but the formatted media fails to open in the SSP application and in the windows OS environment (the user workaround for this is to increase the "Sector per cluster" value in filex properties).
  • For exFAT single partition, If the block media is partially exfat formatted (ie fileX configurator option "total_sectors"<the total sectors in block media), the sd card media opens fine in the board, file operation in the board also works fine, but the media open fails in a PC windows environment (the user workaround for this is to filex format the media in the multiple of 1gb or the complete block media)

For Multiple partition:

  • Partitions that are created, formatted, deleted or re-sized in any OS (for example the sd card partitions created/formatted in windows environment ), when this media partitions is used with synergy platform, the SSP application will give undesired results
  • Interface to below block media drivers is not supported:
    • sf_block_media_qspi (Users can alternately use sf_block_media_lx_nor)
    • sf_block_media_ram
  • Auto initialization option in fileX properties is not supported, and must be disabled.
  • USBX mass storage is not supported.
  • The "Bytes per sector" in fileX properties is only supported for default value ie 512 bytes

Refer to the most recent SSP Release Notes for any additional operational limitations for this module.

Including the FileX On Block Media Framework Module in an Application

This section describes how to include the FileX on Block Media Framework module in an application using the SSP configurator.

Note
It is assumed you are familiar with creating a project, adding threads, adding a stack to a thread and configuring a block within the stack. If you are unfamiliar with any of these items, refer to the first few chapters of the SSP User's Manual to learn how to manage each of these important steps in creating SSP-based applications.

Following steps should be followed by the user for Single Partition (Used total available memory size): partitions:

To add the FileX on Block Media Framework module to an application, simply add it to a thread using the stacks selection sequence given in the following table.

FileX On Block Media Framework Module Selection Sequence

Resource ISDE Tab Stacks Selection Sequence
g_fx_media0FileXonBlock Media Threads New Stack> X-Ware > FileX on Block Media

When the FileX on Block Media Framework module is added to the thread stack as shown in the following figure, the configurator automatically adds any needed lower‑level modules. Any modules needing additional configuration information have the box text highlighted in Red. Modules with a Gray band are individual modules that stand alone. Modules with a Blue band are shared or common; they need only be added once and can be used by multiple stacks. Modules with a Pink band can require the selection of lower-level modules. (This is indicated in the block with the inclusion of this text.) If the addition of lower-level modules is required, the module description include Add in the text. Clicking on any Pink banded modules brings up the New icon and displays possible choices.

fx_bm_MS.png
FileX on Block Media Stacks

The Add Block Media Driver block must be filled in prior to generating the Synergy project code. There are multiple selections possible depending on the physical media targeted. Currently available media include RAM, LX NOR, QSPI, and SDMMC. Options may be different depending on what your target board and associated board support package (BSP) supports.

To enable the exFAT file system support in SSP, the user has to add the fileX source files to the project, and enable the “FileX Source" -&gt; “exFAT support" option in the fileX source configurator properties, and re-build the FileX project.

The following steps should be followed by the user for multiple partitions on the same/different media type:

  1. Select FileX from X-Ware
  2. Select FileX on Block Media
  3. Select Block media framework - sf_block_media_lx_nor or sf_block_media_sdmmc. For example, FileX instance g_fx_media0 is created and it selects lx_nor media type.
  4. Select the second Filex media instance. For example,g_fx_media1 created. For example, g_fx_media0 and g_fx_media1 represent the two partitions.
  5. From the second instance and onward, selecting SF_EL_FX module instance gives two options New and Use.

    fx_bm_new_use.png
  6. Use: If the user selects Use, the partition will be made on the media previously selected by FileX media instance (g_sf_el_fx0 selected lx_nor). For example, g_fx_media0 and g_fx_media1 represent partitions on the same media type lx_nor. 

    fx_bm_use.png
  7. New: If the user selects New, a new instance of SF_EL_FX is created. The user will have the choice to select the different media type. If the new instance of SF_EL_FX is chosen, a different media has to be selected for making the partition. For example: Select a third FileX media instance. Here g_fx_media2 is created. Here g_fx_media0 and g_fx_media1 have partitions on same media type with same instance of SF_EL_FX (g_sf_el_fx0). For g_fx_media2, a different instance of SF_EL_FX is selected (g_sf_el_fx1). g_fx_media2 selects a new instance of SF_EL_FX module (g_sf_el_fx1) which selects SDMMC block media framework. Here, g_fx_media0 and g_fx_media1 have partitions on media type qspi memory. g_fx_media2represents the partition on SDMMC framework.)

    fx_bm_new.png
  8. For g_fx_media3, the user has the choice to select Use (for SF_EL_FX module) or New for a different media type.

Configuring the FileX On Block Media Framework Module

 The SSP configuration window automatically identifies (by highlighting the block in red) any required configuration selections, such as interrupts or operating modes, which must be configured for lower-level modules for successful operation. Only properties that can be changed without causing conflicts are available for modification. Other properties are locked and not available for changes and are identified with a lock icon for the locked property in the Properties window in the ISDE. This approach simplifies the configuration process and makes it much less error-prone than previous manual approaches to configuration. The available configuration settings and defaults for all the user-accessible properties are given in the Properties tab within the SSP Configurator and are shown in the following tables for easy reference.

Note
You may want to open your ISDE, create the module and explore the property settings in parallel with looking over the following configuration table values. This helps to orient you and can be a useful hands-on approach to learning the ins and outs of developing with SSP.

Configuration Settings for the FileX On Block Media Framework Module

ISDE Property Value Description
Name g_fx_media0 Module name.
Format media during initialization Enable, Disable
Default: Disabled
Select to automatically format the media during initialization.
File System is on block media True, False
Default: True
This setting will use code that reads sector size and count from the media device before formatting, if true. If set to false, the format function will use the sector size and count from configuration below.
Formatting Options
   Volume Name Volume 1 This is the volume name to use when formatting the media device. It should be no longer than 11 characters.
   Number of FATs 1 Number of File Allocation Tables.
   Directory Entries Default: 256 Number of directory entries in the root directory.
   Hidden Sectors 0 Number of hidden sectors.
   Total Sectors 3751936 Total number of sectors in the media.
Note
When "File System is on Block media" property is set to false, enter appropriate total sector.
   Bytes per Sector 512 Sector size to format, when using the format function. "File System is on SDMMC" must be disabled for this value to be used.
Note
When selected QSPI as media, Bytes per sector must be at least 4096.
   Sectors per Cluster 1 Sectors per cluster. This value is not used if "File System is on SDMMC" disabled.
   Volume Serial Number 12345 Serial number to be used for this volume. Only used if Format media during initialization is enabled. Used in exFAT media format only.
   Boundary unit 128 Physical data area alignment size, in number of sectors. Only used if Format media during initialization is enabled. Used in exFAT media format only.
Working media memory size 512 This is the number of bytes FileX uses to read and write to the media. It should be at least the size of one sector.
Note
'Working media memory size' must be equal to or greater than 'Block size of media in bytes'. When selected QSPI as media, then working media memory size must be at least 4096 or greater.
Name of generated initialization function fx_media_init0 Name of the initialization function that is generated by SSP.
Auto Initialization Enable, Disable
Default: Enable
Select to enable or disable auto initialization.
Note
 For multi partition Auto initialization and media format during initialization should be disabled.
For multi partition, "Bytes per sector" in filex properties is only supported for default value ie 512 bytes 
The example settings and defaults are for a project using the S7G2 Synergy MCU Group. Other MCUs may have different default values and available configuration settings.
Most of the property settings for lower-level modules are intuitive and usually can be determined by inspection of the associated properties window from the SSP configurator.

For Multi partitions:

sf_el_fx user configuration settings are require for multi-partition operation.

ISDE Property Value Description
Name g_sf_el_fx0 Module name.
Partition info callback A callback can be NULL or the name of the user-defined function. If partitions exist and the system got reset, user callback specifies the partition offset/base address. This callback is called while opening the partition.
Total partitions  >1 The number of partitions users wanted to make on the media.
  1. Partition info callback: Partition will be open as per user requirement by setting partition info callback to user define function or by setting it to NULL value it will open partitions in linear manner.
  2. Total partitions: Total partition specifies the desired number of partitions. Values 0 and 1 represent a single partition. Any value more than 1 indicates the required partition.

Configuration Settings for the FileX On Block Media Framework Lower-Level Modules

Only a small number of settings must be modified from the default for the IP layer and lower-level drivers as indicated via the red text in the thread stack block. Notice that some of the configuration properties must be set to a certain value for proper framework operation and are locked to prevent user modification. The following table identifies all the settings within the properties section for the module:

Configuration Settings for the Block Media Framework on sf_block_media_sdmmc

ISDE Property Value Description
Parameter Checking BSP, Enabled, Disabled

Default: BSP
Enable or disable the parameter checking.
Name g_sf_block_media_sdmmc0 Module name.
Block size of media in bytes 512 Specify the size of a block in bytes.
Note
The example settings and defaults are for a project using the S7G2 Synergy MCU Group. Other MCUs may have different default values and available configuration settings.

Configuration Settings for the SDMMC HAL Module on r_sdmmc

ISDE Property Value Description
Parameter Checking BSP, Enabled, Disabled

Default: BSP
Enable or disable parameter error checking.
Name g_sdmmc0 The name to be used for SDMMC module control block instance. This name is also used as the prefix of the other variable instances.
Channel 0 Select the channel.
Media Type Embedded, Card

Default: Embedded
Media is a card or an embedded device. This allows to firmware to know whether to look for card insertion/removal and write protect pins.
Bus Width 1 Bit, 4 Bits, 8 Bits

Default: 4 Bits
Data bus with as defined by hardware interface. (8 Bits for eMMC only)
Block Size 512 Block size selection.
Card Detection Not Used, CD Pin

Default: CD Pin
Card detection selection.
Callback NULL (Not required if using Filex) Set to name of user callback function. Provides event that caused interrupt: SDMMC_EVENT_CARD_REMOVED, SDMMC_EVENT_CARD_INSERTED, SDMMC_EVENT_ACCESS, SDMMC_EVENT_SDIO, SDMMC_EVENT_TRANSFER_COMPLETE, SDMMC_EVENT_TRANSFER_ERROR
Access Interrupt Priority Priority 0 (highest), Priority 1:14, Priority 15 (lowest - not valid if using ThreadX)

Default: Priority 12
Access interrupt priority selection.
Card Interrupt Priority Priority 0 (highest), Priority 1:14, Priority 15 (lowest - not valid if using ThreadX), Disabled

Default: Disabled
Card interrupt priority selection.
DTC Interrupt Priority Priority 0 (highest), Priority 1:14, Priority 15 (lowest - not valid if using ThreadX), Disabled

Default: Disabled
DTC interrupt priority selection.
Note
The example settings and defaults are for a project using the S7G2 Synergy MCU Group. Other MCUs may have different default values and available configuration settings.

FileX Port Block Media Framework Module Clock Configuration

The SDHI uses the PCLKA for its clock source. There is no need to configure the clock specifically for the SDMMC peripheral unless you need to optimize the data rate. The SDMMC driver selects the appropriate built-in divider based on the PCLKA frequency and the maximum clock rate allowed by the SD, SDIO or eMMC device obtained at media device initialization.

FileX Port Block Media Framework Module Pin Configuration

Use the e2 studio pin configurator to configure the I/O pins for the target media peripheral. The following description applies to the SDHI peripheral used for SDMMC media. Other media will require similar pin settings, and these are easily determined using their associated pin selection sequence in the Synergy Configurator. Consult the appropriate HAL driver section in the SSP User's Manual for additional details.

For SDMMC media, the drive capacity for each pin should be set to "Medium" or "High" for most boards and high-speed memory and SDIO devices.  The following table illustrates the method for selecting the pins within the SSP configuration window and the subsequent table provides an example selection for the module pins.

Note
The operation mode selection determines what peripheral signals are available and what MCU pins are required.

Pin Selection Sequence for the SDHI Peripheral

Resource ISDE Tab Pin selection Sequence
SDHI Pins Select Peripherals> Storage:SHDI> SDHI0
Note
The selection sequence assumes that the SDHI0 is the desired hardware target for the driver.

Pin Configuration Settings for the SDHI Peripheral

Pin Configuration Property Settings Description
Operation Mode Disabled,
Custom,
SD_MMC 1 bit
SD_MMC 4 bit
MMC 8 bit

Default: Custom
Select mode as per application.
CLK None, P413

Default: P413
Clock pin.
CMD None, P412

Default: P412
Command pin.
DAT0-7 None, PXXX

Default: PXXX
Data pin.
CD None, P903

Default: P903
Card detection pin.
WP None, P414

Default: P414
Card write protection pin.
Note
The example values are for a project using the Synergy S7G2 MCU Group and the DK-S7G2 Kit. Other Synergy Kits and other Synergy MCUs may have different available pin configuration settings.

Using the FileX on Block Media Framework Module in an Application

The steps in using the FileX on Block Media Framework module in a typical application are:

  1. Initialize the media using the FileX API fx_system_initialize (FileX on Block Media calls it automatically if Auto Initialization property is set to Enabled in FileX Common on fx)
  2. Optionally, format/create a FAT media using the FileX API “fx_media_format", (or) format/create a exFAT media using the FileX API “fx_media_exFAT_format" (FileX on Block Media automatically formats the media using the auto-generated initialization function if its Format media during initialization property is set to Enabled).
  3. Open the media using the FileX API fx_media_open (FileX on Block Media opens the media automatically if its Auto Initialization property is set to Enabled)
  4. Create and delete files and directories as required using one of the FileX APIs (for example, fx_file_create, fx_file_delete, fx_directory_create, fx_directory_delete)
  5. Read from and write to files on the media as required using one of the FileX API (for example, fx_file_read or fx_file_write)
  6. Read from and write to the media directly as required using one of the FileX API (for example, fx_media_read or fx_media_write)
  7. Close the physical media using the FileX API fx_media_close
Note
After a successful fx_media_open call, all FileX file and directory related APIs can be used. Refer to the FileX User Guide for documentation on all available functions.

These common steps are illustrated in a typical operational flow in the following figure:

fx_bm_TA.png
Flow Diagram of a Typical FileX On Block Media Framework Module Application