Technical University of Łódź Institute of Information Technology Division of Computer Networks

MASTER’S THESIS

Ada’05 for ARM based systems by Bartłomiej Horn

Faculty of Technical Physics, Computer Science and Applied Mathematics Supervisor: dr inż. Michał Morawski Album number: 127218

Łódź, November 30, 2009

Instytut Informatyki 90-924 Łódź, ul. Wólczańska 215, budynek B9 tel. 042 631 27 97, 042 632 97 57, fax. 042 630 34 14, email: offi[email protected]

Contents

Contents iii

1 Introduction 1 1.1. ...... 1 1.2. Ada language ...... 2 1.3. Aims of the thesis ...... 3 1.4. Organisation of the thesis ...... 3 1.5. Another systems ...... 4 1.6. Acknowledgements ...... 4

2 ARM based systems 7 2.1. ARM processors ...... 7 2.2. Memory issues ...... 9

3 GNAT Ada compiler 11 3.1. GNAT ...... 11 3.2. GNU Compiler Collection (GCC) ...... 11 3.2.1. Structure ...... 12 3.3. GNAT compilation model ...... 13

4 Compilation of arm-elf-gnat 15 4.1. ...... 15 4.1.1. Important definitions ...... 15 4.2. Requirements ...... 16

iii iv CONTENTS

4.3. options ...... 18 4.4. Building arm-elf-gnat ...... 19

5 Structure of the Ada front end 21 5.1. Makefile.in ...... 22 5.2. files ...... 23 5.3. system.ads file ...... 25 5.4. Corrupted files ...... 26 5.5. Back end file ...... 27

6 Demo program 29

7 Summary 33 7.1. Future works ...... 33 7.2. Summary ...... 34

A BibTEX 35

B CD Content 37

Bibliography 39 Chapter 1

Introduction

1.1. Microcontrollers

Electronic components are present in a growing number of devices: from TV remote controllers and portable music players to car brake systems and life-support apparatus in hospitals. Each of them has specific functions, which are well known during designing. A very convenient way to con- trol them is to use a —a small computer build on a single integrated circuit. The microcontroller has its own processor, RAM and some additional peripherals—depending on needs (such as timers or serial output). The microcontroller and a program running on it are integral part of the device. This program is often called firmware, and usually it is not replaceable on finished product. High specialisation allows optimisation of software and hardware to perform specific functions. Requirements con- cerning choice of processor are predictable, there is no need for installing chip which has better parameters than sufficient. For the same reasons, microcontrollers that are chosen for a device have only necessary functions. It is possible because there are various models on the market, with dif- ferent processors, peripherals, RAM size, communication ports or power consumption. Processor’s clock rate does not need to be very high—1 MHz

1 2 CHAPTER 1. INTRODUCTION is enough for many applications, and RAM size of 2 kB is not rare. The most popular are the microcontrollers based on ARM processors, described in chapter 2. A compiler for them is the main goal of this thesis. The question is, which language should the compiler compile?

1.2. Ada language

At the very beginning, the most popular language to program microcon- trollers was the . The programmer is able to utilise 100% of the processors strengths and features, however, the assembly code is dif- ficult to maintain and it takes very long to write one comparing to high- levels languages. They have many advantages over assembler—it is easier to maintain, develop and debug code written in high level language. Those advantages are applicable to microcontrollers programming. Nowadays, the standard language for this objective is C. Although much easier than assembler, C is not perfect; for example, it is not strong-typed and lacks Object Oriented Programming. Writing soft- ware in C is a good idea, albeit it is better to have alternatives. In Author’s opinion one of the best languages for programming microcontrollers is Ada. Ada has been created to meet Department of Defense of the USA spe- cial requirements [12]. Generally, the language should be reliable, easy to maintain and enable minimisation of errors in programs. Ada is such a language. It is very strong typed, allows Object Oriented Programming, generic programming, and has a great concept of modularity using pack- ages. Microcontrollers are to meet similar criteria to military systems, as the reliability of programs is extremely important here. Many more of Ada advantages can be retrieved from its reference manual [7]. Ada has a formal standard—reference manual [7]. The latest standard version has been published in 2005, and the current language name is Ada’05 or Ada 2005 (the previous have been Ada 95 and Ada 83). In this work, simple Ada name is used and it means Ada’05, however, most information 1.3.. AIMS OF THE THESIS 3 is correct for previous versions as well. The compiler sticks to the Ada’05 rules, but it can be switched to work with previous standard.

1.3. Aims of the thesis

The goal of the thesis is to provide a working Ada compiler for ARM mi- crocontrollers, basing on the existing GNAT compiler. Next, it is used to compile as an example a simple program for the LPC2148 Edu Board [2]— microcontroller produced by Embedded Artists for educational purposes. The device used in this thesis has been provided by Technical University of Łódź. This program uses FreeRTOS [3]—an destined for industrial purposes employing microcontrollers, where code size is impor- tant.

1.4. Organisation of the thesis

This chapter explains the aims of this thesis, defines the microcontroller term and justifies the choice of the Ada language for writing microcontroller software. In chapter 2, ARM processors are briefly described, with the emphasis on special compilation issues. Chapter 3 describes GNAT as a part of the GNU1 Compiler Collection, describes the structure of GCC and explains the compilation model used in GNAT. Chapter 4 defines some important terms referring to GCC compilation, describes its requirements and gives practical advice on the GNAT compi- lation for ARM based systems. In chapter 5 the structure of GNAT and meaning of its most important files are described.

1GNU is Not Unix, http://www.gnu.org/ 4 CHAPTER 1. INTRODUCTION

Chapter 6 describes the provided demo application, focusing on the aspects specific to programming microcontrollers. Chapter 7 summarises the thesis and gives suggestion on future works.

1.5. Another systems

On the market, there is a large scope of microcontrollers families, such as Microchip Technologies which manufactures PIC microcontrollers: 8, 16 and 32-bits. The other popular solutions are provided by Texas Instru- ments (16-bits MSP430 and 16- or 32-bits TMS320C2xxx families) and Rabbit Semiconductors. Huge part of automotive industry is supplied by Freescale Technologies, which is one of the biggest supplier of engine sys- tems microcontrollers. AVR, Atmel 8-bit microcontrollers are widely used in the electronics industry. Additionally, they are popular among the hobbyists as they are easily programmable. It is notable that there exists an Ada compiler for these systems: AVR-Ada, downloadable from http://sourceforge.net/ projects/avr-ada/. It is also based on GCC and ensures similar function- ality to the compiler developed for this thesis. In July, 2009, AdaCore published GNAT compiler for LEGO MIND- STORMS NXT, educational robotic platform. These small LEGO robots are provided with ARM processors, several different sensors, Bluetooth port, and are perfect for learning embedded programming