C programs not wkg on Beagle Board

Hi,

ARM Assembly program using serial communication works fine on Beagle board.

However when I run the following C program:

/***********************************************************************

  • omap_main.c

************************************************************************/

#define S_PORT (volatile unsigned int *) 0x49020000

int main(void)

{

int i,j,k ;

while(1)

{

for(i=0;i<10;i++)

{

*S_PORT = 0x003f003f;

for(j=0;j<10000;j++)

for(k=0;k<10000;k++) ;

}

}

return 0;

}

I just get a prompt Starting Application …. And nothing else gets displayed.

I am trying to display ? mark in the prog using Serial Port 0x49020000

Can someone indicate what is wrong.

Rgds

Jayasurya

Jayasurya:

If you're running under Ångström or other Linux and your program runs
in user space, Ångström treats all addresses in your program as
virtual addresses, not physical addresses. You need to use mmap() to
get virtual addresses for your physical device registers.

There's some helpful discussion in the BeagleBoard FAQ:
BeagleBoardFAQ - eLinux.org.

Also, using busy wait timing is a bad idea in C. A construct like:

  for\(j=0;j&lt;10000;j\+\+\)
  for\(k=0;k&lt;10000;k\+\+\) ;

will normally be optimized into a NOP by the compiler. Even if it
isn't, the delay is totally implementation-dependent so is not
particularly useful. You're better off using sleep() or a variant.

Hope this helps,
John

Hi John,
Thanks for your suggestions.
I am not using any Linux image. After compiling and generating the bin file and transferring it to the card, I am using fatload to load the bin file into memory form the card. Then even if the delay is not working as expected shouldn't something get displayed?

  Thanks & Regards
    Jayasurya

Jayasurya:

Two things come to mind. One is that if there's no delay, your
program continuously overwrites the transmit data register (assuming
that's what 0x49020000 is). Depending on how the UART is implemented,
writing TX data before the UART is ready could confuse it.

The second is that when you link a C program, you normally link in a
"crtso.s" file (C run-time start-off) which sets up the stack and
interfaces to the operating system. This has to be compatible with
your environment.

Since your assembly language version works, the obvious question is
"what's different"? Your C compiler probably has an option where it
saves the compiler's assembly language file. That would be useful to
look at to see what's different from your own asm version. You could
also try linking it exactly the same way you linked the asm version.

Hope this helps,
John

Thanks John for your suggestions.
I shall try it out today and let you know.
Rgds
Jayasurya

jaya.venu@wipro.com said the following on 05/05/2009 07:11 PM:

Thanks John for your suggestions.
I shall try it out today and let you know.
  

If you are using standalone C program -> remember to setup a stack ->
cinit section also might be relevant..
Regards,
Nishanth Menon