Hi,
We are using LPC2364 device in our project. The problem is we are unable to
perform Flash write. Please any one can help on this.
Regards,
Sankar.K
_________________________________________________________________
Register once and play all contests. Increase your scores with bonus credits for
logging in daily on MSN.
http://specials.msn.co.in/msncontest/index.aspx
LPC2364 Flash writing issues
Started by ●November 27, 2008
Reply by ●November 27, 20082008-11-27
--- In l..., Sankar karuppannan wrote:
> Hi,
> We are using LPC2364 device in our project. The problem is we are
unable to perform Flash write. Please any one can help on this.
>
> Regards,
> Sankar.K
Maybe you accidently set the code lock word ? They do not program
again until you re-program from the serial port and do a full chip
erase first.
Then again, maybe the proper jumpers aren't in place for
either the serial or JTAG programming methods.
boB
> _________________________________________________________________
> Register once and play all contests. Increase your scores with bonus
credits for logging in daily on MSN.
> http://specials.msn.co.in/msncontest/index.aspx
>
>
>
> Hi,
> We are using LPC2364 device in our project. The problem is we are
unable to perform Flash write. Please any one can help on this.
>
> Regards,
> Sankar.K
Maybe you accidently set the code lock word ? They do not program
again until you re-program from the serial port and do a full chip
erase first.
Then again, maybe the proper jumpers aren't in place for
either the serial or JTAG programming methods.
boB
> _________________________________________________________________
> Register once and play all contests. Increase your scores with bonus
credits for logging in daily on MSN.
> http://specials.msn.co.in/msncontest/index.aspx
>
>
>
Reply by ●November 27, 20082008-11-27
hi,
i just succeeded flash write operations.
i added my flash write/erase commands.
they may not be so general but can give you idea.
i wait any further question.
regards
Mehmet
__________________________________________________________________
Looking for the perfect gift? Give the gift of Flickr!
http://www.flickr.com/gift/
----------
/*****************************************************************************
* iap.c: IAP API file for NXP LPC23xx/24xx Family Microprocessors
*
* Copyright(C) 2006, NXP Semiconductor
* M.Riza OZ
*
* History
* 2006.07.12 ver 1.00 Prelimnary version, first Release
*
******************************************************************************/
#include
#include "iap.h"
#include "Common/inc/type.h"
#include "Common/inc/target.h"
#include "Common/inc/irq.h"
#include "LPC23xx.h"
//----------------------------------
unsigned int command[5];
unsigned int result[3];
volatile DWORD buffer[256];
volatile DWORD SectorAddressRange[28][2] = { {0x00000000, 0x00000FFF},
{0x00001000, 0x00001FFF}, {0x00002000, 0x00002FFF}, {0x00003000, 0x00003FFF},
{0x00004000, 0x00004FFF}, {0x00005000, 0x00005FFF}, {0x00006000, 0x00006FFF},
{0x00007000, 0x00007FFF}, {0x00008000, 0x0000FFFF}, {0x00010000, 0x00017FFF},
{0x00018000, 0x0001FFFF}, {0x00020000, 0x00027FFF}, {0x00028000, 0x0002FFFF},
{0x00030000, 0x00037FFF}, {0x00038000, 0x0003FFFF}, {0x00040000, 0x00047FFF},
{0x00048000, 0x0004FFFF}, {0x00050000, 0x00057FFF}, {0x00058000, 0x0005FFFF},
{0x00060000, 0x00067FFF}, {0x00068000, 0x0006FFFF}, {0x00070000, 0x00077FFF},
{0x00078000, 0x00078FFF}, {0x00079000, 0x00079FFF}, {0x0007A000, 0x0007AFFF},
{0x0007B000, 0x0007BFFF}, {0x0007C000, 0x0007CFFF}, {0x0007D000, 0x0007DFFF}};
/*
volatile DWORD SectorAddressRange[28][2] = { {0x00000000, 4096},
{0x00001000, 4096}, {0x00002000, 4096}, {0x00003000, 4096},
{0x00004000, 4096}, {0x00005000, 4096}, {0x00006000, 4096},
{0x00007000, 4096}, {0x00008000, 32768}, {0x00010000, 32768},
{0x00018000, 32768}, {0x00020000, 32768}, {0x00028000, 32768},
{0x00030000, 32768}, {0x00038000, 32768}, {0x00040000, 32768},
{0x00048000, 32768}, {0x00050000, 32768}, {0x00058000, 32768},
{0x00060000, 32768}, {0x00068000, 32768}, {0x00070000, 32768},
{0x00078000, 4096}, {0x00079000, 4096}, {0x0007A000, 4096},
{0x0007B000, 4096}, {0x0007C000, 4096}, {0x0007D000, 4096}};
*/
typedef void (*IAP)(unsigned int*,unsigned int* );
IAP iap_entry =(IAP) IAP_LOCATION;
//----------------------------------
/*int Find_Sect_No(DWORD Address)
{
int i, j;
for(i=0; i<29; i++)
{
for(j=0; j<2; j++)
{
if(Address==SectorAddressRange[i][j])
return i;
}
}
} */
//----------------------------------
int GetPartID ()
{
command[0] = ReadPartID;
iap_entry (command, result);
if (result[0]==CMD_SUCCESS)
{
printf("Get Part ID: CMD_SUCCESS\r\n");
printf("0x%.8X\r\n",result[1]);
}
return result[0];
}
//----------------------------------
int GetBootCodeVersion ()
{
command[0] = ReadBootCodeVersion;
iap_entry (command, result);
if (result[0]==CMD_SUCCESS)
{
printf("Get Boot Code Version: CMD_SUCCESS\r\n");
printf("0x%.8X\r\n",result[1]);
}
return result[0];
}
//----------------------------------
int EraseSector (DWORD start_sect_no, DWORD stop_sect_no, DWORD CCLK_freq)
{
int status;
//prepare sector 4 wright
// VICIntEnClr = 0xFFFFFFFF;//disable all interrupts
status=PrepareSector4Write(start_sect_no,stop_sect_no);
//
//
//erase prepared sector
if (status==CMD_SUCCESS)
{
command[0] = EraseSectors;
command[1] = start_sect_no;
command[2] = stop_sect_no;
command[3] = CCLK_freq;
iap_entry (command, result);
if (result[0]==CMD_SUCCESS)
printf("Erase Sector CMD_SUCCESS\r\n");
else if(result[0]==BUSY)
printf("Erase Sector BUSY\r\n");
else if(result[0]==SECTOR_NOT_PREPARED_FOR_WRITE_OPERATION)
printf("Erase Sector SECTOR_NOT_PREPARED_FOR_WRITE_OPERATION\r\n");
else if(result[0]==INVALID_SECTOR)
printf("Erase Sector INVALID_SECTOR\r\n");
else
printf("none\r\n");
}
// VICIntEnable = 0xFFFFFFFF;//enable all interrupts
return result[0];
}
//----------------------------------
int PrepareSector4Write (DWORD start_sect_no, DWORD stop_sect_no)
{
DWORD temp;
//prepare sector 4 wright
command[0] = PrepareSectors4Write;
command[1] = start_sect_no;
command[2] = stop_sect_no;
iap_entry (command, result);
if (result[0]==CMD_SUCCESS)
printf("Prepare Sector CMD_SUCCESS\r\n");
else if(result[0]==BUSY)
printf("Prepare Sector BUSY\r\n");
else if(result[0]==INVALID_SECTOR)
printf("Prepare Sector INVALID_SECTOR\r\n");
else
printf("none\r\n");
return result[0];
}
//----------------------------------
int CopyRAM2Flash (DWORD dest_flash_addr, DWORD source_ram_addr, DWORD byte_count, DWORD CCLK_freq)
{
int status;
//prepare sector 4 wright
status=PrepareSector4Write(2,2); //sector bulan bir func yazilmali
//erase prepared sector
if (status==CMD_SUCCESS)
{
command[0] = RAM2Flash;
command[1] = dest_flash_addr;
command[2] = source_ram_addr;
command[3] = byte_count;
command[4] = CCLK_freq;
iap_entry (command, result);
if (result[0]==CMD_SUCCESS)
printf("Flash Write CMD_SUCCESS\r\n");
else if(result[0]==BUSY)
printf("Flash Write BUSY\r\n");
else if(result[0]==SECTOR_NOT_PREPARED_FOR_WRITE_OPERATION)
printf("Flash Write SECTOR_NOT_PREPARED_FOR_WRITE_OPERATION\r\n");
else if(result[0]==SRC_ADDR_ERROR)
printf("Flash Write SRC_ADDR_ERROR\r\n");
else if(result[0]==DST_ADDR_ERROR)
printf("Flash Write DST_ADDR_ERROR\r\n");
else if(result[0]==SRC_ADDR_NOT_MAPPED)
printf("Flash Write SRC_ADDR_NOT_MAPPED\r\n");
else if(result[0]==DST_ADDR_NOT_MAPPED)
printf("Flash Write DST_ADDR_NOT_MAPPED\r\n");
else if(result[0]==COUNT_ERROR)
printf("Flash Write COUNT_ERROR\r\n");
else
printf("none\r\n");
}
return result[0];
}
//----------------------------------
int CheckBlankSector (DWORD start_sect_no, DWORD stop_sect_no)
{
command[0] = BlankCheckSectors;
command[1] = start_sect_no;
command[2] = stop_sect_no;
iap_entry (command, result);
if (result[0]==CMD_SUCCESS)
{
printf("Blank Check Sector CMD_SUCCESS\r\n");
//if CMD_SUCCESS comes sector empty
}
else if (result[0]==BUSY)
{
printf("Blank Check Sector BUSY\r\n");
}
else if(result[0]==INVALID_SECTOR)
{
printf("Blank Check Sector INVALID_SECTOR\r\n");
}
else if (result[0]==SECTOR_NOT_BLANK)
{//if SECTOR_NOT_BLANK comes sector is not empty
printf("Blank Check Sector SECTOR_NOT_BLANK\r\n");
//address of the first non empty dword location
printf("Offset of the first non blank word location 0x%.8X\r\n",result[1]);
//content of the first non empty data on the sector
printf("Contents of non blank word location 0x%.8X\r\n",result[2]);
}
return result[0];
}
//----------------------------------
----------
/*****************************************************************************
* iap.h: Type definition Header file for NXP LPC230x Family
* Microprocessors
*
* Copyright(C) 2008, VESTEL ELECTRONICS
* M.Riza OZ
*
* History
* 2008.11.20 ver 1.00 Prelimnary version, first Release
*
******************************************************************************/
#include "Common/inc/type.h"
#define PrepareSectors4Write 50
#define RAM2Flash 51
#define EraseSectors 52
#define BlankCheckSectors 53
#define ReadPartID 54
#define ReadBootCodeVersion 55
#define Compare 56
#define ReinvokeISP 57
#define CMD_SUCCESS 0 // Command is executed successfully.
#define INVALID_COMMAND 1 // Invalid command.
#define SRC_ADDR_ERROR 2 // Source address is not on a word boundary.
#define DST_ADDR_ERROR 3 // Destination address is not on a correct boundary.
#define SRC_ADDR_NOT_MAPPED 4 // Source address is not mapped in the memory map.
#define DST_ADDR_NOT_MAPPED 5 // Destination address is not mapped in the memory
#define COUNT_ERROR 6 // Byte count is not multiple of 4 or is not a permitted value.
#define INVALID_SECTOR 7 // Sector number is invalid.
#define SECTOR_NOT_BLANK 8 // Sector is not blank.
#define SECTOR_NOT_PREPARED_FOR_WRITE_OPERATION 9 //Command to prepare sector for write operation was not executed.
#define COMPARE_ERROR 10 // Source and destination data is not same.
#define BUSY 11
#define IAP_LOCATION 0x7ffffff1
extern volatile DWORD SectorAddressRange[28][2];
extern unsigned int command[5];
extern unsigned int result[3];
extern volatile DWORD buffer[256];
int CheckBlankSector (DWORD start_sect_no, DWORD stop_sect_no);
int GetBootCodeVersion ();
int GetPartID ();
int EraseSector (DWORD start_sect_no, DWORD stop_sect_no, DWORD CCLK_freq);
int PrepareSector4Write (DWORD start_sect_no, DWORD stop_sect_no);
i just succeeded flash write operations.
i added my flash write/erase commands.
they may not be so general but can give you idea.
i wait any further question.
regards
Mehmet
__________________________________________________________________
Looking for the perfect gift? Give the gift of Flickr!
http://www.flickr.com/gift/
----------
/*****************************************************************************
* iap.c: IAP API file for NXP LPC23xx/24xx Family Microprocessors
*
* Copyright(C) 2006, NXP Semiconductor
* M.Riza OZ
*
* History
* 2006.07.12 ver 1.00 Prelimnary version, first Release
*
******************************************************************************/
#include
#include "iap.h"
#include "Common/inc/type.h"
#include "Common/inc/target.h"
#include "Common/inc/irq.h"
#include "LPC23xx.h"
//----------------------------------
unsigned int command[5];
unsigned int result[3];
volatile DWORD buffer[256];
volatile DWORD SectorAddressRange[28][2] = { {0x00000000, 0x00000FFF},
{0x00001000, 0x00001FFF}, {0x00002000, 0x00002FFF}, {0x00003000, 0x00003FFF},
{0x00004000, 0x00004FFF}, {0x00005000, 0x00005FFF}, {0x00006000, 0x00006FFF},
{0x00007000, 0x00007FFF}, {0x00008000, 0x0000FFFF}, {0x00010000, 0x00017FFF},
{0x00018000, 0x0001FFFF}, {0x00020000, 0x00027FFF}, {0x00028000, 0x0002FFFF},
{0x00030000, 0x00037FFF}, {0x00038000, 0x0003FFFF}, {0x00040000, 0x00047FFF},
{0x00048000, 0x0004FFFF}, {0x00050000, 0x00057FFF}, {0x00058000, 0x0005FFFF},
{0x00060000, 0x00067FFF}, {0x00068000, 0x0006FFFF}, {0x00070000, 0x00077FFF},
{0x00078000, 0x00078FFF}, {0x00079000, 0x00079FFF}, {0x0007A000, 0x0007AFFF},
{0x0007B000, 0x0007BFFF}, {0x0007C000, 0x0007CFFF}, {0x0007D000, 0x0007DFFF}};
/*
volatile DWORD SectorAddressRange[28][2] = { {0x00000000, 4096},
{0x00001000, 4096}, {0x00002000, 4096}, {0x00003000, 4096},
{0x00004000, 4096}, {0x00005000, 4096}, {0x00006000, 4096},
{0x00007000, 4096}, {0x00008000, 32768}, {0x00010000, 32768},
{0x00018000, 32768}, {0x00020000, 32768}, {0x00028000, 32768},
{0x00030000, 32768}, {0x00038000, 32768}, {0x00040000, 32768},
{0x00048000, 32768}, {0x00050000, 32768}, {0x00058000, 32768},
{0x00060000, 32768}, {0x00068000, 32768}, {0x00070000, 32768},
{0x00078000, 4096}, {0x00079000, 4096}, {0x0007A000, 4096},
{0x0007B000, 4096}, {0x0007C000, 4096}, {0x0007D000, 4096}};
*/
typedef void (*IAP)(unsigned int*,unsigned int* );
IAP iap_entry =(IAP) IAP_LOCATION;
//----------------------------------
/*int Find_Sect_No(DWORD Address)
{
int i, j;
for(i=0; i<29; i++)
{
for(j=0; j<2; j++)
{
if(Address==SectorAddressRange[i][j])
return i;
}
}
} */
//----------------------------------
int GetPartID ()
{
command[0] = ReadPartID;
iap_entry (command, result);
if (result[0]==CMD_SUCCESS)
{
printf("Get Part ID: CMD_SUCCESS\r\n");
printf("0x%.8X\r\n",result[1]);
}
return result[0];
}
//----------------------------------
int GetBootCodeVersion ()
{
command[0] = ReadBootCodeVersion;
iap_entry (command, result);
if (result[0]==CMD_SUCCESS)
{
printf("Get Boot Code Version: CMD_SUCCESS\r\n");
printf("0x%.8X\r\n",result[1]);
}
return result[0];
}
//----------------------------------
int EraseSector (DWORD start_sect_no, DWORD stop_sect_no, DWORD CCLK_freq)
{
int status;
//prepare sector 4 wright
// VICIntEnClr = 0xFFFFFFFF;//disable all interrupts
status=PrepareSector4Write(start_sect_no,stop_sect_no);
//
//
//erase prepared sector
if (status==CMD_SUCCESS)
{
command[0] = EraseSectors;
command[1] = start_sect_no;
command[2] = stop_sect_no;
command[3] = CCLK_freq;
iap_entry (command, result);
if (result[0]==CMD_SUCCESS)
printf("Erase Sector CMD_SUCCESS\r\n");
else if(result[0]==BUSY)
printf("Erase Sector BUSY\r\n");
else if(result[0]==SECTOR_NOT_PREPARED_FOR_WRITE_OPERATION)
printf("Erase Sector SECTOR_NOT_PREPARED_FOR_WRITE_OPERATION\r\n");
else if(result[0]==INVALID_SECTOR)
printf("Erase Sector INVALID_SECTOR\r\n");
else
printf("none\r\n");
}
// VICIntEnable = 0xFFFFFFFF;//enable all interrupts
return result[0];
}
//----------------------------------
int PrepareSector4Write (DWORD start_sect_no, DWORD stop_sect_no)
{
DWORD temp;
//prepare sector 4 wright
command[0] = PrepareSectors4Write;
command[1] = start_sect_no;
command[2] = stop_sect_no;
iap_entry (command, result);
if (result[0]==CMD_SUCCESS)
printf("Prepare Sector CMD_SUCCESS\r\n");
else if(result[0]==BUSY)
printf("Prepare Sector BUSY\r\n");
else if(result[0]==INVALID_SECTOR)
printf("Prepare Sector INVALID_SECTOR\r\n");
else
printf("none\r\n");
return result[0];
}
//----------------------------------
int CopyRAM2Flash (DWORD dest_flash_addr, DWORD source_ram_addr, DWORD byte_count, DWORD CCLK_freq)
{
int status;
//prepare sector 4 wright
status=PrepareSector4Write(2,2); //sector bulan bir func yazilmali
//erase prepared sector
if (status==CMD_SUCCESS)
{
command[0] = RAM2Flash;
command[1] = dest_flash_addr;
command[2] = source_ram_addr;
command[3] = byte_count;
command[4] = CCLK_freq;
iap_entry (command, result);
if (result[0]==CMD_SUCCESS)
printf("Flash Write CMD_SUCCESS\r\n");
else if(result[0]==BUSY)
printf("Flash Write BUSY\r\n");
else if(result[0]==SECTOR_NOT_PREPARED_FOR_WRITE_OPERATION)
printf("Flash Write SECTOR_NOT_PREPARED_FOR_WRITE_OPERATION\r\n");
else if(result[0]==SRC_ADDR_ERROR)
printf("Flash Write SRC_ADDR_ERROR\r\n");
else if(result[0]==DST_ADDR_ERROR)
printf("Flash Write DST_ADDR_ERROR\r\n");
else if(result[0]==SRC_ADDR_NOT_MAPPED)
printf("Flash Write SRC_ADDR_NOT_MAPPED\r\n");
else if(result[0]==DST_ADDR_NOT_MAPPED)
printf("Flash Write DST_ADDR_NOT_MAPPED\r\n");
else if(result[0]==COUNT_ERROR)
printf("Flash Write COUNT_ERROR\r\n");
else
printf("none\r\n");
}
return result[0];
}
//----------------------------------
int CheckBlankSector (DWORD start_sect_no, DWORD stop_sect_no)
{
command[0] = BlankCheckSectors;
command[1] = start_sect_no;
command[2] = stop_sect_no;
iap_entry (command, result);
if (result[0]==CMD_SUCCESS)
{
printf("Blank Check Sector CMD_SUCCESS\r\n");
//if CMD_SUCCESS comes sector empty
}
else if (result[0]==BUSY)
{
printf("Blank Check Sector BUSY\r\n");
}
else if(result[0]==INVALID_SECTOR)
{
printf("Blank Check Sector INVALID_SECTOR\r\n");
}
else if (result[0]==SECTOR_NOT_BLANK)
{//if SECTOR_NOT_BLANK comes sector is not empty
printf("Blank Check Sector SECTOR_NOT_BLANK\r\n");
//address of the first non empty dword location
printf("Offset of the first non blank word location 0x%.8X\r\n",result[1]);
//content of the first non empty data on the sector
printf("Contents of non blank word location 0x%.8X\r\n",result[2]);
}
return result[0];
}
//----------------------------------
----------
/*****************************************************************************
* iap.h: Type definition Header file for NXP LPC230x Family
* Microprocessors
*
* Copyright(C) 2008, VESTEL ELECTRONICS
* M.Riza OZ
*
* History
* 2008.11.20 ver 1.00 Prelimnary version, first Release
*
******************************************************************************/
#include "Common/inc/type.h"
#define PrepareSectors4Write 50
#define RAM2Flash 51
#define EraseSectors 52
#define BlankCheckSectors 53
#define ReadPartID 54
#define ReadBootCodeVersion 55
#define Compare 56
#define ReinvokeISP 57
#define CMD_SUCCESS 0 // Command is executed successfully.
#define INVALID_COMMAND 1 // Invalid command.
#define SRC_ADDR_ERROR 2 // Source address is not on a word boundary.
#define DST_ADDR_ERROR 3 // Destination address is not on a correct boundary.
#define SRC_ADDR_NOT_MAPPED 4 // Source address is not mapped in the memory map.
#define DST_ADDR_NOT_MAPPED 5 // Destination address is not mapped in the memory
#define COUNT_ERROR 6 // Byte count is not multiple of 4 or is not a permitted value.
#define INVALID_SECTOR 7 // Sector number is invalid.
#define SECTOR_NOT_BLANK 8 // Sector is not blank.
#define SECTOR_NOT_PREPARED_FOR_WRITE_OPERATION 9 //Command to prepare sector for write operation was not executed.
#define COMPARE_ERROR 10 // Source and destination data is not same.
#define BUSY 11
#define IAP_LOCATION 0x7ffffff1
extern volatile DWORD SectorAddressRange[28][2];
extern unsigned int command[5];
extern unsigned int result[3];
extern volatile DWORD buffer[256];
int CheckBlankSector (DWORD start_sect_no, DWORD stop_sect_no);
int GetBootCodeVersion ();
int GetPartID ();
int EraseSector (DWORD start_sect_no, DWORD stop_sect_no, DWORD CCLK_freq);
int PrepareSector4Write (DWORD start_sect_no, DWORD stop_sect_no);