Sunday, April 22, 2007

Build Your Own ARM Cross Compiler Toolchain

GNUARM is a set of open source GNU compiler for ARM microcontroller. The toolchain consists of the GNU binutils, GCC compiler set, Newlib and Insight, the graphical user interface to GNU debugger for Windows and Linux. This article will guide the building process of GNUARM toolchain only for Linux users. For Windows users, there have the installer executable EXE files already. www.scienceprog.com has a tutorial on setting up this tool on Windows environment.

Get the sources
I will demonstrate the building process for GCC-4.1 only. For the others version, you can find the GNUARM distributions files from here. Here is the list of files that are required for the installation.

  • binutils-2.17.tar.bz2 [13.1MB]

  • gcc-4.1.1.tar.bz2 [37.3MB]

  • newlib-1.14.0.tar.gz [7.61MB]

  • insight-6.5.tar.bz2 [20.4MB]


I compiled the sources code with gcc-4.1.1 on Fedora Core 6 (kernel-2.6.18). Note that I built the toolchain as root. I also wanted the arm-target stuff separate from my Linux-native stuff, so I put the toolchain in /usr/local/gnuarm.

Building Instruction
[home]# tar xvf binutils-2.17.tar.bz2
[home]# tar xvf gcc-4.1.1.tar.bz2
[home]# tar xvf newlib-1.14.0.tar.gz
[home]# tar xvf insight-6.5.tar.bz2
[home]# cd binutils-2.17
[binutils-2.17]# ./configure --target=arm-elf \
--prefix=/usr/local/gnuarm --enable-interwork --enable-multilib
[binutils-2.17]# make all install
[binutils-2.17]# export PATH="$PATH:/usr/local/gnuarm/bin"
[binutils-2.17]# cd ../gcc-4.1.1
[gcc-4.1.1]# ./configure --target=arm-elf \
--prefix=/usr/local/gnuarm --enable-interwork \
--enable-multilib --enable-languages="c,c++" \
--with-newlib --with-headers=../newlib-1.14.0/newlib/libc/include
[gcc-4.1.1]# make all-gcc install-gcc
[gcc-4.1.1]# cd ../newlib-1.14.0
[newlib-1.14.0]# ./configure --target=arm-elf \
--prefix=/usr/local/gnuarm --enable-interwork --enable-multilib
[newlib-1.14.0]# make all install
[newlib-1.14.0]# cd ../gcc-4.1.1
[gcc-4.1.1]# make all install
[gcc-4.1.1]# cd ../insight-6.5
[insight-6.5]# ./configure --target=arm-elf \
--prefix=/usr/local/gnuarm --enable-interwork --enable-multilib
[insight-6.5]# make all install

Now, I hope everthing is done. You can test by running arm-elf-gcc command in the shell.

Thursday, April 19, 2007

8051 mcu, von Neumann vs Harvard Architectures

We can classify computer architectures into two categories:

von Neumann architecture: computers has a single, common memory space in which both program instructions and data are stored. There is a single internal data bus that fetches both instructions and data. They can not be performed at the same time.

Harvard architecture: computers have separate memory areas for program instructions and data. There are two or more internal data buses, which allow simultaneous access to both instructions and data. The CPU fetches program instructions on the program memory bus.

The 8051 microcontrollers (MCS-51) have an 8-bit data bus. They can address 64K of external data memory and 64K of external program memory. These may be separate blocks of memory, so that up to 128K of memory can be attached to the microcontroller. Separate blocks of code and data memory are referred to as the Harvard architecture. A single block of memory may be mapped to act as both data and program memory. This is referred to as the Von Neumann architecture.

The 8051 has two separate read signals, RD# (P3.7) and PSEN#. The RD# (P3.7) is activated by clearing to logic level 0 when a byte is to be read from external data memory, PSEN#, from external program memory. All external code is fetched from external program memory. The bytes from external program memory may be read by special read instructions such as the MOVC. And there are separate instructions to read from external data memory, such as the MOVX instruction. In order to read from the same block using either the RD# signal or the PSEN# signal, the two signals are combined with a logic AND operation. This way, the output of the AND gate is low when either input is low.

By adopting the Von Neumann architecture, code may be written to memory as data bytes, and then executed as program instructions.

Further Reading

Thursday, April 12, 2007

Microcontroller Programmer DIY

I search about this issue for a while, "Building programmer of our own designs". I found a few of open source programmer projects so that every body can use and contribute it. Here is an opportunity of learning the microcontroller programmer designs from that open schematics.

Here is a list of Microcontroller Programmer, Do It Yourself (DIY).
    8051
  • ATMEL 89C Series Flash Microcontroller Programmer Ver 1.1 - This programmer was designed in view of to be flexible, economical and easy to built, the programmer hardware utilizes the standard TTL series parts and no special components are used. The programmer is interfaced with the PC parallel port and there is no special requirement for the PC parallel port, so the older computers can also be used with this programmer.

  • Atmel 89C2051 In-Circuit Programmer Schematic - The idea is to add this circuitry to a board with already has ram at 2000 and an 82C55 I/O chip to provide ports A, B and C. This is a "beta release" schematic. Use at your own risk

  • ISP Flash Microcontroller Programmer Ver 3.0 - This ISP Programmer can be used either for in-system programming or as a stand-alone spi programmer for Atmel ISP programmable devices. The programming interface is compatible to STK200 ISP programmer hardware so the users of STK200 can also use the software which can program both the 8051 and AVR series devices.

  • Atmel AT89Cx051 programmer

  • PIC
  • PP06 PIC Programmer Software - PP06 is an open-source Production programmer for Microchip's PIC micros. Specifically designed for use in factory in-circuit programming, and development of master/slave systems it supports many pics,and is easily extended to different hardware.

  • Classic PIC Programmer - The classic PIC 16C84/16F84 programmer. The design is originally by David Tait and modified by Bob Blick

  • AVR
  • AVR911: AVR Open-source Programmer - The AVR Open-source Programmer (AVROSP) is an AVR programmer application that replaces the AVRProg tool included in AVR Studio. It is a command-line tool, using the same syntax as the STK500 and JTAGICE command-line tools in AVR Studio.

  • AVR In-System Programmer - They provide details on our version of the Atmel AVR In-System Programmer (ISP). They provide schematics and printed circuit board (PCB) art to allow you to construct your own programmer.

Sunday, April 8, 2007

Learn Embedded Linux with ARMulator

uClinux is an excellent way to study the embedded operating systems for an engineer, student, hobbyist, Linux-enthusiast. I am interested in Embedded Linux for ARM microcontroller. Before buying a new mcu evaluation board, there is a smart way to study the Embedded Linux. That is studying it with the emulator called ARMUlator.

I tested on Fedora Core 6 Linux with GCC 3.4.x (how to install gcc 3.4 for FC6).

What you get

Here are some files you can use to put together uClinux running in the GDB/ARMulator.

Building the Debugger/Emulator

tar xvf gdb-5.0.tar.bz2
gunzip gdb-5.0-uclinux-armulator-20060104.patch.gz
patch -p0 < gdb-5.0-uclinux-armulator-20060104.patch
cd gdb-5.0
export CC=gcc34
./configure --target=arm-elf
make
make install

Running the precompiled binaries

The ARMulator expects the romfs to be in a file called "boot.rom". You must use the matching kernel/romfs combo's.

gunzip romfs.2.4.x
gunzip linux.2.4.x
ln -s romfs.2.4.x boot.rom
arm-elf-gdb linux-2.4.x
...
gdb> target sim
...
gdb> load
...
gdb> run

Finally, you should get something like this:

ucLinux

Saturday, April 7, 2007

Microcontrollers and the GNU Public License (GPL)

Open Source software is released according to the terms of the GNU Public License, GPL. The GPL is intended to guarantee your rights to use, modify and copy the subject software. Along with the rights comes an obligation. If you modify and subsequently distribute software covered by the GPL, you are obligated to make available the modified source code. The changes become a “derivative work” which is also subject to the terms of the GPL. This allows other users to understand the software better and to make further changes if they wish.

This works well for most software but there is at least one problem. Suppose, for example, that you write a clever application that you wish to keep proprietary. If you link it with a C library covered by the GPL, your application becomes a derivative work and thus you’re required to distribute your source code.

To get around this, and therefore promote the development of Open Source libraries, the Free Software Foundation came up with the “Library GPL.” The distinction is that a program linked to a library covered by the LGPL is not considered a derivative work and so there’s no requirement to distribute the source, although you must still distribute the source to the library itself.
Subsequently, the LGPL became known as the “Lesser GPL” because it offers less freedom to the user. So while the LGPL makes it possible to develop proprietary products using Open Source software, the FSF encourages developers to place their libraries under the GPL in the interest of maximizing openness.

Here is a list of GPL software for microcontroller developers.

  • SDCC: a Freeware, retargettable, optimizing ANSI - C compiler that targets the Intel 8051, Maxim 80DS390, Zilog Z80 and the Motorola 68HC08 based MCUs (GPL)

  • GNUPIC: a collect of GNU software for PIC microcontrollers

  • WinAVR: a suite of executable, open source software development tools for the Atmel AVR series on the Windows

  • GNUARM: GNU toolchain ARM microcontrollers

Friday, April 6, 2007

Linux for Embedded Systems

For a microcontroller learner, Embedded System is a challenge. Linux are used as an operating system for the modern embedded devices. I am a one who are trying to study Linux on an embedded microcontroller, i.e., 8051 mcu and ARM. Let's start together!

This is a list of some sites that are of particular interest to embedded developers.

kernel.org – The Linux kernel archive. This is where you can download the latest kernel versions as well as virtually any previous version.

sourceforge.net – “World’s largest Open Source development website.” Provides free services to open source developers including project hosting and management, version control, bug and issue tracking, backups and archives, and communication and collaboration resources.

linuxdevices.com – A news and portal site devoted to the entire range of issues surrounding embedded Linux.

embedded-linux.org – The Embedded Linux Consortium, a nonprofit, vendor neutral trade association promoting Linux in the embedded space. Its major effort at present is the development of an embedded Linux platform specification.

embedded.com – The web site for Embedded Systems Programming magazine.
This site is not specifically oriented to Linux, but is quite useful as a more general embedded information tool.

Thursday, April 5, 2007

Understanding Processor Architecture: RISC versus CISC

Popular processor designs can be broadly divided into two categories: Complex Instruction Set Computers (CISC) and Reduced Instruction Set Computers (RISC). The dominant processor in the PC market, Pentium, belongs to the CISC category. However, the recent trend is to use the RISC designs. Even Intel has moved from CISC to RISC design for their 64-bit processor.

CISC systems use complex instructions. For example, adding two integers is considered a simple instruction. But, an instruction that copies an element from one array to another and automatically updates both array subscripts is considered a complex instruction. RISC systems use only simple instructions. Furthermore, RISC systems assume that the required operands are in the processor’s internal registers, not in the main memory. It turns out that characteristics like simple instructions and restrictions like register-based operands not only simplify the processor design but also result in a processor that provides improved application performance.

Several factors contributed to the popularity of CISC in the 1970s. In those days, memory was very expensive and small in capacity. Even in the mid-1970s, the price of a small 16 KB memory was about $500. So there was a need to minimize the amount of memory required to store a program. An implication of this requirement is that each processor instruction must do more, leading to complex instruction set designs. Complex instructions meant complex hardware, which was also expensive. This was a problem processor designers grappled with until Wilkes proposed microprogrammed control in the early 1950s.

ISA-level
Figure 1. The ISA-level architecture can be implemented either directly in hardware or through a microprogrammed control.

A microprogram is a small run-time interpreter that takes the complex instruction and generates a sequence of simple instructions that can be executed by the hardware. Thus the hardware need not be complex. Once it became possible to design such complex processors by using microprogrammed control, designers went crazy and tried to close the semantic gap between the instructions of the processor and high-level languages. This semantic gap refers to the fact that each instruction in a high-level language specifies a lot more work than an instruction in the machine language. Think of a while loop statement in a high-level language such as C, for example. If we have a processor instruction with the while loop semantics, we could just use one machine language instruction. This explains why most CISC designs use microprogrammed control, as shown in Figure 1.

RISC designs, on the other hand, eliminate the microprogram layer and use the hardware to directly execute instructions. Here is another reason why RISC processors can potentially give improved performance. One advantage of using microprogrammed control is that we can implement variations on the basic ISA architecture by simply modifying the microprogram; there is no need to change the underlying hardware. Thus it is possible to come up with cheaper versions as well as high-performance processors for the same family of processors.

References

  • Guide to RISC Processors for Programmers and Engineers by Sivarama P. Dandamudi, Springer (2005), ISBN 0-387-21017-2.


Tuesday, April 3, 2007

ASEM-51 step-by-step Installation on Windows XP

Last time I wrote an installation for ASEM-51, a two-pass macro assembler for the Intel MCS-51 family of microcontrollers, using the batch file INSTALL.BAT. For someone who do not like anything that is running automatically, or things are not quite clear, here is an step-by-step installation guide for ASEM-51.

The files we require are ASEM-51 v1.3 for DOS/Windows (599 kB) and a collection of the latest MCU files (188 kB).

1. Create a new directory on your harddisk, e.g. C:\ASEM51 and unpack all files of the ASEM-51 package into this directory (see Figure 1.).

unpack ASEM-51

Figure 1.

2. Unpack MCUFILES into a directory (see Figure 2). Move the *.MCU you want to C:\ASEM51\MCU (see Figure 3). Here I move the P89V51RD2.MCU only.

mcufiles

Figure 2.

move mcufiles

Figure 3.

3. Edit System Variable: Start-->right click on My Computer-->Properties. On System Properties click Advanced Tab then click Environment Variables. On System variables select Path then click Edit and append ;C:\ASEM51 in Variable value (see Figure 4).

edit System Variables

Figure 4.

4. Define ASEM51INC environment variable: On System variables (from 3) click New the fill Variable name with ASEM51INC and Variable value with C:\ASEM51\MCU (see Figure 5).

add new varible

Figure 5.

5. Click OK and close all windows.

6. You can test by typing asem in Command Shell (Start-->Run-->cmd). You should get something like this (see Figure 6).

Test ASEM51

Figure 6.

Sunday, April 1, 2007

Learning Machine Code with 8-bit Microcontrollers

To understand deeply in processor architecture, we have to learn the Machine Code. I decide to select the 8051 microcontroller as a microprocessor model. A microcontroller (or MCU) is a computer-on-a-chip. They integrate many modules on one chip such as RAM, Flash memory, EEPROM, serial ports (UARTs), I²C, Serial Peripheral Interface (SPI), analog-to-digital converters (ADC), clock generator (XTAL) and more.

Humans almost never write programs directly in machine code. Instead, they use a programming language which is translated by the computer into machine code. The simplest kind of programming language is assembly language which usually has a one-to-one correspondence with the resulting machine code instructions but allows the use of mnemonics (ASCII strings) for the "op codes" (the part of the instruction which encodes the basic type of operation to perform) and names for locations in the program (branch labels) and for variables and constants.

Installing ASEM-51

ASEM-51 is a two-pass macro assembler for the Intel MCS-51 family of microcontrollers. It is running on the PC under MS-DOS, Windows and Linux. The ASEM-51 assembly language is based on the standard Intel syntax, and implements conditional assembly, macros, and include file processing. The assembler can output object code in Intel-HEX or Intel OMF-51 format as well as a detailed list file. The ASEM-51 package includes support for more than 180 8051 derivatives, a bootstrap program for MCS-51 target boards, and documentation in ASCII and HTML format. And it is free ...

The simplest way of installing ASEM-51 is copying all files of the package to your working directory, and enjoy the benefits of true plug-and-play compatibility!. Alternatively, I have set it up on Windows XP manually:

  • Downloads the lastest ASEM-51 for DOS/Windows (currently v1.3)

  • Create a new, empty directory on your harddisk (C:\ASEM51).

  • Unpack your ASEM-51 distribution archive into this directory, or copy all files of the ASEM-51 package into it.

  • Make the scratch directory default, run the batch file INSTALL.BAT provided, and follow the instructions.

  • Reboot your PC.


You can update MPU file by downloading http://plit.de/asem-51/mcufiles.zip.

References

Tuesday, March 27, 2007

Understanding Processor Architecture: Simplify Computer Complexity

Computers are complex systems. We study computer systems by using layers of abstraction. We use a hierarchical structure to simplify the management. Each level of management filters out unnecessary details on the lower levels and presents only an abstracted version to the higher-level management.

People can look at computer systems from several different perspectives depending on the type of their interaction. We use the concept of abstraction to look at only the details that are necessary from a particular viewpoint. For example, a computer user interacts with the system through an application program. Suppose you are interested in browsing the Internet. Your obvious choice is to interact with the system through a Web browser such as the Fire fox (FF) or Internet Explorer (IE). On the other hand, if you are a computer architect, you are interested in the internal details that do not interest a normal user of the system.

From the programmer’s viewpoint, there exists a hierarchy from low-level languages to high-level languages (see Figure 1). At the lowest level, we have the machine language that is the language understood by the machine hardware. Because digital computers use 0 and 1 as their alphabet, machine language naturally uses 1s and 0s to encode the instructions. One level up, there is the assembly language as shown in Figure 1. Assembly language does not use 1s and 0s; instead, it uses mnemonics to express the instructions. Assembly language is closely related to the machine language.

computer abstraction layersFigure 1. Abstract layers of Computer Systems

References

  • Guide to RISC Processors for Programmers and Engineers by Sivarama P. Dandamudi, Springer (2005), ISBN 0-387-21017-2.


Monday, March 26, 2007

Understanding Processor Architecture: ISA

A programmer uses the Instruction Set Architecture (ISA) as an abstraction to understand the processor’s internal details. This abstraction suits us very well as we are interested in the logical details of the processor without getting bogged down by the myriad implementation details.

The ISA specifies how a processor functions: what instructions it executes and what interpretation is given to these instructions. If these specifications are precise, they give freedom to various chip manufacturers to implement physical designs that look functionally the same at the ISA level. Thus, if we run the same program on these different implementations, we still get the same results. For example, the Intel 32-bit ISA (IA-32) has several implementations including the Pentium processors, cheaper Celeron processors, high-performance Xeon processors, and so on.

The ISA-level abstraction provides a common platform to execute programs. If a program is written in C, a compiler translates it into the equivalent machine language program that can run on the ISA-level logical processor. Similarly, if you write your program in FORTRAN, use a FORTRAN compiler to generate code that can execute on the ISA-level logical processor.

References

  • Guide to RISC Processors for Programmers and Engineers by Sivarama P. Dandamudi, Springer (2005), ISBN 0-387-21017-2.


Thursday, January 25, 2007

OpenServo

OpenServo is an open community-based project started by Mike Thompson with the goal of creating a low-cost digital servo for robotics. The hardware and software design of the OpenServo is free for anyone to use and modify to meet their particular needs. It is currently being developed by a small group of dedicated individuals striving to maintain the very best in free, open source software and standards. We hope that you will find the OpenServo project interesting and become a member of our community.

The OpenServo is a combination of hardware and software meant to replace the original PCB internal to low-cost analog RC servos such as the Futaba S3003 or HiTec HS-311


Some features of the OpenServo include:

  • High performance AVR 8-bit microcontroller

  • Compact H-Bridge implemented with low-cost MOSFET drivers

  • I2C/TWI based interface for control and feedback

  • Control over servo position and speed

  • Feedback of servo position, speed, voltage and power consumption

  • EEPROM storage of servo configuration information

  • Software written in C using free development tools

  • I2C/TWI based bootloader and Windows GUI programmer

  • Total cost about $20 per servo in quantity ($10 servo hardware + $10 parts)

Information can be found on this site regarding Hardware, Software and Tools & Utilities to create your own OpenServo.

Home page: http://openservo.com/

Tuesday, January 23, 2007

Piklab IDE for PIC and dsPIC microcontrollers

Piklab is an integrated development environment for applications based on Microchip PIC and dsPIC microcontrollers similar to the MPLAB environment. Support for several compiler and assembler toolchains, programmers, debuggers and simulators is integrated. A command-line programmer and debugger is also available.


Piklab home: http://piklab.sourceforge.net/