During any software development investigations a researcher and, especially, a technician may experience a situation, when they need to use a different operating system then the Microsoft Windows™. It could be BSD, Apple MacOS and in most cases it may be one of the numerous Linux implementations, which can be obtained mostly for no charge to the user.
The main purpose of this article is to cover one of the available methods to obtain an Atmel AVR Assembling platform within Linux environment as to use it in cases, where Microsoft Windows™ unavailable by certain conditions.
During this article preparation process a several sources were investigated with the help of Internet search engines. Most of the publications, even if they were oriented on Linux microcontroller programming, covered only C\C++ programming experience and on several internet resources Linux AVR Assembling hits were requested. So, this means that the subject of AVR assembling in Linux wasn’t revealed enough.
Linux software development style is rather different from the Microsoft Windows™ manner. Windows style implicates, mainly, an integrated implementation combined with various IDEs or similar solutions. Linux developing style differs in the way of multi- combinations, i.e. software developers could use any combinations of programming solutions and environments at their choice and combine them with various programming tools from gcc to mono and so on. Indeed, you can hardly find a fully-implemented solution such as Atmel AVR studio under Linux to develop a microcontroller firmware, but, however, possible, and this solution could be constructed by user himself. This article will not cover the issues of installing original AVR Studio under Windows Emulator, expanding it with the Linux distribution; it just shows methodical implementations with the native instruments provided for Linux, especially.
There are many publications and books about Linux on almost all languages spoken in the World and still this operating system is as spanless as the planet Solaris of the book by Stanislav Lem. In this case, I believe I should describe Linux a little more in a short review below.
Linux is a Unix-like operating system that was designed to provide personal computer users a free or very low-cost operating system comparable to traditional and usually more expensive Unix systems. Linux has a reputation as a very efficient and fast-performing system. Linux's kernel (the central part of the operating system) was developed by Linus Torvalds at the University of Helsinki in Finland [1]; an operating system kernel first released October 5, 1991 [2]. To complete the operating system, Torvalds and other team members made use of system components developed by members of the Free Software Foundation for the GNU Project [2].
The GNU Project is a free software, mass collaboration project, announced on September 27, 1983, by Richard Stallman at MIT. It initiated GNU operating system development in January, 1984 [3]. The founding goal of the project was, in the words of its initial announcement, to develop «a sufficient body of free software [...] to get along without any software that is not free». [4]. Linux system distributions may vary in many details of system operation, configuration, and software package selections [3].
Unlike Windows and other proprietary systems, Linux is publicly open and extendible by contributors. Because it conforms to the Portable Operating System Interface standard user and programming interfaces, developers can write programs that can be ported to other operating systems. Linux comes in versions for all the major microprocessor platforms including the Intel, PowerPC, Sparc, and Alpha platforms. It's also available on IBM's S/390. Linux is distributed commercially by a number of companies. A magazine, Linux Journal, is published as well as a number of books and pocket references [1].
Linux is sometimes suggested as a possible publicly-developed alternative to the desktop predominance of Microsoft Windows. Although Linux is popular among users already familiar with Unix, it remains far behind Windows in numbers of users [1]. By intelligence provided by AT Internet, European leader in the field of Web analytics, Linux maintained third place with the visit share of one percent [4]. However, its use in the business enterprise is growing.
Let us return to our muttons. Although, Linux-based operating systems are indeed directed into programming issues, the essence of Linux software development bound on programmers in possession of C/C++ language [5, p. 16]. There is an opinion that even the “all-mighty” GDB won’t work properly with assembled software [6].
The all-know recursive abbreviation of free software foundation: “GNU is Not Unix” in the case of Microsoft Windows could be modified into something like: “Linux in not Windows”. The Rubicon between the states “Linux is the opponent of Windows” and the state described by the phrase above were crossed in 1999–2000 [5, p.267]. Linux is not wholesale. Written by group of enthusiasts, it continues to be developed by them [7, p.5]. All this facts force any author of any Linux oriented publication to describe the terms and software, which he observes.
GDB, which is shown above, or GNU Debugger is the software designed to provide capabilities to check out the workaround of the application in-development and reveal any faults before they could force to programming error issues [8]. During the investigations, which have led to this publication, author used specific compilation of the GDB, the GDB-AVR. This package, according to its short description in Ubuntu application centre, has been compiled to target the Atmel AVR microcontroller architecture and configured as host within ordinary personal computer and AVR architecture as target. The program being debugged can be written on various languages, but as described above the majority in the compatibilities list of GDB remains with C-based programming languages. Evidently, avr-assembler implementation of GDB-AVR is evidently unstable. Author experienced various programming irregularities during exploitation of this software. Indeed, C-based applications are debugging with rather superior quality. Atmel AVR microcontroller implementation of GDB accepts a remote debugging with, amidst the purposes of this article, SimulAVR software. Author of this article possessed compiled version 7.2 of GDB-AVR.
The SimulAVR program is a simulator for the Atmel AVR family of microcontrollers. This can be used as a remote target for GDB-AVR. Application is started out as a C based project and afterwards hardware simulation part were re-developed in C++. The core of the SimulAVR is the software library. This library is linked together with a command-line interface to create a command-line program. The interpreter interfaces as the part are used for inter-link between the library and Pyhton / TCL languages [9]. As before the major language to debug is C. Author of this article possessed compiled version 0.1.2.2 of SimulAVR.
The sole one application, which is particularly oriented on pure AVR assembler implementation is AVRA. AVRA is the Assembler for the Atmel AVR microcontroller family and it is almost compatible with Atmel own assembler AVRASM32 [10]. Author of this article possessed compiled version 1.2.3 build 1 of AVRA.
The Linux-kernel is the set of intermediate operating software programs written in according to POSIX standarts used to provide adequate level of hardware access services for user-level applications. Basically, there are three main sub-levels of kernel are in use: file sub-system, process management and input-output sub-system. Linux-kernels differs in version numbers the current stable 3.2.2 [11]. Each Linux-kernel version covers functions and programming interfaces to support variety of hardware and applications. Each different Linux-kernel version has a various compatibility issues and when anybody observes Linux he obliged to quote the data about the version of his Linux kernel so that reader could analyze the conditions of author’s investigations. Exploitations covered by this article derived under Ubuntu, one most popular Linux distribution. The Linux kernel version were 3.0.0–15-generic-pae as shown on Figure 1 (Network names and domains smudged for security purposes hereinafter).
Figure 1. Part of the Linux Terminal with the conditional information about the current Linux kernel.
Software installation executed through Ubuntu Software Center, a standard tool integrated into graphical environment of this operation system. User interface left untouched as default Unity.
In the table below the test program source were shown.
Table 1
Test program source
Line number |
Program lines |
1 |
.include "2313def.inc» |
2 |
.org 0 |
3 |
rjmp start |
4 |
start: |
5 6 |
CLI LDI R16,127 |
7 |
OUT DDRB, R16 |
8 |
LDI R16, 0 |
9 |
OUT PORTB, R16 |
10 |
LDI R16,0 |
11 |
OUT DDRD,R16 |
12 |
LDI R16,15 |
13 |
OUT PORTD, R16 |
14 |
LDI R16,15 |
15 |
OUT PORTD, R16 |
16 |
SEI |
17 |
LDI R16,1 |
18 |
LDI R17,3 |
19 |
ADD R16,R17 |
20 |
rjmp start |
Test program were not intended for any real developing experience and exploitation under manufacturing condition. There is the only purpose for it to show the essence of Linux AVR assembling methods.
In the first line of the source include directive asks assembler to plug ad hoc header to define the registers of a specific AVR microcontroller. Assembling issue with this directive under the AVRA conditions described below. Afterwards there is mnemonic instruction, which determines a switchover to the main program branch. Hereafter situated an initialization mnemonics preceded by CLI operator, which prevents any interrupts while program were not initialized properly. Then after program text allows a normal workaround (SEI) main program text mnemonics are located [12].
Assembling commands of the AVRA following: avra –I /usr/share/avra test.asm. The “-I” parameter directs AVRA where to obtain an ad-hoc headers to plug with the program source before assembling (sic!) source file name ends this construction. AVRA copies the headers into /usr/share/avra catalogue by default and appears to be using standardized Atmel, Corp. headers of AVRStudio.
The first assembling attempt of the test program using AVRA leads to a fault, which is shown on Figure 2.
Figure 2. AVRA assembling fault
It seems that assembler founds an inconvenient mnemonics in the source file, but as shown in the Table 1 test.asm program is free of any macro definitions such as #ifndef, #define or #pragma. Close inspection of header file 2313def.inc in noticed catalogue reveals that own AVRA header files contains incorrect definitions. Contents of the AVRA header-file are shown below.
Figure 3. AVRA header file contents.
Bolded lines on Figure 3 shows incompatible macro definitions that AVRA appears to be counted as errors, because, as described above, AVRA plugs these headers to program source and assembles combined source afterwards.
Evidently, the ad-hoc header files provided by AVRA are inconvenient. There is branching from this point. First, we could correct the files according to the manual pages of AVRA [13]; on another hand, there is always opportunity of using the original header files of AVR Studio by Atmel (Author have to test version 4.07 Build 240). The last one reveals an interesting AVRA feature. First of all, AVRA seeks header files in the assembling project directory, even if the “-I” parameter are present. The manual page of AVRA notes: AVRA is an assembler for Atmel AVR microcontrollers, and it is almost compatible with Atmel's own assembler AVRASM32. The differences between is support for some extra preprocessor directives, this includes:.define,.undef,.ifdef,.ifndef,.if,.else,.endif,.elif,.warning [13]. Obviously, there is no mention of #pragma or.pragma directive, and AVRA itself notes so while assembling with edited header files as mention of absence of definition for.pragma directive too.
When a developer managed to overcome these difficulties, by any of the means described above, assembling appears to be successful as shown on Figure 4, below.
Figure 4. Successful program assembly.
It needs us look into debugging issues of AVR assembled programs under Linux, from this point.
For debugging purposes there is an opportunity to use both GDB-AVR and SimulAVR. This combination shows tolerable work with assembled programs. SimulAVR allow remote assembled program debugging. In other words, GDB-AVR will connect to the SimulAVR installed on another computing system over the network to create a digital farm for debugging purposes.
As for local debugging using GDB-AVR alone, so, when assembled program loads into virtual memory of GDB, debugging system seeking for debugging symbols at this moment. It seems that with AVRA assembling system it is impossible to provide them for debugger, with the current version, at least. Indeed, SimulAVR system will shape an appropriate virtual environment for the device given.
To enable SimulAVR input: simulavr –d at90s2313 –g; this will start a SimulAVR with an option to listen a network port like on remote computing system over the local network. The results of this actions are shown on the Figure 5. Parameters for this directive will be accounted for as follows: “-d” parameter defines device type to create environment for; with directive simulavr — devices on can learn about compatible list of simulavr and obtain an useful information about what microcontroller chip are able to use with. Obviously, that the version of author’s possession supports a moderate list off microcontrollers, but newer AVRA version 1.3.0, as it seems by source information provided, will in touch with ATTiny2313 as newer version of at90s2313. Indeed, limitations will vanish, when this stable build of the program becomes part of major Linux repositories. If consequences force to compile the program manually, every developer is obliged to do so.
Figure 5. SimulAVR listens port 1212.
To complete debugging farm change directory with Terminal directive “cd” to your project directory and then input: avr-gdb. This initiates shell to use with GDB-AVR. There is no mistake in this directive, as quoted in documentation, GDB-AVR starts with the reverse of its application name directive. Screen of initiated GDB-AVR demonstrated on Figure 6.
Figure 6. Combined GDB-AVR and SumulAVR farm in action
Debug interconnection demands to strongly follow the order below, otherwise, any mistake, probably will lead to segmentation fault amongst the debugging bundle components and this, surely, will crash the programs. So, the safe order will be as follows.
After GDB-AVR initiation input directive that will lead debugger to the remote system with the SimulAVR installed and configured as shown above. If your debugging farm is set within sole computer the phrase would be as good as weird: target remote localhost:1212. This says to the debugger, that it should load programs to remote system with specified address and port, but in the case of sole computer address will transform local host construction, otherwise, there might be an IP address or network computer name. Port will be 1212 by default as Figure 5 demonstrates. Afterwards GDB-AVR will demonstrate log information with zeros, this means that connection established and empty program is loaded into simulated Flash. It is time to upload a specific program from your project directory. Input: load test.hex. And then for the correct assembler symbols displaying input as follows: display/I $pc [6]. Now, one can debug his program with “si” (debugger will bypass functions, while tracing) and “ni” (debugger will not bypass function, while tracing) directives to GDB-AVR console.
There are plenty of upload software in the Ubuntu Software Center: USB, LPT, in-circuit programmer utilities. If you upload hardware used to connect within parallel port, you will, probably, need to grant an authorization to use it as follows: usermod –G lp <user name> [14].
We, surely, will have a full set of microcontroller program features in the future. Even now, Atmel attempts to adopt his AVR Studio for Linux, but application comes in GNU Toolchain integration, this means the GNU C compiler and the GDB [15], which is already mentioned in this article. So, as Atmel description noted there is no sign of authentic Atmel tools as in Microsoft Windows™ version [15]. Indeed, a pure experience with the Linux native AVR microcontroller tools will be helpful.
References:
1. Definition of Linux and description of its history // Search Enterprise Linux [Internet source] — URL: http://searchenterpriselinux.techtarget.com/definition/Linux
2. Linux // Wikipedia Project [Internet source] — URL: http://en.wikipedia.org/wiki/Linux
3. GNU Project // Wikipedia Project [Internet source] — URL: http://en.wikipedia.org/wiki/GNU_Project
4. [Stallman] Stallman, Richard GNU Manifesto // The GNU Project [Internet source] — URL: http://www.gnu.org/gnu/manifesto.en.html
5. Web visit distribution survey // AT Internet, query date 2012/01/29 [Internet source] — URL: http://en.atinternet.com/Resources/Surveys/Internet-user-equipment/Operating-systems-August-2011/index-1–2-7–246.aspx
6. [Соломенчук] Соломенчук, В. Linux.Краткий курс [Текст] // В.Соломенчук — СПб: Питер, 2001. — 288 с.
7. [Касперски] Касперски, Крис Программирование на ассемблер в UNIX // InsidePro [Электронный источник] — режим доступа: http://www.insidepro.com/kk/137/137r.shtml
8. [Rusling] Rusling David A. The Linux Kernel // The Linux Documentation Project [Interbet source] — URL:
9. The GNU Debugger Project [Internet source] — URL: http://www.gnu.org/software/gdb/v
10. The SimulAVR Project [Internet source] — URL: http://http://www.nongnu.org/simulavr/
11. The AVRA project [Internet source] — URL: http://avra.sourceforge.net/
12. The Linux Kernel Archives [Internet source] — URL: http://www.kernel.org/
13. Atmel AVR ATiny213 Datasheet // Atmel [Internet source] — URL: http://www.atmel.com/
14. AVRA manual pages // AVRA Team [Electronic Documentation Source] — Access Mode: Terminal$ man avra
15. Sole Linux microcontroller programming example [Internet source] — URL: http://phantom-a666.livejournal.com/4582.html
16. Atmel products information // Atmel [Internet source] — URL: http://www.atmel.com/dyn/products/tools_card.asp?tool_id=4116