8052 Development for Linux Users
8052 Development for Linux Users
This page is dedicated to the development of 8052 software and hardware
using Linux tools.
After a lot of research I have found a basic set of tools and hardware that
is suitable for 8051 development under Linux.
Hardware #1
An important criteria for hardware selection is ease of
programming via a standard port. There are now many 8051 variants with flash code memory
and most allow ISP (In System Programming) via the serial port. However,
many require special waggling of lines which is difficult without special hardware and PC
software. In addition, many use a unique language to communicate with the 8051 which
would have entailed a lot of programming effort.
After a lot of research I finally came across a series of Philips 8051 variants which
can be programmed via the serial port and use standard Intel Hex files, not only for data
transfer, but also for sending commands to read or erase parts of the flash memory for
example. Development boards for this range of 8051 variants is available from
Kanda in the UK. Their 51 Starter Kits can be fitted
with either a Philips P89C51RB2(H), P89C51RC2(H), P89C51RD2(H), P89C660, P89C662, P89C664,
P89C668 or XA-G49 devices which will cover most development needs with up to 64K flash.
The device features are summarised in the table below.
| Device |
Flash |
RAM |
OSC |
Timers |
PCA |
I2C |
Watch Dog |
Notes |
| P89C51RB2(H) |
16K |
512 |
20MHz |
3 |
Y |
N |
Y |
6 clock instruction cycle |
| P89C51RC2(H) |
32K |
512 |
20MHz |
3 |
Y |
N |
Y |
ditto |
| P89C51RD2(H) |
64K |
1K |
20MHz |
3 |
Y |
N |
Y |
ditto |
| P89C660 |
16K |
512 |
20MHz |
3 |
Y |
Y |
Y |
ditto |
| P89C662 |
32K |
1K |
20MHz |
3 |
Y |
Y |
Y |
ditto |
| P89C664 |
64K |
2K |
20MHz |
3 |
Y |
Y |
Y |
ditto |
| P89C668 |
64K |
8K |
20MHz |
3 |
Y |
Y |
Y |
ditto |
| XA-G49 |
64K |
2K |
30MHz |
3 |
N |
N |
N |
16 bit XA architecture, 1MByte address space |
Hardware #2
Another useful development board is supplied by New
Micros Inc. Their basic 8051 development board, the NMIY-0031, is very cheap at just USD39
and even with the additional 4x40 LCD, 4x5 keypad, serial cable and power supply is still
only USD99. It comes with a very basic 8051 but you can substitute other 44 pin PLCC types,
including the Philips types mentioned above. Instead of using flash programming it has an
on board monitor program in EPROM and a 32K SRAM into which you can download your applications.
The monitor communicates with a PC via a standard RS232 serial link. The supplied monitor
program is a little quirky and cannot be used with a standard PC based terminal program. Instead, New
Micros supply both DOS and Windows terminal emulators specifically designed to work with their monitor. Why
manufacturers do this I have no idea. It certainly makes life difficult for anyone who wants
to use a platform other than DOS or Windows. For the Linux solution to this, see Software #2
below.
Software #1
For software we need a minimum of two programmes; an assembler to create Intel hex files
from source code and a terminal programme to control the development board. There are quite
a few 8051 assemblers that run under Linux. The one I prefer is
ASEM-51, a straightforward command line assembler
which adheres closely to the original Intel assembly standard. It is fast, flexible and accurate.
Last but not least we need a terminal programme which can be used to control the
development board and download code to it. For this I have chosen
gtkterm which is a straightforward
Linux terminal programme that has two key features. First it can communicate not only with
standard serial ports but also with USB ports. This was particularly important to me
because my laptop does not have a serial port so I use a USB to serial adaptor to
connect to the development board. Second it can send raw files straight out the serial
port. This very handy as all the standard commands like erase a block, dump a block or
set a status byte, can be invoked simply by sending pre-written files.
To help other Linux users the table below lists the commands I have already coded
into Intel Hex files.
The normal way to use these files is as follows:
- Connect the development board serial link to a PC
- Run gtkterm and set the port parameters. You can usually run at a
baud rate of 56K without problems
- Power up the development board and set it to ISP mode
- Send capital U from gtkterm. If all is well the U will be echoed
by gtkterm
- Set the clock to 20MHz. This ensures the 8051 uses the correct timing for
flash programming
- Erase block 0
- Send the Intel hex file of your programme
- Dump memory to make sure the flash programming has been successful
- Erase the boot vector and status byte
- Set boot vector back to FCH so that later you can get back into ISP mode
- Press the reset button on the development board and your programme should be running
Software #2
Some development systems will not work with a standard terminal emulator like gtkterm
because they have special requirements. The New Micros monitor, for example, expects the
terminal to wait for the monitor to echo the last character sent before sending another.
Commonly available terminal emulators just do not have this facility so I have written a very
simple one just for the NMI monitor. It is written in Tcl/Tk and can be downloaded from
here. As it is written in Tcl/Tk you need to have this
installed (it is standard in most Linux distros). If you are not sure if you have it just
type wish at a command prompt and a small window should appear.
On mosts sytems, regular users
do not have read/write permissions to serial ports so you will most likely need to run
nmiterm.tcl as root. After downloading it, make sure it is executable by typing chmod +x
nmiterm.tcl after which you can invoke it just by typing ./nmiterm.tcl. When it starts you
first need to set the com port under the Configure menu. The device currently defaults to
/dev/ttyUSB0 which is what I needed for my laptop. You need to change this to whatever
device name is appropriate for your system. The paramters 9600,n,8,1 should not be changed;
they are defined by the NMI monitor program. I made them editable so the terminal could
be used with other monitors. Once the terminal is configured you should power up the NMI
board and you should see the welcoime message on the terminal window. You should then press
the caps lock key, as all the NMI monitor commands begin with capital letters, and press
H which should make the monitor list its commands.
The biggest problem I had was downloading Intel Hex files to the board. As it always
echoes each character sent and waits until the character has been sent back before
processing the character, it soon gets left behind if you try to send it a file. So my
terminal emulator waits for each character to be echoed before it send the next one.
To load an Intel Hex file press L (for the load command) then from the file menu select
Send Raw File from the File menu. Select a file, click OK and it will be sent to the
NMI board, with the results of the transfer shown on the terminal screen
Real Time on the 8051
Erik and I have had some lively discussions about Real Time on the 8051. We both feel that
an RTOS on the 8051 is inappropriate but I am of the view there is much we can learn from
the technniques used in an RTOS in building better 8051 systems. So I have started a page
about this topic. It is currently under construction and subject to change but if you are
interested have a look here.
Links
Here are a few links to other 8051 related Linux pages.
If you are interested in 8052 development under linux please
contact me.
This page last modified 22nd October 2005