Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programming Arduino with Ada

Tags:

arduino

avr

ada

I am am unable to get avr-elf-windows and WinAVR to work. I have managed to build the example supplied with avr-elf-windows (ATmega2560). But if I try and expand to use another chip or start using the WinAVR supplied packages and projects I keep getting errors I cannot work out.

Method 1:

Modify the ATmega2560 example to use the WinAVR packages.

Changed:

with Atmega2560; use Atmega2560;

to:

with AVR; use AVR;
with AVR.Atmega328p; use AVR.atmega328p;

Create a project file to include:

with "C:\WinAVR-20100110\lib\gnat\avr.gpr";
with "C:\WinAVR-20100110\lib\gnat\avr_app.gpr";

Running make I get the following error:

avr-gnatmake: "C:\WinAVR-20100110\lib\gnat\avr_lib\avr-int_img.adb" compilation error

Great, I have a compilation issue, but I cannot see the error.

Method 2:

Open the above project file in GPS. Change the build setting to be gnatmake. GPS now starts reporting errors and warnings:

Project warning: object directory "avr_lib/avr5/obj" not found Project library directory "C:\WinAVR-20100110\lib\gnat\avr_lib\avr5\lib\" does not exist

The latter issue is very clearly the fact that I have not set up GPS correctly to tell it the values of microcontroller and architecture, but I cannot seem to find anything to resolve this.

Method 3:

To use the WinAVR set up directly using makefiles which then gives me the error:

avr-gnatmake: RTS path not valid: missing adainclude and adalib directories

If I follow the instructions I can find by searching the web I can only find details for building the required libraries under Linux.

Platform: Windows 7.


With the combination of the two answers above I have now managed to link my sample code. As to wether it will work on the Arduino, that is a different issue.

Many thanks for the help.

I have found it a bit frustrating to get this far, and I wonder if there are others out there who may just give up on Ada on the Arduino and go back to the Arduino IDE and therefore missing out on the opportunity to learn a language with more structure. There are many misleading pages out there that also do not help.

like image 325
Sean Avatar asked Mar 30 '13 21:03

Sean


Video Answer


1 Answers

You might want to take a look in the paper Integrating 8-bit AVR Micro-Controllers in Ada. Basically you can use a GPS project file arduino.gpr like

project Arduino is

   for Source_Dirs use (".", "src");
   for Object_Dir use "obj";
   for Exec_Dir use "bin";
   for Main use ("main.adb");

   package Compiler is 
    for Default_Switches ("ada") use ("-mmcu=avr5");
   end Compiler;

   package Ide is
      for Gnat use "avr-gnat";
      for Gnatlist use "avr-gnatls";
      for Debugger_Command use "avr-gdb";
   end Ide;

   package Builder is
      for Executable_Suffix use ".elf";
      for Default_Switches ("ada") use ("--RTS=rts-zfp");
   end Builder;

   package Linker is
      for Default_Switches ("ada") use ("obj\crtm328p._o", "-nostdlib", "-lgcc", "-mavr5", "-Tdata=0x00800200", "-mmcu=avr5");
   end Linker;

end Arduino;

and you can code a spec for your ATmega328P like

with Interfaces; use Interfaces;
with System;

package ATmega328P is

   -- PORTB: Port B Data Register
   PORTB : Unsigned_8;
   for PORTB'Address  use System'To_Address (16#25#);

   -- DDRB: Port B Data Direction Register
   DDRB : Unsigned_8;
   for DDRB'Address  use System'To_Address (16#24#);

   -- PINB: Port B Input Pins
   PINB : Unsigned_8;
   for PINB'Address  use System'To_Address (16#23#);

end ATmega328P;

to be imported by your main file or libraries.

like image 58
Rego Avatar answered Sep 29 '22 20:09

Rego