I like to think I write good code, and I’ve used C and C++ almost since their inception. I admit to incorporating more than one unwanted bug into C applications that were eliminated after sometimes tedious diagnostic sessions. Almost every new microcontroller released has a free C/C++ compiler toolchain associated with it.
Unfortunately, C is very unforgiving, and C++ is only a little better. But they are the mainstay for embedded programmers these days. That’s one reason why I have been waiting for AdaCore’s delivery of its Ada 2012 toolchain for Arm’s Cortex-M platform. It is a free download at libre.adacore.com.
The Cortex-M is the main low-end, 32-bit microcontroller utilized by almost all major microcontroller vendors that have adopted the Arm architecture. Vendors like Green Hills Software, Atego, and Adacore have supported the Cortex platform in the past but with earlier Ada standards. Ada 2012 includes a range of new features including contracts (see “Ada 2012: The Joy of Contracts” on electronicdesign.com).
More Articles About Ada and SPARK
Rolling Up My Sleeves
I had already tried out a version of AdaCore’s GNAT Programming Studio (GPS). It generated applications that would run on Linux on the BeagleBone based on the Texas Instruments Cortex-A8 platform (see “ARMing Ada” on electronicdesign.com). The new toolchain targets bare metal, which is needed for many applications.
Setup was easy since GPS was already installed. Setting up the ST-Link debug interface to the STM32 board (see the figure) actually took more time. It was then a matter of running through the flashing LED demo. I included a snippet of code from a flashing LED program to highlight some of the advantages of using Ada 2012 (see the listing).
with LEDs; use LEDs;
with Button; use Button;
with Ada.Real_Time; use Ada.Real_Time;
package body Driver is
type Index is mod 4;
Pattern : constant array (Index) of User_LED := (Orange, Red, Blue, Green);
task body Controller is
Period : constant Time_Span := Milliseconds (75); -- arbitrary
Next_Start : Time := Clock;
Next_LED : Index := 0;
begin
loop
Off (Pattern (Next_LED));
Next_LED := Next_LED +
(if Button.Current_Direction = Counterclockwise then -1 else 1);
On (Pattern (Next_LED));
Next_Start := Next_Start + Period;
delay until Next_Start;
end loop;
end Controller;
end Driver;
More Articles About Ada and SPARK
About the Author
William Wong Blog
Senior Content Director
Bill's latest articles are listed on this author page, William G. Wong.
Bill Wong covers Digital, Embedded, Systems and Software topics at Electronic Design. He writes a number of columns, including Lab Bench and alt.embedded, plus Bill's Workbench hands-on column. Bill is a Georgia Tech alumni with a B.S in Electrical Engineering and a master's degree in computer science for Rutgers, The State University of New Jersey.
He has written a dozen books and was the first Director of PC Labs at PC Magazine. He has worked in the computer and publication industry for almost 40 years and has been with Electronic Design since 2000. He helps run the Mercer Science and Engineering Fair in Mercer County, NJ.
- Check out more articles by Bill Wong on Electronic Design
- Bill Wong on Facebook
- @AltEmbedded on Twitter