Yahoo Groups archive

Lpc2000

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

Thread

_start code crashes

_start code crashes

2006-03-12 by Rebekah Moser

I am using the Keil uVision development environment with the GNU tools
for a Philips LPC2148.  Using the version of GCC currently being
shipped with the debugger (3.3.1 or some such thing - it's 2.5 yrs
old) I stepped through the branch to _start at the end of my startup
assembly file that sets exception vectors, stacks, etc.  It bounced
around a bit then hit a SWI instruction and decided that was
undefined.  I loaded up gcc-4.0.2 and now I am seeing SWI
as the third instruction of _start.  Furthermore, it is SWI 0x00123456
which is really weird.  I checked the linker map to verify that it was
getting the library from the right place, and things looked reasonable
there.  In the Keil tools I am using support for calls between ARM and
THUMB, compiling THUMB code, and enabling ARM/THUMB interworking.  I
did not give the linker any additional include path or commands beyond
what the Keil tool sets up.  I have also tried turning off all the
THUMB stuff to do a straight ARM system, but it didn't help.  Any
suggestions on where to go from here would be greatly appreciated.

Rebekah

Re: [lpc2000] _start code crashes

2006-03-12 by Tom Walsh

Rebekah Moser wrote:

>I am using the Keil uVision development environment with the GNU tools
>for a Philips LPC2148.  Using the version of GCC currently being
>shipped with the debugger (3.3.1 or some such thing - it's 2.5 yrs
>old) I stepped through the branch to _start at the end of my startup
>assembly file that sets exception vectors, stacks, etc.  It bounced
>around a bit then hit a SWI instruction and decided that was
>undefined.  I loaded up gcc-4.0.2 and now I am seeing SWI
>as the third instruction of _start.  Furthermore, it is SWI 0x00123456
>which is really weird.  I checked the linker map to verify that it was
>getting the library from the right place, and things looked reasonable
>there.  In the Keil tools I am using support for calls between ARM and
>THUMB, compiling THUMB code, and enabling ARM/THUMB interworking.  I
>did not give the linker any additional include path or commands beyond
>what the Keil tool sets up.  I have also tried turning off all the
>THUMB stuff to do a straight ARM system, but it didn't help.  Any
>suggestions on where to go from here would be greatly appreciated.
>
>  
>
Reading your post, one assumes that the processor is being caught right 
at startup by the JTAG debugger.  However, this reminds me of a problem 
I ran into very early in development.  I had a bad situation where the 
program would ABORT, I tried to use the JTAG to find the problem but the 
JTAG would only connect me to an aborted processor.

The problem was this, the JTAG (BDI2000) would reset the CPU, then delay 
for a short interval and then go through the process of stopping the CPU 
via the JTAG chain.  During the time between the reset inactive and when 
the JTAG finally "caught" the processor, the CPU had run through a large 
number of instructions and hit the abort point.

This was solved by placing a delay loop in the crt0.S file which forces 
the CPU to configure the secondary JTAG (LPC2106), then delay.  The 
delay allows the Abatron BDI2000 time to "catch" the CPU via the JTAG.  
This a snippet of my LPC2106 startup, and representative of the same 
thing in the LPC2138 which I also use:

============= begin crt0.S ===============
...
...

JTAG2:
   .word 0x55400000
PINSELREG:
   .word 0xe002c004

        .size _boot, . - _boot
        .endfunc


// Setup the operating mode & stack.
// ---------------------------------
        .global _start, start, _mainCRTStartup
        .func   _start

_start:
start:
_mainCRTStartup:
;
      ldr   r0, JTAG2
      ldr   r1, PINSELREG
      str   r0, [r1]       // activate secondary JTAG port.
;
      mov   r3, #0x10000
startdelay:
      subs  r3, r3, #1
      bne   startdelay     // give debugger time to catch us.
;
        ldr   r0,=_stack
        msr   CPSR_c,#MODE_UND|I_BIT|F_BIT // Undefined Instruction Mode

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


TomW



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

Re: _start code crashes

2006-03-13 by Rebekah Moser

--- In lpc2000@yahoogroups.com, Tom Walsh <tom@...> wrote:
> Reading your post, one assumes that the processor is being caught right 
> at startup by the JTAG debugger.  However, this reminds me of a problem 
> I ran into very early in development.  I had a bad situation where the 
> program would ABORT, I tried to use the JTAG to find the problem but
the 
> JTAG would only connect me to an aborted processor.
> 
> The problem was this, the JTAG (BDI2000) would reset the CPU, then
delay 
> for a short interval and then go through the process of stopping the
CPU 
> via the JTAG chain.  During the time between the reset inactive and
when 
> the JTAG finally "caught" the processor, the CPU had run through a
large 
> number of instructions and hit the abort point.
> 
> This was solved by placing a delay loop in the crt0.S file

I did try adding the delay loop before the branch to _start, but it
didn't seem to make a difference.  When I first started debugging I
simply set a breakpoint a ways into my main() routine.  It hung.  I
did a break and found it stuck in the undefined instruction routine
(which just branches to self).  I then set a breakpoint at the branch
to _start and started stepping from there to see what it didn't like.
 JTAG is indeed the debugger connection, but the program was free
running when I first tried it, so I'm thinking JTAG shouldn't be
creating a problem.

Note that I am using the binary version of the GNU tools.  I did not
download source for 4.0.2 (and indeed source code was NOT shipped with
the Keil debugger either, just the binary version).  My startup file
ends with a branch to _start which is supplied by the GNU library so I
don't have control over what it is actually calling.  Interestingly
enough, when I used the older version of GNU I was fine until I added
a call to sprintf which of course brought in more library functions. 
It took awhile to crash, but did eventually.  Using 4.0.2 it seems to
be unhappy with or without sprintf.  I disassembled the code it jumps
to for _start, which looks like so:

0x00000258  E3A00016  MOV       R0,#0x00000016
0x0000025C  E28F10E8  ADD       R1,PC,#0x000000E8
0x00000260  EF123456  SWI       0x00123456
0x00000264  E59F00E0  LDR       R0,[PC,#0x00E0]
0x00000268  E590D008  LDR       R13,[R0,#0x0008]
0x0000026C  E590A00C  LDR       R10,[R0,#0x000C]
0x00000270  E28AAC01  ADD       R10,R10,#0x00000100

It is the SWI that it doesn't like.    Does the code snippet seem
right?  Is there a problem with the precompiled libraries?

One last bit of info, if it helps, the compile and link options
created by Keil are:

-c -mcpu=arm7tdmi -mthumb -gdwarf-2 -MD -Wall -O -mapcs-frame
-mthumb-interwork -IC:\Keil\ARM\INC\Philips\ -o *.o

and

-T .\LinkerScript.ld -mthumb-interwork -Wl,-Map=".\lst\bs1200.map" 
,-Ttext=0

Rebekah

Re: _start code crashes

2006-03-14 by Rebekah Moser

--- In lpc2000@yahoogroups.com, "Rebekah Moser" <moserr@...> wrote:
> I disassembled the code it jumps to for _start,
> which looks like so:
> 
> 0x00000258  E3A00016  MOV       R0,#0x00000016
> 0x0000025C  E28F10E8  ADD       R1,PC,#0x000000E8
> 0x00000260  EF123456  SWI       0x00123456

More info on this - this code comes from crt0.o.  It appears that gcc
version 4.0.2 has several crt0 options:  crt0.o, rdimon-crt0.o,
rdpmon-crt0.o, and redboot-crt0.o.  Not all of them have the offending
SWI instruction in them.  What is the difference between these?

Thanks,
Rebekah

Re: [lpc2000] Re: _start code crashes

2006-03-14 by Robert Adsett

At 12:49 AM 3/14/2006 +0000, Rebekah Moser wrote:
>--- In lpc2000@yahoogroups.com, "Rebekah Moser" <moserr@...> wrote:
> > I disassembled the code it jumps to for _start,
> > which looks like so:
> >
> > 0x00000258  E3A00016  MOV       R0,#0x00000016
> > 0x0000025C  E28F10E8  ADD       R1,PC,#0x000000E8
> > 0x00000260  EF123456  SWI       0x00123456
>
>More info on this - this code comes from crt0.o.  It appears that gcc
>version 4.0.2 has several crt0 options:  crt0.o, rdimon-crt0.o,
>rdpmon-crt0.o, and redboot-crt0.o.  Not all of them have the offending
>SWI instruction in them.  What is the difference between these?

Those are all for different boards (some with built-in monitors) and since 
you are asking in an LPC group it's likely that none are appropriate.  You 
need startup specific to the LPC to deal with its memory map and any other 
init you want to occur before the main C code, just as you would for any 
other microcontroller.

There are multiple examples around.  I think there are some in the groups 
files section.  Also take a look at the newlib-lpc stuff at 
http://www.aeolusdevelopment.com/Articles/download.html although that's set 
up for newlib and the distribution you are using appears to be using a 
different library. You might also want to take a look at the WINARM 
distribution which includes the newlib-lpc stuff. There is also the 
Crossworks distribution which includes a number of other items.

Robert

Re: [lpc2000] Re: _start code crashes

2006-03-14 by Tom Walsh

Robert Adsett wrote:

>At 12:49 AM 3/14/2006 +0000, Rebekah Moser wrote:
>  
>
>>--- In lpc2000@yahoogroups.com, "Rebekah Moser" <moserr@...> wrote:
>>    
>>
>>>I disassembled the code it jumps to for _start,
>>>which looks like so:
>>>
>>>0x00000258  E3A00016  MOV       R0,#0x00000016
>>>0x0000025C  E28F10E8  ADD       R1,PC,#0x000000E8
>>>0x00000260  EF123456  SWI       0x00123456
>>>      
>>>
>>More info on this - this code comes from crt0.o.  It appears that gcc
>>version 4.0.2 has several crt0 options:  crt0.o, rdimon-crt0.o,
>>rdpmon-crt0.o, and redboot-crt0.o.  Not all of them have the offending
>>SWI instruction in them.  What is the difference between these?
>>    
>>
>
>Those are all for different boards (some with built-in monitors) and since 
>you are asking in an LPC group it's likely that none are appropriate.  You 
>need startup specific to the LPC to deal with its memory map and any other 
>init you want to occur before the main C code, just as you would for any 
>other microcontroller.
>
>  
>
You are also going to need a makefile to build your code.  You want to 
disable certain default behaviors of gcc and replace it with your own.  
For example, my gcc compile line looks like this to compile (not link) 
main2106.c :

=================== begin =====================

arm-elf-gcc -c -O0 -mthumb  -mcpu=arm7tdmi -march=armv4t 
-DTOPLEVEL=/home/tom/Mu3Devel/CommCPU/../ -I. -gstabs -DROM_RUN 
-I/home/tom/Mu3Devel/CommCPU/../include 
-I/home/tom/MuxPad3Devel/CommCPU/../libs/include -Wall 
-Wstrict-prototypes -Wcast-align -Wcast-qual -Wimplicit 
-Wmissing-declarations -Wmissing-prototypes -Wnested-externs 
-Wpointer-arith -Wswitch -Wredundant-decls -Wreturn-type -Wshadow 
-Wstrict-prototypes -Wunused -Wa,-adhlns=main2106.lst  -std=gnu99 
-nostdlib -nodefaultlibs 
-L/home/tom/devtools/armThumb-4.0.2/arm-elf/lib/thumb/interwork/ 
-L/home/tom/devtools/armThumb-4.0.2/lib/gcc/arm-elf/4.0.2/interwork/ -MD 
-MP -MF .dep/main2106.o.d -DLPC2106 
-I/home/tom/Mu3Devel/CommCPU//include  -DLPC2106 main2106.c -o main2106.o

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

Just doing a "arm-elf-gcc -c main2106.c -o main2106.o"  just won't 
work.  As to the linking, this is what the linker line looks like:

================== begin ========================

arm-elf-gcc -O0 -mcpu=arm7tdmi -march=armv4t 
-DTOPLEVEL=/home/tom/Mu3Devel/CommCPU/../ -I. -gstabs -DROM_RUN 
-I/home/tom/Mu3Devel/CommCPU/../include 
-I/home/tom/Mu3Devel/CommCPU/../libs/include -Wall -Wstrict-prototypes 
-Wcast-align -Wcast-qual -Wimplicit -Wmissing-declarations 
-Wmissing-prototypes -Wnested-externs -Wpointer-arith -Wswitch 
-Wredundant-decls -Wreturn-type -Wshadow -Wstrict-prototypes -Wunused 
-Wa,-adhlns=main2106.o  -std=gnu99 -nostdlib -nodefaultlibs 
-L/home/tom/devtools/armThumb-4.0.2/arm-elf/lib/thumb/interwork/ 
-L/home/tom/devtools/armThumb-4.0.2/lib/gcc/arm-elf/4.0.2/interwork/ -MD 
-MP -MF .dep/main2106.elf.d -DLPC2106 
-I/home/tom/Mu3Devel/CommCPU//include  -DLPC2106 main2106.o globals.o 
crt0.o --output /home/tom/Mu3Devel/CommCPU/main2106.elf -nostartfiles 
-Wl,-Map=/home/tom/Mu3Devel/CommCPU/main2106.map,--cref -TLPC2106-ROM.ld 
`cat .linkobjs`

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

Granted, the above examples are a mouthful!  But, each statement / 
switch in the compile & link have a specific purpose.  I suggest that 
you get yourself one of the project examples, like blinky, from the 
Yahoo files section and start building it up from there.

Regards,

TomW

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

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.