Me? I'm using WinAVR without any special adjustments.
It looks like this:
###############################################################################
# Makefile for the project test
###############################################################################
## General Flags
PROJECT = test
MCU = atmega48
TARGET = test.elf
CC = avr-gcc.exe
## Options common to compile, link and assembly rules
COMMON = -mmcu=$(MCU)
## Compile options common for all C compilation units.
CFLAGS = $(COMMON)
CFLAGS += -Wall -gdwarf-2 -Os -std=gnu99 -funsigned-char
-funsigned-bitfields -fpack-struct -fshort-enums
CFLAGS += -MD -MP -MT $(*F).o -MF dep/$(@F).d
## Assembly specific flags
ASMFLAGS = $(COMMON)
ASMFLAGS += $(CFLAGS)
ASMFLAGS += -x assembler-with-cpp -Wa,-gdwarf2
## Linker flags
LDFLAGS = $(COMMON)
LDFLAGS += -Wl,-Map=test.map
## Intel Hex file production flags
HEX_FLASH_FLAGS = -R .eeprom
HEX_EEPROM_FLAGS = -j .eeprom
HEX_EEPROM_FLAGS += --set-section-flags=.eeprom="alloc,load"
HEX_EEPROM_FLAGS += --change-section-lma .eeprom=0 --no-change-warnings
## Objects that must be built in order to link
OBJECTS = test.o
## Objects explicitly added by the user
LINKONLYOBJECTS =
## Build
all: $(TARGET) test.hex test.eep test.lss size
## Compile
test.o: ../test.c
$(CC) $(INCLUDES) $(CFLAGS) -c $<
##Link
$(TARGET): $(OBJECTS)
$(CC) $(LDFLAGS) $(OBJECTS) $(LINKONLYOBJECTS) $(LIBDIRS) $(LIBS)
-o $(TARGET)
%.hex: $(TARGET)
avr-objcopy -O ihex $(HEX_FLASH_FLAGS) $< $@
%.eep: $(TARGET)
-avr-objcopy $(HEX_EEPROM_FLAGS) -O ihex $< $@ || exit 0
%.lss: $(TARGET)
avr-objdump -h -S $< > $@
size: ${TARGET}
@echo
@avr-size -C --mcu=${MCU} ${TARGET}
## Clean target
.PHONY: clean
clean:
-rm -rf $(OBJECTS) test.elf dep/* test.hex test.eep test.lss test.map
## Other dependencies
-include $(shell mkdir dep 2>/dev/null) $(wildcard dep/*)
Philipp
Can you post your makefile ?
Eric
----- Original Message ----- From: "Philipp Burch" <[EMAIL PROTECTED]>
To: <avr-gcc-list@nongnu.org>
Sent: Thursday, January 03, 2008 9:54 AM
Subject: Re: [avr-gcc-list] stumped: minor refactoring of simple
program causesit to fail
[EMAIL PROTECTED] wrote:
I've renewed my courage and tried again to make any progress
programming my ATmega48 with avr-gcc. I'm being very systematic this
time, taking small steps and testing after every little thing. This
has led me to something that has me completely baffled.
A very simple program that toggles all ports works fine. But when I
pull three lines out into a function, and call the function where those
three lines used to be, it no longer works. Here's the code that
works:
#include <avr/io.h>
#undef F_CPU
#define F_CPU 8000000UL /* 8MHz */
#include <util/delay.h>
void delay_ms(uint32_t time) {
uint32_t i;
for (i = 0; i < time; i++) {
_delay_ms(1);
}
}
int main() {
/* Set ports to outputs */
DDRB = 0xff;
DDRC = 0x7f; /* PORTC has only 7 pins */
DDRD = 0xff;
while (1) {
PORTB ^= 0xff;
PORTC ^= 0x7f;
PORTD ^= 0xff;
delay_ms( 3000 );
}
return 0;
}
This causes an LED attached to one of the output pins to change state
every three seconds, as expected. But the following version does not:
#include <avr/io.h>
#undef F_CPU
#define F_CPU 8000000UL /* 8MHz */
#include <util/delay.h>
void delay_ms(uint32_t time) {
uint32_t i;
for (i = 0; i < time; i++) {
_delay_ms(1);
}
}
void TogglePorts() {
PORTB ^= 0xff;
PORTC ^= 0x7f;
PORTD ^= 0xff;
}
int main() {
/* Set ports to outputs */
DDRB = 0xff;
DDRC = 0x7f; /* PORTC has only 7 pins */
DDRD = 0xff;
while (1) {
TogglePorts();
delay_ms( 3000 );
}
return 0;
}
With this code, the LED comes on and stays on, never blinking. What in
the name of Kernighan and Ritchie could be going on here? The two
versions should be functionally identical, except perhaps for the very
minor overhead of a function call in the second one. I can't think of
any conditions under which the second one should fail to blink the LED
-- unless it's a compiler bug, which is hard to believe.
Anybody have any idea?
Many thanks,
- Joe
--
Joe Strout
Inspiring Applications, Inc.
http://www.InspiringApps.com
_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list
Hello Joe,
have you ever analyzed the generated assembler code? I've just tried
the code exactly as you have posted it and both versions work fine
(The second one tested with every optimization level). What happens
if you replace
void TogglePorts() {
PORTB ^= 0xff;
PORTC ^= 0x7f;
PORTD ^= 0xff;
}
by
void TogglePorts() {
PINB = 0xff;
PINC = 0x7f;
PINC = 0xff;
}
?
Writing any value to the PINx registers should (on newer AVRs) toggle
the selected PORTx bits.
Philipp
_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list
_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list
_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list