mikrocontroller.net

Forum: Compiler & IDEs AVRGCC C++ undefined reference to Max7456::Max7456()


Autor: Hannes (Gast)
Datum:

Bewertung
0 lesenswert
nicht lesenswert
Hallo,
ich benutze Xcode zum AVR programmieren(328),
leider kann ich kein object aus meiner klasse erzeugen und ich finde den 
Fehler nich.

code:


//including lib`s
#include <stdio.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include "src/AVRTools/ArduinoPins.h"
#include "src/Max7456/max7456.hpp"
#include "src/SPI/SPI.hpp"
#include "src/Uart/uart.h"

//-----define object---//
Max7456 osd;

//-----define global var---//

void setup( void ){

}


int main(void) {
    //init
    setup();

    //main lopp
    while ( 1 )
    {


    }
}

cpp:

//
//  max7456.hpp
//  Quanum_CyclopOSD
//
//  Created by Dominik Loher on 29.08.16.
//  Copyright © 2016 Dominik Loher. All rights reserved.
//

#ifndef max7456_hpp
#define max7456_hpp

//#include <stdio.h>


//def next only if you changed your table for an ascii one
//i.e address 0x00 -> ' '
//....
//    address 0x5A -> 'z'
//#define MAX7456_TABLE_ASCII

#include "max7456registers.h"
#define byte uint8_t


/**
 *  @mainpage Max7456 Arduino library
 */

/**
 *  @example Max7456WriteTable.cpp
 */


/**
 *  @class Max7456
 *  @brief Represents a max7456 device communicating through SPI port
 */
class Max7456
{
public:


    /**
     *  Default constructor
     */
    Max7456();


    /**
     *  Constructor
     *  Initialize communications and device
     *  @param pinCS : pin ~CS of the arduino where max7456 is plugged.
     */
    Max7456(byte pinCS);


    /**
     *  Initialize communications and device
     *  @param pinCS : pin ~CS of the arduino where max7456 is plugged.
     *  @code
     *  Max7456 osd;
     *  osd.init(9); //Note it's that it's the same than usinge 
constructor Max7456(byte pinCS).
     *  @endcode
     */
    void init(byte pinCS);

    /**
     * Set the base time for blink.
     * @param blinkBase : the base time (see datasheet)
     * @param blinkDC : blink Duty cycle (see datasheet).
     */
    void setBlinkParams(byte blinkBase, byte blinkDC);


    /**
     * Set Horizontal and Vertical display offset
     * @param horizontal : the horizontal offset in pixels (between 0 
and 63).
     * @param vertical : the vertical offset in pixels (between 0 and 
31).
     */
    void setDisplayOffsets(byte horizontal, byte vertical);


    /**
     *  Erase Display Memory.
     */
    void clearScreen();


    /**
     *  Activate osd on screen
     *  @param act :
     *  @li if true OSD is activated
     *  @li if false OSD is deactivated
     */
    void activateOSD(bool act = true);


    /**
     *  Activate input video as a background
     *  @param activExtVid :
     *  @li if true external video is displayed
     *  @li if false external video is not displayed (bakground = grey)
     */
    void activateExternalVideo(bool activExtVid = true);


    /**
     *  Put a character in the memory character of max7456
     *  @param array : the byte array representing the character (54 
bytes long)
     *  @param x : the horizontal position of character in memory
     *  @param y : the vertical position of character in memory.
     *  @code
     *  charact c={0x44,....} //Whatever charact here
     *  max.sendCharacter(c,4,5); //put c at 4th line 5th column ie. 
address 54.
     *  max.sendCharacter(c,0x43); //put c in mem at address 43.
     *  @endcode
     */
    void sendCharacter(const charact array, byte x, byte y);
//    void write_NVM(int font_count, uint8_t *character_bitmap);


    /**
     *  Get a character from the character memory of max7456
     *  @param array : the byte array representing the character (54 
bytes long)
     *  @param x : the horizontal position of character in character 
memory
     *  @param y : the vertical position of character in character 
memory
     */
    void getCharacter(charact array, byte x, byte y);


    /**
     *  Put a string in the display memory of max7456
     *  @param string : The string to be displayed
     *  @param x : the horizontal position of the string on screen
     *  @param y : the vertical position of the string on screen
     *  @param blink : if 1 then character will blink
     *  @param inv : if 1 then color character will be inverted
     *  @note : In order to have this function working,
     *  you must rewrite your Max7456 Eeprom memory and make the first
     *  characters the ascii characters between ' ' and 'z'
     *  (' ' being at address 0x00, z being at address 'z'-' ').
     */
    void print(const char string[], byte x, byte y, byte blink = 0,byte 
inv = 0);



    /**
     *  Put a float in the display memory of max7456
     *  @param value : The value to be displayed
     *  @param x : the horizontal position of the value on screen
     *  @param y : the vertical position of the value on screen
     *  @param before : number of digits before comma
     *  @param after : number of digits after comma
     *  @param blink : if 1 then character will blink
     *  @param inv : if 1 then color character will be inverted
     *  @note The number of printed characters will be : before + after 
+ 1.
     *  @note Be aware of having a coherence between the number of 
digits you
     *  enter in the function and the max. value of your double. If not 
may
     *  result in unpredictable printed string.
     *  @code
     *  max.print(3.14,x,y,3,4);
     *  //Will print "003.1400" on screen
     *  @endcode
     */
    void print(double value, byte x, byte y, byte before, byte after, 
byte blink=0,byte inv=0);


    /**
     *  Put some characters in the display memory of max7456.
     *    The characters are given by their address in the
     *    character memory of the max7456.
     *  @param chars : The characters address array to display
     *  @param size : the array size
     *  @param x : the horizontal position of the value on screen
     *  @param y : the vertical position of the value on screen
     *  @param blink : if 1 then character will blink
     *  @param inv : if 1 then color character will be inverted
     *  @code
     *  char chars[0x04,0x45,0x54]; //the chars addresses array to be 
send to function.
     *  max.printMax7456Chars(chars,3,x,y);
     *  @endcode
     */
    void printMax7456Chars(byte chars[],byte size,byte x, byte y, byte 
blink = 0,byte inv = 0);


    /**
     *  Put one character from the character memory in the display 
memory of max7456
     *  @param address : The address in character memory of the 
character to be displayed
     *  @param x : the horizontal position of the string on screen
     *  @param y : the vertical position of the string on screen
     *  @param blink : if 1 then character will blink
     *  @param inv : if 1 then color character will be inverted
     */
    void printMax7456Char(const byte address, byte x, byte y, byte 
blink=0, byte inv=0);

    /**
     *  Print a character to Serial port
     *  @param array : the byte array representing the character (54 
bytes long)
     *  @param img :
     *  @li true : the character will be displayed as a picture
     *  @li false : the character will be displayed as a byte array
     */
    static void printCharacterToSerial(const charact array, bool img = 
true);


    /**
     *  Converts a CARACT character to a byte array representation.
     *  @param car : the CARACT character
     *  @return : the byte array representing the character (54 bytes 
long)
     */
    static byte* CARACT2ByteArray(const CARACT car);


    /**
     *  Converts a byte array to a CARACT character.
     *  @param array : the byte array representing the character (54 
bytes long)
     *  @return : the CARACT character
     */
    static CARACT byteArray2CARACT(const charact array);


    /**
     * Get the ith character from program memory
     * @param table the address of the array in prog memory
     * @param i the index of character.
     * @param c the returned character.
     * @note The table must be in program memory as an array of bytes (a 
multiple of 54).
     * @note When accessing this array, 0x55 are interpreted as 0xFF 
(you can't have 0xFF in program memory.
     * @note See file example for more informations.
     */
    static void getCARACFromProgMem(const char *table, byte i,charact 
c);

private:

    byte giveMax7456CharFromAsciiChar(char ascii);
    static void printPixel(byte value);

    byte _pinCS;
    bool _isActivatedOsd;
    //registers (only here for convenience : not forced to be used).
    REG_VM0   _regVm0;
    REG_VM1   _regVm1;
    REG_HOS   _regHos;
    REG_VOS   _regVos;
    REG_DMM   _regDmm;
    REG_DMAH  _regDmah; // not used yet
    REG_DMAL  _regDmal; // not used yet
    REG_DMDI  _regDmdi; // not used yet
    REG_CMM   _regCmm;
    REG_CMAH  _regCmah; // not used yet
    REG_CMAL  _regCmal; // not used yet
    REG_CMDI  _regCmdi; // not used yet
    REG_OSDM  _regOsdm; // not used yet
    REG_RBN   _regRb[16];  // not used yet
    REG_OSDBL _regOsdbl; // not used yet
    REG_STAT  _regStat; // not used yet
    DMDO  _regDmdo; // not used yet
    REG_CMDO  _regCmdo; // not used yet
};


#endif /* MAX7456_H_ */

: Verschoben durch Moderator
Autor: Oliver S. (oliverso)
Datum:

Bewertung
0 lesenswert
nicht lesenswert
Die Fehlermeldung kommt vom linker, und dem fehlt die Implementierung 
des Konstruktors. In deinem geposteten Quellcode fehlt die auch.

Olivef

Autor: Hannes (Gast)
Datum:

Bewertung
0 lesenswert
nicht lesenswert
dazu gibt es natürlich noch die .cpp.

Die ist doch hier ->
    /**
     *  Default constructor
     */
    Max7456();

Oder was meinst du genau ?

Autor: Oliver S. (oliverso)
Datum:

Bewertung
0 lesenswert
nicht lesenswert
Die cpp ist wohl eher eine hpp.

Und das enthält nur die Deklarationen. Die Implementierungrm dazu stehen 
vermutlich im tatsächlichen (und dir fehlenden) cpp-file.

Oliver

Autor: Hannes (Gast)
Datum:

Bewertung
0 lesenswert
nicht lesenswert
Ja das war ein tipp fehler von mir

//
//  Quanum_CyclopOSD
//
//  Created by Dominik Loher on 29.08.16.
//  Copyright © 2016 Dominik Loher. All rights reserved.
//
#include "max7456.hpp"
#include "SPI.hpp"

//---------------------------------------------------------------------- 
-------
// Implements Max7456::Max7456
//---------------------------------------------------------------------- 
-------
Max7456::Max7456(byte pinCS)
{
    this->init(pinCS);
}

//---------------------------------------------------------------------- 
-------
// Implements Max7456::setBlinkParams
//---------------------------------------------------------------------- 
-------
void Max7456::setBlinkParams(byte blinkBase, byte blinkDC)
{
    _regVm1.bits.blinkingTime = blinkBase;
    _regVm1.bits.blinkingDutyCycle = blinkDC;
    digitalWrite(_pinCS,LOW);
    SPI.transfer(VM1_ADDRESS_WRITE);
    SPI.transfer(_regVm1.whole);
    digitalWrite(_pinCS,HIGH);
}


//---------------------------------------------------------------------- 
-------
// Implements Max7456::setDisplayOffsets
//---------------------------------------------------------------------- 
------
void Max7456::setDisplayOffsets(byte horizontal, byte vertical)
{

    _regHos.whole = 0;
    _regVos.whole = 0;

    _regHos.bits.horizontalPositionOffset = horizontal;
    _regVos.bits.verticalPositionOffset = vertical;

    digitalWrite(_pinCS,LOW);
    SPI.transfer(HOS_ADDRESS_WRITE);
    SPI.transfer(_regHos.whole);

    SPI.transfer(VOS_ADDRESS_WRITE);
    SPI.transfer(_regVos.whole);

    digitalWrite(_pinCS,HIGH);
}

//---------------------------------------------------------------------- 
-------
// Implements Max7456::Max7456
//---------------------------------------------------------------------- 
-------
Max7456::Max7456()
{
}


//---------------------------------------------------------------------- 
-------
// Implements Max7456::sendCharacter
//---------------------------------------------------------------------- 
-------
void Max7456::sendCharacter(const charact chara, byte x, byte y)
{
    byte charAddress;
    if(y<0)
        charAddress = x;
    else
        charAddress = x + (y<<4);
    activateOSD(false);
    //datasheet p38
    digitalWrite(_pinCS,LOW);
    SPI.transfer(CMAH_ADDRESS_WRITE);
    SPI.transfer(charAddress);

    for(byte i = 0 ; i < 54 ; i++)
    {
        SPI.transfer(CMAL_ADDRESS_WRITE);
        SPI.transfer(i);
        SPI.transfer(CMDI_ADDRESS_WRITE);
        SPI.transfer(chara[i]);
    }

    _regCmm = 0xA0; //To write the NVM array
    SPI.transfer(CMM_ADDRESS_WRITE);
    SPI.transfer(_regCmm);
    //while STAT[5] is not good, we wait.
    _regStat.bits.characterMemoryStatus = 1;
    while(  _regStat.bits.characterMemoryStatus ==1)
    {
        SPI.transfer(STAT_ADDRESS_READ);
        _regStat.whole = SPI.transfer(0x00);
    }


    digitalWrite(_pinCS,HIGH);
}


//---------------------------------------------------------------------- 
-------
// Implements Max7456::getCharacter
//---------------------------------------------------------------------- 
-------
void Max7456::getCharacter(charact chara, byte x, byte y)
{
    byte charAddress;


    if(y<=0)
        charAddress = x;
    else
        charAddress = x + y*16;

    activateOSD(false);
    //datasheet p38
    digitalWrite(_pinCS,LOW);


    SPI.transfer(CMAH_ADDRESS_WRITE);
    SPI.transfer(charAddress);

    _regCmm = 0x50; //To read from the NVM array
    SPI.transfer(CMM_ADDRESS_WRITE);
    SPI.transfer(_regCmm);


    for(byte i = 0 ; i < 54 ; i++)
    {
        SPI.transfer(CMAL_ADDRESS_WRITE);
        SPI.transfer(i);

        SPI.transfer(CMDO_ADDRESS_READ); //read from device through spi
        chara[i] = SPI.transfer(0x00);
    }

    digitalWrite(_pinCS,HIGH);

}
//---------------------------------------------------------------------- 
-------
// Implements Max7456::printCharacterToSerial
//---------------------------------------------------------------------- 
-------
void Max7456::printCharacterToSerial(const charact array, bool img)
{

    if(img)
    {
        CARACT car ;
        car = Max7456::byteArray2CARACT(array);

        Serial.println("------------");
        for(int i = 0 ; i < 18 ; i++)
        {
            for(int j = 0 ; j < 3 ; j++)
            {
                printPixel(car.line[i].pixels[j].pix0);
                printPixel(car.line[i].pixels[j].pix1);
                printPixel(car.line[i].pixels[j].pix2);
                printPixel(car.line[i].pixels[j].pix3);
            }

            Serial.println("");
        }
        Serial.println("------------");
    }

    else
    {
        Serial.print("{");
        for(unsigned int i = 0 ; i < 53 ; i++)
        {
            Serial.print("0x");
            Serial.print(String(array[i],HEX));
            Serial.print(", ");
        }
        Serial.print("0x");
        Serial.print(String(array[53],HEX));
        Serial.println("};");
    }
}

void Max7456::printPixel(byte value)
{
    switch(value )
    {
        case COLOR_BLACK :
            Serial.print("#");
            return;
        case COLOR_WHITE :
            Serial.print("*");
            return;
        default:
            Serial.print(" ");
            return;
    }
}


//---------------------------------------------------------------------- 
-------
// Implements Max7456::print
//---------------------------------------------------------------------- 
-------
void Max7456::print(const char string[], byte x, byte y, byte blink,byte 
inv)
{
    char          currentChar;
    byte          size;
    byte *chars = NULL;

    if(!string) return;

    size = 0;
    currentChar = string[0];

    while(currentChar != '\0')
    {
        currentChar = string[++size];
    }

    chars = (byte*) malloc(size * sizeof(byte));

    for(byte i = 0 ; i < size ; i++)
    {
        chars[i] = Max7456::giveMax7456CharFromAsciiChar(string[i]);
    }

    printMax7456Chars(chars, size, x,  y,  blink , inv );
    free(chars);
}


void Max7456::printMax7456Char(const byte address, byte x, byte y, byte 
blink, byte inv)
{
    byte ad = address;
    printMax7456Chars(&ad,1,x,y,blink,inv);
}

//---------------------------------------------------------------------- 
-------
// Implements Max7456::printMax7456Chars
//---------------------------------------------------------------------- 
-------
void Max7456::printMax7456Chars(byte chars[],byte size,byte x, byte y, 
byte blink ,byte inv )
{
    byte          currentCharMax7456;
    byte          posAddressLO;
    byte          posAddressHI;
    unsigned int  posAddress;

    posAddress = 30*y+x;

    posAddressHI = posAddress >> 8;
    posAddressLO = posAddress;

    _regDmm.whole = 0x01;

    _regDmm.bits.INV = inv;
    _regDmm.bits.BLK = blink;

    digitalWrite(_pinCS,LOW);
    SPI.transfer(DMM_ADDRESS_WRITE);



    SPI.transfer(_regDmm.whole);


    SPI.transfer(DMAH_ADDRESS_WRITE); // set start address high
    SPI.transfer(posAddressHI);

    SPI.transfer(DMAL_ADDRESS_WRITE); // set start address low
    SPI.transfer(posAddressLO);


    for(int i = 0; i < size ; i++)
    {
        currentCharMax7456 = chars[i];
        SPI.transfer(DMDI_ADDRESS_WRITE);
        SPI.transfer(currentCharMax7456);

    }

    //end character (we're done).
    SPI.transfer(DMDI_ADDRESS_WRITE);
    SPI.transfer(0xff);

    /*
     _regVm0.bits.
     SPI.transfer(VM0_ADDRESS_WRITE);
     SPI.transfer(0x4c);*/


    digitalWrite(_pinCS,HIGH);
}


//---------------------------------------------------------------------- 
-------
// Implements Max7456::print
//---------------------------------------------------------------------- 
-------

void Max7456::print(double value, byte x, byte y, byte before, byte 
after, byte blink,byte inv)
{
    char *strValue = NULL;

    strValue = (char*) malloc((before+after+2)* sizeof(char));


    if(after==0)
        dtostrf(value,before+after,after,strValue);
    else
        dtostrf(value,before+after+1,after,strValue);

    for(int i = 0 ; i < before+after+1;i++)
    {
        if(strValue[i] == ' ' || strValue[i] == '-')
            strValue[i]='0';
    }
    if(value < 0)
        strValue[0]='-';
    if(after==0) //If the result is bigger, we truncate it so the OSD 
won't be falsed.
        strValue[before]='\0';
    else
        strValue[before+after+1]='\0';

    print(strValue,x,y,blink,inv);

    free(strValue);
}


//---------------------------------------------------------------------- 
-------
// Implements Max7456::giveMax7456CharFromAsciiChar
//---------------------------------------------------------------------- 
-------
byte Max7456::giveMax7456CharFromAsciiChar(char ascii)
{
#ifdef MAX7456_TABLE_ASCII
    if(ascii >= ' ' && ascii <= 'z')
        return ascii-' ';
    else
        return ascii;
#else
    return ascii;
#endif
}


//---------------------------------------------------------------------- 
-------
// Implements Max7456::clearScreen
//---------------------------------------------------------------------- 
-------
void Max7456::clearScreen()
{
    _regDmm.bits.clearDisplayMemory = 1 ;

    digitalWrite(_pinCS, LOW);

    SPI.transfer(DMM_ADDRESS_WRITE);
    SPI.transfer(_regDmm.whole);

    //wait for operation to be complete.
    while(_regDmm.bits.clearDisplayMemory == 1 )
    {
        SPI.transfer(DMM_ADDRESS_READ);
        _regDmm.whole = SPI.transfer(0x00);
    }
    digitalWrite(_pinCS, HIGH); //disable device
}


//---------------------------------------------------------------------- 
-------
// Implements Max7456::init
//---------------------------------------------------------------------- 
-------
void Max7456::init(uint8_t iPinCS)
{
    _pinCS = iPinCS;
    _isActivatedOsd = false;

    _regVm1.whole = 0b01000111;
    pinMode(iPinCS, OUTPUT);
    digitalWrite(iPinCS, HIGH); //disable device
    delay(100); //power up time

    digitalWrite(_pinCS,LOW);
    SPI.transfer(VM0_ADDRESS_WRITE);

    _regVm0.whole = 0x00;
    _regVm0.bits.videoSelect=1; //PAL
    _regVm0.bits.softwareResetBit = 1;
    SPI.transfer(_regVm0.whole);
    digitalWrite(_pinCS,HIGH);
    delay(500);


    digitalWrite(_pinCS,LOW);
    for(int x = 0 ; x < 16 ; x++)
    {
        _regRb[x].whole = 0x00;
        _regRb[x].bits.characterWhiteLevel = 2;
        SPI.transfer(x+RB0_ADDRESS_WRITE);
        SPI.transfer(_regRb[x].whole);
    }

    _regVm0.whole = 0x00;

    _regVm0.bits.verticalSynch = 1;

    SPI.transfer(VM0_ADDRESS_WRITE);

    SPI.transfer(_regVm0.whole);


    //  digitalWrite(_pinCS,HIGH);
    //
    //  digitalWrite(_pinCS,LOW);
    //SPI.transfer(VM1_ADDRESS_WRITE);
    //SPI.transfer(0x0C);

    digitalWrite(_pinCS,HIGH);

}


//---------------------------------------------------------------------- 
-------
// Implements Max7456::activateOSD
//---------------------------------------------------------------------- 
-------
void Max7456::activateOSD(bool act)
{
    if(_isActivatedOsd != act)
    {

        _regVm0.bits.videoSelect = 1;
        if(act)
            _regVm0.bits.enableOSD = 1;
        else
            _regVm0.bits.enableOSD = 0;

        digitalWrite(_pinCS,LOW);
        SPI.transfer(VM0_ADDRESS_WRITE);
        SPI.transfer(_regVm0.whole);
        digitalWrite(_pinCS,HIGH);
        _isActivatedOsd = act;
    }
}


//---------------------------------------------------------------------- 
-------
// Implements Max7456::activateExternalVideo
//---------------------------------------------------------------------- 
-------
void Max7456::activateExternalVideo(bool activExtVid)
{
    if(!activExtVid)
        _regVm0.bits.synchSelect = 3; //11
    else
        _regVm0.bits.synchSelect = 0; //0

    digitalWrite(_pinCS,LOW);
    SPI.transfer(VM0_ADDRESS_WRITE);
    SPI.transfer(_regVm0.whole);
    digitalWrite(_pinCS,HIGH);
}


//---------------------------------------------------------------------- 
-------
// Implements Max7456::CARACT2ByteArray
//---------------------------------------------------------------------- 
-------
byte* Max7456::CARACT2ByteArray(const CARACT car)
{
    byte *array = NULL;
    array = new charact;
    for(int i = 0 ; i < 54 ; i++)
        array[i]= car.whole[i];

    return array;
}


//---------------------------------------------------------------------- 
-------
// Implements Max7456::byteArray2CARACT
//---------------------------------------------------------------------- 
-------
CARACT Max7456::byteArray2CARACT(const charact array)
{
    CARACT car;
    for(int i = 0 ; i < 54 ; i++)
        car.whole[i] = array[i];

    return car;
}


//---------------------------------------------------------------------- 
-------
// Implements Max7456::getCARACFromProgMem
//---------------------------------------------------------------------- 
-------
void Max7456::getCARACFromProgMem(const char *table, byte i, charact 
car)
{
    unsigned long index;
    byte read;
    index = i*54;
    for(unsigned long j = 0 ; j < 54 ; j++)
    {
        read = pgm_read_byte_near(table +index+j );
        car[j] = read;
        if (car[j] == 0x55)
            car[j] = 0xff;
    }
}

Autor: Hannes (Gast)
Datum:

Bewertung
-1 lesenswert
nicht lesenswert
Kann mir mein Problem keiner erklären ?

Autor: Rufus Τ. Firefly (rufus) (Moderator) Benutzerseite
Datum:

Bewertung
1 lesenswert
nicht lesenswert
Welchen Teil von

    Längeren Sourcecode nicht im Text einfügen, sondern als Dateianhang


hast Du jetzt eigentlich nicht verstanden?


Dein Problem ist, daß der Compiler zwar wahrscheinlich Deine *.cpp-Datei 
übersetzt, dem Linker aber das Ergebnis nicht vorgeworfen wird. Sieh Dir 
Deine Projektverwaltung an, sieh Dir Dein Makefile an.

Autor: Hannes (Gast)
Datum:

Bewertung
0 lesenswert
nicht lesenswert
Ich gehöre zu den blutigen Anfängern dh. ist das gerade nicht so
Ich benutze Xavr (Xcode) dies erstellt das Makefile selbst ->

# Hey Emacs, this is a -*- makefile -*-
#----------------------------------------------------------------------------
# WinAVR Makefile Template written by Eric B. Weddington, Jörg Wunsch, et al.
#
# Released to the Public Domain
#
# Additional material for this makefile was written by:
# Peter Fleury
# Tim Henigan
# Colin O'Flynn
# Reiner Patommel
# Markus Pfaff
# Sander Pool
# Frederik Rouleau
#
#----------------------------------------------------------------------------
# On command line:
#
# make all = Make software.
#
# make clean = Clean out built project files.
#
# make coff = Convert ELF to AVR COFF.
#
# make extcoff = Convert ELF to AVR Extended COFF.
#
# make program = Download the hex file to the device, using avrdude.
#                Please customize the avrdude settings below first!
#
# make debug = Start either simulavr or avarice as specified for debugging, 
#              with avr-gdb or avr-insight as the front end for debugging.
#
# make filename.s = Just compile filename.c into the assembler code only.
#
# make filename.i = Create a preprocessed source file for use in submitting
#                   bug reports to the GCC project.
#
# To rebuild project do "make clean" then "make all".
#----------------------------------------------------------------------------

#include conf.mk
# MCU name
MCU = atmega328p


# Processor frequency.
#     This will define a symbol, F_CPU, in all source code files equal to the 
#     processor frequency. You can then use this symbol in your source code to 
#     calculate timings. Do NOT tack on a 'UL' at the end, this will be done
#     automatically to create a 32-bit value in your source code.
F_CPU = 8000000

AVRDUDE_PROGRAMMER = stk500

# com1 = serial port. Use lpt1 to connect to parallel port.
AVRDUDE_PORT = /dev/cu.usbmodem*    # programmer connected to serial device

# Output format. (can be srec, ihex, binary)
FORMAT = ihex


# Target file name (without extension).
TARGET = main


# List C source files here. (C dependencies are automatically generated.)

SRC = $(wildcard *.cpp)

OBJDIR = Builds
# List Assembler source files here.
#     Make them always end in a capital .S.  Files ending in a lowercase .s
#     will not be considered source files but generated files (assembler
#     output from the compiler), and will be deleted upon "make clean"!
#     Even though the DOS/Win* filesystem matches both .s and .S the same,
#     it will preserve the spelling of the filenames, and gcc itself does
#     care about how the name is spelled on its command-line.
ASRC = $(wildcard *.S)


# Optimization level, can be [0, 1, 2, 3, s]. 
#     0 = turn off optimization. s = optimize for size.
#     (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
OPT = s


# Debugging format.
#     Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.
#     AVR Studio 4.10 requires dwarf-2.
#     AVR [Extended] COFF format requires stabs, plus an avr-objcopy run.
DEBUG = stabs


# List any extra directories to look for include files here.
#     Each directory must be seperated by a space.
#     Use forward slashes for directory separators.
#     For a directory that has spaces, enclose it in quotes.
EXTRAINCDIRS = 


# Compiler flag to set the C Standard level.
#     c89   = "ANSI" C
#     gnu89 = c89 plus GCC extensions
#     c99   = ISO C99 standard (not yet fully implemented)
#     gnu99 = c99 plus GCC extensions
CSTANDARD = -std=gnu99


# Place -D or -U options here
CDEFS = -DF_CPU=$(F_CPU)UL


# Place -I options here
CINCS =



#---------------- Compiler Options ----------------
#  -g*:          generate debugging information
#  -O*:          optimization level
#  -f...:        tuning, see GCC manual and avr-libc documentation
#  -Wall...:     warning level
#  -Wa,...:      tell GCC to pass this to the assembler.
#    -adhlns...: create assembler listing
CFLAGS = -g$(DEBUG)
CFLAGS += $(CDEFS) $(CINCS)
CFLAGS += -O$(OPT)
CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
CFLAGS += -Wall -Wstrict-prototypes
CFLAGS += -Wa,-adhlns=$(addprefix $(OBJDIR)/,$(<:.cpp=.lst))
CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
CFLAGS += $(CSTANDARD)
CFLAGS += -gstabs
CFLAGS += -gstrict-dwarf

#---------------- Assembler Options ----------------
#  -Wa,...:   tell GCC to pass this to the assembler.
#  -ahlms:    create listing
#  -gstabs:   have the assembler create line number information; note that
#             for use in COFF files, additional information about filenames
#             and function names needs to be present in the assembler source
#             files -- see avr-libc docs [FIXME: not yet described there]
#  -listing-cont-lines: Sets the maximum number of continuation lines of hex 
#       dump that will be displayed for a given single line of source input.
ASFLAGS = -Wa,-adhlns=$(addprefix $(OBJDIR)/,$(<:.S=.lst)),-gstabs,--listing-cont-lines=100


#---------------- Library Options ----------------
# Minimalistic printf version
PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min

# Floating point printf version (requires MATH_LIB = -lm below)
PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt

# If this is left blank, then it will use the Standard printf version.
PRINTF_LIB = 
#PRINTF_LIB = $(PRINTF_LIB_MIN)
#PRINTF_LIB = $(PRINTF_LIB_FLOAT)


# Minimalistic scanf version
SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min

# Floating point + %[ scanf version (requires MATH_LIB = -lm below)
SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt

# If this is left blank, then it will use the Standard scanf version.
SCANF_LIB = 
#SCANF_LIB = $(SCANF_LIB_MIN)
#SCANF_LIB = $(SCANF_LIB_FLOAT)


MATH_LIB = -lm



#---------------- External Memory Options ----------------

# 64 KB of external RAM, starting after internal RAM (ATmega128!),
# used for variables (.data/.bss) and heap (malloc()).
#EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff

# 64 KB of external RAM, starting after internal RAM (ATmega128!),
# only used for heap (malloc()).
#EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff

EXTMEMOPTS =



#---------------- Linker Options ----------------
#  -Wl,...:     tell GCC to pass this to linker.
#    -Map:      create map file
#    --cref:    add cross reference to  map file
LDFLAGS = -Wl,-Map=$(OBJDIR)/$(TARGET).map,--cref 
LDFLAGS += $(EXTMEMOPTS)
LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)



#---------------- Programming Options (avrdude) ----------------

# Programming hardware: alf avr910 avrisp bascom bsd 
# dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
#
# Type: avrdude -c ?
# to get a full listing.
#

AVRDUDE_WRITE_FLASH = -U flash:w:$(OBJDIR)/$(TARGET).hex
#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep


# Uncomment the following if you want avrdude's erase cycle counter.
# Note that this counter needs to be initialized first using -Yn,
# see avrdude manual.
#AVRDUDE_ERASE_COUNTER = -y

# Uncomment the following if you do /not/ wish a verification to be
# performed after programming the device.
#AVRDUDE_NO_VERIFY = -V

# Increase verbosity level.  Please use this when submitting bug
# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude> 
# to submit bug reports.
#AVRDUDE_VERBOSE = -v -v

AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)



#---------------- Debugging Options ----------------

# For simulavr only - target MCU frequency.
DEBUG_MFREQ = $(F_CPU)

# Set the DEBUG_UI to either gdb or insight.
# DEBUG_UI = gdb
DEBUG_UI = insight

# Set the debugging back-end to either avarice, simulavr.
DEBUG_BACKEND = avarice
#DEBUG_BACKEND = simulavr

# GDB Init Filename.
GDBINIT_FILE = __avr_gdbinit

# When using avarice settings for the JTAG
JTAG_DEV = /dev/com1

# Debugging port used to communicate between GDB / avarice / simulavr.
DEBUG_PORT = 4242

# Debugging host used to communicate between GDB / avarice / simulavr, normally
#     just set to localhost unless doing some sort of crazy debugging when 
#     avarice is running on a different computer.
DEBUG_HOST = localhost



#============================================================================


# Define programs and commands.
SHELL = sh
CC = /usr/local/CrossPack-AVR/bin/avr-gcc
OBJCOPY = /usr/local/CrossPack-AVR/bin/avr-objcopy
OBJDUMP = /usr/local/CrossPack-AVR/bin/avr-objdump
SIZE = /usr/local/CrossPack-AVR/bin/avr-size
NM = /usr/local/CrossPack-AVR/bin/avr-nm
AVRDUDE = /usr/local/CrossPack-AVR/bin/avrdude
REMOVE = rm -f
COPY = cp
WINSHELL = cmd


# Define Messages
# English
MSG_ERRORS_NONE = Errors: none
MSG_BEGIN = -------- begin --------
MSG_END = --------  end  --------
MSG_SIZE_BEFORE = Size before: 
MSG_SIZE_AFTER = Size after:
MSG_COFF = Converting to AVR COFF:
MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
MSG_FLASH = Creating load file for Flash:
MSG_EEPROM = Creating load file for EEPROM:
MSG_EXTENDED_LISTING = Creating Extended Listing:
MSG_SYMBOL_TABLE = Creating Symbol Table:
MSG_LINKING = Linking:
MSG_COMPILING = Compiling:
MSG_ASSEMBLING = Assembling:
MSG_CLEANING = Cleaning project:




# Define all object files.
OBJ = $(addprefix $(OBJDIR)/,$(SRC:.cpp=.o)) $(addprefix $(OBJDIR)/,$(ASRC:.S=.o))

# Define all listing files.
LST = $(addprefix $(OBJDIR)/,$(SRC:.cpp=.lst)) $(addprefix $(OBJDIR)/,$(ASRC:.S=.lst))


# Compiler flags to generate dependency files.
GENDEPFLAGS = -M


# Combine all necessary flags and optional flags.
# Add target processor to flags.
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS)
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)


# Generate dependency files
DEPSDIR   = $(OBJDIR)/.dep
DEPS      = $(SRC:%.cpp=$(DEPSDIR)/%.d)

-include $(DEPS)

$(DEPSDIR):
  mkdir -p $(DEPSDIR)

.DELETE_ON_ERROR:
$(DEPSDIR)/%.d: %.cpp | $(DEPSDIR)
  $(CC) $(ALL_ASFLAGS) $(GENDEPFLAGS) -MT $(patsubst %.cpp,$(OBJDIR)/%.o,$<) -MF $@ $<


# Default target.
all: begin gccversion sizebefore clean build program sizeafter end

build: $(OBJDIR) elf hex eep lss sym

elf: $(OBJDIR)/$(TARGET).elf
hex: $(OBJDIR)/$(TARGET).hex
eep: $(OBJDIR)/$(TARGET).eep
lss: $(OBJDIR)/$(TARGET).lss 
sym: $(OBJDIR)/$(TARGET).sym

$(OBJDIR):
  @mkdir -p $@

# Eye candy.
# AVR Studio 3.x does not check make's exit code but relies on
# the following magic strings to be generated by the compile job.
begin:
  @echo
  @echo $(MSG_BEGIN)

end:
  @echo $(MSG_END)
  @echo


# Display size of file.
HEXSIZE = $(SIZE) --target=$(FORMAT) $(OBJDIR)/$(TARGET).hex
ELFSIZE = $(SIZE) --format=avr $(OBJDIR)/$(TARGET).elf

sizebefore:
  @if test -f $(OBJDIR)/$(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
  2>/dev/null; echo; fi

sizeafter:
  @if test -f $(OBJDIR)/$(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
  2>/dev/null; echo; fi



# Display compiler version information.
gccversion : 
  @$(CC) --version



# Program the device.  
program: $(OBJDIR)/$(TARGET).hex $(OBJDIR)/$(TARGET).eep
  $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)

# Generate avr-gdb config/init file which does the following:
#     define the reset signal, load the target file, connect to target, and set 
#     a breakpoint at main().
gdb-config: 
  @$(REMOVE) $(GDBINIT_FILE)
  @echo define reset >> $(GDBINIT_FILE)
  @echo SIGNAL SIGHUP >> $(GDBINIT_FILE)
  @echo end >> $(GDBINIT_FILE)
  @echo file $(OBJDIR)/$(TARGET).elf >> $(GDBINIT_FILE)
  @echo target remote $(DEBUG_HOST):$(DEBUG_PORT)  >> $(GDBINIT_FILE)
ifeq ($(DEBUG_BACKEND),simulavr)
  @echo load  >> $(GDBINIT_FILE)
endif  
  @echo break main >> $(GDBINIT_FILE)

debug: gdb-config $(OBJDIR)/$(TARGET).elf
ifeq ($(DEBUG_BACKEND), avarice)
  @echo Starting AVaRICE - Press enter when "waiting to connect" message displays.
  @$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \
  $(OBJDIR)/$(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT)
  @$(WINSHELL) /c pause
else
  @$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \
  $(DEBUG_MFREQ) --port $(DEBUG_PORT)
endif
  @$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE)



# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
COFFCONVERT=$(OBJCOPY) --debugging \
--change-section-address .data-0x800000 \
--change-section-address .bss-0x800000 \
--change-section-address .noinit-0x800000 \
--change-section-address .eeprom-0x810000 


coff: $(OBJDIR)/$(TARGET).elf
  @echo
  @echo $(MSG_COFF) $(OBJDIR)/$(TARGET).cof
  $(COFFCONVERT) -O coff-avr $< $(OBJDIR)/$(TARGET).cof


extcoff: $(OBJDIR)/$(TARGET).elf
  @echo
  @echo $(MSG_EXTENDED_COFF) $(OBJDIR)/$(TARGET).cof
  $(COFFCONVERT) -O coff-ext-avr $< $(OBJDIR)/$(TARGET).cof



# Create final output files (.hex, .eep) from ELF output file.
$(OBJDIR)/%.hex: $(OBJDIR)/%.elf
  @echo
  @echo $(MSG_FLASH) $@
  $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@

$(OBJDIR)/%.eep: $(OBJDIR)/%.elf
  @echo
  @echo $(MSG_EEPROM) $@
  -$(OBJCOPY) -j .eeprom --set-section-flags .eeprom=alloc,load \
  --change-section-lma .eeprom=0 -O $(FORMAT) $< $@

# Create extended listing file from ELF output file.
$(OBJDIR)/%.lss: $(OBJDIR)/%.elf
  @echo
  @echo $(MSG_EXTENDED_LISTING) $@
  $(OBJDUMP) -h -S $< > $@

# Create a symbol table from ELF output file.
$(OBJDIR)/%.sym: $(OBJDIR)/%.elf
  @echo
  @echo $(MSG_SYMBOL_TABLE) $@
  $(NM) -n $< > $@



# Link: create ELF output file from object files.
.SECONDARY : $(OBJDIR)/$(TARGET).elf
.PRECIOUS : $(OBJ)
$(OBJDIR)/%.elf: $(OBJ)
  @echo
  @echo $(MSG_LINKING) $@
  $(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)


# Compile: create object files from C source files.
$(OBJDIR)/%.o : %.cpp
  @echo
  @echo $(MSG_COMPILING) $<
  $(CC) -c $(ALL_CFLAGS) "$(abspath $<)" -o $@ 


# Compile: create assembler files from C source files.
$(OBJDIR)/%.s : %.cpp
  $(CC) -S $(ALL_CFLAGS) $< -o $@


# Assemble: create object files from assembler source files.
$(OBJDIR)/%.o : %.S
  @echo
  @echo $(MSG_ASSEMBLING) $<
  $(CC) -c $(ALL_ASFLAGS) $< -o $@

# Create preprocessed source for use in sending a bug report.
$(OBJDIR)/%.i : %.cpp
  $(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@ 


# Target: clean project.
clean: begin clean_list end

clean_list :
  @echo
  @echo $(MSG_CLEANING)
  $(REMOVE) $(OBJDIR)/$(TARGET).hex
  $(REMOVE) $(OBJDIR)/$(TARGET).eep
  $(REMOVE) $(OBJDIR)/$(TARGET).cof
  $(REMOVE) $(OBJDIR)/$(TARGET).elf
  $(REMOVE) $(OBJDIR)/$(TARGET).map
  $(REMOVE) $(OBJDIR)/$(TARGET).sym
  $(REMOVE) $(OBJDIR)/$(TARGET).lss
  $(REMOVE) $(OBJ)
  $(REMOVE) $(LST)
  $(REMOVE) $(OBJDIR)/$(SRC:.cpp=.s)
  $(REMOVE) $(OBJDIR)/$(SRC:.cpp=.d)
  $(REMOVE) $(OBJDIR)/.dep/*


# Listing of phony targets.
.PHONY : all begin finish end sizebefore sizeafter gccversion \
build elf hex eep lss sym coff extcoff \
clean clean_list program debug gdb-config



Autor: Hannes (Gast)
Datum:

Bewertung
0 lesenswert
nicht lesenswert
Ich würde jetzt sagen, dieses Makefile kann ich vergessen. Denn ich will 
C und C++ files Compilern und linken.

Gibt es dazu Abhilfe ?

Autor: Oliver S. (oliverso)
Datum:

Bewertung
0 lesenswert
nicht lesenswert
Ich sach mal:

C++ Buch besorgen
"hello world" ans laufen bekommen
Google bemühen, und nachlesen, was man für C++ auf dem AVR alles tun muß
Alternativ, da mir XCode nichts sagt: RTFM

Vor dem laufen kommt das gehen. Und davor erstmal freihändig auf beiden 
Beinen stehen..

Oliver

Rufus Τ. F. schrieb:
> Welchen Teil von
>
>     Längeren Sourcecode nicht im Text einfügen, sondern als Dateianhang
>
> hast Du jetzt eigentlich nicht verstanden?

Das gilt für alles, auch für makefile. Im Text liest das keiner...

Oliver

Antwort schreiben

Die Angabe einer E-Mail-Adresse ist freiwillig. Wenn Sie automatisch per E-Mail über Antworten auf Ihren Beitrag informiert werden möchten, melden Sie sich bitte an.

Wichtige Regeln - erst lesen, dann posten!

  • Groß- und Kleinschreibung verwenden
  • Längeren Sourcecode nicht im Text einfügen, sondern als Dateianhang

Formatierung (mehr Informationen...)

  • [c]C-Code[/c]
  • [avrasm]AVR-Assembler-Code[/avrasm]
  • [code]Code in anderen Sprachen, ASCII-Zeichnungen[/code]
  • [math]Formel in LaTeX-Syntax[/math]
  • [[Titel]] - Link zu Artikel
  • Verweis auf anderen Beitrag einfügen: Rechtsklick auf Beitragstitel,
    "Adresse kopieren", und in den Text einfügen




Bild automatisch verkleinern, falls nötig
Bitte das JPG-Format nur für Fotos und Scans verwenden!
Zeichnungen und Screenshots im PNG- oder
GIF-Format hochladen. Siehe Bildformate.
Hinweis: der ursprüngliche Beitrag ist mehr als 6 Monate alt.
Bitte hier nur auf die ursprüngliche Frage antworten,
für neue Fragen einen neuen Beitrag erstellen.

Mit dem Abschicken bestätigst du, die Nutzungsbedingungen anzuerkennen.