SparkFun Forums 

Where electronics enthusiasts find answers.

Open source ARM Debugger
By geckosenator
#40680
Hello, I am using this board: (olmex lpc2148 board)
http://www.sparkfun.com/commerce/produc ... cts_id=676
and this programmer (parallel port jtag)
http://www.sparkfun.com/commerce/produc ... cts_id=275

I seem to be able to detect the device and dump the registers, but I cannot load code or set breakpoints.

I have the following config file (arm7_wig.cfg)
Code: Select all
#daemon configuration                                                                   
telnet_port 4444                                                                        
gdb_port 3333                                                                           
                                                                                        
#interface                                                                              
interface parport                                                                       
#parport_port 0x378                                                                     
parport_cable wiggler                                                                   
jtag_speed 5                                                                            
#use combined on interfaces or targets that can't set TRST/SRST separately              
reset_config trst_and_srst srst_pulls_trst                                              
                                                                                        
#jtag scan chain                                                                        
#format L IRC IRCM IDCODE (Length, IR Capture, IR Capture Mask, IDCODE)                 
jtag_device 4 0x1 0xf 0xe                                                               
                                                                                        
#target configuration                                                                   
daemon_startup reset                                                                    
#target <type> <startup mode>                                                           
#target arm7tdmi <reset mode> <chainpos> <endianness> <variant>                         
target arm7tdmi little run_and_halt 0 arm7tdmi-s_r4                                     
target_script 0 reset h2294_init.script                                                 
run_and_halt_time 0 30                                                                  
working_area 0 0x40000000 0x40000 nobackup                                              
                                                                                        
#flash configuration                                                                    
flash bank lpc2000 0x0 0x40000 0 0 0 lpc2000_v1 14765 calc_checksum                     
flash bank cfi 0x80000000 0x400000 2 2 0                                                
                                                                                        
#programming and debugging in flash                                                     
#gdb_memory_map enable
gdb_flash_program enable                                                                

I cannot get load to work in gdb, when I type load:
Code: Select all
(gdb) load
Loading section .text, size 0x29d4 lma 0x0                                              
Load failed         
The output from openocd:
Code: Select all
Warning: arm7_9_common.c:2084 arm7_9_write_memory(): memory write caused data abort (address: 0x00000000, size: 0x4, count: 0x1e8)
I can however telnet to port 4444 and type "load_image program.elf" and it seems to load

I tried setting a breakpoint in main, and I get from openocd:
Code: Select all
Info:    arm7_9_common.c:285 arm7_9_add_breakpoint(): sw breakpoint requested, but software breakpoints not enabled                                                            
Info:    breakpoints.c:73 breakpoint_add(): can't add software breakpoint, resource not available    
If I uncomment 'gdb_memory_map enable' in my config file, then I get a floating-point exception when I try to connect with gdb (target remote localhost:3333)

I am not sure what I am doing wrong. I got the config for openocd from the doc/config folder. I have only had this board for a few hours, so I would appreciate any pointers to better example code that might be easier to debug. So far I am trying to run the elf from lpc2148freertos.

Thanks
By geckosenator
#40684
additionally, when I halt and step, the pc goes from 0x7ffd2d6 to 0x7fffd2d8 to 0x7fffd2da and repeats. I am guessing it is stuck in the bootloader.. any clues there?

Thanks
By dshuman
#40686
geckosenator wrote:
I cannot get load to work in gdb, when I type load:
Code: Select all
(gdb) load
Loading section .text, size 0x29d4 lma 0x0                                              
Load failed         
I don't use GDB, but it looks like you are trying to load code into FLASH as if it were RAM. You can't do that. You have to program the FLASH prior to debugging.
geckosenator wrote:
The output from openocd:
Code: Select all
Warning: arm7_9_common.c:2084 arm7_9_write_memory(): memory write caused data abort (address: 0x00000000, size: 0x4, count: 0x1e8)
That is correct, you cannot write to FLASH, you have to program it.

geckosenator wrote: I tried setting a breakpoint in main, and I get from openocd:
Code: Select all
Info:    arm7_9_common.c:285 arm7_9_add_breakpoint(): sw breakpoint requested, but software breakpoints not enabled                                                            
Info:    breakpoints.c:73 breakpoint_add(): can't add software breakpoint, resource not available    
You cannot use software breakpoints in FLASH, you must use hardware breakpoints.

--Dave
By dshuman
#40688
geckosenator wrote:additionally, when I halt and step, the pc goes from 0x7ffd2d6 to 0x7fffd2d8 to 0x7fffd2da and repeats. I am guessing it is stuck in the bootloader.. any clues there?

Thanks
Yes, it looks like you are in the bootloader running in THUMB mode. If you do not have a valid checksum in your exception vector table, that is exactly what should happen. When you program the FLASH with OpenOCD you need to tell it to calculate that checksum for you with the "calc_checksum" switch, which you seem to have done according to your previous post. Then you need to program the flash with the "flash write_image <file> [offset] [type]" command line. You cannot "load" FLASH in the same way as RAM, you must actually "burn" it via FLASH programming.

--Dave
By geckosenator
#40690
Thank you for clearing up my confusion about what load is supposed to do.

I am not sure how to enable calc_checksum, I have the line:
Code: Select all
flash bank lpc2000 0x0 0x40000 0 0 0 lpc2000_v1 0 14765 calc_checksum
in my cfg file

How do I tell it to use hardware breakpoints only?

Why can I not use software breakpoints in flash? It would have to reflash the whole page each time.

also, all of my pages are listed as protected.. could this be a problem? It is exactly as in this post:
viewtopic.php?t=9013


Thanks
By dshuman
#40693
geckosenator wrote:Thank you for clearing up my confusion about what load is supposed to do.

I am not sure how to enable calc_checksum, I have the line:
Code: Select all
flash bank lpc2000 0x0 0x40000 0 0 0 lpc2000_v1 0 14765 calc_checksum
in my cfg file
You have that correct, so OpenOCD will calculate the vector checksum when you use the "flash write_image" command.
geckosenator wrote: How do I tell it to use hardware breakpoints only?
From the OpenOCD command reference:
arm7 9 sw bkpts <’enable’|’disable’>
Enable or disable the use of software breakpoints.
arm7 9 force hw bkpts <enable|disable>
Force the use of hardware breakpoints.
If you use a debugger over OpenOCD you will probably need to tell it to use hardware breakpoints as well?
geckosenator wrote: Why can I not use software breakpoints in flash? It would have to reflash the whole page each time.
To do that you would need to find a debugger that supports that. It does not seem to be a very practical method though, especially for single stepping. There are only two hardware breakpoints in ARM's EmbeddedICE, so you and/or your debugger will have to be careful managing them.
geckosenator wrote: also, all of my pages are listed as protected.. could this be a problem?
I think OpenOCD's "flash erase" and "flash write" commands will take care of unprotecting the FLASH pages when you erase or burn the FLASH. At least I do not have any specific protect or unprotect commands in my FLASH programming script. If you use IAP you will need to handle that in your own code. You will also need to remember to erase the FLASH before you burn it.

--Dave
Last edited by dshuman on Thu Jan 10, 2008 4:47 am, edited 1 time in total.
By mifi
#40708
Hello,
working_area 0 0x40000000 0x40000 nobackup
This working area is wrong, the size of an LPC2148 is not
0x40000 (256K).

The max size is 0x8000.

Regards,

Michael
User avatar
By ntfreak
#40714
Just a few comments about gdb flash programming.

The latest svn rev 247 and above has a few new features.
1. support for gdb memory maps - gdb will now know where the flash
memory is located and automatically use hardware breakpoints.
2. support for gdb flash programming.

To program in gdb you need to setup flash banks and a working area as before.

# tell gdb our flash memory map
gdb_memory_map enable
# enable flash programming
gdb_flash_program enable

in the config file will tell gdb where flash memory is located.
This will enable both hardware breakpoints for that area and if a load command is used will program using the new gdb vFlash packet interface.

If you need to run a script before gdb programming this can be done via the new command
target_script 0 gdb_program_config config.ocr

Also openocd is now able to act as a extended gdb server
target extended-remote localhost:2000

if you connect using this and issue a start command, gdb will program the flash set a temp breakpoint at main and run your code.

For the memory map support you will need a gdb that has XML support builtin.

It may still have a few issues, but works on all the targets i have tested.

Its all mentioned in the svn docs.

Cheers
Spen
By geckosenator
#40745
Ok, I have now finally managed to make an led blink!

the line that made the difference was:
Code: Select all
flash bank lpc2000 0x0 0x7D000 0 0 0 lpc2000_v2 12000 calc_checksum
before i had
Code: Select all
flash bank lpc2000 0x0 0x40000 0 0 0 lpc2000_v1 14765 calc_checksum
which never let me get out of the bootloader.


Thanks, I got serial and usb code running!
By dshuman
#40746
geckosenator, I am sorry that I did not notice that when I was trying to help you earlier!! I seem to have gotten fixated on the "calc_checksum" parameter.

ntfreak, thank you for covering for my oversight !!!


--Dave