NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Microcontroller Programming » trying to understand MAKE

December 02, 2010
by Gregg
Gregg's Avatar

Just programmed my first project in the nerdkit. I think I am beginning to understand the process, but I am a little stumped on the MAKE FILE. DO I have to create a new MAKEFILE for each program? Where can I get more info on this? Any help would be great! Thanks

December 03, 2010
by nanaeem
nanaeem's Avatar

Hi Gregg,

I am guessing that you already downloaded the Nerdkits guide from the download section. Pages 68-69 have a surprisingly simple explanation of the Makefile. I would suggest starting there.

There is no compulsion to use a Makefile to compile and load your program onto the chip. That said, it is highly recommended. There is a sequence of programs that must be executed to convert you C files into a format that the chip understands followed by loading the chip with the newly compiled program. Without make you would have to execute these programs by writing their run commands directly on the terminal. If nothing else this is time consuming.

Creating one Makefile at the start of a new project is therefore highly recommended.

make is very popular among developers. Simply trying a google search of "Makefile tutorial" will give you a wealth of information. I still strongly suggest starting with the Nerdkits guide explanation. I myself am quite new to microcontoller programming. My first source of information is always the Nerdkits guide, then this forum and then google. In my experience, the Nerdkits guide always gives the most simplified and easy to understand explanation of things. This forum is brilliant too.

-N.

December 03, 2010
by Ralphxyz
Ralphxyz's Avatar

Here is a neat trick to use when making up Makefiles:

# tempsensor 168
GCCFLAGS=-g -Os -Wall -mmcu=atmega168 
LINKFLAGS=-Wl,-u,vfprintf -lprintf_flt -Wl,-u,vfscanf -lscanf_flt -lm
AVRDUDEFLAGS=-c avr109 -p m168 -F -b 115200 -P /dev/cu.PL2303-0000101D

ProjectName = tempsensor

LINKOBJECTS=../libnerdkits/delay.o ../libnerdkits/lcd.o ../libnerdkits/uart.o

all:    ProjectName-upload

ProjectName.hex:    ProjectName.c
    make -C ../libnerdkits
    avr-gcc ${GCCFLAGS} ${LINKFLAGS} -o ProjectName.o ProjectName.c ${LINKOBJECTS}
    avr-objcopy -j .text -O ihex ProjectName.o ProjectName.hex

ProjectName.ass:    ProjectName.hex
    avr-objdump -S -d ProjectName.o > ProjectName.ass

ProjectName-upload: ProjectName.hex
    avrdude ${AVRDUDEFLAGS} -U flash:w:ProjectName.hex:a

Just change the ProjectName to the name of your C code project file (Line 6).

Now you can reuse this Makefile in any of your projects just by changing the ProjectName = ??????????.

You can use XyZ instead of ProjectName of course.

This tip is curtesy of the forum, I can not remember who originated it.

Ralph

December 03, 2010
by bretm
bretm's Avatar

You need to use $(ProjectName) to make it do the name replacement of the ProjectName macro.

December 03, 2010
by Ralphxyz
Ralphxyz's Avatar

I was just coming back to do that.

# tempsensor 168
GCCFLAGS=-g -Os -Wall -mmcu=atmega168 
LINKFLAGS=-Wl,-u,vfprintf -lprintf_flt -Wl,-u,vfscanf -lscanf_flt -lm
AVRDUDEFLAGS=-c avr109 -p m168 -F -b 115200 -P /dev/cu.PL2303-0000101D
//AVRDUDEFLAGS=-c avr109 -p m168 -F -b 115200 -P /dev/cu.PL2303-0000205D

ProjectName = tempsensor

LINKOBJECTS=../libnerdkits/delay.o ../libnerdkits/lcd.o ../libnerdkits/uart.o

all:    $(ProjectName)-upload

$(ProjectName).hex: $(ProjectName).c
    make -C ../libnerdkits
    avr-gcc ${GCCFLAGS} ${LINKFLAGS} -o $(ProjectName).o $(ProjectName).c ${LINKOBJECTS}
    avr-objcopy -j .text -O ihex $(ProjectName).o $(ProjectName).hex

$(ProjectName).ass: $(ProjectName).hex
    avr-objdump -S -d $(ProjectName).o > $(ProjectName).ass

$(ProjectName)-upload:  $(ProjectName).hex
    avrdude ${AVRDUDEFLAGS} -U flash:w:(ProjectName).hex:a

Ralph

December 05, 2010
by Gregg
Gregg's Avatar

Wow! Tons of help guys! I was pretty much thinking I could use one make file by changing the target name. Not compleatly sure about the instructions for The replace macro, but, I think I can figure that out. Thanks again. Gregg

Post a Reply

Please log in to post a reply.

Did you know that multiple MOSFETs can be used in parallel to switch bigger currents on and off? Learn more...