[Search] [Contact Us]
Progettazione Elettronica Controlli di Macchine Automatiche  
 Tooltips 
Cross Compiling
PROGETTAZIONE
Hardware
Firmware uC
Masters PCB
Circuiti Ibridi
Software Custom

SOFTWARE
Eagle CAD
B2Spice A/D
Electra Autorouter
Eagle Power Tools
SuSE Linux

PRODOTTI
Embedded Linux Board
Moduli I/O USB
Moduli I/O Ethernet
Moduli A/D Ethernet

LPC900 Programmer
PRM-W1 Boards
USB Key


Cerca nel sito


Contatti

L'Autore

 8052 List 

Using Keil C51 and A51 under Linux

Update 2005:
This article is quite old but still valid. Nowadays I use SuSE 10.0 with FreeDOS, dosemu and without any FAT partition.
I do not use Nedit no more, instead I use KATE with a special syntax highlighter I wrote. I do not even use my make51 utility no more, because I found that using GNU make for dos is more efficient.
I also wrote some flash downloader for linux that you can find here:

PRECMA LPC900icp
aduc8xx


If you write programs for microcontrollers, you probably use a cross-assembler and/or a cross compiler. A cross-assembler is a program running on a common PC (usually an Intel x86 PC) that can translate a text file written in Assembly language (source code file) into a binary file that you can upload into your microcontroller (OTP, FLASH, EPROM). A cross-compiler works like a cross-assembler, but using a source code file written in a high-level language. They are named "cross-..." because they produce a program executable on a chip different from the one on which they run (i.e. they run under Intel Pentium and produce programs for Microchip PIC family).

Using small (but powerful!) 8 bit microcontrollers like MCS-51 family, the most used programming languages are Assembler and C. And the best assember and compiler for MCS-51 are KEIL C51 and A51, in my opinion.

The most common PC platform in the world is the "Wintel" patform, which stands for "MS-Windows + Intel", and so this is the most common platform also for cross-assembler and cross-compilers. Usually cross-assembler and cross-compilers runs under MS-DOS, and the software house sells also a "Programming Environment" that runs under MS-Windows, including an editor and other facilities.

So, if you are a Linux fan, like I am, it seems that you have no way to use your Linux system for cross-programming! You are forced to use the hated MS-Windows...

That's wrong! With a few work you can organize a perfect cross-programming environment under Linux. What you need is: - A cross-assembler and/or a cross-compiler that runs under MS-DOS command line - The latest Linux distribution you prefer (I like SuSE Linux)

In this article I will refer to KEIL C51 Ver. 4.01 and A51 Ver. 4.6, which are the compiler and assembler I use. They are not the latest version, but they work really very good. Anyway, you can use any cross-compiler/assembler that runs under MS-DOS. KEIL C51 has even an hardware key to connect to the parallel port of the PC.

For the operating system, I will refer to SuSE Linux 6.4 distribution, with Xfree86 and KDE installed (which means a graphical environment). For simplicity, I assume that you're working in a "desktop" environment as a single user, not in a network, and that you can access as the system as root if you need.

Be sure that the distribution you choose include the Linux program "dosemu": this is a really cool MS-DOS emulator. I use the 1.0 version, but I used ver. 0.98 in the past and it works good too.

Install the Linux distribution, if you don't have it installed, and the "dosemu" emulator. I will not discuss about Linux installation and "dosemu" installation, you have to do it yourself.
 
 


Dosemu
The "dosemu" installation produces a directory structure in /var/lib/dosemu/, and we are particularly interested in these subdirectories:
/var/lib/dosemu/DosC
/var/lib/dosemu/drives
/usr/doc/packages/dosemu/
and in the file /etc/dosemu.conf wich contains the settings of dosemu.

/usr/doc/packages/dosemu/ contains dosemu documentation: reading QuickStart and consulting README.txt it's a good idea.
 
 


Partitions
If you are installing Linux on a new hard disk, it's a good idea to create a DOS partition (a few MB like 30/50MB is enough) in which you will install a real complete MS-DOS system (from MS-DOS 3.30 to 7.0) and your cross-compiler/assembler software. You will use this real partition in a dos box under Linux. If you still have a DOS partition with DOS installed, you can use it.

If you already have a Linux system and you don't have a DOS partition (or you don't want to have one), don't worry: after installing dosemu you will have to prepare a socalled 'bootdir'. This is a Linux directory under /var/lib/dosemu, which contains all you normally have in the native DOS partition. You may use the script ./setup-bootdir in /var/lib/dosemu to generate a /var/lib/dosemu/bootdir.first, which will be your "C:\" disk. In order to do this, you need to have a bootable DOS floppy, so prepare one before starting ./setup-bootdir. Then put the line

$_hdimage = "bootdir.first"

into your /etc/dosemu.conf and you can boot from this directory.

In this way you will have a complete DOS system on an ext2fs directory! It's exiting to see a DOS cross compiler running on a Linux machine, installed in a ext2fs directory, and compiling source code from a ext2fs directory!!! Maybe your compiler will never see a FAT16...

Please note that if you want to write files/directory in a such a created bootdir, you have to be its owner. Default owner of this bootdir is root, so you will have to change owner and group to you.
 
 


Free DOS
/var/lib/dosemu/DosC contains DosC, a free DOS kernel MS-DOS compatible. If you don't have a real MS-DOS partition on your hard disk, may be you can use this free DOS for installing your assemblers and compilers. I've never tried to do that. I recommend to use a MS-DOS version instead of FreeDOS, installing the MS-DOS files in one bootdir directory.
 
 
DOS Emulator Virtual Drives
/var/lib/dosemu/drives contains soft links to the DOS drives. Dosemu consider these links in alphabetical order, and assign each a "drive letter". That means that if I have in /var/lib/dosemu/drives the soft links:
c-system -> /mnt/dos//
d-document -> /mnt/documenti//
e-cdrom -> /cdrom//
f-freedos -> ../dosC/
means that my dosemu DOS session will have 4 drives: drive C will correspond to the mounted partition /mnt/dos, drive D will correspond to the mounted partition /mnt/documenti, drive E will correspond to the cd-rom drive, drive F will correspond to the /var/lib/dosemu/DosC directory. When you start dosemu, it will boot from the virtual "drive C", in my example it will boot from /mnt/dos.

Note this: you have to mount the drives and/or partitions from "Linux" if you want that dosemu can use them. The only exception to this rule is for floppy drives: you DON'T have to mount floppy drives for using them with dosemu. In my drives configuration, drive D (/mnt/documenti) is a phisical hard disk DOS partition containing all my documents, so that I can share them between Linux and MS-Windows. All my programs are saved in /mnt/documenti, so that when I use dosemu I can assemble and compile them accessing to drive D.

FAT16 and FAT32 don't have a good "permission" system as unix files systems have: if you mount a FAT16 or a FAT32 as root, only root will have access to these partitions. So it's better not to automount these partitions at Linux boot, and mount them as "user" afterwards.
 
 


Starting Dosemu and the assembler/compiler
Try to run dosemu typing "dosemu" on the command line. If you are running an X-console, try "xdos" from a terminal emulator. A black window will appear, and a DOS system will boot inside it, showing the classic DOS path C:/>. Create in /var/lib/dosemu/drives the soft-links to the partition or directories that you plan to use under dosemu (you have to do that as "root"), restart it, and try to access to that "virtual drives". Remember: you have to mount the partitions from Linux, first (if you have).

So, you have installed dosemu, and you have set the soft link drives. Now you have to install the cross-assemblers/compilers on your dosemu boot drive: do this directly from a dosemu session: start dosemu and do the cross-assemblers/compilers setup in the DOS window.

If your cross-assemblers/compilers need to use an hardware key, you must modify the parallel port access in /etc/dosemu.conf. Dosemu originally access the parallel port using Linux services, but your hardware key probably need a direct access. As root, open the file /etc/dosemu.conf and find the line:

$_ports = ""

then change it in:

$_ports = "device /dev/lp0 fast range 0x378 0x37f"

the last numbers must correspond to the BIOS parallel port settings.
 
 


Integrated Development Environment
What you need at this point is an "IDE" (Integrated Development Environment) or something that seems like that: a programmer's editor and a "make" utility.

If you normally use a DOS IDE, like KEIL IShell, you can go on using this IDE in a Linux DOS box. But I recommend to try a graphical editor.

If you usually use a Windows IDE, like KEIL uVision, unfortunately you can't continue using it under Linux... if you are really attached to your Windows IDE, you have to use Windows. There is not a good MS-Windows emulator for Linux at the moment (WMWare seems to work, but it's too heavy - and not for free!). But if you try out some programmer's editor for Linux, you will probably like them more than your original IDE!!


The Programmer's Editor
Linux offers a lot of really cool programmer's editor, you just have to browse in your distribution CD-ROMs and try out some of them. The unix fans often use Emacs. Emacs is more than an editor... many programmers think that Emacs is a little operating system (!). I think that Emacs is too much for my needs, and moreover it is not "graphical" (yes, there is a graphical version, but it's not in Emacs "tradition" to be graphical). I recommend to use a "graphical" editor: sincerly, I can't understand "vi" fans... :-)

I use Nedit (Nirvana Editor, http://www.nedit.org), and I think that it is a great programmer's editor. Also KWrite works good, but I prefer Nedit. What you problably will really need in the editor is the possibility to save source text files in the "DOS" format, which means using <CR><LF> when you press "enter". Unix systems text format use only <LF>, and may be that your compiler or assembler can't recognize it. For example, my compiler do works good also with unix text format, but my assembler do not works.

Both Nedit (5.1.1) and KWrite (0.9.0) support MS-DOS text format.


The MAKE utility
If you usually use a DOS MAKE utility, like KEIL AMake, you can go on using this in a Linux DOS box.

Otherwise, you can try out my own PRECMA MAKE51 utility for DOS, downloading it (for free) from this web site. You can also download source files, if you need them. It's a simple utility written in QuickBASIC 4.5 (not so much modern, I know...) that generates a set of BATCH files that can be used to compile, link and assemble your project. My MAKE51 utility is designed to be used with KEIL C51 and A51, but you can modify the source code to use it with other compilers/assemblers.
 
 


What's Next?
Now, what's next? You may want to use your simulator and/or your emulator under Linux. Well, I've never tried, because I use a Linux PC for programming and a different Windows PC for testing/simulating/emulating. Anyway, you can understand that if your emulator and simulator run under DOS, it's possible to make it run in a Linux dosemu box. If you have an emulator ISA board, may be you will have to change something in the /etc/dosemu.conf in order to have direct access to the ISA ports, as we have done for the parallel port and its hardware key.

If you have a simulator or emulator board with a Windows interface, I don't know how you will use it under Linux (sorry...). In case of an emulator board with serial interface (RS-232), you can consider to write a full communication program under Linux. If you are a C/C++ programmer, you will find that Linux is a great programming environment, and you can develop personally the interface for your emulator program. You obviously have to know the communication protocol of your emulation board, but I think that the manufacturer will be pleased to help you in such a work.


PRECMA S.r.l.
Cross Compiling
 8052 List 


Site made with Sworg - Simple Web Organizer
©Copyright 1998-Today PRECMA S.r.l.
All Rights Reserved - Copyright Notice