8051 and ARM microcontrollers
The microcontroller type I have mostly used is a derivative of the Intel 8051
microcontroller. There are several free and commercial C and
Assembler compiler on the market. To name a few I can mention these
I have used Sdcc and ASEM-51 myself. Sdcc is a C compiler and now I
have stopped using Assembler except for very simple time demanding
codes. The assembler code for Sdcc and ASEM-51 is unfortunately not
compatible.
Raisonance and Keil are expensive integrated
development environments that have free trial version. However, these
are exclusively Windows programs. I have run both Raisonance and
Keil under Wine but it was problematic. I will test again and write
about the result.
8052 is a
derivative or an enhanced version of the Intel 8051 version with extra
hardware like larger RAM, extra timer, hardware UART or I2C bus. There are many different versions of the 8051 with different addons.
I have mostly used the P89C668
version from NXP (former Philips semiconductors). This particular
version is not recommended for new designs but all the information is
applicable to for example the P89V664 wich has 2KB of RAM instead of
8KB.
To upload programs I use my own simple utility called progphil. Currently only the P89C66x controllers are supported.
ARM microcontroller
I bought an LPC-2148-R2 development board from Olimex. It is a surplus production, marked IAR.
I got the IAR CD with the package but no JTAG connector with it.
I did not find out how to use the IAR tools without a JTAG connector
and so far I cannot afford one nor the IAR tools. Therefore I shifted
to the Open Source tools.
The development is powered by the computers USB cable (you have to
change a jumper setting). The serial cable is used to program the
device.
The best thing to start with is the following page.
There is a thorough description from Bdale Garbee on how to install the
gcc compiler for ARM devices on Debian. The same description with minor
changes can be found here. I don't use sudo and there are new versions of the tools available.
The source code can be downloaded with the command line program lpc21isp. You have to join the group to be able to download the program.
To program the device do the following: Move the blue switch to "ON",
then press the small (reset) button above and then use the following
command to upload the program file:
$ lpc21isp -control test.hex /dev/ttyS0 <baud rate> <clock crystal in kHz>
The -control option is needed. I haven't been able to run the program
with higher baud rate than 38400. I have tested it with 9600, 19200,
38400 but it doesn't work with 57600 and above. To run the program,
move the switches to "OFF" position and then press the reset button
again.
I found some example programs at the Olimex
homepage, that I cannot find anymore and did not compile with gcc but
they could be changed quite easily. I made a tar file with three example programs. The following programs are supplied:
-
rs232. This program answers every character from the serial port with the same character followed by '*'.
-
lcd. Writes 'Hello World' to the LCD display of the development board.
-
adc. Reads the voltage of the potentiometer and writes it to the LCD.
It contains the following files
To compile the program just type
$ make
To install it, put both blue switches to ICPS. Then press RST and finally run
$ lpc21isp -control main.hex /dev/ttyS0 38400 12000
Move the switches to RUN and open a terminal program like gtkterm. There is a problem with gtkterm. It cannot read '\0' and if it gets a '\0' input, then the following bytes may be scrambled.
Writing a makefile isn't as simple as for normal Linux programs since a
linker script must be written. The linker script must contain
information about the memory layout of the microcontroller. The
original linker script from the Olimex source fails when using the
sprintf function.
Now I have bought an LPC-H2148 header board from Olimex and an ARM-USB-TINY-H,
high speed JTAG connector. There is an open usbstack at sourceforge
called lpcusb that works nicely on the lpc2148. There was a wiki page
attached to it but it has been down for some time. I recommend that you
get the svn version:
svn co https://lpcusb.svn.sourceforge.net/svnroot/lpcusb lpcusb
because it contains a benchmark program for the. It can be compiled on Debian with the following makefile (I have renamed the c file from main.c to benchmark.c).
You need to install libusb-dev, apt-get install libusb-dev.
Uwe Hermann has packaged
openocd for Debian (many thanks), he also has good explanations on how
to set upt the arm toolchain on Debian/Ubuntu.
apt-get install openocd.
I managed to program my device with the following command:
$ openocd -f lpc2148.cfg -f olimex-arm-usb-tiny-h.cfg -c init -c "mt_flash custom.hex"
where olimex-arm-usb-tiny-h.cfg is the original file from openocd but lpc2148.cfg is slightly changed.
The programming ends with a lot of error messages but it works and the output of the benchmark program is:
# ./benchmark
Testing blocksize 64
* read : 95872 bytes in 3001 ms = 31 kB/s
* write: 96000 bytes in 3001 ms = 31 kB/s
64,95872,3001,64,96000,3001
Testing blocksize 128
* read : 192000 bytes in 3002 ms = 63 kB/s
* write: 192128 bytes in 3002 ms = 64 kB/s
128,192000,3002,128,192128,3002
Testing blocksize 256
* read : 383744 bytes in 3002 ms = 127 kB/s
* write: 384256 bytes in 3002 ms = 128 kB/s
256,383744,3002,256,384256,3002
Testing blocksize 512
* read : 767488 bytes in 3002 ms = 255 kB/s
* write: 768000 bytes in 3002 ms = 255 kB/s
512,767488,3002,512,768000,3002
Testing blocksize 1024
* read : 1026048 bytes in 3001 ms = 341 kB/s
* write: 1026048 bytes in 3001 ms = 341 kB/s
1024,1026048,3001,1024,1026048,3001
Testing blocksize 2048
* read : 1048576 bytes in 2046 ms = 512 kB/s
* write: 1048576 bytes in 2046 ms = 512 kB/s
2048,1048576,2046,2048,1048576,2046
Testing blocksize 4096
* read : 1048576 bytes in 1540 ms = 680 kB/s
* write: 1048576 bytes in 1540 ms = 680 kB/s
4096,1048576,1540,4096,1048576,1540
Testing blocksize 8192
* read : 1048576 bytes in 1406 ms = 745 kB/s
* write: 1048576 bytes in 1406 ms = 745 kB/s
8192,1048576,1406,8192,1048576,1406
Testing blocksize 16384
* read : 1048576 bytes in 1335 ms = 785 kB/s
* write: 1048576 bytes in 1335 ms = 785 kB/s
16384,1048576,1335,16384,1048576,1335
By the way. You need to run the program as root but by adding a lpc2000.rules file to /etc/udev/rules.d it can be run if by members of the iocard group.
Last modified: 2010-05-16