Forums

running lpcusb on Olimex-h2148 problem

Started by Mohamad Tayssir Alkowatly August 27, 2009
Hi all

I'm trying to run lpcusb virtual COM example on Olimex h-2148 board using
Eclipse/GNUARM (gcc4.2.2), OpenOCD-0.2/Olimex-arm-usb-OCD wiggler. I'm able
to compile and flash a newly checked out virtual com program without any
trouble

I used a USB analyzer on windows and i'm sure noting happens when the board
is plugged. And as i don't have a serial interface fitted with the board, I
was trying to do some sort of blink code for debugging purposes when I
discovered the following facts about my program:
1- I found that when using no compilation optimization (-O0) even if I put
an empty while (1) loop just after the HalSysInit (mcu initialization code),
the system stuck in the UNDEF routine !!
2- when using code size or level two compilation optimization (-Os or -O2),
instead of blinking, the LED faintly lights as if the delay loops between
the LED turn on and turn off are not executed
3- when removing the delay loops between the LED turn on and turn off the
LED lights exactly in the same way as in case (2)
4- the same blink code with the same mcu clock setup and delay loops works
fine with the blink demo
5- the previous 4 cases are tested mainly with virtual com example
(main_serial) but they are valid for all other examples shipped with lpcusb

when putting all the previous results together, one can tell that I've make
a very stupid but subtle mistake that is probably a low level one and not
related to lpcusb, but unfortunately I'm new to ARM development and I don't
have any clue what am I missing

Any pointers will be very helpful

Thanks in advance

Tayseer


An Engineer's Guide to the LPC2100 Series

--- In l..., Mohamad Tayssir Alkowatly wrote:
>
> Hi all
>
> I'm trying to run lpcusb virtual COM example on Olimex h-2148 board using
> Eclipse/GNUARM (gcc4.2.2), OpenOCD-0.2/Olimex-arm-usb-OCD wiggler. I'm able
> to compile and flash a newly checked out virtual com program without any
> trouble
>
> I used a USB analyzer on windows and i'm sure noting happens when the board
> is plugged. And as i don't have a serial interface fitted with the board, I
> was trying to do some sort of blink code for debugging purposes when I
> discovered the following facts about my program:
> 1- I found that when using no compilation optimization (-O0) even if I put
> an empty while (1) loop just after the HalSysInit (mcu initialization code),
> the system stuck in the UNDEF routine !!
> 2- when using code size or level two compilation optimization (-Os or -O2),
> instead of blinking, the LED faintly lights as if the delay loops between
> the LED turn on and turn off are not executed
> 3- when removing the delay loops between the LED turn on and turn off the
> LED lights exactly in the same way as in case (2)
> 4- the same blink code with the same mcu clock setup and delay loops works
> fine with the blink demo
> 5- the previous 4 cases are tested mainly with virtual com example
> (main_serial) but they are valid for all other examples shipped with lpcusb
>
> when putting all the previous results together, one can tell that I've make
> a very stupid but subtle mistake that is probably a low level one and not
> related to lpcusb, but unfortunately I'm new to ARM development and I don't
> have any clue what am I missing
>
> Any pointers will be very helpful
>
> Thanks in advance
>
> Tayseer
>
>

Spin loops are optimized away. Code like

for (i = 0; i < 1000000;i++)
{
}

will be eliminated when the optimization is turned on.
You might want to look at jcwren's code for using USB with the LPC2148. See www.jcwren.com/arm

Richard
On Thu, Aug 27, 2009 at 3:03 PM, rtstofer wrote:

> -
> >
> > Spin loops are optimized away. Code like
>
> for (i = 0; i < 1000000;i++)
> {
> }
>
> will be eliminated when the optimization is turned on.
>
> You might want to look at jcwren's code for using USB with the LPC2148. See
> www.jcwren.com/arm
>
> Richard
>

Thanks Richard, strangely enough I noticed that even a loop like this will
be optimized:

for (i=0; i<1000000; i++)
j+=i;

my running blink loop now is
while (1)
{
for (j = 0; j < 500000; j++ )
IO1SET = 0x01000000;

for (j = 0; j < 500000; j++ )
IO1CLR = 0x01000000;
}

i think it's fine for debugging purposes.

Now i'm still wondering what causes UNDEF interrupt in the non optimized
code (-O0)

Regards,

Tayseer


On Thu, Aug 27, 2009 at 3:03 PM, rtstofer wrote:

> You might want to look at jcwren's code for using USB with the LPC2148. See
> www.jcwren.com/arm
>
> Richard
>
That USB example is not working as well. as with the lpcusb, nothing happens
and nothing appear of the USB analyzer

I've noticed that the processor stuck in UNDEF routine when executing this
line:

// configure P0.23 for Vbus sense
PINSEL1 = (PINSEL1 & ~(3 << 14)) | (1 << 14); // P0.23

which enables the VBUS sensing on P0.23. Would this indicate what is wrong ?

Kind Regards,

Tayseer


Accessing PINSEL1 causes undefined exception, Here is the C code:
BOOL USBHwInit(void)
{
PINSEL1 = PINSEL1;
....

and here is the disassembly of this chunk:
LDR r4, [pc, #260]
LDR r3, [r4, #4]
MOV r0, #1
STR r3, [r4, #4]

the mcu fires an undefined exception when executing the STR instruction
because r4 value is 0 and not the value that would make r4+4=PINSEL1 address

How come the assembler doesn't put the correct value of PINSEL1 address in
the registers before the store instruction ? this is way over my head :(
Can anyone please tell me what nasty thing did that ?

Cheers

Tayseer