WORK IN PROGRESS!!! Installing Ceedling and the AVR toolchain
THIS NEEDS A BETTER INTRO ABOUT UNITY AND THE TOOLCHAIN Ceedling is a build system for C projects that is something of an extension around Ruby’s Rake (make-ish) build system. Ceedling is primarily targeted at Test-Driven Development in C and is designed to pull together CMock, Unity, and CException -- three other awesome open-source projects you can’t live without if you're creating awesomeness in the C language. In order to spread the awesomeness around, Ceedling is an extensible contraption with a nice plugin mechanism.Before we install Ceedling, let's start by installing a compiler for the AVR ATmega328P, the microcontroller onboard the Arduino Uno. I'm going to show the installation commands for a typical Linux system, but the instructions for Windows and OSX follow a similar pattern. Open a terminal and type the following command:
ngourlay@craxine:~$ sudo apt-get install binutils-avr avr-libc avrdude gcc-avr
After installing Ceedling and the avr tools create a new project and edit the generated rakefile using your favourite text editor:
ngourlay@craxine:~$ ceedling new 74HC595
create 74HC595/vendor/ceedling/docs/CeedlingPacket.pdf
create 74HC595/vendor/ceedling/docs/CExceptionSummary.pdf
... many other messages from Ceedling ...
create 74HC595/project.yml
create 74HC595/rakefile.rb
Project '74HC595' created!
- Tool documentation is located in vendor/ceedling/docs
- Execute 'rake -T' to view available test & build tasks
ngourlay@craxine:~$ cd 74HC595/
ngourlay@craxine:/74HC595~$ emacs rakefile.rb
You'll need to add a couple of targets ('convert' and 'program') , plus a dummy target ('serial_port') to ensure that the required environmental variable has been set. For most projects, the following rakefile will be sufficient:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PROJECT_CEEDLING_ROOT = "vendor/ceedling" | |
load "#{PROJECT_CEEDLING_ROOT}/lib/rakefile.rb" | |
task :default => %w[ test:all release ] | |
# Dummy task to ensure that the SERIAL_PORT environment variable is set. | |
# It can be set on the command line as follows: | |
# $ rake SERIAL_PORT=[serial port name] | |
task :serial_port do | |
unless ENV['SERIAL_PORT'] | |
raise "SERIAL_PORT is not defined in the environment!" | |
end | |
end | |
desc "Convert the output binary to a hex file for programming to the Arduino" | |
task :convert => :release do | |
bin_file = "build/release/#{RELEASE_BUILD_OUTPUT}.bin" | |
hex_file = "build/release/#{RELEASE_BUILD_OUTPUT}.hex" | |
cmd = "#{ENV['OBJCOPY']} -O ihex -R .eeprom #{bin_file} #{hex_file}" | |
puts cmd | |
sh cmd | |
end | |
desc "Program the Arduino over the serial port." | |
task :program => [:convert, :serial_port] do | |
hex_file = "build/release/#{RELEASE_BUILD_OUTPUT}.hex" | |
cmd = "avrdude -F -V -c arduino -p #{ENV['MCU']} -P #{ENV['SERIAL_PORT']} -b 115200 -U flash:w:#{hex_file}" | |
puts cmd | |
sh cmd | |
end |
Now edit the project.yml file. Uncomment the 'release_build' variables, and add some environmental variables. Changes to the standard boilerplate are marked in bold, below.
:project:
:use_exceptions: FALSE
:use_test_preprocessor: TRUE
:use_auxiliary_dependencies: TRUE
:build_root: build
:release_build: TRUE
:test_file_prefix: test_
:release_build:
:output: 74HC595
# :use_assembly: FALSE
:environment:
- :mcu: atmega328p
- :f_cpu: 16000000UL
- :serial_port: /dev/ttyACM0 # change this to the correct port
- :objcopy: avr-objcopy
:extension:
:executable: .bin
:tools:
:release_compiler:
:executable: avr-gcc
:arguments:
- ${1}
- -DTARGET
- -DF_CPU=#{ENV['F_CPU']}
- -mmcu=#{ENV['MCU']}
- -Iinclude/
- -Wall
- -Os
- -c
- -o ${2}
:release_linker:
:executable: avr-gcc
:arguments:
- -mmcu=#{ENV['MCU']}
- ${1}
- -o ${2}.bin
No comments:
Post a Comment