Integrating 8-Bit AVR Micro-Controllers in Ada: Pablo Vieira Rego
Integrating 8-Bit AVR Micro-Controllers in Ada: Pablo Vieira Rego
avr/default.aspx avr/default.aspx
2 http://www.atmel.com/microsite/atmel_studio6/ 7 http://www.barello.net/avrx/index.htm
3 http://winavr.sourceforge.net/index.html 8 http://www.freertos.org/
4 http://arduino.cc/en/Main/Software 9 http://www.rtems.com/
5 http://avr-eclipse.sourceforge.net/wiki/index. 10 http://sourceforge.net/apps/mediawiki/avr-ada/
php/The_AVR_Eclipse_Plugin index.php?title=Main_Page
end ATmega328P;
The required applications are the GNAT AVR GPL edition13 ,
which comes with the IDE and the Windows cross-compiler;
and WinAVR, which provides CRT libraries for the micro- 2.2.2 GPS Project File
controllers. The GPS project file has to include the AVR configurations
for the packages Ide, Compiler, Builder and Linker. Below
For generating the output .hex file on Windows, the simple are presented some suggestions on how to configure these
project consists of the following elements: project file packages in order to build the .elf output which
will be used to generate the .hex output.
• Specification package which will map the AVR registers;
• Main file which will include the chip specification pack- Listing 2: GPS Project File for ATmega328P
age;
−− arduino.gpr
• GPS .gpr configuration file; project Arduino is
for Default_Switches ("ada") use ("−mmcu=avr5"); 2.2.4 The Hex & Burn Batch Script
end Compiler;
An option for a batch script to generate the .hex and burn it
package Builder is on a micro-controller in COM7 follows.
for Executable_Suffix use ". elf " ;
for Default_Switches ("ada") use ("−−RTS=rts−zfp");
end Builder;
Listing 4: Batch script for converting the .elf and burn the re-
sulting .hex
package Linker is
for Default_Switches ("ada") use ("obj\crtm328p._o", " @rem hexitandburn_duemilanove.bat
−nostdlib", "−lgcc", "−mavr5", "−Tdata=0
x00800200", "−−mmcu=avr5"); @echo Converts .elf to .hex
end Linker; avr−objcopy −O ihex main.elf main.hex
The Main file contains the main task available by ZFP and
the libraries related to the code. The following dummy code 3 Limitations of the Zero Footprint Profile
should be modified in order to code the micro-controller.
The Zero Footprint Profile defines an Ada run-time certifiable
run-time with a memory footprint reduced to null. It excludes
Listing 3: Dummy main file in particular the use of dynamic Ada semantic. The ZFP still
allows the use of the major Ada features such as generics,
with ATmega328P; use ATmega328P;
child units, library-level tagged types, interfaces and local
procedure Main is exception handling [19]. The ZFP is suitable for software
begin certification using DEF Stan 00-55 standard [15].
null ;
end Main; The ZFP limitations are [20]:
• Constructs defined in the ARM Section 9 (Tasking and
14 C Run-Time Library. Synchronization)
15 In this case, the crtm328p.o has its extension renamed to _o to avoid
been deleted when the user makes a project clean. • Exception propagation
16 The file crt1-atmega2560.S can be found on GNAT AVR GPL
2012 installation in the folder C:\GNAT\2012\share\examples\gnat- • Packed arrays with component size other than 1, 2, 4, 8
cross\avr\atmega2560. or 16 bits
ULN2803AP
GND
5 Conclusion
Figure 1: Connections between Arduino Duemilanove, Led,
This paper shows an approach for developing Ada applica-
ULN2803AP and Stepper Motor.
tions for 8-bit AVR micro-controllers, using GNAT AVR as
the Microsoft Windows cross-compiler, and GNAT Program-
ming Studio as IDE. GNAT AVR follows the Zero Footprint
−− main.adb Profile for Real-Time Library, thus not all Ada Real-Time
with ATmega328P; use ATmega328P;
features are present in this development such as multi-tasks.
procedure Main is We believe that Ada can improve the quality of the applica-
−− Stepper Motor coils definitions
tions for AVRs. The AVR community is invited to try this
COIL0 : constant := 2 ∗∗ 0; approach. Also the Ada community is encouraged to propa-
COIL1 : constant := 2 ∗∗ 2; gate its knowledge about real-time applications to the AVRs
field in a mean that it certainly will gain more popularity over [10] K. N. Gregertsen, “Execution time control : A hard-
more one embedded software branch. ware accelerated ada implementation with novel support
for interrupt handling,” Ph.D. dissertation, Norwegian
University of Science and Technology, Department of
References Engineering Cybernetics, 2012.
[1] J. D. Brock, R. F. Bruce, and S. L. Reiser, “Using [11] J. Ras and A. M. Cheng, “A deterministic run-
Arduino for introductory programming courses,” J. time environment for Ada-05 on the ATmega16
Comput. Sci. Coll., vol. 25, no. 2, pp. 129–130, Dec. microcontroller,” Ada Lett., vol. 30, no. 3, pp. 13–22,
2009. [Online]. Available: http://dl.acm.org/citation. Oct. 2010. [Online]. Available: http://doi.acm.org/10.
cfm?id=1629036.1629057 1145/1879097.1879072
[2] P. Jamieson, “Arduino for Teaching Embedded Systems. [12] J. S. Andersen, “Programming Arduinos in Ada.” Free
Are Computer Scientists and Engineering Educators and Open Source Software Developers’ European Meet-
Missing the Boat?” International Conference on ing (FOSDEM’12), February 2012.
Frontiers in Education: Computer Science and [13] AdaCore. (2009, Mar) GNATPro available for 8-bit
Computer Engineering (FECS’11), 2011, accessed: AVR Microcontroller. NY, USA. Accessed: 23/06/2012.
23/06/2012. [Online]. Available: http://www.users. [Online]. Available: http://www.adacore.com/press/
muohio.edu/jamiespa/html_papers/fecs_11.pdf 8-bit-avr-microcontroller/
[3] R. Balogh. Robotics course with the Acrob robot. [14] ——. Ada Development Environment for the Atmel
Österreichische Gesellschaft für innovative Comput- AVR 8-bit microcontroller. NY, USA. [Online]. Avail-
erwissenschaften. Accessed: 23/06/2012. [Online]. able: http://www.adacore.com/gnatpro-safety-critical/
Available: http://www.innoc.at/fileadmin/user_upload/ platforms/avr/
_temp_/RiE/Proceedings/15.pdf
[15] Ministry of Defence, Requirements for Safety Related
[4] ——, “Acrob - an Educational Robotic Platform,” AT&P Software in Defense Equipment, Directorate of Standard-
Journal Plus, vol. 10, no. 2, pp. 6–9, 2010, ISSN 1336- ization - Defense Standard, Rev. INTERIM Def Stan
5010. 00-55/Issue 1, Apr 1991.
[5] I. B. Gartseev, L.-F. Lee, and V. N. Krovi, “A Low- [16] Atmel Corporation. 8-bit AVR Microcontroller with
Cost Real-Time Mobile Robot Platform (ArEduBot) 4/8/16/32K Bytes In-System Programmable Flash:
to support Project-Based Learning in Robotics & ATmega48PA/ ATmega88PA/ ATmega168PA/ AT-
Mechatronics,” R. Stelzer and K. Jafarmadar, Eds. mega328P. San Jose, CA, USA. Accessed: 21/06/2012.
INNOC - Austrian Society for Innovative Computer [Online]. Available: http://www.atmel.com/Images/
Sciences, 2011, pp. 117–124, accessed: 23/06/2012. doc8161.pdf
[Online]. Available: http://www.innoc.at/fileadmin/ [17] J. W. McCormick, F. Singhoff, and J. Hugues, Building
user_upload/_temp_/RiE/Proceedings/25.pdf Parallel, Embedded, and Real-Time Applications with
Ada, 1st ed. New York, USA: Cambridge University
[6] K. N. Gregertsen and A. Skavhaug, “An efficient and Press, 2011.
deterministic multi-tasking run-time environment for
Ada and the Ravenscar profile on the Atmel AVR32 [18] AVR Topics: J.2 Compiler and Linker Flags for AVR.
UC3 microcontroller,” in Design, Automation Test in Accessed: 24/06/2012. [Online]. Available: http://docs.
Europe Conference Exhibition, 2009., April 2009, pp. adacore.com/gnat-cross-docs/html/gnat_ugx_12.html
1572 –1575. [19] AdaCore. Runtime Profiles. [Online]. Available:
[7] ——, “A Real-Time Framework for Ada 2005 and the http://www.adacore.com/gnatpro/toolsuite/runtimes/
Ravenscar Profile,” in Software Engineering and Ad- [20] ——. Ada Restrictions in the Zero Footprint Pro-
vanced Applications, 2009. SEAA ’09. 35th Euromicro file. [Online]. Available: http://docs.adacore.com/
Conference on, aug. 2009, pp. 515 –522. gnat-hie-docs/html/gnathie_ug_4.html#SEC27
[8] ——, “Execution-time control for interrupt han-
dling,” Ada Lett., vol. 30, no. 1, pp. 33–
44, May 2010. [Online]. Available: http:
//doi.acm.org/10.1145/1806546.1806550