更换语言:
Contact Us
Home  ›  CooCox CoFlash › Flash Algorithm

CooCox CoFlash Flash Algorithm  

When there is no corresponding flash algorithm for your device, you have to write one yourself. Here we will introduce how to write a flash algorithm by yourself.

Quick Navigation:

 

What is a flash algorithm

The flash algorithm is a small piece of code that handles the actual writing to flash memory and a number of device information.

 

CoFlash mechanism

CoFlash mechanism
The following steps will be performed when program starts:
  1. CoFlash downloads the flash loader into target RAM.
  2. CoFlash reads the application code and write it into ram(image data buf).
  3. CoFlash starts execution of the flash driver.
  4. The driver programs the image data into flash memory.
  5. The flash program terminates.

 

Setting up your flash algorithm

  • Command line mode:by the “--driver=FILE” option.
  • GUI mode:special your algorithm file in the Flash Driver part on the config tab.

 

Composition

CoFlash Driver Composition

 

Building your own flash loader


  1. Install ARMGCC compiler.
  2. Make a copy of CoFlash\FlashAlgorithm\source\template, then rename it.
  3. Write you own FlashInit, FlashUnInit, FlashEraseChip, FlashEraseSector, FlashProgramPage, FlashVerify functions.
  4. Modify FLASH_CHIP's value to the file name of target algorithm in gccProject/makefile.
  5. Enter the gccProgject directory through the command line, run make command, then your algorithm file will be in the directory of FlashAlgorithm .

 

The flash algorithm API


Flash Device Description structure:

struct FlashSector
{
    unsigned long size;                                  // Sector Size in Bytes
    unsigned long addr;                                 // Address of Sector
};

// Flash Device Info
struct FlashDevice
{
    unsigned long type;                                  // Flash Device Type
    unsigned long baseAddr;                            // Flash Device Base Address
    unsigned long totalSize;                             // Flash Device Total Size(Bytes)
    unsigned long pageSize;                             // Page Size(Bytes)
    unsigned char initialVal;                              // Initial Vaule of Erased Memory
    struct FlashSector sectors[FLASH_SECTORS_NUM];   // Sectors
};

struct FlashAlgorithm
{
    unsigned long version;  
    // Algorithm Version (FLASH_FRAMEWORK_VERSION << 16 | YourVersion)
    char description[FLASH_ALGO_DESC_SIZE];    // Description of the Algorithm
    struct FlashDevice deviceInfo;
};

 If all the sectors in the flash have the same size, you only need to specify the size and set the sector address to an invalid value of 0xFFFFFFFF, just like the template example. Otherwise, you need to list all the sectors one by one.

FlashInit

int FlashInit (unsigned long baseAddr,unsigned long clk, unsigned long operateFuc)
* @brief           Initialize before Flash Programming/Erase Functions
* @param[in]    baseAddr     Flash device base address.
* @param[in]    clk              Flash program clock.
* @param[in]    operateFuc  Init for what operation                            (FLASH_OPT_ERASECHIP/FLASH_OPT_ERASESECTORS/FLASH_OPT_PROGRAMPAGE/ FLASH_OPT_VERIFY/ FLASH_OPT_BLANKCHECK).
* @param[out]  None
* @retval         0                All is OK.
* @retval         others         Some error occurs.
* @details        This function is called before flash programming/erase.

FlashUnInit

int FlashUnInit(unsigned long operateFuc)
* @brief           Un-Init after Flash Programming/Erase…  Functions
* @param[in]    operateFuc    Init for what operation                         (FLASH_OPT_ERASECHIP/FLASH_OPT_ERASESECTORS/FLASH_OPT_PROGRAMPAGE/ FLASH_OPT_VERIFY/ FLASH_OPT_BLANKCHECK).
* @param[out]  None
* @retval         0                  All is OK.
* @retval         others           Some error occurs.            
* @details        This function is called after flash programming/erase….

FlashEraseChip

int FlashEraseChip (void)
* @brief            Erase the full chip
* @param[in]     None
* @param[out]   None
* @retval          0              All is OK.
* @retval          others       Some error occurs.            
* @details     

FlashEraseSector

int FlashEraseSector (unsigned long sectorAddr)
* @brief             Erase the select Sector
* @param[in]      sectorAddr   Sector's start address.
* @param[out]    None
* @retval           0              All is OK.
* @retval           others       Some error occurs.            
* @details     

FlashProgramPage

int FlashProgramPage (unsigned long pageAddr, unsigned long size, unsigned char *buf)
* @brief             Proram a page
*@param[in]       pageAddr    Page's start address
*@param[in]       size           Page size
*@param[in]       buf            source buf point
*@param[out]     None
* @retval           0              All is OK.
* @retval           others       Some error occurs.            
* @details     

FlashVerify
optional function. When this function is absence, Colink will read flash memory directly to do verify.

int FlashVerify(unsigned long verifyAddr,unsigned long size,unsigned char *buf)

* @brief            Page Verify Function
* @param[in]     verifyAddr     Verify Start Address(Usually page start address)
* @param[in]     size             Verify size
* @param[in]     buf              source buf point
* @param[out]   None
* @retval          0                 Verify pass.
* @retval          others          Some error occurs or verify failed.            
* @details 

FlashBlankCheck
optional function. When this function is absence, Colink will read flash memory directly to do blank check.

int FlashBlankCheck (unsigned long checkAddr,unsigned long size)
* @brief             Page Blank Check Function
* @param[in]      checkAddr    Check Start Address(Usually page start address)
* @param[in]      size             Check size
* @param[out]    None
* @retval           0                Check pass.
* @retval           others         Some error occurs or Check failed.   
* @ details    
* @note             Sector can be significant.We check the page rather than the sector, having regard to the actual size of the ram.

© 2010 CooCox - Terms of Use         Business Model         Market             About us