Yahoo Groups archive

Lpc2000

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

Thread

problem write in flash

problem write in flash

2004-11-10 by dasbento@aeiou.pt

Hello,

I already tried the code the message 3905 for write in flash and the
program stop in command:

"iap_entry(command, result);"

It can be because boot.s ???? if yes, anyone know someone boot.s that
work well with IAP???

Thanks
      Domingos
_________________________________________________________
CEAC Cursos de forma\ufffd\ufffdo profissional - pe\ufffda informa\ufffd\ufffdes aqui.:
http://ceac.online.pt/

Re: [lpc2000] problem write in flash

2004-11-10 by Robert Adsett

At 06:21 PM 11/10/04 +0000, you wrote:
>I already tried the code the message 3905 for write in flash and the
>program stop in command:
>
>"iap_entry(command, result);"
>
>It can be because boot.s ???? if yes, anyone know someone boot.s that
>work well with IAP???

Well, the startup has to reserve space for the IAP working memory.  Other 
than that there shouldn't be an issue with startup code.  Personally I'd 
use an external serial (SPI or I2C FRAM or EE) for parameter storage in 
order to allow finer grained updating (ie byte at a time).  On the other 
hand a large block of relatively constant (such as calibration) parameters 
would work well.

Robert

" 'Freedom' has no meaning of itself.  There are always restrictions,
be they legal, genetic, or physical.  If you don't believe me, try to
chew a radio signal. "

                         Kelvin Throop, III

Re: [lpc2000] problem write in flash

2004-11-10 by dasbento@aeiou.pt

Hello,


I want use the flash into the arm since are only more or less 50 bytes
the constants variables!!!   

I would like somebody to see if this boot.s works with IAP??

the boot.s that I use is:


/*
*   TLIB revision history:
*   1 crt0.s 30-Dec-2003,10:32:32,`RADSETT' First archival version.
*   2 crt0.s 03-Mar-2004,15:56:50,`RADSETT' Add stack setup for each
CPU mode to
*        allow support of interrupts.
*   TLIB revision history ends.
*/

	.extern	main 		/*  Usual C startup.			*/

 /* .text is used instead of .section .text so it works with
arm-aout too. */ 

	.text 
	.code 32 

	.align 	0

	/*  Defined in link script so startup knows where everything 	*/
	/* is.								*/
	.extern	__bss_beg__	
	.extern	__bss_end__
	.extern __stack_end__
	.extern __data_beg__
	.extern __data_end__
	.extern __data_beg_src__

	.global	start 
	.global	endless_loop

	.set INIT_FIQ_MODE,		0x11
	.set INIT_IRQ_MODE,		0x12
	.set INIT_SUPERVISOR_MODE,	0x13
	.set INIT_ABORT_MODE,		0x17
	.set INIT_UNDEFINED_MODE,	0x1B
	.set INIT_SYSTEM_MODE,		0x1F

/********************* start ********************************************/
/*  start (AKA _start, _mainCRTStartup) -- Gains control on reset and	*/
/* set up environment before running the operating C program. 		*/
start: 
_start:
_mainCRTStartup:

	/*  Start by setting up a stack					*/
	/* Set up the stack pointer to end of bss 			*/
	msr	cpsr_c, #INIT_FIQ_MODE
	ldr	sp, =__stack_end_fiq__
	msr	cpsr_c, #INIT_IRQ_MODE
	ldr	sp, =__stack_end_irq__
	msr	cpsr_c, #INIT_SUPERVISOR_MODE
	ldr	sp, =__stack_end_supervisor__
	msr	cpsr_c, #INIT_ABORT_MODE
	ldr	sp, =__stack_end_abort__
	msr	cpsr_c, #INIT_UNDEFINED_MODE
	ldr	sp, =__stack_end_undefined__
	msr	cpsr_c, #INIT_SYSTEM_MODE
	ldr	sp, =__stack_end__

	sub	sl, sp, #512	/* Assumes 512 bytes below sp 		*/

	mov 	a2, #0		/* Fill value 				*/
	mov	fp, a2		/* Null frame pointer 			*/ 
	mov	r7, a2		/* Null frame pointer for Thumb 	*/
	
	ldr 	r1, .LC1	/*  __bss_beg__ set in link script to 	*/
				/* point at beginning of uninitialized	*/
				/* ram.					*/ 
	ldr 	r3, .LC2	/*  __bss_beg__ set in link script to 	*/
				/* point at end of uninitialized ram.	*/ 
	subs 	r3, r3, r1	/*  Subtract two to find length of 	*/
				/* uninitialized ram.			*/ 
	beq	.end_clear_loop	/*  If no uninitialzed ram skip init.	*/

	mov 	r2, #0		/*  Value used to init ram.		*/

.clear_loop:
	strb	r2, [r1], #1	/*  Clear byte at r1, advance to next	*/
	subs	r3, r3, #1	/*  One less to do			*/
	bgt	.clear_loop	/*  If not done go the next.		*/

.end_clear_loop:
	
	ldr	r1, .LC3	/*  __data_beg__ set in link script to 	*/
				/* point at beginning of initialized ram*/
	ldr 	r2, .LC4	/*  __data_beg_src__ set in link script	*/
				/* to point to beginning of flash copy 	*/
				/* of the initial values of initialized	*/
				/* variables.				*/ 
	ldr 	r3, .LC5	/*  __data_end__ set in link script to 	*/
				/* point at end of initialized ram	*/
	subs	r3, r3, r1	/*  Calculate length of area in ram	*/
				/* holding initialzed variables.	*/
	beq	.end_set_loop	/*  If no initialized vars skip init.	*/

.set_loop: 
	ldrb	r4, [r2], #1	/* Read byte from flash (increment ptr),*/
	strb	r4, [r1], #1  	/* store it in ram (increment ptr) and, */
	subs	r3, r3, #1  	/* reduce bytes to copy by 1.		*/
	bgt 	.set_loop	/* Continue until all copied.		*/

.end_set_loop: 

	/*  Set up arguments to main and call.				*/

	mov		r0, #0		/*  no arguments  */ 
	mov		r1, #0		/* no argv either */

	bl		main 

	/*  Returning from main in this environment is really an error.	*/
	/* Go into a dead loop.						*/
endless_loop:
	b		endless_loop

	/* For Thumb, constants must be after the code since only 
	positive offsets are supported for PC relative addresses. */
	
	.align 0
.LC1: 
.word	__bss_beg__ 
.LC2:   
.word	__bss_end__
.LC3:
.word	__data_beg__
.LC4:
.word	__data_beg_src__
.LC5:
.word	__data_end__

	/**** Exception/Interrupt table ****/

	/*  defaults are defined in the link script.  The reserved	*/
	/* exception should be overridden by the download program 	*/
	/* (see LPC210X documentation).					*/

.section .startup,"ax" 
	.code 32 
	.align 0

	b	start
	b	undefined_instruction_exception
	b	software_interrupt_exception
	b	prefetch_abort_exception
	b	data_abort_exception
	b	reserved_exception
/*	b	interrupt_exception*/
	ldr	pc,[pc,#-0xFF0]	    	/* Vector via VIC		*/
	b	fast_interrupt_exception


Thanks
        Domingos







Well, the startup has to reserve space for the IAP working memory.  Other 

than that there shouldn't be an issue with startup code.  Personally I'd 

use an external serial (SPI or I2C FRAM or EE) for parameter storage in 

order to allow finer grained updating (ie byte at a time).  On the other 

hand a large block of relatively constant (such as calibration)
parameters 

would work well.



Robert
_________________________________________________________
CEAC Cursos de forma\ufffd\ufffdo profissional - pe\ufffda informa\ufffd\ufffdes aqui.:
http://ceac.online.pt/

Re: [lpc2000] problem write in flash

2004-11-10 by Robert Adsett

At 10:58 PM 11/10/04 +0000, you wrote:

>Hello,
>
>
>I want use the flash into the arm since are only more or less 50 bytes
>the constants variables!!!
>
>I would like somebody to see if this boot.s works with IAP??
>
>the boot.s that I use is:
>

<snip>


>Well, the startup has to reserve space for the IAP working memory.  Other
>
>than that there shouldn't be an issue with startup code.  Personally I'd
>
>use an external serial (SPI or I2C FRAM or EE) for parameter storage in
>
>order to allow finer grained updating (ie byte at a time).  On the other
>
>hand a large block of relatively constant (such as calibration)
>parameters
>
>would work well.

The simple answer is no.  It doesn't reserve the space needed.  The 
simplest place to reserve it would actually be in the ld file.

As a quick fix change the following in the ld file

MEMORY {
   flash : ORIGIN = 0, LENGTH = 120K
   ram : ORIGIN = 0x40000000, LENGTH = 16K
   }

__ram_size__ = 16K;

Change the LENGTH parameter of ram: and the size of __ram_size__ to leave 
the amount of space needed at the top of ram.  You'll have to read the 
documentation I don't remember what the amount of space needed is.  Feel 
free to contribute it back to the newlib-lpc collection.  It's not been 
added so far because no-one who is contributing (including me) has needed 
and contributed the change.  It is on my list by rather low on it.

Robert


" 'Freedom' has no meaning of itself.  There are always restrictions,
be they legal, genetic, or physical.  If you don't believe me, try to
chew a radio signal. "

                         Kelvin Throop, III

Re: [lpc2000] problem write in flash

2004-11-11 by dasbento@aeiou.pt

Hello Robert:

only a question, you want say even "Change the LENGTH parameter of
ram", not is change the length parameter of flash???


I will have the whole pleasure in contributing to the newlib-lpc
collection!!!

Regards 
       Domingos





The simple answer is no.  It doesn't reserve the space needed.  The 

simplest place to reserve it would actually be in the ld file.



As a quick fix change the following in the ld file



MEMORY {

   flash : ORIGIN = 0, LENGTH = 120K

   ram : ORIGIN = 0x40000000, LENGTH = 16K

   }



__ram_size__ = 16K;



Change the LENGTH parameter of ram: and the size of __ram_size__ to leave 

the amount of space needed at the top of ram.  You'll have to read the 

documentation I don't remember what the amount of space needed is.  Feel 

free to contribute it back to the newlib-lpc collection.  It's not been 

added so far because no-one who is contributing (including me) has needed 

and contributed the change.  It is on my list by rather low on it.



Robert


_________________________________________________________
CEAC Cursos de forma\ufffd\ufffdo profissional - pe\ufffda informa\ufffd\ufffdes aqui.:
http://ceac.online.pt/

Re: [lpc2000] problem write in flash

2004-11-11 by Robert Adsett

At 12:13 AM 11/11/04 +0000, you wrote:
>only a question, you want say even "Change the LENGTH parameter of
>ram", not is change the length parameter of flash???

Ram.  The IAP routines use some memory at the top of ram as a scratchpad as 
I remember.  Check the user manual.

You could also change the flash length too as a way of reserving flash (or 
you could use a const array).

Robert

" 'Freedom' has no meaning of itself.  There are always restrictions,
be they legal, genetic, or physical.  If you don't believe me, try to
chew a radio signal. "

                         Kelvin Throop, III

Re: problem write in flash

2004-11-11 by lp2000c

Are you using the latest version of the on-chip boot-loader software, 
as described in the errata sheet?


--- In lpc2000@yahoogroups.com, dasbento@a... wrote:
> Hello,
> 
> I already tried the code the message 3905 for write in flash and the
> program stop in command:
> 
> "iap_entry(command, result);"
> 
> It can be because boot.s ???? if yes, anyone know someone boot.s 
that
Show quoted textHide quoted text
> work well with IAP???
> 
> Thanks
>       Domingos
> _________________________________________________________
> CEAC Cursos de formação profissional - peça informações aqui.:
> http://ceac.online.pt/

Re: problem write in flash

2004-11-11 by dasbento@aeiou.pt

Hello

No, I'm using boot-loader software original.


Regards 
       Domingos








Are you using the latest version of the on-chip boot-loader software, 

as described in the errata sheet?





--- In lpc2000@yahoogroups.com, dasbento@a... wrote:

> Hello,

> 

> I already tried the code the message 3905 for write in flash and the

> program stop in command:

> 

> "iap_entry(command, result);"

> 

> It can be because boot.s ???? if yes, anyone know someone boot.s 

that

> work well with IAP???

> 

> Thanks

>       Domingos
_________________________________________________________
CEAC Cursos de forma\ufffd\ufffdo profissional - pe\ufffda informa\ufffd\ufffdes aqui.:
http://ceac.online.pt/

Re: [lpc2000] problem write in flash

2004-11-12 by dasbento@aeiou.pt

hello,

Excuse to be still in the same issue, but already upgrad the boot
loader  revision 6.3, and change the file .ld and the problem
persist!!! in first comand "iap_entry(command, result);" the arm stop!!!


I'm using LPC2129, that have 256K flash and 16K ram.


Anyone can help me??


Thanks
       Domingos


I changed the following:



MEMORY {
  flash : ORIGIN = 0, LENGTH = 248K
  ram : ORIGIN = 0x40000000, LENGTH = 14K
  }

__ram_size__ = 14K;





#define IAP_LOCATION 0x7ffffff1




void savesetup(struct SETUP *setup){
   typedef void (*IAP)(unsigned int [],unsigned int[]);
   unsigned int command[5];
   unsigned int result[2];
   IAP iap_entry;

	//One copy of the structure in RAM

	//struct SETUP setup;

	//Pointer to the non volatile copy

	//struct SETUP *nonvolatile;
	//nonvolatile = (struct SETUP*)0x38000; // Points to page 14 in Flash
(LPC2129)

	//copy to RAM (if you need)

	//setup=*nonvolatile;


	disableIRQ();
	disableFIQ();

	iap_entry=(IAP) IAP_LOCATION;
	// get part ID
	command[0]=54;
	result[0]=0;
	escreve_UART0("SEIL AL ");
	iap_entry(command, result); // I do this just for a laugh
	// result in result[1]
	// prepare to erase
	command[0]=50;
	command[1]=14;
	command[2]=14;
	escreve_UART0("SEIL AL0 ");
	iap_entry(command, result);
	escreve_UART0("SEIL AL1 ");
	if (result[0] != 0) {
		escreve_UART0("bum");
		enableIRQ();
	}
	// erase
	command[0]=52;
	command[1]=14;
	command[2]=14;
	command[3]=10000;
	escreve_UART0("SEIL AL 1");
	iap_entry(command, result); // erase the block - else you get old +
new data mixed !!!
		escreve_UART0("SEIL AL 2 ");
	if (result[0] != 0) {
		escreve_UART0("bum");
		enableIRQ();
	}
	// prepare to program
	iap_entry=(IAP) IAP_LOCATION;
	command[0]=50;
	command[1]=14;
	command[2]=14;
	iap_entry(command, result);
	if (result[0] != 0) {
		escreve_UART0("bum");
		enableIRQ();
	}
	// program
		escreve_UART0("SEIL AL 3");
	command[0]=51;
	command[1]=0x3C000;
	command[2]=(int)setup;
	command[3]=512;
	command[4]=10000;
	iap_entry(command, result);
	if (result[0] != 0){
		escreve_UART0("bum");
		enableIRQ();
	}
	enableIRQ();

_________________________________________________________
CEAC Cursos de forma\ufffd\ufffdo profissional - pe\ufffda informa\ufffd\ufffdes aqui.:
http://ceac.online.pt/

Re: [lpc2000] problem write in flash

2004-11-15 by Robert Adsett

At 05:59 PM 11/12/04 +0000, you wrote:
>Excuse to be still in the same issue, but already upgrad the boot
>loader  revision 6.3, and change the file .ld and the problem
>persist!!! in first comand "iap_entry(command, result);" the arm stop!!!
>
>I'm using LPC2129, that have 256K flash and 16K ram.
>
>Anyone can help me??

I see no one else has piped up.  I can't help much since I haven't worked 
on it myself but maybe I can add a pointer.

<snip>
>I changed the following:
>

<snip>

>#define IAP_LOCATION 0x7ffffff1
>
>
>void savesetup(struct SETUP *setup){
>    typedef void (*IAP)(unsigned int [],unsigned int[]);
>    unsigned int command[5];
>    unsigned int result[2];
>    IAP iap_entry;
>
>         //One copy of the structure in RAM
>
>         //struct SETUP setup;
>
>         //Pointer to the non volatile copy
>
>         //struct SETUP *nonvolatile;
>         //nonvolatile = (struct SETUP*)0x38000; // Points to page 14 in Flash
>(LPC2129)
>
>         //copy to RAM (if you need)
>
>         //setup=*nonvolatile;
>
>
>         disableIRQ();
>         disableFIQ();
>
>         iap_entry=(IAP) IAP_LOCATION;
>         // get part ID
>         command[0]=54;
>         result[0]=0;
>         escreve_UART0("SEIL AL ");
>         iap_entry(command, result); // I do this just for a laugh

I seem to remember there being something about Thumb mode being involved 
here.  Either having to call as a thumb routine or from a thumb 
routine.  Check the user manual, also take a look through past posts there 
has been a fair amount of discussion on the topic.

And if someone were to jump in and clarify...

Robert

" 'Freedom' has no meaning of itself.  There are always restrictions,
be they legal, genetic, or physical.  If you don't believe me, try to
chew a radio signal. "

                         Kelvin Throop, III

Re: [lpc2000] problem write in flash

2004-11-15 by Charles Manning

Read the appnote this explains how to do things properly.

If your code is in ARM mode (most likely scenario) then you need some 
mechansim to jump to the IAP code which is in Thumb mode.

I use a bit of assempber code that looks like:

   .text
   .code 32

@ void DoIAPCommand(unsigned *inBuf, unsigned *outBuf)
    .global DoIAPCommand

DoIAPCommand
     stmfd r13!,{r0-r12,r14}
     bl iap_jump
     ldmfd r13!{r0-r12,r14}
     mov pc,lr

iap_jump:
      ldr r12,=0x7ffffff1
      bx r12

The DoIAPCommand can then be called from C.
Show quoted textHide quoted text
On Tuesday 16 November 2004 10:24, Robert Adsett wrote:
> At 05:59 PM 11/12/04 +0000, you wrote:
> >Excuse to be still in the same issue, but already upgrad the boot
> >loader  revision 6.3, and change the file .ld and the problem
> >persist!!! in first comand "iap_entry(command, result);" the arm stop!!!
> >
> >I'm using LPC2129, that have 256K flash and 16K ram.
> >
> >Anyone can help me??
>
> I see no one else has piped up.  I can't help much since I haven't worked
> on it myself but maybe I can add a pointer.
>
> <snip>
>
> >I changed the following:
>
> <snip>
>
> >#define IAP_LOCATION 0x7ffffff1
> >
> >
> >void savesetup(struct SETUP *setup){
> >    typedef void (*IAP)(unsigned int [],unsigned int[]);
> >    unsigned int command[5];
> >    unsigned int result[2];
> >    IAP iap_entry;
> >
> >         //One copy of the structure in RAM
> >
> >         //struct SETUP setup;
> >
> >         //Pointer to the non volatile copy
> >
> >         //struct SETUP *nonvolatile;
> >         //nonvolatile = (struct SETUP*)0x38000; // Points to page 14 in
> > Flash (LPC2129)
> >
> >         //copy to RAM (if you need)
> >
> >         //setup=*nonvolatile;
> >
> >
> >         disableIRQ();
> >         disableFIQ();
> >
> >         iap_entry=(IAP) IAP_LOCATION;
> >         // get part ID
> >         command[0]=54;
> >         result[0]=0;
> >         escreve_UART0("SEIL AL ");
> >         iap_entry(command, result); // I do this just for a laugh
>
> I seem to remember there being something about Thumb mode being involved
> here.  Either having to call as a thumb routine or from a thumb
> routine.  Check the user manual, also take a look through past posts there
> has been a fair amount of discussion on the topic.
>
> And if someone were to jump in and clarify...
>
> Robert
>
> " 'Freedom' has no meaning of itself.  There are always restrictions,
> be they legal, genetic, or physical.  If you don't believe me, try to
> chew a radio signal. "
>
>                          Kelvin Throop, III
>
>
>
>
>
> Yahoo! Groups Links
>
>
>

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.