EmbeddedRelated.com
Forums

Linker and startup file for LPC2387 / 88

Started by bartddgd January 20, 2013
Hi,

I'm new to the ARM world, but have used AVR and AVR32 MCUs before with GNU and IAR compilers. Right now I'm trying to get started in the ARM7 world using an already existing custom board that is populated with a LPC2387.

My tool chain is Yagarto + Eclipse and I have a Segger J-Link EDU and a Olimex ARM-USB-OCD-H available.

What I'm now looking for are linker control and startup files for the GNU compiler.

Any ideas where I can get such files?

Thanks in advance,
Bernd

An Engineer's Guide to the LPC2100 Series

Hi Bernd,

Welcome to the ARM world. As a quick note, the ARM7 architecture is slowly
superseded by the Cortex family for various technical reasons.

Yagarto and Eclipse are fine choices (we may see a flame war at some point
about Eclipse but it does the job). Note that you will need an additional
resource, which is OpenOCD to interface the Olimex JTAG probe to GDB.

There are several sources for your first steps:
http://ics.nxp.com/support/design/microcontrollers/ (I suspect that these
examples rely on the Keil compiler...)
https://www.olimex.com/Products/ARM/NXP/LPC-H2148/ (These may support
IAR...)
... and more that I can't find just now (http://www.lpcware.com may be
another one but it's down at the time of writing)

If you need a jump start, you can have a look at a zip file I put up in
http://www.gautherot.net/doku.php?id=firmware:homesample_lpc2148_project
It does not do much at all but you will find the basics of a Makefile, a
linker definition file, a sample boot strap with vectors table and a main
that invokes another function. It's not directly for the LPC2368 but the
LPC2148 may be close enough. This sample app has been generated by
CodeBlocks and modified to support an independent Makefile (included).

It may be wise to check how to disable the internal application and
activate the boot monitor before you play with the PLL. If all goes fine,
it's a no brainer but if you get it wrong, the CPU may stop responding...

Before you start hitting JTAG problems, this distribution includes a
.gdbinit file that performs a couple of tricks (comments in parenthesis):
target remote localhost:3333 (Connection to OpenOCD)
mon adapter_khz 100 (Proved to be necessary on a chip running
off the default internal clock)
mon reset init (Make sure the CPU stops before you
start playing with it)
load (Load the program)
mon reset halt (I suspect "load" will start the
execution...)
mon mwb 0xE01FC040 1 1 (Check if the MEMMAP register is at the same
location and activate the user Flash)
b main (Make sure it will stop somewhere
useful...)
c (Resume execution until the
breakpoint)

I'm not sure whether all is needed but the command "adapter_khz 100"
happened to be what revived my board (at some point, I thought it was
dead...)
Hope it helps
--
Olivier Gautherot
o...@gautherot.net
Cel:+56 98 730 9361
www.gautherot.net
http://www.linkedin.com/in/ogautherot
On Sat, Jan 19, 2013 at 5:44 PM, bartddgd wrote:

> **
> Hi,
>
> I'm new to the ARM world, but have used AVR and AVR32 MCUs before with GNU
> and IAR compilers. Right now I'm trying to get started in the ARM7 world
> using an already existing custom board that is populated with a LPC2387.
>
> My tool chain is Yagarto + Eclipse and I have a Segger J-Link EDU and a
> Olimex ARM-USB-OCD-H available.
>
> What I'm now looking for are linker control and startup files for the GNU
> compiler.
>
> Any ideas where I can get such files?
>
> Thanks in advance,
> Bernd
>
>
>


My CMAKE scripts project generate automatically linker scripts and
makefiles for
LPC23xx and LPC24xx MCU. Also there is a lot of sources and examples with
my sources
so I hope you can use some of them.
2013/1/20 bartddgd

> **
> Hi,
>
> I'm new to the ARM world, but have used AVR and AVR32 MCUs before with GNU
> and IAR compilers. Right now I'm trying to get started in the ARM7 world
> using an already existing custom board that is populated with a LPC2387.
>
> My tool chain is Yagarto + Eclipse and I have a Segger J-Link EDU and a
> Olimex ARM-USB-OCD-H available.
CMAKE can generate project files for Eclipse and Codeblocks.

--
CMake build environment project
for micro-controllers (use
it or
addyou
favorite MCU )


2013/1/21 Olivier Gautherot

> Hi Bernd,
>
> Welcome to the ARM world. As a quick note, the ARM7 architecture is slowly
> superseded by the Cortex family for various technical reasons.
Any way the LPC2378 is a not bad Controller to start with ARM. You could
easy migrate to Cortex LPC1768 after that because it is pin to pin
compatible and it is possible to write MCU independent source because
Peripherals register is the same (about 95%) as it in LPC1768

--
CMake build environment project
for micro-controllers (use
it or
addyou
favorite MCU )


Thanks guys for your support so far!

I've got Yagarto + Eclipse working. Makefiles and linker scripts have been adjusted for the LPC2387 board that I and the code compiles and links without any error.

Next step will be to test out flash programming and debugging with OpenOCD and J-LINK EDU.

The first sample code will be just an port pin toggle in the main while() loop. When this works I'll check out the timer interrupt for port pin toggle.
Best regards,
Bernd

Hi again,

I've made a lot of progress during the last days. PLL is working, I have a basic timer interrupt running and can even send CAN messages.

In the meantime I've also switched to Code::Blocks as my IDE. So far I've used the internal UART boot loader and FlashMagic to program my target MCU.

Now I'm trying to get JTAG programming and debugging to work. As JTAG adapter I use a Segger JLINK EDU. Flashing works fine, but debugging always fails :-(

In the "Before connection" field of the GDB config in Code::Blocks I have:

file ./obj/lpc2387_88_test.elf
set mem inaccessible-by-default off
target remote localhost:2331
monitor flash device = LPC2387
monitor flash breakpoints = 1
monitor flash download = 1
monitor endian little
monitor speed auto
monitor reset
monitor long 0xE01FC040 = 1
load

The "After connection" field contains:

monitor reset
thbreak main
continue

My program gets upload and starts running if I remove the "thbreak main" line. If I leave this line in, the program gets uploaded and even seems to stop at main(), but from that point on no other debug function in Code::Blocks work. All the stepping options are greyed out and I cannot terminate the debug session. I have to close and restart Code::Blocks and the Segger GDB server.

Any ideas how to get debugging to work in Code::Blocks?

Best regards,
Bernd

Let me answer my last question by myself. I asked a similar questions in the Code::Blocks Embedded forum and got some quick response how to do it correctly.

The "Before" commands for GDB now look like this:
file ./obj/lpc2387_88_test.elf
set mem inaccessible-by-default off
monitor flash device = LPC2387
monitor flash breakpoints = 1
monitor flash download = 1
monitor endian little
monitor speed auto
monitor reset
monitor long 0xE01FC040 = 1
load
monitor reset

Note that esp. the line "target remote localhost:2331" line is gone. These parameters must instead be configured in the "Remote connection" tab of the GDB projects settings.

Since this change I can debug, single step and watch variables in Code::Blocks.

Best regards,
Bernd

I guess I you should move all strings to after connection.

afterconnection= before connection + after connetction

2013/3/3 bartddgd

> **
> Hi again,
>
> I've made a lot of progress during the last days. PLL is working, I have a
> basic timer interrupt running and can even send CAN messages.
>
> In the meantime I've also switched to Code::Blocks as my IDE. So far I've
> used the internal UART boot loader and FlashMagic to program my target MCU.
>
> Now I'm trying to get JTAG programming and debugging to work. As JTAG
> adapter I use a Segger JLINK EDU. Flashing works fine, but debugging always
> fails :-(
>
> In the "Before connection" field of the GDB config in Code::Blocks I have:
>
> file ./obj/lpc2387_88_test.elf
> set mem inaccessible-by-default off
> target remote localhost:2331
> monitor flash device = LPC2387
> monitor flash breakpoints = 1
> monitor flash download = 1
> monitor endian little
> monitor speed auto
> monitor reset
> monitor long 0xE01FC040 = 1
> load
>
> The "After connection" field contains:
>
> monitor reset
> thbreak main
> continue
>
> My program gets upload and starts running if I remove the "thbreak main"
> line. If I leave this line in, the program gets uploaded and even seems to
> stop at main(), but from that point on no other debug function in
> Code::Blocks work. All the stepping options are greyed out and I cannot
> terminate the debug session. I have to close and restart Code::Blocks and
> the Segger GDB server.
>
> Any ideas how to get debugging to work in Code::Blocks?
>
> Best regards,
> Bernd
>
>
>

--
CMake build environment project
for micro-controllers (use
it or
addyou
favorite MCU )