I'm encountering a strange error with avr-gcc 4.6.3 and 4.7.2 using the timer interrupt. The code I'm using is attached. As you can see, I was trying to tie in to the Arduino environment (with Eclipse) so that I could help my students wean off that set of functions to being able to use the hardware directly.
When I set up the library, I encountered a strange error and was able to trace it back to this simple program that sets up the timer with a prescalar of 1024 and then increments an unsigned long counter when that timer overflows. When the counter reaches a specific value, I toggle the built-in LED on the Arduino board connected to PORTB. The strange behavior is that if I initialize the counter to 0, the code doesn't work--appearing to hang. If I initialize the counter to 1, everything works perfectly. I have verified that if I make a similar change to the Arduino libraries that the original code begins to work properly. I'm not sure what the exact error is since I can use the Arduino environment on my machine without a problem, but when I try to compile it through Eclipse it gives me this error. I'll include the build log as an attachment in case particular compiler/linker flags are triggering the error. -- Jonathan Geisler --
/* * main.cpp * * Created on: Feb 8, 2013 * Author: Jonathan Geisler */ //#define JGG #ifdef JGG #include "Arduino.h" #else #include <avr/interrupt.h> #endif void setup() { #ifdef JGG pinMode(13, OUTPUT); #else TCCR0A = 0; TCCR0B = 5; TIMSK0 = 1; sei(); DDRB |= 0x20; #endif } volatile unsigned long count = 1; // bad executable if initialized to 0!!! void loop() { #ifdef JGG digitalWrite(13, HIGH); delay(1000); digitalWrite(13, LOW); delay(1000); #else if (count > 50) { PORTB ^= 0x20; count = 0; } #endif } #ifndef JGG ISR(TIMER0_OVF_vect) { ++count; } void init() { /* do nothing */ } #endif int main() { init(); #ifdef USBCON USBDevice.attach(); #endif setup(); while (1) { loop(); } }
make all Building file: ../main.cpp Invoking: AVR C++ Compiler avr-g++ -I"/home/jgeisler/src/eclipse/Arduino_Core/src" -DARDUINO=103 -Wall -Os -ffunction-sections -fdata-sections -fno-exceptions -mmcu=atmega328p -DF_CPU=16000000UL -MMD -MP -MF"main.d" -MT"main.d" -c -o "main.o" "../main.cpp" Finished building: ../main.cpp Building target: Arduino-on-Eclipse-1.elf Invoking: AVR C++ Linker avr-gcc -Wl,-Map,Arduino-on-Eclipse-1.map,--cref -Wl,--gc-sections -Os -L"/home/jgeisler/src/eclipse/Arduino_Core/328P_16MHz" -mmcu=atmega328p -o "Arduino-on-Eclipse-1.elf" ./main.o -lArduino_Core -lm Finished building target: Arduino-on-Eclipse-1.elf Invoking: AVR Create Extended Listing avr-objdump -h -S Arduino-on-Eclipse-1.elf >"Arduino-on-Eclipse-1.lss" Finished building: Arduino-on-Eclipse-1.lss Create Flash image (ihex format) avr-objcopy -R .eeprom -O ihex Arduino-on-Eclipse-1.elf "Arduino-on-Eclipse-1.hex" Finished building: Arduino-on-Eclipse-1.hex
signature.asc
Description: Digital signature
_______________________________________________ AVR-GCC-list mailing list AVR-GCC-list@nongnu.org https://lists.nongnu.org/mailman/listinfo/avr-gcc-list