avr-chat
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-chat] HowTo split a program into several files ?


From: David Kelly
Subject: Re: [avr-chat] HowTo split a program into several files ?
Date: Mon, 12 Sep 2005 21:14:22 -0500


On Sep 12, 2005, at 5:55 PM, Vincent Trouilliez wrote:

The Makefile I sent to you started life as one of Joerg's demo
Makefiles. The TWI demo IIRC.

Anyway, mine has some enhancements, yet its still simple. Just list your
.c files in the SRCS definition. Is currently one file per line. The
last character before newline is a backslash. Backslash escapes the
newline and continues the logical line to the next physical line.

David I love you !!! :o)

It worked ! I just added main.c and lcd.c in your file, selected my
ATmega32 chip at the top of the file, and... it complained that my chip
couldn't use the "-gdwarf-2" option.  Not having the slightest clue as
to what this options meant, I simply removed it, ran make again, and
after a few apparently harmless warnings, it eventually coughed a few
files !!! :-)

What I think it means is that you have an old version of avr-gcc. Or that dwarf-2 was not compiled into your avr-gcc. Its not a function of your ATmega32 vs my 64. Don't go jumping to 4.x just yet, stay with 3.4.x.

% avr-gcc --version
avr-gcc (GCC) 3.4.4
Copyright (C) 2004 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

The one called "object_flash.hex" caught my eye, tried downloading that
into the AVR using Avrdude and oh, magic, my program's running
perfectly !! :o)

IIRC Dwarf-2 is a debugging extension added to elf format. AVR Studio needs the Dwarf-2 stuff to properly source-code debug. I normally load the elf file but enhanced the Makefile to generate separate .hex files for flash and eeprom in order to use the Atmel ISP for the production line.

Only thing I miss is that your "list" file, although it does contain the
entire program (main and lcd) doesn't show the C statements.

I built my project just now without -gdwarf-2 and also did not get source interspersed with assembly in object.list. Upgrade/update your avr-gcc. With -gdwarf-2 the source and assembly appear together in the list file:

//
//      ee_writes( sram source, ee dest, count );
//
void
ee_writes(const void *cp, void *addr, uint16_t n)
{
    32a4:       fc 01           movw    r30, r24
        uint8_t sreg;           //  store SREG

        for( ; n ; n-- ) {
    32a6:       41 15           cp      r20, r1
    32a8:       51 05           cpc     r21, r1
32aa: b9 f0 breq .+46 ; 0x32da <ee_writes +0x36>
                wdt_reset();
    32ac:       a8 95           wdr
                while( EECR & (1<<EEWE) )       //  wait until ready
    32ae:       e1 99           sbic    0x1c, 1 ; 28
32b0: fe cf rjmp .-4 ; 0x32ae <ee_writes +0xa>
                        ;
...

Wow, what a day ! I learnt how to split my programs correctly using .c
and .h files, and I can also use Makefiles (and I already love them,
especially the "make clean" option ! :-), so convenient now I know it
does actually work ! ;-)

I think you'll learn to love "make depend" more than "make clean"  :-)

--
David Kelly N4HHE, address@hidden
========================================================================
Whom computers would destroy, they must first drive mad.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]