EmbDev.net

Forum: ARM programming with GCC/GNU tools Problem programing Flash


von Jim L. (doctek)


Rate this post
useful
not useful
I'm using the amazing and outstanding Yagarto Tool Kit. I have built and 
tested the RAM version of the Test program and it all works great. 
However, I get the following error from OOCD/GDB when I try to run the 
ROM version.
"Error erasing flash with vFlashErase packet". GDB hangs showing 27% 
completion.

Can anyone shed any light on what my problem might be?

Also, I don't see exactly where the ROM/Flash programming is done. Is it 
done with an OOCD command or a GDB command?

I'm using the Olimex USB Tiny and a SAM7-256 Atmel ARM processor.

Thanks for any help.

von Jim L. (doctek)


Rate this post
useful
not useful
So I did some more digging and now know that the GDB debug script 
doesn't automatically program flash.

The real problem is how to program the flash. Does anyone have a 
complete example showing how to do this? Something like the Yagarto 
tutorial on Ram debugging is what I'm looking for. While Jim Lynch's 
tutorial is great, it's now out of date with the latest OOCD release.

I've tried several approaches and nothing seems to work. Any help would 
be greatly appreciated.

von Martin T. (mthomas) (Moderator)


Rate this post
useful
not useful
When using the OpenOCD target-library and the defaults the flash can be 
written with gdb's load command. It has been some time since I played 
around with AT91SAM7SE, OpenOCD and Eclipse so this may be outdated too 
and not the best solution:

OpenOCD start (external tools):
openocd.exe -d1 -f interface/jtagkey.cfg -f openocd.cfg

openocd.cfg-file:
debug_level 3
fast disable
jtag_speed 200
jtag_nsrst_delay 200
jtag_ntrst_delay 200
script target/eir-sam7se512.cfg
jtag_khz 6000
fast enable
init
debug_level 1


Eclipse GDB Hardware Debugging:
C/C++ application: xxxx.elf ("Project binary")
gdb-command: arm-none-eabi-gdb (or arm-elf-gdb)
use remote, device generic, localhost, port 3333
startup: all checkboxes off,
Init-commands:
 monitor debug_level 3
 monitor soft_reset_halt
 monitor flash probe 0
 load
 monitor soft_reset_halt
 set mem inaccessible-by-default off
 monitor debug_level 1
Run-Commands:
 stepi

von Jim L. (doctek)


Rate this post
useful
not useful
Thanks for the helpful suggestions, Martin.

I must admit I haven't tried them yet, however. Since they seem to be a 
very simple approach, I plan to try them.

Here's what I did do instead. While I was waiting for a reply to my 
earlier email, I discovered this site:

http://www.siwawi.arubi.uni-kl.de/avr_projects/arm_projects/openocd_intro/index.html#at91sam7int

(I assume that you are the same Martin Thomas, no?) Anyway, I used the 
scripts shown there and updated them to use the most recent OOCD 
commands and it all worked (after a little tweaking). There are now just 
two files - one called from Make, and one called as a script file by the 
first one.
---------------------------------------------------------------
openocd_at91sam7s_flash_ftdi.cfg ::
#
# Flash AT91SAM7S memory using openocd
# and a FTDI FT2232-based JTAG-interface
#
# created by Martin Thomas
# based on information from Dominic Rath
# Modified to use Olimex JTAG, latest OOCD - 4/29/09 -jkl
#

#daemon configuration
telnet_port 4444
gdb_port 3333

#interface
#interface ft2232
#ft2232_device_desc "Amontec JTAGkey A"
#ft2232_layout jtagkey
#ft2232_vid_pid 0x0403 0xcff8
interface ft2232
ft2232_device_desc "Olimex OpenOCD JTAG TINY A"
ft2232_layout olimex-jtag
ft2232_vid_pid 0x15ba 0x0004
#jtag_speed 0
#jtag_khz 6000
jtag_khz 500

jtag_nsrst_delay 200
jtag_ntrst_delay 200

#use combined on interfaces or targets that can't set TRST/SRST 
separately
reset_config srst_only srst_pulls_trst

set  _CHIPNAME sam7s256
set  _ENDIAN little
set _CPUTAPID 0x3f0f0f0f

#jtag scan chain
#format L IRC IRCM IDCODE (Length, IR Capture, IR Capture Mask, IDCODE)
#jtag_device 4 0x1 0xf 0xe
jtag newtap $_CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0xf 
-expected-id $_CPUTAPID

#target configuration  -- do nothing here - may change to reset init??
#daemon_startup reset

#target <type> <startup mode>
#target arm7tdmi <reset mode> <chainpos> <endianness> <variant>
#target arm7tdmi little run_and_init 0 arm7tdmi
set _TARGETNAME [format "%s.cpu" $_CHIPNAME]

target create $_TARGETNAME arm7tdmi -endian $_ENDIAN -chain-position 
$_TARGETNAME -variant arm7tdmi

# run_and_halt_time 0 30

# flash-options AT91
#target_script 0 reset openocd_at91sam7s_flash.script
#working_area 0 0x00200000 0x4000 nobackup
#flash bank at91sam7 0 0 0 0 0

$_TARGETNAME configure -event reset-start "script 
openocd_at91sam7s_flash.script"

$_TARGETNAME configure -work-area-virt 0 -work-area-phys 0x00200000 
-work-area-size 0x4000 -work-area-backup 0

#flash bank <driver> <base> <size> <chip_width> <bus_width>
flash bank at91sam7 0 0 0 0 0

init
reset run
sleep 30
#halt

# Information:
# erase command (telnet-interface) for complete flash:
# flash erase <num> 0 numlockbits-1 (can be seen from output of flash 
info 0)
# SAM7S64 with 16 lockbits and bank 0: flash erase 0 0 15
# set/clear NVM-Bits:
# at91sam7 gpnvm <num> <bit> <set|clear>
# disable locking from SAM-BA
# flash protect 0 0 1 off
----------------------------------------------------------------
openocd_at91sam7s_flash.script ::

#
# The following command wills be executed on
# reset (because of run_and_init in the config-file)
# - halt target
# - init ecr
# - flash content of file main.bin into target-memory
# - shutdown openocd
#
# created by Martin Thomas
# http://www.siwawi.arubi.uni-kl.de/avr_projects/arm_projects
# based on information from Dominic Rath
# modified for latest oocd - 4/29/09  -jkl
#

halt
sleep 10

# moved from below
# AT91SAM7 flash command-"batch"
# adapted by Martin Thomas based on information from Dominic Rath - 
Thanks
arm7_9 dcc_downloads enable

# added from internet script
armv4_5 core_state arm
arm7_9 fast_memory_access enable
# end added from script
# end moved section

# Init - taken from the script openocd_at91sam7_ecr.script
mww 0xfffffd44 0x00008000  # disable watchdog
mww 0xfffffd08 0xa5000001  # enable user reset
mww 0xfffffc20 0x00000601  # CKGR_MOR : enable the main oscillator
sleep 10
mww 0xfffffc2c 0x00481c0e   # CKGR_PLLR: 96.1097 MHz
sleep 10
mww 0xfffffc30 0x00000007  # PMC_MCKR : MCK = PLL / 2 ~= 48 MHz
sleep 10
mww 0xffffff60 0x003c0100  # MC_FMR: flash mode (FWS=1,FMCN=60)
# arm7_9 force_hw_bkpts enable  # program resides in flash

# section was here

sleep 10

poll
flash probe 0
# added from script on internet
#flash protect 0 0 31 off
#flash erase_sector 0 0 31
#flash erase_sector 0 0 31
# end add from script
flash write_bank 0 blink1ROM_rom.bin 0x0
#reset run
#sleep 10
shutdown

-------------------------------------------------------------
From my makefile::


# directory where openocd executable and configuration files reside
OPENOCD_DIR = 'D:/ARMTOOLS/openocd-r1454/'

# specify OpenOCD executable
#OPENOCD = $(OPENOCD_DIR)openocd-pp.exe
OPENOCD = $(OPENOCD_DIR)bin/openocd-ftd2xx.exe

# specify OpenOCD configuration file (pick the one for your device)
OPENOCD_CFG = openocd_at91sam7s_flash_ftdi.cfg

# program the AT91SAM7S256 internal flash memory
#program: $(TARGET)
program: $(PROJECT)_rom.elf
  @echo "Flash Programming with OpenOCD..."  # console message
  $(OPENOCD) -d 3 -f $(OPENOCD_CFG) # program the onchip FLASH here
  @echo "Flash Programming Finished."  # console message
----------------------------------------------------------------------

I've left lines from the original files so you can see what's changed. 
These worked and programmed my Flash perfectly. Hopefully, these will 
help others.

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.