Yahoo Groups archive

Lpc2000

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

Thread

Calling IAP-routines from thumb mode

Calling IAP-routines from thumb mode

2006-01-22 by conrado

Hi Guys,

I try to call the IAP-routines from ARM-mode with help of the code 
to enter THUMB-mode from the file section:

static void callIAP(void)
{
  // fast way to get the address of flashParams[] directly into r0
  register void *pFP asm("r0") = flashParams;

  asm volatile(" mov r1, r0\n"          // copy &flashParams[] into 
r1
               " bx  %[iapLocation]"    // 'bx' because IAP is Thumb 
mode
               :
               : "r" (pFP), [iapLocation] "r" (IAP_LOCATION)
               : "r1" );
}

The code runs fine, the IAP is entered in thumb mode and returns to 
ARM-mode again. Only nothing happens: when I try to read the Part Id 
(command 0x36) it returns 0. The same for the Boot Code (command 
0x37). R0 / R1 points to the (same) FlashParams. With help of the 
debugger I see the 0x36/0x37-commands in these parameters are 
overwritten by zero.

Who can help me please?

Thanks in advance,

Conrado

Re: [lpc2000] Calling IAP-routines from thumb mode

2006-01-23 by Tom Walsh

conrado wrote:

>Hi Guys,
>
>I try to call the IAP-routines from ARM-mode with help of the code 
>to enter THUMB-mode from the file section:
>
>static void callIAP(void)
>{
>  // fast way to get the address of flashParams[] directly into r0
>  register void *pFP asm("r0") = flashParams;
>
>  asm volatile(" mov r1, r0\n"          // copy &flashParams[] into 
>r1
>               " bx  %[iapLocation]"    // 'bx' because IAP is Thumb 
>mode
>               :
>               : "r" (pFP), [iapLocation] "r" (IAP_LOCATION)
>               : "r1" );
>}
>
>The code runs fine, the IAP is entered in thumb mode and returns to 
>ARM-mode again. Only nothing happens: when I try to read the Part Id 
>(command 0x36) it returns 0. The same for the Boot Code (command 
>0x37). R0 / R1 points to the (same) FlashParams. With help of the 
>debugger I see the 0x36/0x37-commands in these parameters are 
>overwritten by zero.
>
>  
>
I dunno, mine works and I didn't bother with ASM:

======== begin C call to ID ============

#define  IAP_LOCATION            0x7ffffff1

typedef void (*IAP)(unsigned int [],unsigned int[]);
unsigned int command_iap[5], result_iap[3];
IAP   iap_entry;


static int iapCommand (iap_calls_t command, int parm1, int parm2, int parm3)
{ // execute ISP similar command via IAP calls.
   iap_entry = (IAP) IAP_LOCATION;
   switch (command) {
...
...
      case IAP_READ_PART_ID:
         command_iap [0] = 54;
         disableIRQ(); iap_entry(command_iap,result_iap); enableIRQ();
         return result_iap[1];
...
...
    }
    return False;
}


=========== snip =================

Regards,

TomW

-- 
Tom Walsh - WN3L - Embedded Systems Consultant
http://openhardware.net, http://cyberiansoftware.com
"Windows? No thanks, I have work to do..."
----------------------------------------------------

Re: [lpc2000] Calling IAP-routines from thumb mode

2006-01-23 by Robert Adsett

At 11:36 PM 1/22/06 -0500, Tom Walsh wrote:
>I dunno, mine works and I didn't bother with ASM:
>
>======== begin C call to ID ============
>
>#define  IAP_LOCATION            0x7ffffff1
>
>typedef void (*IAP)(unsigned int [],unsigned int[]);
>unsigned int command_iap[5], result_iap[3];
>IAP   iap_entry;
>
>
>static int iapCommand (iap_calls_t command, int parm1, int parm2, int parm3)
>{ // execute ISP similar command via IAP calls.
>    iap_entry = (IAP) IAP_LOCATION;
>    switch (command) {
>....
>....
>       case IAP_READ_PART_ID:
>          command_iap [0] = 54;
>          disableIRQ(); iap_entry(command_iap,result_iap); enableIRQ();

That only works if the compiler uses a bx to call iap_entry.  Not all do 
and there is AFAIK nothing that would require a compiler to (keep) doing so.

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
http://www.aeolusdevelopment.com/

Re: [lpc2000] Calling IAP-routines from thumb mode

2006-01-23 by Tom Walsh

Robert Adsett wrote:

>At 11:36 PM 1/22/06 -0500, Tom Walsh wrote:
>  
>
>>I dunno, mine works and I didn't bother with ASM:
>>
>>======== begin C call to ID ============
>>
>>#define  IAP_LOCATION            0x7ffffff1
>>
>>typedef void (*IAP)(unsigned int [],unsigned int[]);
>>unsigned int command_iap[5], result_iap[3];
>>IAP   iap_entry;
>>
>>
>>static int iapCommand (iap_calls_t command, int parm1, int parm2, int parm3)
>>{ // execute ISP similar command via IAP calls.
>>   iap_entry = (IAP) IAP_LOCATION;
>>   switch (command) {
>>....
>>....
>>      case IAP_READ_PART_ID:
>>         command_iap [0] = 54;
>>         disableIRQ(); iap_entry(command_iap,result_iap); enableIRQ();
>>    
>>
>
>That only works if the compiler uses a bx to call iap_entry.  Not all do 
>and there is AFAIK nothing that would require a compiler to (keep) doing so.
>
>  
>
Yes, and having a JTAG unit is a good thing!  :-)

TomW

-- 
Tom Walsh - WN3L - Embedded Systems Consultant
http://openhardware.net, http://cyberiansoftware.com
"Windows? No thanks, I have work to do..."
----------------------------------------------------

Re: Calling IAP-routines from thumb mode

2006-01-23 by conrado

Thanks guys,

I checked the BX-call several times and debugged even in the the 
THUMB-part. I overlooked however the result comes in Params[1].

Small step voor de ARM, large step for me...

Conrado


--- In lpc2000@yahoogroups.com, Tom Walsh <tom@o...> wrote:
>
> Robert Adsett wrote:
> 
> >At 11:36 PM 1/22/06 -0500, Tom Walsh wrote:
> >  
> >
> >>I dunno, mine works and I didn't bother with ASM:
> >>
> >>======== begin C call to ID ============
> >>
> >>#define  IAP_LOCATION            0x7ffffff1
> >>
> >>typedef void (*IAP)(unsigned int [],unsigned int[]);
> >>unsigned int command_iap[5], result_iap[3];
> >>IAP   iap_entry;
> >>
> >>
> >>static int iapCommand (iap_calls_t command, int parm1, int 
parm2, int parm3)
> >>{ // execute ISP similar command via IAP calls.
> >>   iap_entry = (IAP) IAP_LOCATION;
> >>   switch (command) {
> >>....
> >>....
> >>      case IAP_READ_PART_ID:
> >>         command_iap [0] = 54;
> >>         disableIRQ(); iap_entry(command_iap,result_iap); 
enableIRQ();
> >>    
> >>
> >
> >That only works if the compiler uses a bx to call iap_entry.  Not 
all do 
> >and there is AFAIK nothing that would require a compiler to 
(keep) doing so.
Show quoted textHide quoted text
> >
> >  
> >
> Yes, and having a JTAG unit is a good thing!  :-)
> 
> TomW
> 
> -- 
> Tom Walsh - WN3L - Embedded Systems Consultant
> http://openhardware.net, http://cyberiansoftware.com
> "Windows? No thanks, I have work to do..."
> ----------------------------------------------------
>

Re[2]: [lpc2000] Calling IAP-routines from thumb mode

2006-01-23 by NITA

Hi!
 
>>#define  IAP_LOCATION            0x7ffffff1
                                            ^
>>          disableIRQ(); iap_entry(command_iap,result_iap); enableIRQ();
> That only works if the compiler uses a bx to call iap_entry.  Not all do
> and there is AFAIK nothing that would require a compiler to (keep) doing so.

 Addres of function force compiler to call THUMB mode function.

 Alex

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.