For one part of ESTCube-1 satellite we need to compile big and changing project to our AVR ATmega. Just using AVR Studio doesn't fit because we have people with linux (me), windows and mac in our team. The other common way - using hand modified AVR Studio Makefile doesn't fit either because it is prone to errors and irritating when working with tens of files. Lets use build automation tools! First though was Makefiles. After half a week of studying about the cryptic ways of Makefiles it was clear that it is not the right way. So lets use something simple (simple usually means python) - Scons. It is a tool very similar to Makefiles. But instead of writing cryptic and non debuggable pseudo code we can use python! I worked on it for couple of days, finally taught myself Scons with really really simple example and then copied the structure to real project.
The base for the code comes from some weird german wiki.
#coding=utf8 env = Environment() mcu = 'atmega1280' if len(COMMAND_LINE_TARGETS): Target = COMMAND_LINE_TARGETS else: Target = '' # Optimization level, can be [0, 1, 2, 3, s]. opt = "2" env['CC'] = 'avr-gcc -mmcu='+mcu+' -O'+opt env.Append(CCFLAGS = "-Wall") env.Append(CPPPATH = 'EPS_Library') # Make elf env.Program(Target+'.elf', [Glob('Library/*/*.c'), 'Tests/'+Target+'.c']) # Make hex env.Command(Target+".hex", Target+".elf", 'avr-objcopy -j .text -j .data -O ihex $SOURCE $TARGET') # Show memory usage env.Command(None, Target+".hex", "avr-size $SOURCE") # Program the thing env.Command(None, Target+".hex", 'sudo avrdude -c dragon_jtag -P usb -p m1280 -u -U flash:w:$SOURCE')
To run it just write:
Where "Test0" is the name of the target file in the Tests directory.
The code compiles the test and library to elf with avr-gcc. Then the the elf to hex. The avr-size then shows the size. Finally avrdude, using AVR Dragon JTAG erases the device and flashes fresh .hex file. For clean command the target must also be specified.