It has been a few weeks since I felt like sitting down and working on a few of my projects. Tonight I decided to put in a little more work on trying to get text displayed on an OLED screen (DN2015-001). Imagine my frustration when I attempted to compile my code only to be presented with errors. Now my code will generate a few errors at the best of times due to the odd typo, but even after correcting these I was still having no luck. Time to Google the error message.
This time it seems I am not at fault. The search revealed that during my upgrade to Fedora 23 I gained a new version of avr-gcc (5.1.0). This version however appears to be broken and has been for a few months. So if I want to continue I have to downgrade to version 4.x. Not something I can be bothered to do when the clock is approaching midnight. I guess that's all I'm going to get done tonight.
I have been making use of the Arduino Makefile from ed.am for some time but recently I needed more functionality from the Makefile.
I ran across a case when needed to check the number of instructions/clock cycles that my C/C++ code was generating. To do this I needed to have a look at the assembly listing that was created. Reading just the assembly is tricky so adding in the C/C++ that creates it makes following it a little easier.
The instructions contained here detail the commands required to generate the debugging information and the flags for avr-objdump which allow the C++/ASM listing to be generated. Typing in all these commands takes time, hence why I am using a Makefile in the first place. What I needed was to add them to the existing ed.am Makefile.
It turns out that the easiest way to do this is not to modify the original Makefile. Instead I created a blank Makefile for my project and include the ed.am Makefile. Having done this I can overload and add to its contents.
This is what I came up with, using “make list” will generate a program listing interspersed with the source code.
# Include Arduino Makefile
# Arduino Makefile downloaded from:
# Override some of the included Makefile settings
# Add '-g' to compiler flag to embed debug info (doesn't end up in .hex)
CPPFLAGS += -g
# Locate avr-objdump on system
OBJDUMP := $(call findsoftware,avr-objdump)
# Create a listing of asm and C source code
@echo "Generating Listing"
$(OBJDUMP) -h -S $(TARGET).elf > $(TARGET).lst
# Override clean target to remove additonal files
rm -f $(OBJECTS)
rm -f $(TARGET).elf $(TARGET).hex $(ARDUINOLIB) *~
rm -rf .lib .dep
rm -f $(TARGET).map $(TARGET).lst