LPC-P2148 "The big getting started guide"

Boys & Girls,

The reason why i start this topic is because i’m a real newbie in the world of ARM/LPC and i’m having a bit trouble to get started here. Hopefully the info posted here will be of help for me and other (noobs) like me :lol:

So i got the LPC-P2148 in the mail today and after hooking it up to the power it started bleeping and led’s started blinking all shiny and stuff and even the buttons work :smiley:

And now?

In a post prior to this I found out there are 2 ways of programming this sucker.

1: JTAG (well its underway, i hope)

2: Simple RS232

I would like to fiddle around a bit with the code which is already on the chip. I found the demo code “board peripherials demo code” and after unpacking finally something familiair… C code :wink:

So i have Crossworks for ARM 1.7 from a friend to start expirimenting but this is where i get stuck. I installed the LPC2xxx support libs and this is where my story ends.

The question i have:

For now i need to use the rs232 for programming but how do i set this up in Crossworks (or another tool)?

Plug a serial cable in PC and connect it to RS232_0??

Any sugestions are welcome.

Cheers,

Ernst

Get FlashMagic, if you want to load code via RS-232. You will need to create a hex file with CrossWorks.

Leon

OK so i started a new project in crossworks using the “Generic LPC21XX” option and selected "executable in the right pane.

I left the oscilator at 12MHz and the lpc2148 as the target processor.

After opening the main.c file from the “board peripherials demo code” and hitting (shift-F7) it pops up with an error:

Build solution — 78 ms — 1 error
  Building “base” in configuration “ARM Flash Debug” — 1 error
    Linking base.elf — 1 error
      ARM Flash Debug/crt0.o: In function `memory_set':
      C:/Program Files/Rowley Associates Limited/CrossWorks for ARM 1.7/source/crt0.s:303: undefined reference to `main'
Build failed

Now the compile option is available and if i hit that it says “compile succesful”

In the target dir D:\ARM\RTC i see 2 dir’s “ARM Flash Debug” & “ARM Flash release”. There are some .o and .d files but no .hex here.

What am i missing here?

You select Linker options in the Project Properties and set Additional Output Format to hex.

You also need to enable Startup_from_Reset. Details are on the Rowley web site.

Leon

KidE:
So i got the LPC-P2148 in the mail today and after hooking it up to the power it started bleeping and led’s started blinking all shiny and stuff and even the buttons work :smiley:

On my site you'll find some nice simple newb C programs for the LPC-P2148. I did them with Crosswork, though I'm using Eclipse/yagarto now. Link at bottom of message.

Have a look at some of the Sparkfun widgets. Lots of them use the LPC2148 and can give you a good idea of how things work.

Products like the Logomatic, KinetaMap, PackageTracker etc.

futz:
On my site you’ll find some nice simple newb C programs

Ok thx futz, i found the “enoying bleeping one”.

So i open a new project, select the “generic LPC2148 board”, set the additional output to hex (tnx Leon) and we are cooking.

I see in 1 of the screens that a lot of LPC201x files are linked to the project. Doesnt this clash with the LP214x.h file from “keil.com”? doing this in the Linux kernel world will most certain give you problems.

After creating a main.c and pasting in the code it gives an error when i try to compile:

Build solution — 78 ms — 6 errors
  Building “ledbeep” in configuration “ARM Flash Debug” — 6 errors
    Compiling main.c — 6 errors
      D:/ARM/PROJECTS/ledbeep/main.c: In function 'init':
      'PLLCFG' undeclared (first use in this function)
      (Each undeclared identifier is reported only once
      for each function it appears in.)
      'PLLFEED' undeclared (first use in this function)
      'PLLCON' undeclared (first use in this function)
      'PLLSTAT' undeclared (first use in this function)
Build failed

Looking into the lpc214x.h file i found

/* Phase Locked Loop 0 (PLL0) */
#define PLL0CON         (*((volatile unsigned char *) 0xE01FC080))
#define PLL0CFG         (*((volatile unsigned char *) 0xE01FC084))
#define PLL0STAT        (*((volatile unsigned short*) 0xE01FC088))
#define PLL0FEED        (*((volatile unsigned char *) 0xE01FC08C))

/* Phase Locked Loop 1 (PLL1) */
#define PLL1CON         (*((volatile unsigned char *) 0xE01FC0A0))
#define PLL1CFG         (*((volatile unsigned char *) 0xE01FC0A4))
#define PLL1STAT        (*((volatile unsigned short*) 0xE01FC0A8))
#define PLL1FEED        (*((volatile unsigned char *) 0xE01FC0AC))

After changing all the PLL to PLL0 it compiled without a problem.

futz: this was the idea though?

To see if i could programm i started Flash magic and selected the correct comm port and set the BD to 9600

ehmm nothing except an error that says:

“Operation failed. (failed to autobaud - step 1)”

I checked google but no luck so far. I checked the comm cable connected to RS232_0 and that one is working ok.

Are there any jumpers on the board that i need to switch form normal to programming mode because i cannot find anything about that.

But anyway i’m at least 1 step closer :lol:

There should be a jumper for P0.14. That pin enables the on-chip boot loader when it is held low during reset.

Leon

If i check P0.14 in http://www.olimex.com/dev/images/ARM/LP … -D-sch.gif i see it’s not connected and comes out as a breakout pin at the side of the board.

In the upper left corner there is a blue jumper block with 2 switches http://www.olimex.com/dev/lpc-p2148.html which says RUN and ICSP.

I found out that ICSP is the programmer setting but if i power off the board and set sw1 in ICSP nothing changes

Perhaps they forgot to connect it. The P0.14 net is marked BSL, which means that it’s intended for boot loading.

If it isn’t connected you will either have to modify the board or use a JTAG I/F. The Embedded Artists boards have jumper options to connect P0.14 and RESET to RTS and DTR on the RS-232 connector so that they can be controlled by FlashMagic. It’s a much better way to do it.

Leon

i’ve send a mail to olimex explaining the problem to find out if it is even possible to program it via RS232. I’ll keep you posted.

KidE:
i’ve send a mail to olimex explaining the problem to find out if it is even possible to program it via RS232. I’ll keep you posted.

Oh! You're trying to program the Olimex LPC-P2148 with the bootloader? Easy! :p
  1. Plug your RS232 cable into UART0.

1a. Set your programming software to 9600 baud.

  1. Power cycle the board (just in case). That means pull the power plug and plug it back in. Usually not necessary.

  2. Move DIP switch #1 into the ON position (leave #2 off). On is toward the RS232 plug.

  3. Press the reset button once or twice.

  4. Program away.

  5. When done programming/verifying or whatever you want to do, just switch DIP #1 back to off and push the reset button again. Your program should run.

KidE:
If i check P0.14 in http://www.olimex.com/dev/images/ARM/LP … -D-sch.gif I see it’s not connected and comes out as a breakout pin at the side of the board.

Look again. See how P0.14 is labeled BSL where it ends by the chip in the schematic. Now look up by the reset switch and the DIP switch. Look just below R11 and you'll see a stub labelled BSL. That's where BSL goes to. DIP switch #1 pulls P0.14 low for bootloader operation.

On bigger schematics like that it gets very difficult to show all the lines, so they make some invisible (or bus them - see P1 and the JTAG on the left). If you’re viewing the original in Eagle you can show those invisible wires or turn them off.

I got a Olimex ARM-USB-OCD today so after installing the cd and running the demo from eclipe i decided to run the demo program from Futz

After creating a new project and started the debugger i got the following error

Info:    openocd.c:93 main(): Open On-Chip Debugger (2007-09-05 09:00 CEST)
Error:   embeddedice.c:181 embeddedice_build_reg_cache(): unknown EmbeddedICE version (comms ctrl: 0x80000000)
Error:   armv4_5.c:186 armv4_5_mode_to_number(): invalid mode value encountered
Error:   arm7_9_common.c:1075 arm7_9_debug_entry(): cpsr contains invalid mode value - communication failure
Error:   target.c:1157 handle_target(): couldn't poll target, exiting

Now even the demo doesnt work anymore and gives the same error when i debug it.

help

After poking around in the JTAG config i figured that i had to set the JTAG speed to 3 instead of 2 to connect in a good way.

The blinking led software is up & Running.

KidE:
After poking around in the JTAG config i figured that i had to set the JTAG speed to 3 instead of 2 to connect in a good way.

The blinking led software is up & Running.

With Crossworks my USB-ARM-TINY won't even connect unless I set the JTAG divider to 4. No lower. Your machine may vary, of course.

I also had to set nTRST Open Drain to No.

i played around now with eclipse and somehow i find it more natural to work with so i think i’ll stick to that.

I tried to build your LED buzzer thing with LPC210x.h but that is givving some problems which i have to dig into. Atleast i have the first code working and that is a real relief :wink:

I was wondering a few things and maybe you can give me an awnser to this.

If i want to test my code in eclips to see if i written it correctly. Normally this would be done by debug but debug also writes the code diretcly to the chip. Is there a way to debug it without directly writing the code?

You talked about the bootloader a few post back. Is it normal that you always use the bootloader or are there also different ways to use this chip?

Is there a way to debug the chip to see what it is doing or going wrong in some points. I figure this is what JTAG is for but how do you see these messages. I read something about UART logging am i right/\

On http://jcwren.com i found an enormous bunch of demo code for my board so this give me together with your stuff a bunch of work for the next year.

Tnx a lot upfront

ARM chips are usually debugged and programmed with a JTAG interface. I have a design for a parallel port I/F if you want to build your own.

Leon

leon_heller:
ARM chips are usually debugged and programmed with a JTAG interface. I have a design for a parallel port I/F if you want to build your own.

Ya, but who has a parallel port anymore? Only the oldest klunkers here in the swamp have parallels, and I don't use those old machines for programming (I hardly use them at all). I'm too impatient! :mrgreen:

KidE:
i played around now with eclipse and somehow i find it more natural to work with so i think i’ll stick to that.

Really? I really loved Crossworks for ARM, but I wanted to have a go at getting Eclipse/yagarto/OpenOCD working (and save $150 in the process), so I did. :mrgreen:

I tried to build your LED buzzer thing with LPC210x.h but that is giving some problems which i have to dig into.

Why don't we get on the same page here. Grab "my" (not really mine - I downloaded it from somewhere) [[LPC214x header file](http://ghmicro.com/images/junk/LPC214x.rar). It has worked just fine since I started out.

If I want to test my code in eclipse to see if i written it correctly. Normally this would be done by debug but debug also writes the code directly to the chip. Is there a way to debug it without directly writing the code?

I think there's a simulator mode, but I really am not sure. I almost never use sims because, really what's the point if you have the chip sitting right there :roll:, so I just didn't care to look into it. If you find one and figure out how to use it, tell me! :mrgreen:

Or maybe you mean to debug the same code without writing it to the chip again, maybe in a second session or something? Yes, you can do that too. Just do a debug with the usual init script

target remote localhost:3333
monitor arm7_9 force_hw_bkpts enable
monitor reset
#set MEMMAP to User Flash Mode
monitor mww 0xE01FC040 0x0001
monitor flash write_image erase c:/gccfd/projects/rtc_clock/rtc_clock.bin
break main
monitor soft_reset_halt
continue

but leave out (or comment out) the “flash write_image” line.

You talked about the bootloader a few post back. Is it normal that you always use the bootloader or are there also different ways to use this chip?

The built-in bootloader is for loading your code through the RS232 port. I rarely do that. I'm too impatient, and I need debugging, so JTAG it is. You can also add a [[USB bootloader](http://www.sparkfun.com/commerce/tutorial_info.php?tutorials_id=94) and use that. Again, no debugging - only very fast program loading.

But you have a JTAG dongle. Why would you even care about bootloaders? JTAG is fast and does debugging. Best of both worlds.

Is there a way to debug the chip to see what it is doing or going wrong in some points. I figure this is what JTAG is for but how do you see these messages.

Yes, that's what JTAG is for. If you aren't using it for debugging then using JTAG is kinda pointless.

If you’re using Eclipse and yagarto (or other GCC toolchain) just dig thru the docs for gdb documentation. Eclipse has a few icons for simple single-stepping and other very basic debug commands, as well as register & variable and memory views, but to really use gdb you need to know and type in the commands. Make a cheat sheet - there’s a lot of them.

You’ll find Eclipse debugging very flaky and buggy compared to Crossworks. But once you get used to it it’s not so bad. You just have to learn where the bugs and weirdnesses are and work around them.

Guess I should make a Eclipse/yagarto/OpenOCD debugging beginner page on my site one of these days…

I read something about UART logging am i right?

I have no idea what UART logging is. Never heard of it.

On http://jcwren.com i found an enormous bunch of demo code for my board so this give me together with your stuff a bunch of work for the next year.

Ya, that's a nice collection. I downloaded it all, but haven't looked at it yet. I prefer to figure it out on my own if possible. Sticks better that way. :mrgreen:

I currently have the RTC doing a clock on my LCD. It’s still in the rough stages. When I get a bit further along I’ll post the article on my site. The RTC is ultra simple to use without interrupts. With interrupts it becomes slightly less simple but much more useful. That’s next for me. Polling just isn’t going to cut it for this project.](http://www.sparkfun.com/commerce/tutorial_info.php?tutorials_id=94)](http://ghmicro.com/images/junk/LPC214x.rar)