AVR Build Erros

Hi,

I installed and got the blink LED example to work a couple of months ago. Now I cannot get anything to build in the AVR Studio. I get the following message:

gcc plug-in: No AVR Toolchain installation found. The AVR GCC plug-in can still be used if you set up your own build tools.

The code never builds into the hex file. Any thoughts?

Tyler

Hello, mkomkom.

I’m sorry you are having trouble.

I think you should be able to fix it by going to Project -> Configuration Options -> Custom Options and telling AVR Studio the location of WinAVR’s avr-gcc.exe and make.exe.

This error has happened to a few of our customers recently and I’m not sure what’s causing it. What version of AVR Studio do you have?

–David

Thanks David,

I’m using AVRStudio 4. This is odd b/c I got the FlashLED to work a couple months ago, then I set the Baby Oran aside and now I have the problems. I have used an Arduino in the interim, so maybe that caused a conflict? I ran a seach for the files avr-gcc.exe and make.exe, but they only turned up in the Arduino and CodeBlocks folders…

I tried to install the AVRStudio again but couldn’t as it was already intalled. Should I try to uninstall it all and reinstall again?

No. If you can’t find your WinAVR installation folder and the tools inside, you should try installing WinAVR again.

–David

OK, I reinstalled and now I’m getting a different error:

avr-objcopy: ‘BlinkLED.elf’: No such file

Maybe AVR Studio 4 is failing to invoke the compiler correctly so it’s not generating an ELF file. Could you tell me which two executables are listed in Project -> Configuration Options -> Custom Options ?

Also, could you select Build -> Rebuild all and then copy and paste the entire output from the Build window here?

Here’s an example of a good build output from my computer:

Build started 2.3.2012 at 09:47:45
avr-gcc  -mmcu=atmega328p -Wall -gdwarf-2 -std=gnu99 -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -MD -MP -MT test.o -MF dep/test.o.d  -c  ../test.c
avr-gcc -mmcu=atmega328p -Wl,-gc-sections -Wl,-Map=test.map test.o    -lpololu_atmega328p  -o test.elf
avr-objcopy -O ihex -R .eeprom -R .fuse -R .lock -R .signature  test.elf test.hex
avr-objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 --no-change-warnings -O ihex test.elf test.eep || exit 0
avr-objdump -h -S test.elf > test.lss

AVR Memory Usage
----------------
Device: atmega328p

Program:    9256 bytes (28.2% Full)
(.text + .data + .bootloader)

Data:        169 bytes (8.3% Full)
(.data + .bss + .noinit)


Build succeeded with 0 Warnings...

OK sure. As default, under custom options, the Use AVR Toolchain is checked with no executables listed under it. If I try it that way I get:

rm -rf BlinkLED.o  BlinkLED.elf dep/* BlinkLED.hex BlinkLED.eep BlinkLED.lss BlinkLED.map
Build succeeded with 0 Warnings...
mmcu=atmega328p -Wall -gdwarf-2 -Os -std=gnu99 -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -MD -MP -MT BlinkLED.o -MF dep/BlinkLED.o.d  -c  ../BlinkLED.c
/usr/bin/sh: -Wall: command not found
make: [BlinkLED.o] Error 127 (ignored)
mmcu=atmega328p -Wl,-Map=BlinkLED.map BlinkLED.o     -o BlinkLED.elf
/usr/bin/sh: -Wl,-Map=BlinkLED.map: command not found
make: [BlinkLED.elf] Error 127 (ignored)
avr-objcopy -O ihex -R .eeprom -R .fuse -R .lock -R .signature  BlinkLED.elf BlinkLED.hex
avr-objcopy: 'BlinkLED.elf': No such file
make: *** [BlinkLED.hex] Error 1
Build failed with 1 errors and 0 warnings...

If I put in the avr-gcc.exe and make.exe into the custom options, I get the following:

rm -rf BlinkLED.o  BlinkLED.elf dep/* BlinkLED.hex BlinkLED.eep BlinkLED.lss BlinkLED.map
Build succeeded with 0 Warnings...
avr-gcc  -mmcu=atmega328p -Wall -gdwarf-2 -Os -std=gnu99 -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -MD -MP -MT BlinkLED.o -MF dep/BlinkLED.o.d  -c  ../BlinkLED.c
../BlinkLED.c: In function 'delayms':
../BlinkLED.c:8: error: (Each undeclared identifier is reported only once
../BlinkLED.c:8: error: for each function it appears in.)
make: *** [BlinkLED.o] Error 1
Build failed with 3 errors and 0 warnings...

OK, we’re making progress. Are you sure you posted the entire build output? It looks incomplete because the message about “Each undeclared indentifier” usually comes after an error message that actually says which identifier was undeclared.

I’m not sure exactly what version of BlinkLED.c you have, so could you copy and paste the entire thing here so I can see what’s on line 8 and make sure it looks good?

–David

Sorry, I might have missed a line. I can’t copy more than one line at a time…

OK, let’s try this again. I have a Baby O. Here’s the code:

#define F_CPU 20000000UL   // Baby Organtuan Frequency (20MHz)
#include <avr/io.h>
#include <util/delay.h>

void delayms( uint16_t millis ) {
	while ( millis ) {
		_delay_ms( 1 );
		milias--;
	}
}

int main( void ) {
	DDRD |=1 << DDD1;	// set LED pin PD1 to output
	while (1) {
		PORTD &= ~( 1 << PORTD1 ); // LED off
		delayms (900);  // delay 900 ms
		PORTD |= 1 << PORTD1; // LED on
		delayms(100);  // delay 100 ms
	}
	return 0;
}

And here is the build message:

rm -rf BlinkLED.o  BlinkLED.elf dep/* BlinkLED.hex BlinkLED.eep BlinkLED.lss BlinkLED.map
Build succeeded with 0 Warnings...
avr-gcc  -mmcu=atmega328p -Wall -gdwarf-2 -Os -std=gnu99 -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -MD -MP -MT BlinkLED.o -MF dep/BlinkLED.o.d  -c  ../BlinkLED.c
../BlinkLED.c: In function 'delayms':
../BlinkLED.c:8: error: 'milias' undeclared (first use in this function)
../BlinkLED.c:8: error: (Each undeclared identifier is reported only once
../BlinkLED.c:8: error: for each function it appears in.)
make: *** [BlinkLED.o] Error 1
Build failed with 3 errors and 0 warnings...

Hello.

You can copy all of the build output of AVR Studio 4 by clicking in the “Build” window and typing Ctrl+A Ctrl+C.

The problem is that the compiler doesn’t know what to do with “milias”. When you write an identifier like “milias” in your code, the compiler will try to figure out what you are referring to, but you never declared “milias” anywhere so it generates this error. I think you meant to type “millis”. From the error message, you can see that the problem is on line 8.

–David

OK, I feel dumb. Obviously I am a rookie. Thanks Dave, I know you have much more interesting questions to tackle.

I am having problems with another example, the motors1:

#include <pololu/orangutan.h> 
  
/* 
 * motors1: for the Orangutan LV-168, Orangutan SV-xx8, Orangutan SVP, 
 *    and Baby Orangutan B 
 * 
 * This example uses the OrangutanMotors functions to drive 
 * motors in response to the position of user trimmer potentiometer 
 * and blinks the red user LED at a rate determined by the trimmer 
 * potentiometer position.  It uses the OrangutanAnalog library to measure 
 * the trimpot position, and it uses the OrangutanLEDs library to provide 
 * limited feedback with the red user LED. 
 * 
 * https://www.pololu.com/docs/0J20 
 * https://www.pololu.com 
 * https://forum.pololu.com 
 */
  
unsigned long prevMillis = 0; 
  
int main() 
{ 
  while(1) 
  { 
    // note that the following line could also be accomplished with: 
    // int pot = analogRead(7); 
    int pot = read_trimpot();    // determine the trimpot position 
    int motorSpeed = pot/2-256;  // turn pot reading into number between -256 and 255 
    if(motorSpeed == -256) 
        motorSpeed = -255; // 256 is out of range 
    set_motors(motorSpeed, motorSpeed); 
    
    int ledDelay = motorSpeed; 
    if(ledDelay < 0) 
      ledDelay = -ledDelay;  // make the delay a non-negative number 
    ledDelay = 256-ledDelay; // the delay should be short when the speed is high 
  
    red_led(1);       // turn red LED on 
    delay_ms(ledDelay); 
  
    red_led(0);       // turn red LED off 
    delay_ms(ledDelay); 
  } 
}

I 'm trying to work through these erros:

Build started 6.3.2012 at 21:10:22
avr-gcc  -mmcu=atmega328p -Wall -gdwarf-2 -Os -std=gnu99 -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -MD -MP -MT motor1d.o -MF dep/motor1d.o.d  -c  ../motor1d.c
avr-gcc -mmcu=atmega328p -Wl,-Map=motor1d.map motor1d.o     -o motor1d.elf
motor1d.o: In function `main':
C:\Documents and Settings\Tyler\My Documents\Pololu\motor1d\default/../motor1d.c:27: undefined reference to `read_trimpot'
C:\Documents and Settings\Tyler\My Documents\Pololu\motor1d\default/../motor1d.c:31: undefined reference to `set_motors'
C:\Documents and Settings\Tyler\My Documents\Pololu\motor1d\default/../motor1d.c:39: undefined reference to `delay_ms'
C:\Documents and Settings\Tyler\My Documents\Pololu\motor1d\default/../motor1d.c:42: undefined reference to `delay_ms'
make: *** [motor1d.elf] Error 1
Build failed with 4 errors and 0 warnings...

Do I need to add some functions? :confused:

When you invoke the linker to build motor1d.elf, you are missing the “-lpololu_atmega328p” command that tells it to actually use the Pololu AVR C/C++ Library and you are missing other useful options too. I suspect that you created this AVR Studio project yourself instead of using the example project files in libpololu-avr/examples. Please go to libpololu-avr/examples/atmega328p/motors1/ and double click on motors1.aps. This should give you an AVR Studio project that has already been configured correctly.

–David

You’re right. The .aps exaple works. I thought I followed the steps in the Pololu AVR C/C++ Library User’s Guide to a tee…

I assume I can just load the .aps example and just modify the code from there. Then I’ll know it’s at least configured correctly! Thanks Dave.