Compiling C in AVRStudio

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

I am experimenting with AVRStudio 4.12 and WinAVR. I entered this in AVRStudio as an AVR GCC project:

#include 
#include 

int main (void) {
	
	DDRD = 0xff;
		
		while (1) 
		{
		
			for (i = 1; i <= 100; i++)
			{
				PORTD = i;
			}
		
		}

}

and received these warnings and errors:

-----------------------

Build started 28.4.2006 at 16:25:53
avr-gcc.exe -mmcu=atmega8515 -Wall -gdwarf-2 -O0 -MD -MP -MT testC.o -MF dep/testC.o.d -c ../testC.c
In file included from ../testC.c:4:
C:/WinAVR/avr/include/avr/delay.h:36:2: warning: #warning "This file has been moved to ."
In file included from C:/WinAVR/avr/include/avr/delay.h:37,
from ../testC.c:4:
C:/WinAVR/avr/include/util/delay.h:136:3: warning: #warning "F_CPU not defined for "
../testC.c: In function `main':
../testC.c:15: error: `i' undeclared (first use in this function)
../testC.c:15: error: (Each undeclared identifier is reported only once
../testC.c:15: error: for each function it appears in.)
make: *** [testC.o] Error 1
Build failed with 3 errors and 2 warnings...

-----------------------

The undeclared 'i' seems logical since I didn't say "int i;", but I have seen a few examples with undeclared variables that seem to work. I am wondering what I am missing here?

Regarding the paths to the include files, I am not sure what the problem is.

Any help please? Thanks.

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

The more recent WinAVR packages (which AVRStudio links to) have newer versions of AVRLibC, which has different include paths for some of the files. As the warning says "avr/delay.h" has been moved to "util/delay.h", so change that #include in your code.

F_CPU is a define usually set in your makefile which tells the compiler what target clock your AVR will run it - it uses that value for the delay routines, etc. AVRStudio handles the makefile for you, but you can set the F_CPU value in the menu Project->Configuration Options.

Lastly, the ability to declare and use a variable inside the for loop's header is part of the new C standard set in 1999. GCC by default uses the old 1989 standard, and to use the newer standard requires a command line switch. You can set this in AVRStudio by Project->Configuration Options->Custom Options Tab and adding the line "-std=gnu99" to the "[All Files]" section.

EDIT: Oh sorry, I thought you were using the C99 standard for declaring a variable inside the for loop, like:

for (unsigned char i=0; i<50; i++)
{
/...
}

But you're not declaring "i" at all. You need to declare i somewhere, be it inside the for like above or before it.

- Dean :twisted:

Make Atmel Studio better with my free extensions. Open source and feedback welcome!

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

Awesome, thanks.

So am I correct that my F_CPU setting for the 8515L would be between 0 and 8000000?

Thanks in advance.

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

Yep, thoretical range for the 8515 <= 8MHz, or 8000000Hz.

- Dean :twisted:

Make Atmel Studio better with my free extensions. Open source and feedback welcome!

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

One small thing. You are including delay.h, but you are not actually calling anything declared in delay.h, so the inclusion is unnecessary.

Regards,
Steve A.

The Board helps those that help themselves.

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

Right. Actually I stripped the code down to just try to get it running and isolate the issue. I had a delay in there originally. Thanks though.

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

Hi,

Im just learning C and have an error too when trying to compile these code as an AVR GCC project in AVR STUDIO

#include 

int main(void)
{
  // Set Port B pins as all outputs
  DDRB = 0xff;

  // Set all Port B pins as HIGH
  PORTB = 0xff;

  return 1;
}

and the error are as follow:
---------------------------
Build started 12.11.2010 at 16:02:34
MAKE Version 5.2 Copyright (c) 1987, 1998 Inprise Corp.
Error Makefile 77: Command syntax error
*** 1 errors during make ***
Build failed with 1 errors and 0 warnings...
------------------------------------------------
please somebody advised me what caused the error?

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

I am not sure who Inprise Corp is.

avr-gcc requires the GNU make to work properly.
Every 'MSDOS' language compiler tends to install its own brain-dead utilities. They also like putting their search paths at the head of directories to search.

WinAVR is no better in this respect. Re-install it, and it will write its path at the head of the PATH environmental variable.

You will probably find that your 'MSDOS' package will work ok with the GNU make.

There are two solutions:

1. re-install WinAVR. Force GNU tools to the front of PATH. This will possibly upset your 'MSDOS' package.
2. In your Studio Project, click on 'Edit Configuration Options'. In the 'Custom' tab, choose 'Use WinAVR' and the proper GNU make tool: "C:\WinAVR-20100110\utils\bin\make.exe"

Remember that when you invoke a command from the command-line, it will just choose the first match that is found along the PATH.

David.

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

Hi


just one observation about your code... I thought it was a no-no for main() to return in a MCU? as there is no actual calling system to return to!

--greg
Still learning, don't shout at me, educate me.
Starting the fire is easy; the hardest part is learning how to keep the flame!

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

The avr-gcc tool chain actually has a "trap" for a returning main(). An eternal loop with interrupts disabled - might not be what you want...

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

JohanEkdahl wrote:
The avr-gcc tool chain actually has a "trap" for a returning main(). An eternal loop with interrupts disabled - might not be what you want...

Ah... and quite right.. 'I' would never want that :roll:

--greg
Still learning, don't shout at me, educate me.
Starting the fire is easy; the hardest part is learning how to keep the flame!

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

david.prentice wrote:

1. re-install WinAVR. Force GNU tools to the front of PATH. This will possibly upset your 'MSDOS' package.

Finnaly,.. I reinstall the winavr, and there is no more error :D

Thanks david

best regard

davids

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

I'm having a similar issue, just getting it to compile the code initially. I tried to find answers elsewhere, but I have failed. It looks like the compiler doesn't recognize my processor name...

#include 
//#include 
//#include 
#include 

int main(void){
	//Set port B pins as all outputs
	DDRB = 0xFF;

	//Set Port B pins as High
	PORTB = 0xFF;

	return 1;
}

Here is the error:

rm -rf Atmega128KOM992.o  Atmega128KOM992.elf dep/* Atmega128KOM992.hex Atmega128KOM992.eep Atmega128KOM992.lss Atmega128KOM992.map
Build succeeded with 0 Warnings...
avr-gcc  -mmcu=atmega128a -Wall -gdwarf-2 -std=gnu99 -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -MD -MP -MT Atmega128KOM992.o -MF dep/Atmega128KOM992.o.d  -c  ../Atmega128KOM992.c
unknown MCU 'atmega128a' specified
Known MCU names:
   avr2
   at90s2313
   at90s2323
   at90s2333
   at90s2343
   attiny22
   attiny26
   at90s4414
   at90s4433
   at90s4434
   at90s8515
   at90c8534
   at90s8535
   avr25
   ata6289
   attiny13
   attiny13a
   attiny2313
   attiny2313a
   attiny24
   attiny24a
   attiny4313
   attiny44
   attiny44a
   attiny84
   attiny84a
   attiny25
   attiny45
   attiny85
   attiny261
   attiny261a
   attiny461
   attiny461a
   attiny861
   attiny861a
   attiny43u
   attiny87
   attiny48
   attiny88
   at86rf401
   avr3
   at43usb355
   at76c711
   avr31
   atmega103
   at43usb320
   avr35
   at90usb82
   at90usb162
   atmega8u2
   atmega16u2
   atmega32u2
   attiny167
   avr4
   atmega8
   atmega48
   atmega48a
   atmega48p
   atmega88
   atmega88a
   atmega88p
   atmega88pa
   atmega8515
   atmega8535
   atmega8hva
   at90pwm1
   at90pwm2
   at90pwm2b
   at90pwm3
   at90pwm3b
   at90pwm81
   avr5
   atmega16
   atmega16a
   atmega161
   atmega162
   atmega163
   atmega164a
   atmega164p
   atmega165
   atmega165a
   atmega165p
   atmega168
   atmega168a
   atmega168p
   atmega169
   atmega169a
   atmega169p
   atmega169pa
   atmega16hva
   atmega16hva2
   atmega16hvb
   atmega16m1
   atmega16u4
   atmega32
   atmega323
   atmega324a
   atmega324p
   atmega324pa
   atmega325
   atmega325a
   atmega325p
   atmega3250
   atmega3250a
   atmega3250p
   atmega328
   atmega328p
   atmega329
   atmega329a
   atmega329p
   atmega329pa
   atmega3290
   atmega3290a
   atmega3290p
   atmega32c1
   atmega32m1
   atmega32u4
   atmega32u6
   atmega406
   atmega64
   atmega640
   atmega644
   atmega644a
   atmega644p
   atmega644pa
   atmega645a
   atmega645p
   atmega645
   atmega6450
   atmega6450a
   atmega6450p
   atmega649
   atmega649a
   atmega649p
   atmega6490
   atmega6490a
   atmega6490p
   atmega64c1
   atmega64m1
   atmega64hve
   atmega32hvb
   at90can32
   at90can64
   at90pwm216
   at90pwm316
   atmega16c1
   atmega32c1
   atmega64c1
   atmega16m1
   atmega32m1
   atmega64m1
   atmega16u4
   atmega32u4
   atmega32u6
   at90scr100
   at90usb646
   at90usb647
   at94k
   m3000
   avr51
   atmega128
   atmega1280
   atmega1281
   atmega1284p
   atmega128rfa1
   at90can128
   at90usb1286
   at90usb1287
   avr6
   atmega2560
   atmega2561
   avrxmega2
   atxmega16a4
   atxmega16d4
   atxmega32a4
   atxmega32d4
   avrxmega4
   atxmega64a3
   atxmega64d3
   avrxmega5
   atxmega64a1
   atxmega64a1u
   avrxmega6
   atxmega128a3
   atxmega128d3
   atxmega192a3
   atxmega192d3
   atxmega256a3
   atxmega256a3b
   atxmega256d3
   avrxmega7
   atxmega128a1
   atxmega128a1u
   avrtiny10
   attiny4
   attiny5
   attiny9
   attiny10
   attiny20
   attiny40
   avr1
   at90s1200
   attiny11
   attiny12
   attiny15
   attiny28
../Atmega128KOM992.c:1: error: MCU 'atmega128a' supported for assembler only
In file included from ../Atmega128KOM992.c:1:
c:\program files\atmel\avr tools\avr toolchain\bin\../lib/gcc/avr/4.4.3/../../../../avr/include/avr/io.h:422:6: warning: #warning "device type not defined"
../Atmega128KOM992.c:4:21: error: mega128.h: No such file or directory
../Atmega128KOM992.c: In function 'main':
../Atmega128KOM992.c:8: error: 'DDRB' undeclared (first use in this function)
../Atmega128KOM992.c:8: error: (Each undeclared identifier is reported only once
../Atmega128KOM992.c:8: error: for each function it appears in.)
../Atmega128KOM992.c:11: error: 'PORTB' undeclared (first use in this function)
make: *** [Atmega128KOM992.o] Error 1
Build failed with 6 errors and 1 warnings...

Thanks for any help in advance. :? :? :? :? :? :? :? :? :? :?

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

Build for atmega128 not atmega128a

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

I just tried it and it worked! Will there be any issues downloading it to the Atmega128A? I don't have one in my possession yet, but I plan to simulate for now.

And is here a good way to download to the Atmega128A that is a square, surface mount? The other processors that can be plugged into a breadboard are easy, but I'm stuck with this one :cry:

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

Normally, you DO NOT include the processor specific include file. That is all done in avr/io.h IF you specify the processor in the project setup information. When you start a new project, it asks you for the target. You select the processor there. Done.

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

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

Quote:
Normally, you DO NOT include the processor specific include file.
And in this case, "normally" means never.

Regards,
Steve A.

The Board helps those that help themselves.

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

Quote:

I just tried it and it worked! Will there be any issues downloading it to the Atmega128A? I don't have one in my possession yet, but I plan to simulate for now.

The A models are just a process change in manufacturing to make a die shrink for power and cost saving (and because that's what Atmel's current fabricator happens to use). As they are otherwise binary compatible (they have the same 3 signature bytes) then it matters not whether you build for mega128 or mega128A
Quote:

And is here a good way to download to the Atmega128A that is a square, surface mount? The other processors that can be plugged into a breadboard are easy, but I'm stuck with this one

Design the PCB to run the ISP signals out to a 2x3 0.1" pin header and the JTAG signals to a 2x5 0.1" header then you have a choice of whether you program the chip with ISP or JTAG.