hi can anybody provide me c code examples for flash erase and programming.
and tell me whether it is necessary to save the pages or that is optional.
will the below will do?
/* Page size array (512 instruction words) */
C_UBYTE Luilow_Page_Array[512];
C_UBYTE Luihigh_Page_Array[512];
C_UINT16 Luipage_Count;
/* Save Current page */
C_UINT16 SAV_TBLPAG = TBLPAG;
C_UINT16 *LppPM_Destination_Address = (C_UINT16 *)(Lul_Sector_Addr);
/* A dummy table write to any location in the page selects the address of
the row to be erased.
* The program memory must be erased at an even 512 instruction word
address boundary. Therefore,
* the 10 Least Significant bits of the table write program memory address
have no effect when
* a page is erased */
Luipage_flash_addr = (Lul_Sector_Addr & 0xFFFC00);
/* Save flash page data */
for(Luipage_Count=0; Luipage_Count<512; Luipage_Count++)
{
Luilow_Page_Array[Luipage_Count] = __builtin_tblrdl(Luipage_flash_addr+
(2 * Luipage_Count));
Luihigh_Page_Array[Luipage_Count]= __builtin_tblrdh(Luipage_flash_addr+
(2 * Luipage_Count)) & 0xFF;
}
/* Setup NVMCON to erase one page of Program Memory */
NVMCON=PAGE_ERASE;
/* Select the Page to be erased */
/* Upper byte address */
TBLPAG = ((Luiflash_addr>>16)&(0xFF));
/* Dummy write */
__builtin_tblwtl(Luipage_flash_addr, 0xFFFF);
/* Write the KEY Sequence */
NVMKEY=KEY_SEQ_1;
NVMKEY=KEY_SEQ_2;
/* Start the erase operation */
/* __builtin_write_NVM();*/
NVMCON|=ERASE_INIT;
Nop()
Nop()
/* Wait till the Erase operation completes */
while(NVMCON_WR);
/* Restore Table page */
TBLPAG = SAV_TBLPAG;
---------------------------------------
This message was sent using the comp.arch.embedded web interface on
http://www.EmbeddedRelated.com