Sunday, 9 November 2008

How to use Eclipse and GDB to debug the .NET Micro Framework

In my last post we were using GCC to build the .NET Micro Framework firmware for the i.MXS reference board. Now we go one step further and will debug the firmware using GDB.

What do we need?
First an overview of our setup:



The installation should be straight forward. Here are the configuration steps...
  • Open a command window, invoke setenv_gcc.cmd and run Eclipse from this initialized build environment.

  • Create a new C++ Project in Eclipse:

    File->New->C++ Project



    (I set the workspace to "C:\" and named the project like the installation directory of the porting kit "MicroFrameworkPK_v3_0".)

  • Configure Build:

    Project->Properties->C/C++ Build
    Add a new configuration e.g. "iMXS Debug RAM"
    Build command: msbuild.exe
    Build directory: ${workspace_loc:/MicroFrameworkPK_v3_0/Solutions/iMXS}



    Build (Incremental build): dotNetMF.proj /t:build /p:flavor=debug;memory=ram;platform=iMXS
    (This builds a debug version of the iMXS firmware that executes from RAM. To build a release version that executes from FLASH, don't add any additional arguments after dotNetMF.proj)


  • We add OpenOCD as an external tool:

    Run->External Tools->External Tools Configuration...
    Name: OpenOCD
    Location: C:\Program Files\openocd-r247\bin\openocd-ftd2xx.exe
    Working Directory: C:\Program Files\openocd-r247\bin\
    Arguments: -f imxs.cfg
    (For a sample imxs.cfg file look here.)



  • Finally we configure gdb:

    Run->Debug Configurations...
    Add "Zylin Embedded debug (native)" configuration
    Name: iMXS tinyclr
    C/C++ Application: C:\MicroFrameworkPK_v3_0\BuildOutput\ARM\GCC4.2\RAM\debug\iMXS\bin\tinyclr.axf



    GDB Debugger: C:\Programs\Raisonance\Ride\arm-gcc\bin\arm-none-eabi-gdb.exe



    Initialize commands:

    target remote 127.0.0.1:3333
    monitor reset
    monitor sleep 500
    monitor poll
    monitor soft_reset_halt
    monitor arm7_9 sw_bkpts enable

    break PreStackEntry
    load
    continue

    (This connects to the gdb server, enables software breakpoints, sets a breakpoint at the function PreStackEntry, loads the firmware into RAM and starts... )



  • Now we can settle back and only press some buttons...

    First we build a debug version that executes from RAM







    ...run our JTAG server OpenOCD






    ...and hit the debug button!
    Now it takes some seconds to transfer our debug firmware into the RAM of the i.MXS board.



    The firmware starts and immediately stops at PreStackEntry. Now we can discover the code line by line... :)



5 comments:

Nuno said...

hello, where can i download the porting kit ????

Damian Barnett said...

Hi nuno,
thought the answer to your question was worth a post: Have a look here:
http://discovertheexperience.blogspot.com/2008/11/net-micro-framework-porting-kit-30.html

Kevin Townsend said...

Stefan:

Thanks for this very helpful tutorial. I had to make a few changes to make it work for me, and I'm using a different toolchain and processor, but for an LPC2478 and using only internal sram/flash (meaning you need to do hardware debugging because of size restrictions), these are the steps I had to follow:

http://msmicroframework.blogspot.com/2009/02/configuring-eclipse-openocd-gcc-to.html

Thanks for not only doing all the heaby lifting, but being willing to graciously share it!

peruli said...

Now it is June 2009, and the
zylin pluging is not available.
Has anyone gotten Eclipse Ganymede to work with cortex M3 Luminary
chips ??

Stefan Schmidt said...

Hi peruli,
the zylin plugin moved to http://opensource.zylin.com/embeddedcdt.html
The new Eclipse Update Site is http://opensource.zylin.com/zylincdt