EmbeddedRelated.com
Forums

LPC2106 IAP

Started by David Bermingham March 21, 2004
Hello,
Im trying to write some data from the RAM to the flash using the IAP, I followed the application note pdf given by philips but when I call the iap_entry function the processor seems to hang...nothing happens at all!!!
 
Do you pass the command code and command parameters into the command data structure or am I missing something..even when I try to do something simple like read the Part ID it seems to hang!
Thanks....again!
David


An Engineer's Guide to the LPC2100 Series

--- In , David Bermingham <crwpulsar@y...>
wrote:
> Hello,
> Im trying to write some data from the RAM to the flash using the
IAP, I followed the application note pdf given by philips but when I
call the iap_entry function the processor seems to hang...nothing
happens at all!!!
>
> Do you pass the command code and command parameters into the
command data structure or am I missing something..even when I try to
do something simple like read the Part ID it seems to hang!
> Thanks....again!
> David

When you say "nothing happens at all", what do you mean? Is it stuck
in the IAP code or did it cause an exception?

There are a few things that I can think of that might be causing
problems:
* Incorrect set up of parameters. Likely to cause a data abort.
* Incorrect set up of the thumb bx stuff. Likely to cause a prefetch
or other abort.

-- Charles



Yeah, I call iap_entry(command,result) and the next line of the code is printf something and it never calls the printf. I pretty much copied the philips code from the app note because this stuff is new to me!(Like most of it!!!) so it must be incorrect parameter passing??

embeddedjanitor <m...@actrix.gen.nz> wrote:
--- In l...@yahoogroups.com, David Bermingham <crwpulsar@y...>
wrote:
> Hello,
> Im trying to write some data from the RAM to the flash using the
IAP, I followed the application note pdf given by philips but when I
call the iap_entry function the processor seems to hang...nothing
happens at all!!!

> Do you pass the command code and command parameters into the
command data structure or am I missing something..even when I try to
do something simple like read the Part ID it seems to hang!
> Thanks....again!
> David

When you say "nothing happens at all", what do you mean? Is it stuck
in the IAP code or did it cause an exception?

There are a few things that I can think of that might be causing
problems:
* Incorrect set up of parameters. Likely to cause a data abort.
* Incorrect set up of the thumb bx stuff. Likely to cause a prefetch
or other abort.

-- Charles



--- In , David Bermingham <crwpulsar@y...>
wrote:
> Yeah, I call iap_entry(command,result) and the next line of the code
is printf something and it never calls the printf. I pretty much
copied the philips code from the app note because this stuff is new to
me!(Like most of it!!!) so it must be incorrect parameter passing??

I guess you are using the GCC compiler and the ARM instruction set?
Because I'm using that (along with AsIDE) and had exactly the same
problem.

After some reading, and googling and some more reading and some
assembly debugging we found some clues that lead to the solution.

In short: turn on the compiler option '-mthumb-interwork'. This is
nessecary since the bootloader function you are accessing is written
in Thumb code, see page 193 of the user manual of 2003 okt 02.

You should jump from ARM to Thumb using the BX instruction from the
ARM instruction set. This is automatically done by your compiler but
GCC has this function (thumb-interwork) disabled by default since it
generates slightly bigger code. When you switch it on you shuld be
fine...

Hope that helped!
Greetings,
Herman



Thanks for the reply, Im using ARM ADS 1.2 to compile the code! Does anybody know how or if I have to turn on interworking for ADS?
 
Also, I have a routine which has to be executed out of RAM instead of Flash to operate properly. When I change the scatterloading file so that aes.o is loaded in RAM the program never branches to it...its like its not there!!
When I check the map file generated by ADS it says the code is located in RAM.
 
Is there a way to set up the scatterloading file so that the routine is copied from Flash to RAM and executed from RAM?
 
Sorry for all the questions!
Thanks,
David

deballendeballen <y...@grin.sambalbij.nl> wrote:
--- In l...@yahoogroups.com, David Bermingham <crwpulsar@y...>
wrote:
> Yeah, I call iap_entry(command,result) and the next line of the code
is printf something and it never calls the printf. I pretty much
copied the philips code from the app note because this stuff is new to
me!(Like most of it!!!) so it must be incorrect parameter passing??

I guess you are using the GCC compiler and the ARM instruction set?
Because I'm using that (along with AsIDE) and had exactly the same
problem.

After some reading, and googling and some more reading and some
assembly debugging we found some clues that lead to the solution.

In short: turn on the compiler option '-mthumb-interwork'. This is
nessecary since the bootloader function you are accessing is written
in Thumb code, see page 193 of the user manual of 2003 okt 02.

You should jump from ARM to Thumb using the BX instruction from the
ARM instruction set. This is automatically done by your compiler but
GCC has this function (thumb-interwork) disabled by default since it
generates slightly bigger code. When you switch it on you shuld be
fine...

Hope that helped!
Greetings,
Herman



--- In , David Bermingham <crwpulsar@y...>
wrote:
> Thanks for the reply, Im using ARM ADS 1.2 to compile the code!
Does anybody know how or if I have to turn on interworking for ADS?

Hi David, yes you need to turn on interworking, however this is done
for you automatically if you create an application using the
Thumb/ARM interworking template. This is convenient as you simply
place source files to be built as ARM code in the ARM subproject,
and the IDE takes care of all the other details.

Alternatively, you'll find the interworking tickbox in the project
settings dialog, under the ATPCS tab when you select the assembler,
ARM C compiler or Thumb C compiler. A major irritation (for me
anyway) is that you have to set this for each subproject (Thumb and
ARM), each target (Debug, DebugRel, Release) and each tool (asm, C,
C++) that you use.

>
> Also, I have a routine which has to be executed out of RAM instead
of Flash to operate properly. When I change the scatterloading file
so that aes.o is loaded in RAM the program never branches to
it...its like its not there!!
> When I check the map file generated by ADS it says the code is
located in RAM.
>
> Is there a way to set up the scatterloading file so that the
routine is copied from Flash to RAM and executed from RAM?

Can I ask first if you have a main() function in your project? If
you have, then the linker pulls in some C-startup code, which
includes a section to move code and initialised data from their load
positions (in Flash) to their execute positions in RAM.

If not, you have to write your own code snippets in the reset
handler to move the code and data around. Conveniently, the linker
will generate symbols giving you the load address, execution
address, and length of each region to be moved. See page 4-2 of the
Linker and Utilities guide, for a description of the format for
these symbols.

HTH, Peter.



Hi Peter,
Thanks for the info....that solved the IAP issue!!Works prefectly now!
 
As regards the second problem/issue, The startup file Im using just initialises the exception vectors, stacks and branches to main(). Do I need another assembly routine to move the data from Flash to RAM?? I thought the scatterloading file set that up?
The problem I have is that any global variables or buffers in the code seem to cause the error! I can remove the problem by using local variables and passing them between functions but this is less than pretty!!!
 
Thanks,
David
 
 
 
 
 

Peter <f...@codesprite.com> wrote:
--- In l...@yahoogroups.com, David Bermingham <crwpulsar@y...>
wrote:
> Thanks for the reply, Im using ARM ADS 1.2 to compile the code!
Does anybody know how or if I have to turn on interworking for ADS?

Hi David, yes you need to turn on interworking, however this is done
for you automatically if you create an application using the
Thumb/ARM interworking template. This is convenient as you simply
place source files to be built as ARM code in the ARM subproject,
and the IDE takes care of all the other details.

Alternatively, you'll find the interworking tickbox in the project
settings dialog, under the ATPCS tab when you select the assembler,
ARM C compiler or Thumb C compiler. A major irritation (for me
anyway) is that you have to set this for each subproject (Thumb and
ARM), each target (Debug, DebugRel, Release) and each tool (asm, C,
C++) that you use.


> Also, I have a routine which has to be executed out of RAM instead
of Flash to operate properly. When I change the scatterloading file
so that aes.o is loaded in RAM the program never branches to
it...its like its not there!!
> When I check the map file generated by ADS it says the code is
located in RAM.

> Is there a way to set up the scatterloading file so that the
routine is copied from Flash to RAM and executed from RAM?

Can I ask first if you have a main() function in your project? If
you have, then the linker pulls in some C-startup code, which
includes a section to move code and initialised data from their load
positions (in Flash) to their execute positions in RAM.

If not, you have to write your own code snippets in the reset
handler to move the code and data around. Conveniently, the linker
will generate symbols giving you the load address, execution
address, and length of each region to be moved. See page 4-2 of the
Linker and Utilities guide, for a description of the format for
these symbols.

HTH, Peter.



--- In , David Bermingham <crwpulsar@y...>
wrote:
> Hi Peter,
> Thanks for the info....that solved the IAP issue!!Works prefectly
now!
>
> As regards the second problem/issue, The startup file Im using
just initialises the exception vectors, stacks and branches to main
(). Do I need another assembly routine to move the data from Flash
to RAM?? I thought the scatterloading file set that up?
> The problem I have is that any global variables or buffers in the
code seem to cause the error! I can remove the problem by using
local variables and passing them between functions but this is less
than pretty!!!
>
> Thanks,
> David
>

Hi David,

Excellent - glad the IAP is working now. For the scatterloading
problem, try branching to __main instead of main. Have you also
written your own version of __user_initial_stackheap, to tell the C
startup code where to place the heap base and stack limit?

Peter.




No I was just using the startup file given with Keil's IDE for ADS...
 
Section of Startup.s
 
; Setup Stack for each mode
                LDR     R0, =Top_Stack
;  Enter Undefined Instruction Mode and set its Stack Pointer
                MSR     CPSR_c, #Mode_UND:OR:I_Bit:OR:F_Bit
                MOV     SP, R0
                SUB     R0, R0, #UND_Stack_Size
;  Enter Abort Mode and set its Stack Pointer
                MSR     CPSR_c, #Mode_ABT:OR:I_Bit:OR:F_Bit
                MOV     SP, R0
                SUB     R0, R0, #ABT_Stack_Size
;  Enter FIQ Mode and set its Stack Pointer
                MSR     CPSR_c, #Mode_FIQ:OR:I_Bit:OR:F_Bit
                MOV     SP, R0
                SUB     R0, R0, #FIQ_Stack_Size
;  Enter IRQ Mode and set its Stack Pointer
                MSR     CPSR_c, #Mode_IRQ:OR:I_Bit:OR:F_Bit
                MOV     SP, R0
                SUB     R0, R0, #IRQ_Stack_Size
;  Enter Supervisor Mode and set its Stack Pointer
                MSR     CPSR_c, #Mode_SVC:OR:I_Bit:OR:F_Bit
                MOV     SP, R0
                SUB     R0, R0, #SVC_Stack_Size
;  Enter User Mode and set its Stack Pointer
                MSR     CPSR_c, #Mode_USR
          MOV     SP, R0

; Enter the C code
                IMPORT  __main
                LDR     R0, =__main
                BX      R0
The gcc Startup files have the loop to move .data section and clear the .bss section before jumping to main so I assume there is a setting in ADS to do this automatically during assembly? Like I say, the code wont execute on anything with global variables....I get either random data or program crash and that it must be due to how im initializing the micro!
 
David.
 


Peter <p...@codesprite.com> wrote:
--- In l...@yahoogroups.com, David Bermingham <crwpulsar@y...>
wrote:
> Hi Peter,
> Thanks for the info....that solved the IAP issue!!Works prefectly
now!

> As regards the second problem/issue, The startup file Im using
just initialises the exception vectors, stacks and branches to main
(). Do I need another assembly routine to move the data from Flash
to RAM?? I thought the scatterloading file set that up?
> The problem I have is that any global variables or buffers in the
code seem to cause the error! I can remove the problem by using
local variables and passing them between functions but this is less
than pretty!!!

> Thanks,
> David


Hi David,

Excellent - glad the IAP is working now. For the scatterloading
problem, try branching to __main instead of main. Have you also
written your own version of __user_initial_stackheap, to tell the C
startup code where to place the heap base and stack limit?

Peter.




> The gcc Startup files have the loop to move .data section and
clear the .bss section before jumping to main so I assume there is a
setting in ADS to do this automatically during assembly? Like I say,
the code wont execute on anything with global variables....I get
either random data or program crash and that it must be due to how
im initializing the micro!
>
> David.

Hmmm... the C startup code should move all the initialised data and
zero the ZI (.bss) data for you. I can't see that Keil's IDE would
be changing things. We had better take this offline, and post the
fix back to the group (if appropriate) when we've sorted it out.

Peter.