library: is the correct device necessary ?

Go To Last Post
8 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have written some functions for a circular buffer.

These functions should be available as a library for further usage in several Projects.

The library contains no hradware specific stuff, only C++-Code which handles packets in the buffer.

The library-porject is under AVR-Studio 6.2, therefore a device is given to the Compiler (i.e. ATmega128).

Is this necessary - or - can I use the compiled library for other devices - say, AT90CAN32 without new compilation?

Is there a goo tutorial for handling libraries with AVR-Studio ?

I program like a man:
COPY CON: > firmware.hex

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Is this necessary - or - can I use the compiled library for other devices - say, AT90CAN32 without new compilation?
Will an object file compiled for one AVR work for all AVRs? Not likely. Not all AVRs support all opcodes.

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

or - can I use the compiled library for other devices

If you look in your GCC installation you will find something like 17 different copies of libc, libgcc, libm, etc. because of CPU differences like tiny's not having MUL, 8K and smaller devices only having RJMP/RCALL but no JMP/CALL, real big devices having ELPM and things like 24bit CALL etc.

So, no, anything but the simplest code will need to be built for at least those 17 variants. This is why (apart from libc, libgcc, libm) almost no code for AVR is ever built/supplied as .a static libraries and, instead "libraries" are supplied in source form as .c and .h files.

BTW it might not be 17 but it's something in that region and I think there are 8 (is it?) that are differing Xmega variants.

Last Edited: Sat. Dec 28, 2013 - 07:10 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I usually collect the source for these things in one folder. Mine is called "Lib," and is just a collection of .h and .c files I use in different programs.

In the project properties, under the toolchain tab, select Directories and add the lib folder. Do this for any project you want to use your library of functions.

Now, you can add any of these files to the project. Right click the project in the tree and select "Add existing file." Navigate to your lib folder and select whatever file or files you want to add, but DON'T click the open button, click the arrow next to the open button and select "Add as link."

If the code needs to know something about the specific hardware, the .c files includes "Config.h" For example, my NRF module looks for NRFCEPort and NRFCEPin to be defined in Config.h. But here, C is a little brain damaged: It will complain there is no Config.h. You have to argue with it. Click the included C file in the solution explorer gimwachet and find where it says "Custom Compilation Settings," in the property box. In that miniscule space, fill in

-I"full\path\to\project\source\folder"

So now, the compiler will know where to find Config.h while it's compiling the file linked from the library folder.

The largest known prime number: 282589933-1

It's easy to stop breaking the 10th commandment! Break the 8th instead. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Okay. sounds better. I will try it.

I program like a man:
COPY CON: > firmware.hex

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

BTW it might not be 17

15 in my tool chain:

C:\Program Files\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.2.1002\avr8-gnu-toolchain\lib\gcc\avr\4.7.2>dir /b avr*
avr25
avr3
avr31
avr35
avr4
avr5
avr51
avr6
avr7
avrtiny
avrxmega2
avrxmega4
avrxmega5
avrxmega6
avrxmega7

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Missed some:

C:\Program Files\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.2.1002\avr8-gnu-toolchain\avr\lib>find . -name libc.a
./avr25/libc.a
./avr25/tiny-stack/libc.a
./avr3/libc.a
./avr31/libc.a
./avr35/libc.a
./avr4/libc.a
./avr5/libc.a
./avr51/libc.a
./avr6/libc.a
./avr7/libc.a
./avrtiny/libc.a
./avrxmega2/libc.a
./avrxmega4/libc.a
./avrxmega5/libc.a
./avrxmega6/libc.a
./avrxmega7/libc.a
./libc.a
./tiny-stack/libc.a

C:\Program Files\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.2.1002\avr8-gnu-toolchain\avr\lib>find . -name libc.a | wc -l

     18

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
find . -name libc.a | wc -l

I should learn not to pick a fight with the master of Bashelonia. :D

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]