Any simple examples for LPC2148 out there?

So I would love if someone can post or email me a SIMPLE working project file that I can use to begin playing with the LPC2148? Either C or assembly would be fine.

I tried to use this project

http://www.olimex.com/dev/soft/arm/LPC/LPC2148_BUT.zip

but it doesn’t compile because the compiler cannot find these variables

IODIR0_bit

IODIR1_bit

IOPIN0_bit

IOSET0_bit

IOCLR0_bit

Using GOOGLE I cannot find these anywhere, and the IAR Embedded Workbench does not seem to have them either.

THUS, all I would like is something really simple, that I can build on. Thanks,

AH

The Olimex example is probably written for the gcc compiler, not IAR.

Leon

In my tutorial “ARM Cross Development with Eclipse”, there’s an appendix that shows how I modified a simple blinky example project from the LPC2106 to the LPC2148 (also taking advamtage of the faster IO port pins).

The tutorial can be downloaded here:

http://www.olimex.com/dev/pdf/ARM%20Cro … on%203.pdf

The sample source files can be downloaded from here:

http://www.olimex.com/dev/soft/arm/LPC/sourcecode.zip

O.K., it’s for the GCC toolkit, but maybe it will give you some inspiration.

Good luck,

Jim Lynch

Thanks Jim,

I actually got through your tutorial and I got your 2148 demo to work. However I have little experience using the GCC ARM programs.

  1. Can you or anyone explain what these lines from the MAKEFILE do?

arm-elf-gcc -I./ -c -fno-common -O0 -g main.c

arm-elf-as -ahls -mapcs-32 -o crt.o crt.s > crt.lst

arm-elf-ld -v -Map main.map -Tdemo2148_blink_flash.cmd -o main.out crt.o main.o

arm-elf-objdump -O ihex main.out > main.dmp

arm-elf-objcopy -O ihex main.out main.hex

  1. Also, the final output is a HEX file, but it is actually a TEXT file? I was surprised by this since I expected a binary file.

  2. Also, since this first example is so involved (many files involved), can this be done any simpler? Case in point, can this be done with only 1 file, or even in assembly. It would be nice to get even closer to the hardware and not have anyting hidden.

Thanks again Jim for creating the tutorial. It has at least got me programming the actual hardware.

Thanks,

AH

Hello,

  1. I’ll try to explain what the Makefile lines do:

arm-elf-gcc -I./ -c -fno-common -O0 -g main.c

arm-elf-gcc is the GNU C compiler for ARM

-I./ adds the current directory (./) to the search directories for include files

-c tells gcc to compile the file, but not to link

-fno-common tells gcc not to put uninitialized globals into common blocks, but into the data section. if the same global is declared in several files, without a prepending “extern”, you’ll get an error

-O0 disables optimization (good for debugging)

-g includes debug information in the output

main.c is the C file to be compiled

arm-elf-as -ahls -mapcs-32 -o crt.o crt.s > crt.lst

arm-elf-as is the GNU assembler for ARM

-ahls tells the assembler to create a listing with lots of information (put into crt.lst)

-mapcs-32 tells the assembler to use the ARM procedure call standard APCS-32. You have to use the same procedure call standard for all object files

-o crt.o tells the assembler to output into the file crt.o

crt.s is the source assembly file

crt.lst redirects all output to crt.lst (produced by -ahls above)

arm-elf-ld -v -Map main.map -Tdemo2148_blink_flash.cmd -o main.out crt.o main.o

arm-elf-ld is the ARM linker

-v outputs version information

-Map main.map tells the linker to output a map file with the used memory configuration, sections, globals, functions

-Tdemo2148_blink_flash.cmd tells the linker to use demo2148_blink_flash.cmd as the linker script

-o output everything into main.out (an ELF file)

crt.o main.o include these objects into the executable

arm-elf-objdump -O ihex main.out > main.dmp

arm-elf-objdump dumps information about ARM object files

don’t know where you got this line from, in my makefiles this looks different.

arm-elf-objcopy -O ihex main.out main.hex

arm-elf-objcopy is used to convert between file formats

-O ihex tells objcopy to output an Intel Hex file (a human-readable ascii file containing addresses and hex values)

main.out is the source file to be copied

main.hex is the destination file

  1. The reason for outputting a Hex file is that this is what the Philips flash tool expects. When using the OpenOCD (an open source jtag debugger, openocd.berlios.de, which coincidentally happens to be written by me ;)), you would have to output a plain binary file (-O binary), as this is what the OpenOCD expects.

  2. You can’t use less files (not without a loss of maintainability, readability and comfort). Similar files are being used by commercial ideas, you just don’t see what’s going on (or don’t have to look at it).

The crt.s is the startup file provides the exception vectors, and sets up the data/bss sections and the stack, giving you a environment where C code an execute. The header file contains definitions for the on-chip peripherals (you could do without this, but that would make the code less readable and less maintainable). main.c is the application itself. demo2148_blink_flash.cmd is the linker script, which tells the linker how the executable fits into target memory. The makefile is required to get everything together.

Actually, this is really close to the hardware - just look at the linker script and the startup file to see how the hardware is being initialized.

Regards,

Dominic

If I may add one additional thought to Dominic’s cogent and thorough analysis of the make file - you want to avoid writing assembly language for these modern RISC processors.

Some of the assembler addressing is dependent of where the current instruction is in the pipeline. For example, in the vector table within the assember file crt.s is the following bit of ARM magic.

ldr PC, [PC,#-0xFF0]

Specifically, the IRQ address is effectively 0x00018 + 8 (for the pipeline).

Subtracting 0xFF0 from this wraps-arouind and gives an address of 0xFFFFFF020 which is the vector address register that contains the address of the IRQ routine that should be run.

What are your chances of catching these kinds of nuiances when coding in assembler?

Let the machine do it! Get a boilerplate crt.s assembler startup file working and from that point onward, try to stick to C language. The compiler will usually write better assembler code than you can.

Cheers,

Jim Lynch

so, what is the code meant to do. I only have pin10 blinking.

Is that all that it does?

The purpose of the tutorial “ARM Cross Development with Eclipse” is to demonstrate how to put together an Eclipse-base ARM software development environment.

As such, I decided to make the example program as simple as possible, no interrupts, no use of the fancy onboard peripherials. Think of the example source code as the embedded version of “Hello World!”.

That’s all it does, blink a LED.

To do more, I’d have to write a bona fide book.

Cheers,

Jim Lynch

lynchzilla:
To do more, I’d have to write a bona fide book.

So, uh... What's the ETA on that?

[edit]: No, seriously. I mean, I would totally pay money. :slight_smile:

So, uh… What’s the ETA on that?

[edit]: No, seriously. I mean, I would totally pay money.

I agree that Jim would write a fine book! His attention to detail and his passion to help newbies are qualities that aren’t often matched.

But until Jim writes his book, did you check out the Hitex book in PDF form? This has examples for the Keil and gcc compilers. You can get the book here:

http://www.hitex.com/download/docs/lpc/

And the code samples are here:

http://www.keil.com/lpc/lpc2100_overview.asp

I also have some errata I put together from various posts in the yahoo forum, if anyone is interested.

Eric