Sign in

username:

password:



Not a member?

Search AT91SAM



Search tips

Subscribe to AT91SAM



New!

Thinking MCU? Think TI
Visit the new
TI MCU resource center for the latest videos and documents to help support your design efforts.

Discussion Groups

See Also

DSPFPGAElectronics

Discussion Groups | AT91SAM ARM | C++ on a at91sam9260-ek with Yagarto

For users of the Atmel AT91SAM7 and AT91SAM9 ARM CPU chips. Atmel has taken a new direction by combining on chip flash and ram with the ARM CPU on a single die. This provides low cost devices for small systems using the ARM CPU. This group is to exchange information to help users get started and learn how to use the devices.

C++ on a at91sam9260-ek with Yagarto - gene_klein2000 - Aug 14 15:36:43 2009

Hi,

I would like to start programming in c++ on a at91sam9260-ek.

Is there anyone who can help me with the linker file and startup code for the constructors\destructors(if i need them).

What I'm using now is the AT91lib & getting started as an starting point.

My compiler are the Yagarto tools.

thanks ,
gene
------------------------------------

______________________________
LaunchPad Kit for MSP430 Value Line: Complete open source tool for harnessing 16-bit performance and ultra-low power. Click for Details


(You need to be a member of AT91SAM -- send a blank email to AT91SAM-subscribe@yahoogroups.com )


Re: C++ on a at91sam9260-ek with Yagarto - Dan Lyke - Aug 14 17:59:34 2009

On Fri, 14 Aug 2009 18:36:39 -0000
"gene_klein2000" wrote:
> I would like to start programming in c++ on a at91sam9260-ek.
>
> Is there anyone who can help me with the linker file and startup code
> for the constructors\destructors(if i need them).

On the AT91SAM9XE-EK, I just set up my Makefile to have C++ targets,
basically everywhere I had a CC I duplicated it with CXX and made the
appropriate change in the dependency rules from .c to .cxx compiled 'em
with $(CROSS)g++, and everything worked.
A quick look through my Makefile... Add

CXX = $(CROSS)g++
# like CFLAGS, except no -std=c99 -fgnu89inline
CXXFLAGS = -mlong-calls -ffunction-sections -Wall
# and just like CFLAGS
CXXFLAGS += -g $(OPTIMIZATION) $(INCLUDES) -D$(CHIP)

Setup your CXX_OBJECTS just like your C_OBJECTS (remember that you'll
need to "extern C {...}" your include files to call C_OBJECTS compiled
bits:

CXX_OBJECTS = main.o
CXX_OBJECTS += ...

Down in your "define RULES" section, do something similar to the
C_OBJECTS with CXX_OBJECTS and make sure you add $$(CXX_OBJECTS_$(1))
to the dependencies for your $(1)

CXX_OBJECTS_$(1) = $(addprefix $(OBJ)/$(1)_, $(CXX_OBJECTS))

$$(CXX_OBJECTS_$(1)): $(OBJ)/$(1)_%.o: %.cxx Makefile
$(CXX) $(CXXFLAGS) -D$(1) -c -o $$@ $$<
Dan
------------------------------------



(You need to be a member of AT91SAM -- send a blank email to AT91SAM-subscribe@yahoogroups.com )

Re: C++ on a at91sam9260-ek with Yagarto - gene_klein2000 - Aug 15 6:17:32 2009

Thanks Dan,

Already did this.

The problem is when I use a class the system goes crazy.

Added this code to board_startup.S for initializing the constructors

/* call C++ constructors of global objects */

LDR r0, =__ctors_start__
LDR r1, =__ctors_end__
ctor_loop:
CMP r0, r1
BEQ ctor_end
LDR r2, [r0], #4
STMFD sp!, {r0-r1}
MOV lr, pc
BX r2
LDMFD sp!, {r0-r1}
B ctor_loop
ctor_end:

/* Branch to main() */

to the linker file I've added

. = ALIGN(0x4);
PROVIDE(__ctors_start__ = .);
KEEP (*crtbegin.o(.ctors))
KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))
KEEP (*(SORT(.ctors.*)))
KEEP (*crtend.o(.ctors))
PROVIDE(__ctors_end__ = .);

. = ALIGN(4);
_efixed = .;

And made a small class like this

class TOptel
{
public :
int getal;

TOptel()
{
getal = 0;
}

void Task()
{
getal++;
}

};
extern TOptel Optel;

I've verified the calling of the constructor for this class.
A simple debug print in the constructor and i see the text.
So it is called.

The main loop is like this

int main()
{
unsigned long teller = 0;

// setup debug port
DBGU_Configure( DBGU_STANDARD, 115200, BOARD_MCK );

LED_Configure( LED_YELLOW );

// Optel.Task();

// the main loop
while( 1 )
{
teller ++;
if( teller >= 5000000 )
{
teller = 0;

LED_Toggle( LED_YELLOW );

DBGU_PutChar('"x' );
}

}
}

Normally this put an X on the terminal window every second or so.
As soon as I uncomment the line Optel.Task();
The terminal window is filled with X's.
And the delay is no more there
What is the problem here, what am I doing wrong ???
Thanks for any help,

Gene


(You need to be a member of AT91SAM -- send a blank email to AT91SAM-subscribe@yahoogroups.com )

Re: Re: C++ on a at91sam9260-ek with Yagarto - Dan Lyke - Aug 15 11:27:37 2009

On Sat, 15 Aug 2009 08:34:33 -0000
"gene_klein2000" wrote:
> The problem is when I use a class the system goes crazy.

Huh. I have several classes instantiated globally with no problems.
However, in looking back at my code I am just using it for code
organization, no vtables, no constructor code, and I'm not using any
dynamic allocation.

Sorry for that dead-end.

Dan
------------------------------------



(You need to be a member of AT91SAM -- send a blank email to AT91SAM-subscribe@yahoogroups.com )