Sean
Sean

Reputation: 145

Programming Arduino with 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.

Upvotes: 10

Views: 6829

Answers (3)

Sean
Sean

Reputation: 145

It appears that having a mix of 3 or 4 tool chains installed that provide one of aspects of WinAvr, AvrAda causes significant problems (these included WinAvr, Avr-Ada, Cygwin, AVR compiler by Adacore and MinWG).

Starting with a brand new Win7 or Win8 installation perform the following:

Install WinAVR-20100110 to C:\WinAVR-20100110

Copy the content of the Avr-Ada-1.2.0_bin to C:\avr-ada-1.2.0

Add C:\avr-ada-1.2.0\bin to the PATH 

Compiling the content of each of the examples in C:\avr-ada-1.2.0\share\doc\avr-ada\apps identifies that some DLLs are missing: libiconv-2.dll, libgmp-10.dll, libmpc-2.dll, libmpfr-1.dll

These can be found in a MinGW installtion. 
Create a virtual machine to install MinGW on, in order to ensure it did not mess with the main PC. 
Copy the missing DLLs in C:\WinAVR-20100110\bin

The example in DS1820 will not compile due to crc_lib being missing. 

In order to upload to the Arduino the makefiles must be modified for your local installation, board type etc.

Upvotes: 1

Rego
Rego

Reputation: 1116

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.

Upvotes: 8

user1818839
user1818839

Reputation:

Bear with me if this isn't the immediate answer; I have only used the AVR-Ada toolchain on Linux, so we may have to iterate towards a solution unless someone else spots the problem first.

The first thing to decipher is which version of the AVR-Ada tools you have:

your project file USED to need (using avr-ada 1.1)

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

Now with avr-ada 1.2.1 you need (instead)

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

for building applications, and <same path>/avr_lib.gpr for libraries.

I don't believe you ever need both! And they may conflict with each other.

I don't know the state of the Windows binary build, but if you need the latest version (recommended : it's a real improvement) you may need to build it from source.

Method 1 : were you running Make from a command line? If so, I would expect to see errors in all their gory details.

Method 2 : can't help you here, I don't know GPS well enough. However I can say that on Linux there are no "avr5" folders in [wherever]/avr/lib/gnat/avr_lib. (AVR5 is correct for the 328p)

Instead there IS a [wherever]/avr/lib/avr5 containing libc and other C-related objects - including the crtm328p.o that Rego names in his linker switches, and a [wherever]/lib/gcc/avr/4.7.2/avr5 folder containing libgcc.a. You probably need to find the former and point GPS at it...

Method 3 : This looks the easiest to fix. The "gnatmake" command needs an --RTS= option pointing at the correct RTS for the 328p. This should be --RTS=rts/avr5 assuming the RTS is correctly installed.

Alternatively a full path ought to work. Here, that would be

--RTS=/opt/avr_472_gnat/lib/gcc/avr/4.7.2/rts/avr5

on Windows you may have to poke around to find the correct path. Using Method 1 this --RTS option is automatically generated by avr_app.gpr.

Upvotes: 3

Related Questions