This article from http://www.realview.com.cn/bbs/dispbbs.asp? Boardid = 2 & id = 1537 & page = 1
Embest Xu liangping
In realview MDK, The Flash burning algorithm is not common and is applicable to specific flash storage chips. Because there are many types of flash on the market, it is impossible for realview MDK to contain all flash chip burning programs. However, in specific applications, developers may not find the flash burning program they need in realview MDK. In this case, users must add their own flash burning programs. This method will be discussed in detail in this article.
The realview MDK has defined the flash burning algorithm interfaces added to it, including one structure describing the flash chip and six function definitions for flash chip operations. For details, refer to the following code.
Struct flashdevice {
Unsigned short vers; // architecture and version number;
Char devname [128]; // Device Name and description;
Unsigned short devtype; // device type, such as onchip, ext8bit, and ext16bit;
Unsigned long devadr; // The start address of the default device;
Unsigned long szdev; // total device capacity;
Unsigned long szpage; // page size;
Unsigned long res; // reserved for future extension;
Unsigned char valempty; // The value of the stored unit after flash erasure;
Unsigned long toprog; // The time when the paging function times out;
Unsigned long toerase; // time-out period of the Sector erasure function;
Struct flashsectors sectors [sector_num]; // array of the Start address and capacity of the sector.
};
Extern int Init (unsigned long ADR, unsigned long CLK, unsigned long FNC );
Extern int uninit (unsigned long FNC );
Extern int blankcheck (unsigned long ADR, unsigned long SZ, unsigned char Pat );
Extern int erasechip (void );
Extern int erasesector (unsigned long ADR );
Extern int programpage (unsigned long ADR, unsigned long SZ, unsigned char * BUF );
Extern unsigned long verify (unsigned long ADR, unsigned long SZ, unsigned char * BUF );
In realview MDK, the essence of the flash burning algorithm is to fill in the struct above and implement the six functions. As for how several functions are called by realview MDK, you don't have to worry about them. These functions are automatically managed by realview MDK. As long as the above content is correctly implemented, developers can download the program compiled by the realview MDK to their flash chips. The following describes how to add a Flash program:
1. Create an empty subfolder under C: "Keil" arm "Flash;
2. in the flash folder, select an existing file that is similar to the Flash algorithm you want to add (for example .. "arm" Flash "lpc_iap_256) copy to this new file and use this algorithm as the template of the new algorithm;
3. Rename the project file maid to indicate the new Flash ROM device name, as shown in figure 29F 400. Open uv2 with μ vision ide;
4. In the project-options for target-output dialog box, replace all output file names (for example, lpc_iap_256) with the new device names;
5. Edit the flashprg. c file and define function code for erasechip, eraseblock, and programblock. Compile the initialization and uninstallation Code required by the algorithm in the init and uninit functions;
6. Define the device parameters in the struct flashdevice struct in the flashdev. c file;
7. Re-compile the project. A flash Programming Algorithm in *. flx format will be generated in the C: "Keil" arm "Flash folder. This file is the added flash programming algorithm;
8. Use the Add button in configure flash download to add this programming algorithm file to the target application project.