Yahoo Groups archive

Lpc2000

Index last updated: 2026-04-28 23:31 UTC

Message

Re: difficulties at using IAP routines

2005-07-05 by Dave

--- In lpc2000@yahoogroups.com, "cris_ullmann" <cris.ullmann@t...> wrote:
> Hi Tom,
> 
> thank you for your help. The result is still not my problem. I changed
> that sometimes from reslut[1] to result[0].
> 
> The problem is, the programm sticks at the call of the IAS-routine.
> 
> Any idea??
> 
> Best regards  Cris
> --- In lpc2000@yahoogroups.com, Tom Convent <ur_tom1977@y...> wrote:
> > Hello Cris,
> >  
> >                  In your code result[1] contains the ID...you should
> return result[1] instead of result[0]. results[0] only says the
> cammand is sucess.
> >  
> > regards,
> >  
> > Tom
> > 
> > cris_ullmann <cris.ullmann@t...> wrote:
> > Hello friends,
> > 
> > I'm still pretty unexperienced in programming the LPC2xxx processors. 
> > I want read and write the internal flash using IAP. At first, I tried 
> > to read the processor ID from the flash.
> > 
> > My code is:
> > 
> > int IAP_ID()
> > {
> > #define IAP_LOCATION 0x7FFFFFF1
> > unsigned int command[5];
> > unsigned int result[2];
> > typedef void (*IAP)(unsigned int[],unsigned int[]);
> > IAP iap_entry;
> > 
> > int ID;
> > int Ergebnis;
> >   __DISABLE_INTERRUPT();
> > iap_entry=(IAP)IAP_LOCATION;
> > command[0]=54;             //read par ID
> > result[0]=0;
> > iap_entry(command,result);
> > Ergebnis=result[0];
> > ID=result[1];
> > return Ergebnis;
> > } 
> > 
> > By the way, I use the ICCARM compiler, the boot loader version is 1.64
> > 
> > Is there anybody who can help me? As I learned from this forum, the 
> > problem might laying in switching to the thumb mode when calling the 
> > IAP-routine. Who do I have to do this?
> > 
> > Best regards
> > 
> > Cris
> > 
> > 
> > 
> > 
> > 
> > ---------------------------------
> > YAHOO! GROUPS LINKS 
> > 
> > 
> >     Visit your group "lpc2000" on the web.
> >   
> >     To unsubscribe from this group, send an email to:
> >  lpc2000-unsubscribe@yahoogroups.com
> >   
> >     Your use of Yahoo! Groups is subject to the Yahoo! Terms of
> Service. 
> > 
> > 
> > ---------------------------------
> > 
> > 
> > 
> > __________________________________________________
> > Do You Yahoo!?
> > Tired of spam?  Yahoo! Mail has the best spam protection around 
> > http://mail.yahoo.com 
> > 
> > [Non-text portions of this message have been removed]


Hello,

  I have had success using the IAP commands to extract partID and
bootloader version. I have also managed to program the flash once.
However, I cannot erase the flash sector that I managed to program, so
that I may program it again. Also, the flash programming call seems to
'stick', but if left long enough eventually comes back. The functions
to read partID and bootloader version do not require interrupts to be
disabled, or the PLL to be disabled, or the MAM to be disabled. The
flash programming functions require all of these to be disabled.


//--------------------------------------------------------

// IAP (In Application Programming) interface
//
struct iap_in {
  unsigned int cmd;
  unsigned int par[4];  
};

typedef void (*IAP)(struct iap_in *in, unsigned int *result);

// IAP entry point
#define iap_entry ((IAP) 0x7FFFFFF1)

//--------------------------------------------------------
//--------------------------------------------------------

// IAP command codes
#define IAP_PREPARE_WRITE				50
#define IAP_PROGRAM_FLASH				51
#define IAP_ERASE_SECTOR				52
#define IAP_BLANK_CHECK					53
#define IAP_READ_PART_ID				54
#define IAP_READ_BOOT_CODE_VER			55
#define IAP_COMPARE						56
#define IAP_REINVOKE_ISP				57

// IAP return code values
#define IAP_RESULT_SUCCESS				0
#define IAP_RESULT_INVALID_COMMAND		1
#define IAP_RESULT_SRC_ADDR_ERROR		2
#define IAP_RESULT_DST_ADDR_ERROR		3
#define IAP_RESULT_SRC_ADDR_NOT_MAPPED	4
#define IAP_RESULT_DST_ADDR_NOT_MAPPED	5
#define IAP_RESULT_COUNT_ERROR			6
#define IAP_RESULT_INVALID_SECTOR		7
#define IAP_RESULT_SECTOR_NOT_BLANK		8
#define IAP_RESULT_SECTOR_NOT_PREPARED	9
#define IAP_RESULT_COMPARE_ERROR		10
#define IAP_RESULT_BUSY					11

//--------------------------------------------------------
//--------------------------------------------------------

//
// IAP Read Part Identification command
//
// This command is used to read the part identification number.
//
//  device   code(dec)  code(hex)
//	LPC2131     196353  0x0002 FF01
//  LPC2132     196369  0x0002 FF11
//  LPC2134     196370  0x0002 FF12
//  LPC2136     196387  0x0002 FF23
//  LPC2138     196389  0x0002 FF25
//
static unsigned int iap_read_part_id(void)
{
	// IAP input parameters
	struct iap_in iap;

	// IAP results
	unsigned int result[2];

	iap.cmd = IAP_READ_PART_ID;
	iap_entry (&iap, result);

	return result[1];
}

//
// IAP Read Boot code version number command
//
// This command is used to read the boot code version number.
//
static unsigned int iap_read_boot_code_version(void)
{
	// IAP input parameters
	struct iap_in iap;

	// IAP results
	unsigned int result[2];

	iap.cmd = IAP_READ_BOOT_CODE_VER;
	iap_entry (&iap, result);

	// 2 bytes of boot code version number in ASCII format.
	// It is to be interpreted as <byte1(Major)>.<byte0(Minor)>
	return result[1];
}

//--------------------------------------------------------
//--------------------------------------------------------

typedef struct partIDToDesc_s {
	unsigned int id;
	char* desc;
}
partIDToDesc_t;

#define NUM_PART_IDS	5
static partIDToDesc_t partIDs[NUM_PART_IDS] = {
	//  device   code(dec)
	{196353, "LPC2131"},	//	LPC2131     196353  0x0002 FF01
	{196369, "LPC2132"},	//  LPC2132     196369  0x0002 FF11
	{196370, "LPC2134"},	//  LPC2134     196370  0x0002 FF12
	{196387, "LPC2136"},	//  LPC2136     196387  0x0002 FF23
	{196389, "LPC2138"},	//  LPC2138     196389  0x0002 FF25
};

unsigned int flashGetPartID(void)
{
	return part_id;
}

char* flashGetPartName(unsigned int part_id)
{
	char* name = "Unknown";
	for (int i = 0; i < NUM_PART_IDS; i++) {
		if (part_id == partIDs[i].id) {
			name = partIDs[i].desc;
			break;
		}
	}
	return name;
}

unsigned int flashGetBootloaderVersion(void)
{
	return iap_read_boot_code_version();
}

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.