Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
capitan
PostPosted: Aug 16, 2007 - 01:30 PM
Rookie


Joined: Aug 03, 2007
Posts: 23


Hi all,

I finally got the evk110 and the JTag unit.
I installed the UC30 frame work, I have managed to create my own workspace in the APLICATIONS folder, I also created a standard c project with the make files from DRIVERS/*.*/EXAMPLES/*.*/GCC/, I just needed to change some PATHs. And they work very well! So far so good! Smile

It’s all good in C, now I want to use my C++ code, but the make files provided in the DRIVERS/*.*/EXAMPLES/*.*/GCC/ don’t like my main.c to be a main.cpp.
1-Can these makefile and config files be modify to take c++ compiler, if so, is it difficult?

2-I have also built a project using Managed C++ make file, some driver files needed small changes and they build ok and I can also debug it on the evk, BUT Interrupts are not working anymore!!, I can manage to set the usart and pins but that is as far as it goes. It’s a bit frustrating thought.
I have to mention that in debug mode it build ok, but if I try to build in Release mode one, lots of errors show up Confused

The make files looks complete different, in the Standard way you only have two files (makefile and config) but in the Managed way, you get four types of files ( makefile, object, sources, subdir ).
They also look very different.

Has someone managed to compile in Managed C++ successfully?

Regards
 
 View user's profile Send private message  
Reply with quote Back to top
capitan
PostPosted: Aug 16, 2007 - 04:17 PM
Rookie


Joined: Aug 03, 2007
Posts: 23


Just to add: I’ve written a small app using AVR32 Managed C++ and using a main.cpp
I set a delay counter for(i=0;i<1000;i++) ; to print a simple’.’ and also I set the usart RX interrupt.
The program runs ok until I send a character, then it stops there.

When debugging it, the software stops on exit.c, the AVR32 Studio is asking for a path to this file, I can’t find any ‘exit.c’ anywhere.
On the Debug Perspective, it shows a blank tab (the one is trying to open exit.c witht a message saying:
2 exit() exit.c:60 0x80037890

This address is close to the reset address, is in the Interrupt vector area?

I think the interrupt is definitely happening but it doesn’t know how to deal with it or it is jumping into a unknown address.

I tried to include in the project the startup and also the linker files, but not luck.. Confused

Any idea

Regards
 
 View user's profile Send private message  
Reply with quote Back to top
capitan
PostPosted: Aug 17, 2007 - 11:16 AM
Rookie


Joined: Aug 03, 2007
Posts: 23


Hi All,

I managed to disassembly the error and when the interrupt happens, the code jumps into the following part;

0x80010150 <_handle_exception>: lddpc r10,0x80010184 <_handle_scall+14>
0x80010152 <_handle_exception+2>: mfsr r12,0x10
0x80010156 <_handle_exception+6>: lddsp r11,sp[0x1c]
0x80010158 <_handle_exception+8>: ld.w r10,r10[0x0]
0x8001015a <_handle_exception+10>: lsl r12,0x2
0x8001015c <_handle_exception+12>: add r10,r10,r12
0x80010160 <_handle_exception+16>: mcall r10[0]


The JTag shows lots of activity after reaching the last line but it doesn’t go anywhere else.

I have attached the source code for the example;

To create the project, File->New-AVR32 Managed Make C++,
Name:’Test’,
Target:UC3A0512,
Project Type: Executable.

And then I just imported the files and compile.

Help gurus!! Surprised

Thanks
 
 View user's profile Send private message  
Reply with quote Back to top
KaiBen
PostPosted: Aug 17, 2007 - 01:06 PM
Wannabe


Joined: Jul 27, 2007
Posts: 58


capitan wrote:
1-Can these makefile and config files be modify to take c++ compiler, if so, is it difficult?

They can. Try the following:
In your Makefile, replace
Code:
OBJFILES  = $(CSRCS:.c=.o) $(ASSRCS:.S=.o)

with
Code:
OBJFILES  = $(patsubst %.cpp,%.o,$(CSRCS:.c=.o)) $(ASSRCS:.S=.o)

And insert
Code:
%.o: %.cpp %.d
   @echo $(MSG_COMPILING)
   $(VERBOSE_CMD)$(CC) -c $(CPPFLAGS) -MD -MP -MT '$*.i $*.x' $(CFLAGS) -o $@ $<
   @touch $*.d
   @touch $@
   $(VERBOSE_NL)

after
Code:
%.o: %.c %.d
   @echo $(MSG_COMPILING)
   $(VERBOSE_CMD)$(CC) -c $(CPPFLAGS) -MD -MP -MT '$*.i $*.x' $(CFLAGS) -o $@ $<
   @touch $*.d
   @touch $@
   $(VERBOSE_NL)

I've not tested it, but it should not be far from working if it does not.

If you need to use .c/.h files containing C++, you will also have to replace
Code:
CC        = avr32-gcc

with
Code:
CC        = avr32-g++


Note that avr32-gcc does not link with the C++ library by default and that avr32-g++ considers .c/.h files as C++ code if the -x option is not used.

If you want to use avr32-gcc with the C++ library, append stdc++ to the variable LIBS in your config.mk and add -nostdlib to the variable LD_EXTRA_FLAGS.

To use UC3 SW FW make files with C++ you will also have to remove in config.mk crt0.S from ASSRCS, $(UTIL_PATH)/LINKER_SCRIPTS/AT32UC3A/0512/GCC/link_uc3a0512.lds from LINKER_SCRIPT and -nostartfiles and -nostdlib from LD_EXTRA_FLAGS.

capitan wrote:
2-I have also built a project using Managed C++ make file, some driver files needed small changes and they build ok and I can also debug it on the evk, BUT Interrupts are not working anymore!!, I can manage to set the usart and pins but that is as far as it goes. It’s a bit frustrating thought.
I have to mention that in debug mode it build ok, but if I try to build in Release mode one, lots of errors show up Confused

The make files looks complete different, in the Standard way you only have two files (makefile and config) but in the Managed way, you get four types of files ( makefile, object, sources, subdir ).
They also look very different.

The make files of the UC3 SW FW are hand-written while those from AVR32 Studio are auto-generated. That's why they're quite different.

++
Ben
 
 View user's profile Send private message  
Reply with quote Back to top
KaiBen
PostPosted: Aug 17, 2007 - 03:34 PM
Wannabe


Joined: Jul 27, 2007
Posts: 58


capitan wrote:
When debugging it, the software stops on exit.c, the AVR32 Studio is asking for a path to this file, I can’t find any ‘exit.c’ anywhere.
On the Debug Perspective, it shows a blank tab (the one is trying to open exit.c witht a message saying:
2 exit() exit.c:60 0x80037890

This is because exit.c is a source file from Newlib you don't have in you project. You only have its .o from libc.a.

To solve your issue, simply remove intc.h and intc.cpp from your project and use the modified main_peripheral_test.cpp I attach.

Your issue was due to the UC3 SW FW INTC module which can not be used with C++. Moreover, <sys/interrupts.h> can not be used with C++ because extern "C" is missing from function declarations.

Also note that you are using the same USART from the interrupt and outside at the same time, what is unsafe. You need to use some synchronization mechanism or you may miss characters or get a dead lock in some loop.

++
Ben
 
 View user's profile Send private message  
Reply with quote Back to top
capitan
PostPosted: Aug 18, 2007 - 05:26 PM
Rookie


Joined: Aug 03, 2007
Posts: 23


Hi Ben,

Brilliant contribution, thanks for that. Razz

It would be good if AT32UC3 would include this type of startup projects in their future release, it would definitely help as I think AVR32 & processors are very good engines.
I have to admit, I do straggle coming outside the comfort zone of ‘standard c compilers’.

I looked at the file you sent me, it’s more simple than UC3 drivers, but it still doesn’t jump into the interrupt, but now at list it doesn’t crash .

When in debug mode, it doesn’t find the following libraries for these functions;
set_interrupts_base((void *)&AVR32_INTC);
init_interrupts();
register_interrupt(&usart_int_handler,
EXAMPLE_USART_IRQ/INT_LINES,
EXAMPLE_USART_IRQ % INT_LINES, INT1);

would that make any difference at all?

I searched in the hole cygwin directory but there is no reference to this functions.

1-Wasn’t it the case of just using Newlib files in the first place?

I also had a four wear warning msg, but I had it when compiling in c some times and all the executables where happy with it.

Compiling Msg:
make -k all
avr32-gcc (GCC) 4.1.2-atmel.1.1.0
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Compiling `pm.cpp' to `pm.o'.
Compiling `gpio.cpp' to `gpio.o'.
Compiling `usart.cpp' to `usart.o'.
usart.cpp: In function 'int usart_set_baudrate(volatile avr32_usart_t*, unsigned int, long int)':
usart.cpp:96: warning: comparison between signed and unsigned integer expressions
usart.cpp:104: warning: comparison between signed and unsigned integer expressions
Compiling `main_peripheral_test.cpp' to `main_peripheral_test.o'.
Assembling `../../../../SERVICES/USB/CLASS/DFU/EXAMPLES/ISP/BOOT/trampoline.S' to `../../../../SERVICES/USB/CLASS/DFU/EXAMPLES/ISP/BOOT/trampoline.o'.
Linking to `uc3a0512-main_peipheral_test.elf'.
/usr/local/lib/gcc/avr32/4.1.2/../../../../avr32/bin/ld: uc3a0512-main_peipheral_test.elf: warning: allocated section `.dalign' not in segment
/usr/local/lib/gcc/avr32/4.1.2/../../../../avr32/bin/ld: uc3a0512-main_peipheral_test.elf: warning: allocated section `.bss' not in segment
/usr/local/lib/gcc/avr32/4.1.2/../../../../avr32/bin/ld: uc3a0512-main_peipheral_test.elf: warning: allocated section `.heap' not in segment
/usr/local/lib/gcc/avr32/4.1.2/../../../../avr32/bin/ld: uc3a0512-main_peipheral_test.elf: warning: allocated section `.stack' not in segment
Creating extended listing to `uc3a0512-main_peipheral_test.lss'.
Creating symbol table to `uc3a0512-main_peipheral_test.sym'.
Creating Intel HEX image to `uc3a0512-main_peipheral_test.hex'.
Creating binary image to `uc3a0512-main_peipheral_test.bin'.


uc3a0512-main_peipheral_test.elf :
section size addr
.reset 0x2008 0x80000000
.got 0xc 0x918
.init 0x1c 0x80002008
.text 0x857c 0x80002024
.exception 0x200 0x8000a600
.fini 0x18 0x8000a800
.rodata 0x37c 0x8000a818
.lalign 0x4 0x8000ab94
.dalign 0x4 0x4
.eh_frame 0x84c 0x8
.gcc_except_table 0xb0 0x854
.ctors 0x8 0x904
.dtors 0x8 0x90c
.jcr 0x4 0x914
.data 0x838 0x924
.balign 0x4 0x115c
.bss 0x78 0x1160
.heap 0xde28 0x11d8
.comment 0x97e 0x0
.debug_aranges 0xbf0 0x0
.debug_pubnames 0x2204 0x0
.debug_info 0x3608d 0x0
.debug_abbrev 0x8451 0x0
.debug_line 0x8f13 0x0
.debug_frame 0x2f0c 0x0
.debug_str 0x6579 0x0
.debug_loc 0x1172f 0x0
.stack 0x1000 0xf000
.debug_ranges 0x1900 0x0
Total 0x81b4b

text data bss dec hex filename
0xab34 0x1154 0xeeac 109364 1ab34 uc3a0512-main_peipheral_test.elf

I think we are getting somewhere.

Any idea.

Regards

PS:I’m still looking at the modify standard make file. Wink
 
 View user's profile Send private message  
Reply with quote Back to top
KaiBen
PostPosted: Aug 18, 2007 - 08:31 PM
Wannabe


Joined: Jul 27, 2007
Posts: 58


Hi capitan,

capitan wrote:
Brilliant contribution, thanks for that. Razz

Glad to help.

capitan wrote:
I looked at the file you sent me, it’s more simple than UC3 drivers, but it still doesn’t jump into the interrupt, but now at list it doesn’t crash .

It worked for me with the debug configuration in debug mode. Sending a character to the MCU did trigger the interrupt.

capitan wrote:
When in debug mode, it doesn’t find the following libraries for these functions;
set_interrupts_base((void *)&AVR32_INTC);
init_interrupts();
register_interrupt(&usart_int_handler,
EXAMPLE_USART_IRQ/INT_LINES,
EXAMPLE_USART_IRQ % INT_LINES, INT1);

would that make any difference at all?

The debug/release configuration should not matter, except if you made changes to your project settings. I think you should clean up things by removing your project, extracting your sources from your ZIP file, removing intc.h and intc.cpp, adding my main_peripheral_test.cpp and creating a new AVR32 Studio Managed AVR32 C++ project.

The errors you mention are undefined references that appear at link time when these functions are called from a .cpp file without being declared with `extern "C"'. It is the case if you include <sys/interrupts.h>. You should instead use the code I placed in the #if 1 in main_peripheral_test.cpp. You can create your own interrupts.h to place this code.

These functions can be found in the UC version of libc.a with `avr32-objdump -t libc.a | grep init_interrupts' for instance. This library is automatically used by avr32-g++ besides libstdc++.a.

capitan wrote:
I also had a four wear warning msg, but I had it when compiling in c some times and all the executables where happy with it.

For the warnings in usart.cpp, you can cast the signed integers to the corresponding unsigned types.

The warnings that appear at link time are caused by the linker script you use. The explanation is given by the official documentation of the UC3 SW FW in /.docsrc/AVR32_FrameworkGCC.html:
Quote:
When using the default linker scripts provided with avr32-gcc, the ELF LOAD program headers are generated automatically from the output sections, including BSS and the stack which are only allocated areas. In its current revision, avr32program programs allocated LOAD program headers that do not have to be filled with data from the ELF file, what wastes time. This behavior of avr32program will be changed in a future release, but until this is achieved, the linker scripts provided with the software framework are changed to place the allocated-only output sections in NULL ELF program headers ignored by avr32program, hence the warnings when linking.


++
Ben
 
 View user's profile Send private message  
Reply with quote Back to top
capitan
PostPosted: Aug 24, 2007 - 04:45 PM
Rookie


Joined: Aug 03, 2007
Posts: 23


Hi All,

Ben, You were right!, again..

I it does work, I just needed to switch everything off and live it for a while, it worked for me. Mr. Green

Following your instructions I managed to use usart interrupt and I also added external-int and timer interrupts. Going well.

I just need to do some work to ensure the processor runs at full speed and then I should be ready.

I also I’m trying to compile some code that uses sin, cos, asin, acos, tan, atan2 and sqrt.

I have tried to include <cmath>, <math.h> and ‘nada’. Should it work with these libraries anyone?

I also tried to include the dsp.h library and use dsp32_op_sin() but it doesn’t work, would it work in c++??

And finally I tried ‘using namespace std’ and just define on top Using std::sin; and absolutely nothing. Confused

Has someone used this type of functions in c++ before??

Regards
 
 View user's profile Send private message  
Reply with quote Back to top
KaiBen
PostPosted: Aug 25, 2007 - 02:42 AM
Wannabe


Joined: Jul 27, 2007
Posts: 58


Hi capitan,

All you have to do is #include <math.h> and add libm.a to the libraries to use at link time (linker options in the build properties). Once done, the option `-lm' should be used by AVR32 Studio when linking, after all .o and .a on the command line. The `-l' link option means that the following library (`m' here) should be added to the files to link. The file name of the library is built by prefixing the library name with `lib' and suffixing it with `.a', what produces here `libm.a'.

If <math.h> is not written properly (i.e. not using `extern "C"' when C++ is detected), you will have to create your own "math.h" by copying the contents of <math.h> and enclosing the declarations with `extern "C" {}'.

The DSP library from the UC3 software framework is not written properly for C++, but you could use `extern "C"' declarations as well and it would work if you included the library sources in your project. This would be faster than libm.a, but less handy and less accurate.

++
Ben
 
 View user's profile Send private message  
Reply with quote Back to top
capitan
PostPosted: Aug 28, 2007 - 09:24 AM
Rookie


Joined: Aug 03, 2007
Posts: 23


Hi there,

I have included <math.> but I’m using a standard make files, which it doesn’t give me the option “Properties-> C/C++Build->ToolSettings->AVR32/GNUC++Limker->Linraries”.

I gees I need to add it to the makefile of the config.mk files, the closes option I can find is: LD_EXTRA_FLAGS but it doesn’t like to be changed.

Does anyone knows where or how to add ‘libm.a’ or ‘–lm’ option??

Regards
 
 View user's profile Send private message  
Reply with quote Back to top
cboulang
PostPosted: Aug 28, 2007 - 10:28 AM
Wannabe


Joined: Jun 26, 2007
Posts: 72


You should write a single 'm' to the LIBS variable in config.mk; the Makefile adds the -l (seen in the "Math function problem" thread http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=52526&start=0&postdays=0&postorder=asc&highlight=)

Cyr.
.
 
 View user's profile Send private message  
Reply with quote Back to top
capitan
PostPosted: Aug 28, 2007 - 11:10 AM
Rookie


Joined: Aug 03, 2007
Posts: 23


Hi Cyr.

Thanks for clarifying that.

In my config.mk file it originally had a stdc++ and when I add the ‘m’ or (,’m’) it doesn’t like it.

If I remove the stdc++, it takes the ‘-lm’ ok but the compiler start showing link errors in random places saying:
‘Undefined reference to __gxx_personality_v0’

How do I get back the stdc++ into the equation?

Regards
 
 View user's profile Send private message  
Reply with quote Back to top
cboulang
PostPosted: Aug 28, 2007 - 01:43 PM
Wannabe


Joined: Jun 26, 2007
Posts: 72


Following what KaiBen previously wrote:
Quote:
If <math.h> is not written properly (i.e. not using `extern "C"' when C++ is detected), you will have to create your own "math.h" by copying the contents of <math.h> and enclosing the declarations with `extern "C" {}'.

could you try to include fastmath.h (instead of math.h)?

Cyr.
.
 
 View user's profile Send private message  
Reply with quote Back to top
capitan
PostPosted: Sep 18, 2007 - 09:35 AM
Rookie


Joined: Aug 03, 2007
Posts: 23


Hi There,

I’m back!

The only change I needed to do is to ensure I was using avr32-g++ instead of avr32-gcc.

It works now.

Thanks for that.
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits