Recipe for target(.elf) failed and Id returned 1 exit status

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

Hello to every one,

I am new with the programming and Atmel studio so I was actually making a project and I have already the code but when I just build that code it makes an error in the error list.

Here is my program of project

#include "fNIRS_EVAL_v4_functions.h"
#include <avr/io.h>
#include <avr/interrupt.h>
#include <stdlib.h>
#include <util/delay.h>

void Timer_init() {        
    OCR0A = 195;                    // Output Compare Match with prescaler 1/1024: Every ~10ms
    TCCR0A |= (1<<WGM01);            // Clear Timer on Compare match (CTC), Mode 2
    TCCR0B |= (1<<CS02) | (1<<CS00);                // Prescaler 1/1024
    TIMSK0 |= (1<<OCIE0A);            // Timer/Counter1 Output Compare Interrupt Request
}

 void Calibration_cycle(uint8_t *currPWMlvl, uint8_t *currDAClvl){
    uint8_t adclevel;
    set_DAC_level(3, currDAClvl);
    set_PGA(128, currPWMlvl);
    
    for (int i=0; i<8; i++){
        set_MUX(i);
        enable_MUX();
        _delay_ms(100);
            
        while (PGA_errorflag()){            // While PGA puts out Error Flag (Signal clips to supply rail) reduce Gain by one step
            _delay_ms(100);
            set_PGA(0, currPWMlvl);
        }
        
        adclevel = ADC_get_value();
        while (adclevel > 113){                // While Signal higher than 113 (=2.2V. 2.5V is the upper range of mainboard ADC)
            set_PGA(0, currPWMlvl);
            _delay_ms(100);
            adclevel = ADC_get_value();
        }
        disable_MUX();
    }    
    ADC_disable();
 }
     
  
 void ADC_init(){
    ADMUX |= (1<<REFS0)|(1<<ADLAR)|(1<<MUX2)|(1<<MUX1)|(1<<MUX0);        // AVCC Reference with external capacitor at AREF; Left Adjust result (8MSBits from ADCH); ADC7 select
    ADCSRA |= (1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0)|(1<<ADSC)|(1<<ADATE);            // 1/ 128Prescaling bit for ~150kHz ADC clock, Single Ended Conversion; Auto Trigger Enable, Free Running Mode        // 
    ADCSRA |= (1<<ADEN)|(1<<ADSC);                                            // Enable ADC, Set ADC Start Conversion Bit      
  }
  
  void ADC_disable(){
    ADCSRA &= ~(1<<ADEN);            // Disable ADC for Power Saving
  }
  
  uint8_t ADC_get_value(){
      uint8_t val =0;
      val = ADCH;
      return val;
  }

 void set_DAC_level(uint8_t val, uint8_t *currDAClvl){        // sets DAC-Word (4 steps: 1-4)
     switch (val){
        case 0:{                    // reduce DAClvl by one step
            if (*currDAClvl == 4){
                PORTC = 0b10000000;    
                *currDAClvl =3;
            }
            if (*currDAClvl == 3){
                PORTC = 0b01111111;
                *currDAClvl =2;
            }
            if (*currDAClvl == 2){
                PORTC = 0b00000000;
                *currDAClvl =1;
            }
            if (*currDAClvl == 1){
                PORTC = 0b00000000;
                *currDAClvl =1;
            }
            break;
        } 
        case 1:{
            PORTC = 0b00000000;        // 440mV
            *currDAClvl =1;
            break;
        }
        case 2:{
            PORTC = 0b01111111;        // 960mV
            *currDAClvl =2;
            break;
        }
        case 3:{
            PORTC = 0b10000000;        // 1.44V
            *currDAClvl =3;
            break;
        }
        case 4:{
            PORTC = 0b11111111;        // 1.96V
            *currDAClvl =4;
            break;
        }
         default: break;
     }     
 }
 
 
 void enable_MUX(){                // Enables MUX (E)
     PORTA &= ~(1<<PINA0);
 }
 
 void disable_MUX(){
     PORTA |= (1<<PINA0);
 }
 
 void set_MUX(uint8_t channelnumber){                    // Sets MUX output channel
     switch (channelnumber){
         case 0:{
            PORTA &= ~((1<<PINA3) | (1<<PINA2) | (1<<PINA1));        // Y0: 0b000
            break;
         }
         case 1:{
            PORTA &= ~((1<<PINA2) | (1<<PINA1));                    // Y1: 0b001
            PORTA |= (1<<PINA3);  
            break;
         }
         case 2:{
            PORTA &= ~((1<<PINA3) | (1<<PINA1));                    // Y2: 0b010
            PORTA |= (1<<PINA2);
            break;
         }
         case 3:{
            PORTA &= ~(1<<PINA1);                                    // Y3: 0b011
            PORTA |= (1<<PINA3) | (1<<PINA2);
            break;
         }
         case 4:{
            PORTA &= ~((1<<PINA3) | (1<<PINA2));                    // Y4: 0b100
            PORTA |= (1<<PINA1);
            break;
         }         
         case 5:{
            PORTA &= ~(1<<PINA2);                                    // Y5: 0b101
            PORTA |= (1<<PINA3) | (1<<PINA1);
            break;
         }
         case 6:{
            PORTA &= ~(1<<PINA3);                                    // Y6: 0b110
            PORTA |= (1<<PINA2) | (1<<PINA1);
            break;
         }         
         case 7:{
            PORTA |= ((1<<PINA3) | (1<<PINA2) | (1<<PINA1));        // Y7: 0b111
            break;
         }
         default:    break;
     }

 }
 
 void PWM_init(){
     //Initialize Lock-In-PWM-Signal
     PRR0 &= ~(1<<PRTIM2);                                                    // Power Reduction Register: Timer2 Enable
     TCCR2A=(1<<COM2A0) | (1<< WGM20);                                        // WGM22:0 = 101 PWM, Phase Correct Mode; COM2A0=1 Toggle on Compare Match
     TCCR2B=(1<<CS21) | (1<<WGM22);                                            // 1/8 prescaling,
     //set_LOCK_PWM(62);                                                        // PWM: 10,08 kHz, 50% Duty Cycle
     //set_LOCK_PWM(250);                                                    // PWM: 2,50 kHz
     set_LOCK_PWM(200);                                                        // PWM: 3,125 kHz
 }
 
 void enable_LOCK_PWM(){
     TCCR2A |= (1<<COM2A0);                        // Phase correct PWM Mode, Toggle OC1A on Compare Match
 }
 
 void disable_LOCK_PWM(){
     TCCR2A &= ~(1<<COM2A0);                    // Non PWM Mode, Normal port operation, OC1A disconnected 
 }
 
 void set_LOCK_PWM(uint8_t pwm_val){
     OCR2A = pwm_val;
 }
 
 void set_PGA(uint8_t PGA_val, uint8_t *currPGAlvl){        // Available Gains: 1, 2, 4, 8, 16, 32, 64, 128 NOTE: *1.375 / 2 because of Single-Output-Use & G4=1
      /*    
        PB4                Logic            44        LSB        G0
          PB3                Logic            43                G1
          PB2                Logic            42                G2
          PB1                Logic            41                G3
          PB0                Logic            40        MSB        G4*/
      switch (PGA_val){
          case 0:{                    // Reduce Gain by one step
            if (*currPGAlvl ==128){
                PORTB = 0b00001001;
                *currPGAlvl = 64;
            }
            if (*currPGAlvl ==64){
                PORTB = 0b00001000;
                *currPGAlvl = 32;
            }
            if (*currPGAlvl ==32){
                PORTB = 0b00000111;
                *currPGAlvl = 16;
            }
            if (*currPGAlvl ==16){
                PORTB = 0b00000110;
                *currPGAlvl = 8;
            }
            if (*currPGAlvl ==8){
                PORTB = 0b00000101;
                *currPGAlvl = 4;
            }
            if (*currPGAlvl ==4){
                PORTB = 0b00000100;
                *currPGAlvl = 2;
            }
            if (*currPGAlvl ==2){
                PORTB = 0b00000011;
                *currPGAlvl = 1;
            }
            if (*currPGAlvl ==1){
                PORTB = 0b00000011;
                *currPGAlvl = 1;
            }  
            break;
          }
          case 1:{
            PORTB = 0b00010011;        // Gain = 0.688; G4 = 1, G3:G0= 0011, 
            *currPGAlvl=1;
            break;
          }
          case 2:{
            PORTB = 0b00010100;        // Gain = 1.375; G4 = 1, G3:G0= 0100
            *currPGAlvl=2;
            break;
          }
          case 4:{
            PORTB = 0b00010101;        // Gain = 2.75; G4 = 1, G3:G0= 0101
            *currPGAlvl=4;
            break;
          }
          case 8:{
            PORTB = 0b00010110;        // Gain = 5.5; G4 = 1, G3:G0= 0110
            *currPGAlvl=8;
            break;
          }
          case 16:{
            PORTB = 0b00010111;        // Gain = 11; G4 = 1, G3:G0= 0111
            *currPGAlvl=16;
            break;
          }      
          case 32:{
            PORTB = 0b00011000;        // Gain = 22; G4 = 1, G3:G0= 1000
            *currPGAlvl=32;
            break;
          }      
          case 64:{
            PORTB = 0b00011001;        // Gain = 44; G4 = 1, G3:G0= 1001
            *currPGAlvl=64;
            break;
          }
          case 128:{
            PORTB = 0b00011010;        // Gain = 88; G4 = 1, G3:G0= 1010
            *currPGAlvl=128;
            break;    
          } 
          default: break;
      }  
 }
 
 bool PGA_errorflag(){
     bool portflag = (PIND & 0x01);
     return portflag;
 }
 
 void LED1_on(){
     PORTA |= (1<<PINA4);
 }
 
 void LED1_off(){
     PORTA &= ~(1<<PINA4);
 }
 
 void LED2_on(){
     PORTA |= (1<<PINA5);
 }
 
 void LED2_off(){
     PORTA &= ~(1<<PINA5);
 }
 
 
 void LED_Init(){
     LED1_on();
     LED2_on();
     _delay_ms(500);
     LED1_off();
     LED2_off();
     _delay_ms(500);
     LED1_on();
     LED2_on();
     _delay_ms(500);
     LED1_off();
     LED2_off();
 }
 
 void test_PGA(uint8_t *currPGAval){
    LED1_on();
    set_PGA(1,currPGAval);
    _delay_ms(2000);
    LED1_off();
    
    LED2_on();
    set_PGA(2,currPGAval);
    _delay_ms(2000);
    LED2_off();

    LED1_on();
    set_PGA(4,currPGAval);
    _delay_ms(2000);
    LED1_off();
    
    LED2_on();
    set_PGA(8,currPGAval);
    _delay_ms(2000);
    LED2_off();
    
    LED1_on();
    set_PGA(16,currPGAval);
    _delay_ms(2000);
    LED1_off();
    
    LED2_on();
    set_PGA(32,currPGAval);
    _delay_ms(2000);
    LED2_off();
    
    LED1_on();
    set_PGA(64,currPGAval);
    _delay_ms(2000);
    LED1_off();
    
    LED2_on();
    set_PGA(128,currPGAval);
    _delay_ms(2000);
    LED1_off();                    
 }
 
 void test_MUX(){
    LED1_on();
    set_MUX(0);
    enable_MUX();
    _delay_ms(1000);
    LED1_off();
    disable_MUX();
    
    LED2_on();
    set_MUX(1);
    enable_MUX();
    _delay_ms(1000);
    LED2_off();
    disable_MUX();
    
    LED1_on();
    set_MUX(2);
    enable_MUX();
    _delay_ms(1000);
    LED1_off();
    disable_MUX();
    
    LED2_on();
    set_MUX(3);
    enable_MUX();
    _delay_ms(1000);
    LED2_off();
    disable_MUX();
        
    LED1_on();
    set_MUX(4);
    enable_MUX();
    _delay_ms(1000);
    LED1_off();
    disable_MUX();
    
    LED2_on();
    set_MUX(5);
    enable_MUX();
    _delay_ms(1000);
    LED2_off();
    disable_MUX();
    
    LED1_on();
    set_MUX(6);
    enable_MUX();
    _delay_ms(1000);
    LED1_off();
    disable_MUX();
    
    LED2_on();
    set_MUX(7);
    enable_MUX();
    _delay_ms(1000);
    LED2_off();
    disable_MUX();        
        
 }
   
 void test_DAC(uint8_t *currDACval){
      LED1_on();
      set_DAC_level(1,currDACval);
      _delay_ms(1000);
      LED1_off();
      
      LED2_on();
      set_DAC_level(2,currDACval);
      _delay_ms(1000);
      LED2_off();      

      LED1_on();
      set_DAC_level(3,currDACval);
      _delay_ms(1000);
      LED1_off();

      LED2_on();
      set_DAC_level(4,currDACval);
      _delay_ms(1000);
      LED2_off();            
 }

 

Kindly help me what this error means and from where I can fix these errors.

And I also want to understand this code so refer me any book or website.

Thanks for your consideration.

ibrar

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

It would have been of more use if you posted the contents of the "Output" tab when you try to build so we could all see the error that is being reported. As your code has "private" headers like   "fNIRS_EVAL_v4_functions.h"  then no one here can do very much with the code you posted.

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

------ Build started: Project: FNIRS Module, Configuration: Debug AVR ------
Build started.
Project "FNIRS Module.cproj" (default targets):
Target "PreBuildEvent" skipped, due to false condition; ('$(PreBuildEvent)'!='') was evaluated as (''!='').
Target "CoreBuild" in file "C:\Program Files (x86)\Atmel\Studio\7.0\Vs\Compiler.targets" from project "c:\users\user\Documents\Atmel Studio\7.0\FNIRS Module\FNIRS Module.cproj" (target "Build" depends on it):
    Task "RunCompilerTask"
        Shell Utils Path C:\Program Files (x86)\Atmel\Studio\7.0\shellUtils
        C:\Program Files (x86)\Atmel\Studio\7.0\shellUtils\make.exe all --jobs 4 --output-sync 
        Building file: .././main.c
        Invoking: AVR/GNU C Compiler : 5.4.0
        "C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-gcc.exe"  -x c -funsigned-char -funsigned-bitfields -DDEBUG  -I"C:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\include"  -O1 -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -g2 -Wall -mmcu=atmega164a -B "C:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\gcc\dev\atmega164a" -c -std=gnu99 -MD -MP -MF "main.d" -MT"main.d" -MT"main.o"   -o "main.o" ".././main.c" 
        Finished building: .././main.c
        C:/Program Files (x86)/Atmel/Studio/7.0/Packs/atmel/ATmega_DFP/1.2.209/gcc/dev/atmega164a/avr5/crtatmega164a.o:../../../../crt1/gcrt1.S:310: undefined reference to `main'
        Building target: FNIRS Module.elf
collect2.exe(0,0): error: ld returned 1 exit status
        make: *** [FNIRS Module.elf] Error 1
        Invoking: AVR/GNU Linker : 5.4.0
        "C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-gcc.exe" -o "FNIRS Module.elf"  main.o   -Wl,-Map="FNIRS Module.map" -Wl,--start-group -Wl,-lm  -Wl,--end-group -Wl,--gc-sections -mmcu=atmega164a -B "C:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\gcc\dev\atmega164a"  
c:\users\user\Documents\Atmel Studio\7.0\FNIRS Module\Debug\Makefile(106,1): error: recipe for target 'FNIRS Module.elf' failed
        The command exited with code 2.
    Done executing task "RunCompilerTask" -- FAILED.
Done building target "CoreBuild" in project "FNIRS Module.cproj" -- FAILED.
Done building project "FNIRS Module.cproj" -- FAILED.

Build FAILED.
========== Build: 0 succeeded or up-to-date, 1 failed, 0 skipped ==========

 

 

 

Here is my Output window
 

ibrar

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

Wahla Ibrar wrote:
   C:/Program Files (x86)/Atmel/Studio/7.0/Packs/atmel/ATmega_DFP/1.2.209/gcc/dev/atmega164a/avr5/crtatmega164a.o:../../../../crt1/gcrt1.S:310: undefined reference to `main'
Well there is the error. You have a C program that has no function called main(). All C programs must have this somewhere as it's the entry point for the code that runs before you own code.

 

(looking at your code there are a load of XXX_init() and XXX_set() functions but no sign of a main() that pulls them all together)

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

Well, this is good new Sir, but what you think where I can add this main() function in my code, my code is in the above post. Actually, I have copied this code to somewhere related to my project that,s why I don't know about the code.

.

ibrar

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

Have you ever written a C program? If not I'd start by getting a good tutoriak guide and following it. That will tell you all about main() and so on.
.
But if you really wrote all those functions in the first post yourself how were you planning for them to be used?
.
EDIT have you previously been using Arduino perhaps?

Last Edited: Wed. Oct 17, 2018 - 04:15 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Dear Clawson,

I have not written C program by myself that,s why I don,t know about programming and it is honored from you if you refer me a tutorial for programming, And no I don,t use Arduino.

ibrar

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

How can you expect to be able to program if you don't learn a program language first?

 

if it was me I would forget about AVRs for now. It's far easier to learn C when writing PC programs as the edit/compile/run cycle is much quicker, the debugger is better and more powerful and a PC version of C has immediate connection to things like stdout so you can just use printf() and see things happen. In fact on a PC the "first program" most people write is:

#include <stdio.h>

int main(void) {
    printf("hello world\n");
}

That has an immediate effect on a PC while to get that to do something on an AVR is far more complex.

 

On a PC it is as simple as this:

D:\c>type hello.c
#include <stdio.h>

int main(void) {
    printf("hello world\n");
}

D:\c>cl hello.c
Microsoft (R) C/C++ Optimizing Compiler Version 19.11.25547 for x86
Copyright (C) Microsoft Corporation.  All rights reserved.

hello.c
Microsoft (R) Incremental Linker Version 14.11.25547.0
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:hello.exe
hello.obj

D:\c>hello
hello world

I built then ran this and saw the immediate output.

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

Dear Clawson,

Actually that basic I know but now I haven't enough time to learn from basic if it is possible that I burn this code to my Atmega164A microcontroller after that I promise I learn from basic but first priority is that to burn that code and understand that code after that learn the basics of programming

ibrar

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

Yeah but you can't "burn" until you can "build" and you can't build until you make a complete C program. As I say all valid C programs have a function called main() somewhere. So maybe try adding something like this to the code above:

int main(void) {
    uint8_t PGAval, DACval;
    
    Timer_init();
    ADC_init();
    PWM_init();
    LED_init();

    PGAval = 123;
    DACval = 231;

    while(1) {
        test_MUX();
        test_DAC(&DACval);
        test_PGA(&PGAval);
    }
}

I have no idea what your functions do so I just randomly collected together a few of the more likely sounding ones and made calls to them from main(). You presumably know the intention of these functions and which ones you want to use so maybe you have some other ideas about what main() should contain?

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

Dear Clawson,

Actually, I have seen all the code and in my code, after void, there is some function so I don,t know where I add the main function in my code if you understand my code then let me know where I have added the main function in my code.

Thanks to you for helping me.

ibrar

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

It's YOUR code! You must know what the functions do and why you wrote them? Only you can know how the various functions interact and which ones you planned to call from main().

 

This product/project must have some kind of overall design plan? What does that say the thing is supposed to do? Is it an alarm clock? Is it a water detecting plant feeder? Is it a missile guidance system?

 

Only you have access to the design documents and know what the thing is supposed to do. So only you can know what order you intended each function to be used in and why each one exists.

Last Edited: Thu. Oct 18, 2018 - 09:21 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Dear Clawson,

I mean that this code is not written by me I just copy this code to somewhere related to my project and I don,t know what functions they call for it. so I apologized to you for saying that my code

ibrar

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

Well you can only do the copy/paste thing if you understand how to program. So you are going to have to spend a few months learning to program in C before you can do anything with this code

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

Ok, Sir, I want to learn to programme so you refer me some tips about coding.
Thank You 

ibrar