Embedded Freaks..

September 18, 2010

Running the BootROM for LPC32xx using JTAG-GDB

Filed under: ARM9, embedded-tips — Tags: — kunilkuda @ 6:06 pm

I’m using Segger J-Link with GDB server (free for personal use and evaluation) and Phytec3250. I have a program that’s needed to be run after the bootloader has been run (because the program doesn’t have all kind of initializations: SDRAM, MMU, etc).

Here’s a tip to debug the application that’s needed to be run ‘after‘ the bootloader has been loaded and run.

  1. Connect the J-Link into the JTAG port. Run the GDB server, and make sure that your ARM core is recognized. Set the JTAG speed if necessary.
  2. From command prompt, type:
     d:\> arm-none-eabi-gdb your_application.elf 
  3. Then connect your GDB with the board:
     (gdb) target remote localhost:2331

    You may need to change the port number (‘2331’ in my case) according to your GDB port no.

  4. Now, this one is LPC32xx specific, but may applicable to other ARM MCU as well.The LPC32xx has BOOT_MAP register to control which memory that is mapped in 0x00. If BOOT_MAP = 0, the LPC32xx internal ROM (contains the boot code to load the bootloader from NAND flash) will be loaded into address 0x00. If BOOT_MAP = 1, the LPC32xx internal SRAM will be loaded into address 0x00.Since we want to run the bootloader (inside the NAND flash), we want to have BOOT_MAP = 0. To check the BOOT_MAP value
     (gdb) x/1w 0x40004014
    0x40004014:     1

    To change the BOOT_MAP value:

    (gdb) set *(unsigned int*) 0x40004014=0

    Then we can check BOOT_MAP value again with:

    (gdb) x/1w 0x40004014
    0x40004014:     0
  5. The next step is to reset the MCU using JTAG:
    (gdb) mon reset
    Resetting target
  6. After that, you can run the bootloader with:
    (gdb) cont
  7. Usually, on normal debug (debugging application without JTAG), I will wait until bootloader boots (come out with prompt, like ‘uboot>’ or ‘phy3250>’) then I run bootloader command to load my application into SDRAM. But using JTAG, once the bootloader prompt appears, I can stop the bootloader execution and load my application directly into SDRAM
    <ctrl+c pressed>
    Program received signal SIGTRAP, Trace/breakpoint trap.
    0x0000c138 in ?? ()
  8. Then load my application with
    (gdb) load
    Loading section .text, size 0xc64 lma 0x80000000
    Loading section .text.dummy_delay, size 0x4 lma 0x80000c64
    Loading section .text.term_dat_recv_cb, size 0x60 lma 0x80000c68
    Loading section .text.term_dat_send_cb, size 0x74 lma 0x80000cc8
    Loading section .text.term_dat_out, size 0xac lma 0x80000d3c
    Start address 0x80000000, load size 9269
    Transfer rate: 11 KB/sec, 174 bytes/write.
  9. Ok. Now I can set up the break point and start debugging my application
    (gdb) break c_entry
    Breakpoint 1 at 0x80000f40: file adc_example.c, line 346.
    (gdb) cont
    Breakpoint 1, c_entry () at adc_example.c:346
    346         disable_irq_fiq();


  1. Tried OpenOCD to drive Segger J-Link and GDB under Linux, but could not get OpenOCD configured properly. By the way, our target is also the Phytec LPC3250 board. There were several mistakes in the configuration files, which when fixed allowed OpenOCD to proceed a little further with the J-Link initialization. However, at the end of several days of struggling, I still can’t download or debug through the J-Link with OpenOCD.

    Is there a correct configuration file out there for OpenOCD and the Segger J-Link?

    If not, is there an alternative JTAG setup that will work with GDB?

    Comment by Mike Nelson — November 16, 2010 @ 4:55 am

  2. Sorry Mike..Haven’t tried playing around with OpenOCD yet

    Comment by kunilkuda — November 17, 2010 @ 10:08 pm

  3. No worries. We got OpenOCD / GDB / DDD working with the Olimex ARM-USB-TINY USB to JTAG adapter.

    Comment by Mike Nelson — November 18, 2010 @ 3:07 am

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: