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
Kontrabass
PostPosted: Mar 11, 2010 - 08:41 PM
Wannabe


Joined: Mar 08, 2010
Posts: 55
Location: Santa Monica, CA

Hi,
I am trying to compile a simple code.
Have searched and found many who have the same issue.
But first things first, as per the "how to guide"


Software Verions:
111111111111111111111111111111111111111111
AVR Studio 4.18.692
GUI Version 4, 18, 0, 685
AVR Simulator 1, 0, 2, 1
ATMEGA169P 41
WinAVR - 20100110
XP SR3
111111111111111111111111111111111111111111

"Code" button does not work! Just leaves a dotted rectangular on the button itself (see attachement before shouting at me).
Code:
222222222222222222222222222222222222222222
// adc-test
#define F_CPU 1000000l//
#include <stdio.h>
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <util/delay.h>
#include "ADC.h"

int main (void)
{
volatile int sense = 0;
{
while(1)
{
ADC_init(1);
sense = ADC_read();
}
return 1;
}
}
222222222222222222222222222222222222222222


Problem:
333333333333333333333333333333333333333333
../adc-test.c:8:17: error: ADC.h: No such file or directory
../adc-test.c:18: warning: implicit declaration of function 'ADC_init'
../adc-test.c:19: warning: implicit declaration of function 'ADC_read'
333333333333333333333333333333333333333333


What I tried so far:
444444444444444444444444444444444444444444
I did RTFM.

Then I did STFW.
I read the many questions (and the very few actual helpful answers) in the same regard.

Have copied the ADC.h file in same directory where the source is.

Even added it to the default path of GCC.

Have added ADC.c to "Source Files" (right click etc)

Have tried the "samples" provided in the newbie section (UART sample brings same errors, even after adding to "Source Files").

Have deinstalled and reinstalled GCC and everything (with everything default as in the FAQ)

Still, pressing F7 (or any rebuild, recompile etc) returns those errors!
444444444444444444444444444444444444444444

Question:
555555555555555555555555555555555555555555
What else do I need to do to have the compiler include that dreaded ADC.h file (or UART.H for that matter)?
555555555555555555555555555555555555555555


It must be something simple I am missing.
Well me and many more who come up in google with those keywords and exactly same questions.

Thanks a lot for your kind and helpful guidance on this matter!
 
 View user's profile Send private message  
Reply with quote Back to top
Koshchi
PostPosted: Mar 11, 2010 - 08:55 PM
10k+ Postman


Joined: Nov 17, 2004
Posts: 14669
Location: Vancouver, BC

Are you sure that the filename is ADC.h (case matters)?

_________________
Regards,
Steve A.

The Board helps those that help themselves.
 
 View user's profile Send private message  
Reply with quote Back to top
Kontrabass
PostPosted: Mar 11, 2010 - 11:23 PM
Wannabe


Joined: Mar 08, 2010
Posts: 55
Location: Santa Monica, CA

Yes, positive.
 
 View user's profile Send private message  
Reply with quote Back to top
atomicdog
PostPosted: Mar 11, 2010 - 11:42 PM
Posting Freak


Joined: Jan 14, 2008
Posts: 1169
Location: San Diego

Quote:
"Code" button does not work! Just leaves a dotted rectangular on the button itself
Are you using firefox with noscript? When avrfreaks.net is set to untrusted it will do as you described.
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
atomicdog
PostPosted: Mar 11, 2010 - 11:45 PM
Posting Freak


Joined: Jan 14, 2008
Posts: 1169
Location: San Diego

Please show us the exact and complete command line invocation of avr-gcc.
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
Kontrabass
PostPosted: Mar 12, 2010 - 08:26 AM
Wannabe


Joined: Mar 08, 2010
Posts: 55
Location: Santa Monica, CA

Thanks for the "code" trick, atomicdog!
I had indeed firefox with noscript on.

Today the errors are less, maybe the reboot helped it? Eventhough I did that several times (restore point) when reinstalling everything.

I don't know yet how to get to "the exact and complete command line invocation of avr-gcc", but here is what the "Build" window gives me.
Please tell me where to look for the the command line invocation of avr-gcc, thanks!

But I still get errors:
Code:
Build started 11.3.2010 at 23:54:19
avr-gcc -mmcu=atmega169p -Wl,-Map=adc-test.map adc-test.o     -o adc-test.elf
adc-test.o: In function `main':
C:\projects\electronics\avr\adc-test\default/../adc-test.c:18: undefined reference to `ADC_init'
C:\projects\electronics\avr\adc-test\default/../adc-test.c:19: undefined reference to `ADC_read'
make: *** [adc-test.elf] Error 1
Build failed with 2 errors and 0 warnings...


Here is the content of that directory:
Code:
<DIR>             .
<DIR>             ..
2,740       adc-test.aps
325       adc-test.c
16,742       ADC.c
502       ADC.h
<DIR>             default
5 File(s)       20,309 bytes


"ADC.c" in that directory contains (all originally downloaded from Atmel and untouched!):
Code:
//***************************************************************************
//  File........: ADC.c
//  Author(s)...: ATMEL Norway
//  Target(s)...: ATmega169
//  Compiler....: AVR-GCC 3.3.1; avr-libc 1.0
//  Description.: AVR Butterfly ADC routines
//  Revisions...: 1.0
//  YYYYMMDD - VER. - COMMENT                                       - SIGN.
//  20030116 - 1.0  - Created                                       - LHM
//  20031009          port to avr-gcc/avr-libc                      - M.Thomas
//***************************************************************************

Which in turn has this defined:
Code:
/*****************************************************************************
*
*   Function name : ADC_init
*   Returns :       None
*   Parameters :    char input
*   Purpose :       Initialize the ADC with the selected ADC-channel
*
*****************************************************************************/
void ADC_init(char input)
{
    ADMUX = input;    // external AREF and ADCx
    ADCSRA = (1<<ADEN) | (1<<ADPS1) | (1<<ADPS0);    // set ADC prescaler to , 1MHz / 8 = 125kHz   
    input = ADC_read();        // dummy
}


I am really confused on why such a simple thing can make so much trouble.
What am I missing?
Thanks!
 
 View user's profile Send private message  
Reply with quote Back to top
JohanEkdahl
PostPosted: Mar 12, 2010 - 09:19 AM
10k+ Postman


Joined: Mar 27, 2002
Posts: 21371
Location: Lund, Sweden

Quote:

What am I missing?


Code:
Build started 11.3.2010 at 23:54:19
avr-gcc -mmcu=atmega169p -Wl,-Map=adc-test.map adc-test.o     -o adc-test.elf
adc-test.o: In function `main':
C:\projects\electronics\avr\adc-test\default/../adc-test.c:18: undefined reference to `ADC_init'
C:\projects\electronics\avr\adc-test\default/../adc-test.c:19: undefined reference to `ADC_read'
make: *** [adc-test.elf] Error 1
Build failed with 2 errors and 0 warnings...

I see no traces of compilation here at all. It is just a link step. And with only adc-test.o as inputs.

Id suggest copying the source files to a safe place, delete the whole project and then set it up again. Move the source files back and add them to the project.
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
clawson
PostPosted: Mar 12, 2010 - 09:54 AM
10k+ Postman


Joined: Jul 18, 2005
Posts: 69337
Location: (using avr-gcc in) Finchingfield, Essex, England

If using Studio then in the project tree at the left under "Source files" what do you have listed there? My guess is that it's ONLY adc-test.c, right click "Source files" and use "Add existing source file(s)..." then pick the .c file that contains ADC_init() and ADC_read() - I'm guessing it may be called simply adc.c or ADC.c ?

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
JohanEkdahl
PostPosted: Mar 12, 2010 - 10:23 AM
10k+ Postman


Joined: Mar 27, 2002
Posts: 21371
Location: Lund, Sweden

Cliff! That was what I also thought initially, but re-reading the thread I found that OP has stated
Quote:

Have added ADC.c to "Source Files" (right click etc)


If this holds, then if a clean + build does not activate the compilation steps I'd say that the project setup somehow got corrupt and a fresh start will be the easiest way out.
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
Kontrabass
PostPosted: Mar 12, 2010 - 05:35 PM
Wannabe


Joined: Mar 08, 2010
Posts: 55
Location: Santa Monica, CA

Hi & thanks for your ideas.
Both of you were right.
After the reinstall, I had initially added the ADC.c to "Source Files" (right click etc), but that resulted in even more errors, so I deleted it again.
2 errors vs 22 errors, which way would you go?

That ADC.c has in turn another bunch of declarations and definitions.
However, I don't use any of those as you can see.

Do I still have to include all those "#include"'s from ADC.c too?

Here is the error report with ADC.c added to "Source Files" (right click etc)

Code:
rm -rf adc-test.o  adc-test.elf dep/* adc-test.hex adc-test.eep adc-test.lss adc-test.map
Build succeeded with 0 Warnings...
avr-gcc  -mmcu=atmega169p -Wall -gdwarf-2 -Os -std=gnu99 -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -MD -MP -MT adc-test.o -MF dep/adc-test.o.d  -c  ../adc-test.c
avr-gcc  -mmcu=atmega169p -Wall -gdwarf-2 -Os -std=gnu99 -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -MD -MP -MT ADC.o -MF dep/ADC.o.d  -c  ../ADC.c
../ADC.c:27:25: error: pgmspacehlp.h: No such file or directory
../ADC.c:28:20: error: button.h: No such file or directory
../ADC.c:31:18: error: main.h: No such file or directory
../ADC.c:33:17: error: BCD.h: No such file or directory
../ADC.c:34:27: error: LCD_functions.h: No such file or directory
../ADC.c:35:20: error: timer0.h: No such file or directory
../ADC.c: In function 'ADC_read':
../ADC.c:131: warning: implicit declaration of function 'sbiBF'
../ADC.c:153: warning: implicit declaration of function 'cbiBF'
../ADC.c: In function 'ADC_periphery':
../ADC.c:206: warning: implicit declaration of function 'LCD_putc'
../ADC.c:227: warning: implicit declaration of function 'CHAR2BCD2'
../ADC.c:251: warning: implicit declaration of function 'CHAR2BCD3'
../ADC.c:307: warning: implicit declaration of function 'pgm_read_float_hlp'
../ADC.c: In function 'TemperatureFunc':
../ADC.c:399: warning: implicit declaration of function 'Timer0_RegisterCallbackFunction'
../ADC.c:402: warning: implicit declaration of function 'LCD_UpdateRequired'
../ADC.c:402: error: 'TRUE' undeclared (first use in this function)
../ADC.c:402: error: (Each undeclared identifier is reported only once
../ADC.c:402: error: for each function it appears in.)
../ADC.c:404: error: 'KEY_PREV' undeclared (first use in this function)
../ADC.c:407: warning: implicit declaration of function 'Timer0_RemoveCallbackFunction'
../ADC.c:411: error: 'ST_TEMPERATURE' undeclared (first use in this function)
../ADC.c:413: error: 'KEY_PLUS' undeclared (first use in this function)
../ADC.c:420: error: 'KEY_MINUS' undeclared (first use in this function)
../ADC.c:428: error: 'ST_TEMPERATURE_FUNC' undeclared (first use in this function)
../ADC.c: In function 'VoltageFunc':
../ADC.c:458: error: 'TRUE' undeclared (first use in this function)
../ADC.c:460: error: 'KEY_PREV' undeclared (first use in this function)
../ADC.c:467: error: 'ST_VOLTAGE' undeclared (first use in this function)
../ADC.c:470: error: 'ST_VOLTAGE_FUNC' undeclared (first use in this function)
../ADC.c: In function 'LightFunc':
../ADC.c:501: error: 'TRUE' undeclared (first use in this function)
../ADC.c:503: error: 'KEY_PREV' undeclared (first use in this function)
../ADC.c:510: error: 'ST_LIGHT' undeclared (first use in this function)
../ADC.c:513: error: 'ST_LIGHT_FUNC' undeclared (first use in this function)
make: *** [ADC.o] Error 1
Build failed with 22 errors and 9 warnings...
I read in the manual that the compiler is smart enough to see what is not used and totally ignore that. Am I wrong on that assumption?
Attached please find the ADC.c and ADC.h.
I can not find where I downloaded them anymore.
Thanks!
 
 View user's profile Send private message  
Reply with quote Back to top
clawson
PostPosted: Mar 12, 2010 - 08:31 PM
10k+ Postman


Joined: Jul 18, 2005
Posts: 69337
Location: (using avr-gcc in) Finchingfield, Essex, England

Quote:

which way would you go?

How can omitting large parts of the source possibly help?

Anyway where did you get this ADC.c from anyway? And which C compiler was it written for.

Things such as pgmspacehlp.h sound "unusual". GCC has <avr/pgmspace.h> but it won't be a direct substitution as the functions available are almost certainly different.

But you are only calling TWO functions in ADC.c anyway (ADC_init and ADC_read) - I find it a little difficult to believe that those two functions require PGM support or BCD.h or LCD_functions.h or ...

Try cutting just those two routines out to a new adc.c and then see what else is missing with just that and your original .c file

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
JohanEkdahl
PostPosted: Mar 13, 2010 - 09:35 AM
10k+ Postman


Joined: Mar 27, 2002
Posts: 21371
Location: Lund, Sweden

Quote:

I had initially added the ADC.c to "Source Files" (right click etc), but that resulted in even more errors, so I deleted it again.
2 errors vs 22 errors, which way would you go?

Well, I wouldn't stick my head in the sand, as you obviously did. Rolling Eyes

If you have a headache, do you chop your head off?

Tell us where the code you are using comes from so that we can have a look and maybe understand for what tool-chain it was written.
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
Kontrabass
PostPosted: Mar 13, 2010 - 05:23 PM
Wannabe


Joined: Mar 08, 2010
Posts: 55
Location: Santa Monica, CA

Before deciding on which product (AVR vs Pic) I tired to educate myself as much as I could. I mostly frequented the manufacturer's sites, and that is where I got the files for the butterfly:

http://www.atmel.com/dyn/products/tools.asp?family_id=607
search for "Rev07"

Regarding my issue: I am simply trying to sample a few voltages with the butterfly and for debugging purposes want to send those values out serially.

That's what started my whole ordeal, neither the ADC.c nor UART worked.

From what I am gathering now the issue seems to be which compiler I am using (i.e. if it is smart enough to ignore unused code).

I am trying to get an update for my old Keil compiler which I bought very cheap when I was a student.

Hope that resolves the issues I am having.

I read the AVR Tutorials reg. UART
and ADChttp://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=58886

and ADC tutorials, but again, I am hoping to resolve the main question which came up now with your help.

Again the question:
Is the GCC compiler smart enough to see what is not used and totally ignore that code in general?

I would like to find that out before I dive into dissecting existing libraries as suggested.

Because if it is really a GCC issue, I'd rather go with Keil and be done with it!

Thanks!
 
 View user's profile Send private message  
Reply with quote Back to top
JohanEkdahl
PostPosted: Mar 13, 2010 - 05:39 PM
10k+ Postman


Joined: Mar 27, 2002
Posts: 21371
Location: Lund, Sweden

OK, so I downloaded the AVR Butterfly app rev07 from http://www.atmel.com/dyn/products/tools ... ily_id=607 and looked in the file ADC.c. It starts like so:
Code:
//***************************************************************************
//
//  File........: ADC.c
//
//  Author(s)...: ATMEL Norway
//
//  Target(s)...: ATmega169
//
//  Compiler....: IAR EWAAVR 4.20a
//
//  Description.: AVR Butterfly ADC routines
//
//  Revisions...: 1.0
//
//  YYYYMMDD - VER. - COMMENT                                       - SIGN.
//
//  20030116 - 1.0  - Created                                       - LHM
//
//***************************************************************************

but above you wrote
Quote:

"ADC.c" in that directory contains (all originally downloaded from Atmel and untouched!):
Code:
//***************************************************************************
// File........: ADC.c
// Author(s)...: ATMEL Norway
// Target(s)...: ATmega169
// Compiler....: AVR-GCC 3.3.1; avr-libc 1.0
// Description.: AVR Butterfly ADC routines
// Revisions...: 1.0
// YYYYMMDD - VER. - COMMENT - SIGN.
// 20030116 - 1.0 - Created - LHM
// 20031009 port to avr-gcc/avr-libc - M.Thomas
//***************************************************************************


Someone or something is confused here. It might well be me. I don't get a file saying "port to avr-gcc/avr-libc".

Could it be that you downloaded the port from Martin Thomas site http://www.siwawi.arubi.uni-kl.de/avr_projects/#bf_app ?
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
Kontrabass
PostPosted: Mar 13, 2010 - 07:54 PM
Wannabe


Joined: Mar 08, 2010
Posts: 55
Location: Santa Monica, CA

That confusion is definetly me, to be honest I lost track on the libraries.
I have been trying several and all had the mentioned issues.

Then there is the real life inbetween where I lose track of where I was.

I simply wanted to get that ADC running without inventing the wheel again.

Meanwhile I tried the ADC tutorial from here, but one version is interrupt driven (which I cannot use right now) and the other won't compile.

Maybe it is because I have been out of the loop for so many years, but I still don't understand why the compiler issues those errors.

After going through pitfalls like the small "L" (from the examples) vs. 1000000"UL" for the frequency and much more, I am wondering what else might be there hidden.

But I will totally give up on this if somebody could tell me if the Keil compiler would skip those parts (thus issuing no errors).

I would just get me that compiler and move on.

Thanks.
 
 View user's profile Send private message  
Reply with quote Back to top
clawson
PostPosted: Mar 13, 2010 - 08:18 PM
10k+ Postman


Joined: Jul 18, 2005
Posts: 69337
Location: (using avr-gcc in) Finchingfield, Essex, England

Quote:

and the other won't compile.

Tell us more about that - what errors?

There is no Keil compiler for AVR as far as I know.

As for compiler's skipping unused parts - GCC will do the with -function-sections and --gc-sections but the code DOES have to compiler without error for that to work

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
JohanEkdahl
PostPosted: Mar 13, 2010 - 08:26 PM
10k+ Postman


Joined: Mar 27, 2002
Posts: 21371
Location: Lund, Sweden

Quote:

But I will totally give up on this if somebody could tell me if the Keil compiler would skip those parts (thus issuing no errors).

No. A compiler will not "skip parts" of the code in the sense you are describing. It will not skip parts of code based on if they are "used" or not. If the code is there, the compiler will read it, and code seen by the compiler must be free of errors (syntactic and sematic). That a compiler might then decide not to generate machine code for parts of the source code it has seen (ie optimization) is a different matter.

Parts of your problem is that you seem to be "all over the place" to the extent that you yourself can not keep track of what you have done, where you got example code etc. Working like that is a good recipe for faliure.

The remedy is to work in a more structured manner, keep to one piece of demo code, stay with one compiler for the time being etc.. And pose good questions here to help push your process forward. "Good" involves giving potential helpers a fair chance of analyzing your problem. For that they need clear facts, which you must supply. And so we are back to a structured way of working..

AFAIK there is no port of the Butterfly app for the Keil compiler. So you go either with the IAR compiler and the Butterfly app from Atmels site or the avr-gcc compiler (ie WinAVR) and Martin Thomas port of the app.
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
Kontrabass
PostPosted: Mar 15, 2010 - 01:38 AM
Wannabe


Joined: Mar 08, 2010
Posts: 55
Location: Santa Monica, CA

Thanks for the info on Keil, that Keil does not support AVR.
I had read about Keil's support for Atmel on their site, but it is indeed only for Atmels '51 series.

Thanks also all for the clarifications reg. compiler.

Bottom line, (to conclude this thread), here are my findings, please correct me if I still got it wrong:

Even unused "#include"'s and defines/libraries mentioned in a program must be wholy present during compilation.

The compiler is not smart enough to discard those if they are not used in the program at all.

Only after the compiler has found all the routines in the program (and it's libraries) will it start to optimize away unnessesary code.

Bottom line, I was under the wrong impression that the compiler won't need unused liebraries etc.

In the past I had worked with Keil and IAR, but we would use batch files and I don't remember which switches were on/off during compilation.

Is it possible that those compilers don't need the libraries present?

Because I never had those issues before in my life.

I have another question (totally unrelated), should I start a new thread or shall I keep it here?

Thanks!
 
 View user's profile Send private message  
Reply with quote Back to top
atomicdog
PostPosted: Mar 15, 2010 - 02:30 AM
Posting Freak


Joined: Jan 14, 2008
Posts: 1169
Location: San Diego

Quote:
The compiler is not smart enough to discard those if they are not used in the program at all.

Only after the compiler has found all the routines in the program (and it's libraries) will it start to optimize away unnessesary code.
The compiler is smart enough, it's just waiting for permission by you to do so. Keil's IDE hides it from you (probable with just a check box... I can't remember anymore). With avr-gcc you need to use -ffunction-sections and -Wl,--gc-sections. There may be times were you don't want the compiler to remove unused code so the compiler leaves it up to you to decide.


Quote:
I have another question (totally unrelated), should I start a new thread or shall I keep it here?
A new thread is better.

_________________
~~John
TWI C source code
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
JohanEkdahl
PostPosted: Mar 15, 2010 - 08:40 AM
10k+ Postman


Joined: Mar 27, 2002
Posts: 21371
Location: Lund, Sweden

Quote:
Even unused "#include"'s and defines/libraries mentioned in a program must be wholy present during compilation.

OK, I see where we've been misunderstanding each other. I'll try to remedy that:

1) It is of no significance at all if the compiler sees eg a function prototype as an effect of a #include, or if the prototype is present in the C source file as such. The #include is handled by the C pre-processor, which "mangles" the code before the compiler proper sees it. There is no tight one-to-one coupling between a header file and a library. Indeed, one library might very well come with several header files. This is the case eg with avr-libc.

2) You can have a declaration (a prototype) of a function, and then not call it anywhere in the source code. Then the compiler won't complain. Neither will the linker, but see next point.

3) Unless special options are given, if a library is linked into the binary application all of the code in the library will be linked into the binary application. So even if you do not call a function in a library its machine code will be included in the binary application. Again, this holds unless you feed the compiler and linker with special switches.
 
 View user's profile Send private message Visit poster's website 
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