Skip to main content
Skip table of contents

Flash File System Integration Guide

The following are the steps to integrate or enable AWE Flash File System. Make sure the flash device is fully erased for the first time before enabling AWE Flash File System.

  1. Define the following macros corresponding to flash memory size in bytes, erasable block size and the start offset for the Flash File System. Make sure the start offset does not overlap with other applications usage. It is recommended to use the free space in the flash from the end. Following are the example macros of a 64MB flash device:

    CODE
    /* ----------------------------------------------------------------------
    ** Specify flash memory available for flash file system
    ** ------------------------------------------------------------------- */
    #define FLASH_MEMORY_SIZE_IN_BYTES 0x4000000
    #define ERASEABLE_SECTOR_SIZE 0x10000
    #define FILE_SYSTEM_START_OFFSET 0xB0000
    #define SECTOR_ERASE_TIME_MS	400
  2. Declare a global AWE Flash File System instance:

    CODE
    /** Flash file system instance */
    AWEFlashFSInstance g_AWEFlashFSInstance;
  3. Initialize global AWE Flash File System instance to zero:

    CODE
    // Setup the flash file system */
    memset(&g_AWEFlashFSInstance, 0, sizeof(AWEFlashFSInstance) );
  4. Initialize the callbacks for ‘cbInit’, ‘cbEraseSector’, ‘cbFlashWrite’ and ‘cbFlashRead’:

    CODE
    g_AWEFlashFSInstance.cbInit = &usrInitFlashFileSystem;
    g_AWEFlashFSInstance.cbEraseSector = &usrEraseFlashMemorySector;
    g_AWEFlashFSInstance.cbFlashWrite = &usrWriteFlashMemory;
    g_AWEFlashFSInstance.cbFlashRead = &usrReadFlashMemory;
  5. Initialize flash memory size, erasable block size, start offset and block erase time:

    CODE
    g_AWEFlashFSInstance.flashSizeInBytes = FLASH_MEMORY_SIZE_IN_BYTES;
    g_AWEFlashFSInstance.flashErasableBlockSizeInBytes = ERASEABLE_SECTOR_SIZE;
    g_AWEFlashFSInstance.flashStartOffsetInBytes = FILE_SYSTEM_START_OFFSET;
    g_AWEFlashFSInstance.flashEraseTimeInMs = (INT32)((FLOAT32)((( (FLASH_MEMORY_SIZE_IN_BYTES - FILE_SYSTEM_START_OFFSET)/ ERASEABLE_SECTOR_SIZE)*SECTOR_ERASE_TIME_MS/1000) + 0.5f) + 5);
  6. Initialize the Flash File System by calling awe_initFlashFS:

    CODE
    awe_initFlashFS(&g_AWEInstance, &g_AWEFlashFSInstance);
  7. Assign pFlashFileSystem in AWE Instance to Flash File System instance:

    CODE
    g_AWEInstance.pFlashFileSystem = &g_AWEFlashFSInstance;
  8. Define callback functions for ‘Init’, ‘Erase’, ‘Write’ and ‘Read’:

    CODE
    {
    	// Implement any flash specific initializations
    	return 1;
    }   // End usrInitFlashFileSystem
    
    
    ///-----------------------------------------------------------------------------
    /// @name  BOOL usrReadFlashMemory(UINT32 nAddress, UINT32 * pBuffer, UINT32 nDWordsToRead)
    /// @brief Read 4-byte words from flash memory
    ///
    /// @param[in]	UINT32  nAddress - address in flash to start reading
    /// @param[in]	UINT32 *pBuffer  - buffer to read into
    /// @param[in]	UINT32  nDWordsToRead - number of 4-bytes elements to read
    ///
    /// @retval  	SUCCESS - read succeeded
    /// @retval 	FAILURE - read failed
    ///-----------------------------------------------------------------------------
    BOOL usrReadFlashMemory(UINT32 nAddress, UINT32 * pBuffer, UINT32 nDWordsToRead)
    {
    	BOOL bSuccess = 0;
    
    	// Check for the count zero and skip remaining
    	if(nDWordsToRead == 0)
    		return 1;
    
    	// Flash specific read implementation
    
    }   // End usrReadFlashMemory
    
    
    
    
    
    ///-----------------------------------------------------------------------------
    /// @name  BOOL usrWriteFlashMemory(UINT32 nAddress, UINT32 * pBuffer, UINT32 nDWordsToWrite)
    /// @brief Write 4-byte words to flash memory
    ///
    /// @param[in]	UINT32  nAddress - address in flash to start writing
    /// @param[in]	UINT32 * pBuffer  - buffer to write into
    /// @param[in]	UINT32  nDWordsToWrite - number of 4-bytes elements to write
    ///
    /// @retval  	SUCCESS - write succeeded
    /// @retval 	FAILURE - write failed
    ///-----------------------------------------------------------------------------
    BOOL usrWriteFlashMemory(UINT32 nAddress, UINT32 * pBuffer, UINT32 nDWordsToWrite)
    {
    	BOOL bSuccess = 0;
    
    	// Check for the count zero and skip remaining
    	if(nDWordsToWrite == 0)
    		return 1;
    
    	// Flash device write specific implementation
    
    }   // End usrWriteFlashMemory
    
    
    
    ///-----------------------------------------------------------------------------
    /// @name  BOOL usrEraseFlashSector(UINT32 nStartingAddress, UINT32 nNumberOfSectors)
    /// @brief Erase flash memory starting at address for number of sectors
    ///
    /// @param[in]	UINT32  nStartingAddress - address in flash to start erasing
    /// @param[in]	UINT32  nNumberOfSectors  - number of flash memory sectors to erase
    ///
    /// @retval  	SUCCESS - erase succeeded
    /// @retval 	FAILURE - erase failed
    ///-----------------------------------------------------------------------------
    //AWE_OPTIMIZE_FOR_SPEED
    BOOL usrEraseFlashSector(UINT32 nStartingAddress, UINT32 nNumberOfSectors)
    {
        UINT32 nSectorAddress, index, nSector;
        ERROR_CODE ErrorCode = NO_ERR;
    
    
        nSectorAddress = nStartingAddress;
    
        // Loop through number of sectors and erase each sector
        for (index = 0; index < nNumberOfSectors; index++)
        {
        	// Flash device specific sector erase implementation
    
    	nSectorAddress += ERASEABLE_SECTOR_SIZE;
        }
    
    	return 1;
    
    }	// End usrEraseFlashMemorySector

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.