fast/slow flash

HI,

I noticed, that flasing my AT91SAM7X256 takes very different amounts ouf time. In most cases, it takes abt. 15 s (which seems to be long for a 1k file). But sometimes it takes just a second.

Could it be that the µC executes some code in background during long flash, wheras no code during short flash? I use exact the same .cfg etc.

I see the diff in timing if i reflash exact the same bin several times, too.

→ different code running could not be the case. perhaps the system gets halted at different positions of the flashed code?

(I use the following files:

http://www.tec-sol.org/hpprogs/kickarm.html

download>

sam7_ft2232_olimex_auto.cfg and sam7_ft2232_olimex_auto.script)

I think I read about flasing speed depending on the code that runs in background anywhere, but I can’t find text any more. If somebody knows where to find it, please point me there…

Alex

Hi

15 s for a 1k bin is much to long :frowning: , around a second is more resonable.

The uC core is halted during flash write so there should be no interference that way.

The first suspect for this behaviour is the USB communications, do you have other USB units active ?

Try running openocd with debug output. -d flag , then you will se when each flash page

write starts and ends. For even more information you could add an extra debug ouput statement at line 675 in the file src/flash/at91sam7.c

target->type->write_memory(target, bank->base, 4, wcount, buffer+buffer_pos);

  • DEBUG(“Flash memory page downloaded”);

/* Send Write Page command to Flash Controller */

To reload original flash boot into SAM-BA, using NVMBIT 2 = 0, this sets up a faster clock. Then flash.

Or reprogram the clock control registers using memory writes using the same

sequence of mww’s from openocd as in the normal clock setup code.

Regards,

Magnus

The reason for the differences you’re seeing is the core’s frequency. With the PLL enabled, it takes a second (after successfully flashing a working image), when the code you flashed didn’t enable the PLL it takes 15 seconds.

As Magnus told you, you should program the clocks with the mww commands, after that, it should work every time.

Regards,

Dominic

I actually set the mww. this is the code i use as openocd script:

Init - taken form 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

AT91SAM7 flash command-“batch”

adapted by Martin Thomas based on information from Dominic Rath - Thanks

arm7_9 dcc_downloads enable

sleep 10

poll

flash probe 0

flash erase 0 0 15

flash write 0 bin/main.bin 0x0

reset run

sleep 10

shutdown

using -d i see that the progess stops after this lines

Info:    openocd.c:82 main(): Open On-Chip Debugger (2006-09-07 20:00 CEST)
Debug:   jtag.c:1211 jtag_init():
Debug:   ft2232.c:941 ft2232_init(): 'ft2232' interface using FTD2XX with 'olimex-jtag' layout
Debug:   ft2232.c:1010 ft2232_init(): current latency timer: 2
Debug:   ft2232.c:1253 olimex_jtag_init(): 80 08 1b
Debug:   ft2232.c:1296 olimex_jtag_init(): 82 09 0f
Debug:   ft2232.c:224 ft2232_speed(): 86 00 00
Debug:   jtag.c:247 jtag_call_event_callbacks(): jtag event: 1
Debug:   jtag.c:1097 jtag_reset_callback():
Debug:   jtag.c:247 jtag_call_event_callbacks(): jtag event: 1
Debug:   jtag.c:1097 jtag_reset_callback():
Debug:   openocd.c:98 main(): jtag init complete
Debug:   arm7_9_common.c:655 arm7_9_assert_reset(): target->state: unknown
Debug:   jtag.c:247 jtag_call_event_callbacks(): jtag event: 0
Debug:   jtag.c:1097 jtag_reset_callback():
Debug:   jtag.c:247 jtag_call_event_callbacks(): jtag event: 1
Debug:   jtag.c:1097 jtag_reset_callback():
Warning: arm7_9_common.c:679 arm7_9_assert_reset(): srst resets test logic, too
Debug:   jtag.c:247 jtag_call_event_callbacks(): jtag event: 0
Debug:   jtag.c:1097 jtag_reset_callback():
Debug:   jtag.c:247 jtag_call_event_callbacks(): jtag event: 1
Debug:   jtag.c:1097 jtag_reset_callback():
Debug:   ft2232.c:718 olimex_jtag_reset(): trst: 0, srst: 1, high_output: 0x03, high_direction: 0x0f
Debug:   ft2232.c:718 olimex_jtag_reset(): trst: 0, srst: 1, high_output: 0x03, high_direction: 0x0f

for 99% of the total time, then finishes the rest:

Debug: arm7_9_common.c:718 arm7_9_deassert_reset(): target->state: reset

Debug: jtag.c:247 jtag_call_event_callbacks(): jtag event: 2

Debug: jtag.c:1097 jtag_reset_callback():

Debug: ft2232.c:718 olimex_jtag_reset(): trst: 0, srst: 0, high_output: 0x09, high_direction: 0x0f

Debug: openocd.c:102 main(): target init complete

Debug: openocd.c:106 main(): flash init complete

Debug: gdb_server.c:1347 gdb_init(): gdb service for target arm7tdmi at port 3333

Debug: embeddedice.c:157 embeddedice_read_reg_w_check(): 1

Debug: jtag.c:247 jtag_call_event_callbacks(): jtag event: 3

Debug: jtag.c:1097 jtag_reset_callback():

Debug: arm7_9_common.c:781 arm7_9_halt(): target->state: running

Debug: embeddedice.c:253 embeddedice_write_reg(): 9: 0xffffffff

Debug: embeddedice.c:253 embeddedice_write_reg(): 11: 0xffffffff

Debug: embeddedice.c:253 embeddedice_write_reg(): 12: 0x00000100

Debug: embeddedice.c:253 embeddedice_write_reg(): 13: 0x000000f7

Debug: embeddedice.c:157 embeddedice_read_reg_w_check(): 1

Debug: arm7_9_common.c:619 arm7_9_poll(): DBGACK set, dbg_state->value: 0x9

Debug: embeddedice.c:253 embeddedice_write_reg(): 0: 0x00000005

Debug: embeddedice.c:253 embeddedice_write_reg(): 12: 0x00000000

Debug: arm7_9_common.c:919 arm7_9_debug_entry(): target entered debug from ARM state

Debug: arm7_9_common.c:951 arm7_9_debug_entry(): target entered debug state in System mode

Debug: arm7_9_common.c:980 arm7_9_debug_entry(): r0: 0x00000002

Debug: arm7_9_common.c:980 arm7_9_debug_entry(): r1: 0x00000080

Debug: arm7_9_common.c:980 arm7_9_debug_entry(): r2: 0x0039b972

Debug: arm7_9_common.c:980 arm7_9_debug_entry(): r3: 0x005b8d7f

Debug: arm7_9_common.c:980 arm7_9_debug_entry(): r4: 0x804260c3

Debug: arm7_9_common.c:980 arm7_9_debug_entry(): r5: 0x9b683a20

Debug: arm7_9_common.c:980 arm7_9_debug_entry(): r6: 0x88004483

Debug: arm7_9_common.c:980 arm7_9_debug_entry(): r7: 0xda8d4fde

Debug: arm7_9_common.c:980 arm7_9_debug_entry(): r8: 0xa40098de

Debug: arm7_9_common.c:980 arm7_9_debug_entry(): r9: 0x90280e69

Debug: arm7_9_common.c:980 arm7_9_debug_entry(): r10: 0xd00ca413

Debug: arm7_9_common.c:980 arm7_9_debug_entry(): r11: 0x002ffec8

Debug: arm7_9_common.c:980 arm7_9_debug_entry(): r12: 0x002ffeb0

Debug: arm7_9_common.c:980 arm7_9_debug_entry(): r13: 0x002ffeb0

Debug: arm7_9_common.c:980 arm7_9_debug_entry(): r14: 0x00000194

Debug: arm7_9_common.c:980 arm7_9_debug_entry(): r15: 0x00000130

Debug: arm7_9_common.c:986 arm7_9_debug_entry(): entered debug state at PC 0x130

Debug: target.c:442 target_call_event_callbacks(): target event 0

Info: target.c:219 target_init_handler(): executing reset script ‘openocd/sam7_ft2232_olimex_auto.script’

Debug: target.c:1255 handle_halt_command():

Debug: arm7_9_common.c:781 arm7_9_halt(): target->state: halted

Warning: arm7_9_common.c:785 arm7_9_halt(): target was already halted

Debug: arm7_9_common.c:1795 arm7_9_write_memory(): address: 0xfffffd44, size: 0x00000004, count: 0x00000001

Debug: embeddedice.c:253 embeddedice_write_reg(): 0: 0x00000004

Debug: embeddedice.c:157 embeddedice_read_reg_w_check(): 1

Debug: embeddedice.c:253 embeddedice_write_reg(): 0: 0x00000005

Debug: arm7_9_common.c:1795 arm7_9_write_memory(): address: 0xfffffd08, size: 0x00000004, count: 0x00000001

Debug: embeddedice.c:253 embeddedice_write_reg(): 0: 0x00000004

Debug: embeddedice.c:157 embeddedice_read_reg_w_check(): 1

Debug: embeddedice.c:253 embeddedice_write_reg(): 0: 0x00000005

Debug: arm7_9_common.c:1795 arm7_9_write_memory(): address: 0xfffffc20, size: 0x00000004, count: 0x00000001

Debug: embeddedice.c:253 embeddedice_write_reg(): 0: 0x00000004

Debug: embeddedice.c:157 embeddedice_read_reg_w_check(): 1

Debug: embeddedice.c:253 embeddedice_write_reg(): 0: 0x00000005

Debug: arm7_9_common.c:1795 arm7_9_write_memory(): address: 0xfffffc2c, size: 0x00000004, count: 0x00000001

Debug: embeddedice.c:253 embeddedice_write_reg(): 0: 0x00000004

Debug: embeddedice.c:157 embeddedice_read_reg_w_check(): 1

Debug: embeddedice.c:253 embeddedice_write_reg(): 0: 0x00000005

Debug: arm7_9_common.c:1795 arm7_9_write_memory(): address: 0xfffffc30, size: 0x00000004, count: 0x00000001

Debug: embeddedice.c:253 embeddedice_write_reg(): 0: 0x00000004

Debug: embeddedice.c:157 embeddedice_read_reg_w_check(): 1

Debug: embeddedice.c:253 embeddedice_write_reg(): 0: 0x00000005

Debug: arm7_9_common.c:1795 arm7_9_write_memory(): address: 0xffffff60, size: 0x00000004, count: 0x00000001

Debug: embeddedice.c:253 embeddedice_write_reg(): 0: 0x00000004

Debug: embeddedice.c:157 embeddedice_read_reg_w_check(): 1

Debug: embeddedice.c:253 embeddedice_write_reg(): 0: 0x00000005

Debug: embeddedice.c:157 embeddedice_read_reg_w_check(): 1

Debug: arm7_9_common.c:619 arm7_9_poll(): DBGACK set, dbg_state->value: 0x9

Debug: arm7_9_common.c:1649 arm7_9_read_memory(): address: 0xfffff240, size: 0x00000004, count: 0x00000001

Debug: embeddedice.c:157 embeddedice_read_reg_w_check(): 1

Debug: at91sam7.c:310 at91sam7_read_part_info(): nvptyp: 0x002, arch: 0x0075, alt_id: 0x0000, alt_addr: 0x0000

Debug: arm7_9_common.c:1649 arm7_9_read_memory(): address: 0xfffffc24, size: 0x00000004, count: 0x00000001

Debug: embeddedice.c:157 embeddedice_read_reg_w_check(): 1

Debug: arm7_9_common.c:1649 arm7_9_read_memory(): address: 0xfffffc30, size: 0x00000004, count: 0x00000001

Debug: embeddedice.c:157 embeddedice_read_reg_w_check(): 1

Debug: arm7_9_common.c:1649 arm7_9_read_memory(): address: 0xfffffc2c, size: 0x00000004, count: 0x00000001

Debug: embeddedice.c:157 embeddedice_read_reg_w_check(): 1

Debug: arm7_9_common.c:1649 arm7_9_read_memory(): address: 0xfffffc2c, size: 0x00000004, count: 0x00000001

Debug: embeddedice.c:157 embeddedice_read_reg_w_check(): 1

Debug: arm7_9_common.c:1649 arm7_9_read_memory(): address: 0xffffff68, size: 0x00000004, count: 0x00000001

Debug: embeddedice.c:157 embeddedice_read_reg_w_check(): 1

Debug: arm7_9_common.c:1649 arm7_9_read_memory(): address: 0xfffffc24, size: 0x00000004, count: 0x00000001

Debug: embeddedice.c:157 embeddedice_read_reg_w_check(): 1

Debug: arm7_9_common.c:1649 arm7_9_read_memory(): address: 0xfffffc30, size: 0x00000004, count: 0x00000001

Debug: embeddedice.c:157 embeddedice_read_reg_w_check(): 1

Debug: arm7_9_common.c:1649 arm7_9_read_memory(): address: 0xfffffc2c, size: 0x00000004, count: 0x00000001

Debug: embeddedice.c:157 embeddedice_read_reg_w_check(): 1

Debug: arm7_9_common.c:1649 arm7_9_read_memory(): address: 0xfffffc2c, size: 0x00000004, count: 0x00000001

Debug: embeddedice.c:157 embeddedice_read_reg_w_check(): 1

Debug: at91sam7.c:225 at91sam7_set_flash_mode(): fmcn: 81

Debug: arm7_9_common.c:1795 arm7_9_write_memory(): address: 0xffffff60, size: 0x00000004, count: 0x00000001

Debug: embeddedice.c:253 embeddedice_write_reg(): 0: 0x00000004

Debug: embeddedice.c:157 embeddedice_read_reg_w_check(): 1

Debug: embeddedice.c:253 embeddedice_write_reg(): 0: 0x00000005

Debug: arm7_9_common.c:1795 arm7_9_write_memory(): address: 0xffffff64, size: 0x00000004, count: 0x00000001

Debug: embeddedice.c:253 embeddedice_write_reg(): 0: 0x00000004

Debug: embeddedice.c:157 embeddedice_read_reg_w_check(): 1

Debug: embeddedice.c:253 embeddedice_write_reg(): 0: 0x00000005

Debug: at91sam7.c:268 at91sam7_flash_command(): Flash command: 0x5a000008, pagenumber:

Debug: arm7_9_common.c:1649 arm7_9_read_memory(): address: 0xffffff68, size: 0x00000004, count: 0x00000001

Debug: embeddedice.c:157 embeddedice_read_reg_w_check(): 1

Debug: at91sam7.c:239 at91sam7_wait_status_busy(): status: 0x400

Debug: arm7_9_common.c:1649 arm7_9_read_memory(): address: 0xffffff68, size: 0x00000004, count: 0x00000001

Debug: embeddedice.c:157 embeddedice_read_reg_w_check(): 1

Debug: at91sam7.c:239 at91sam7_wait_status_busy(): status: 0x400

Debug: arm7_9_common.c:1649 arm7_9_read_memory(): address: 0xffffff68, size: 0x00000004, count: 0x00000001

Debug: embeddedice.c:157 embeddedice_read_reg_w_check(): 1

Debug: at91sam7.c:243 at91sam7_wait_status_busy(): status: 0x401

Debug: at91sam7.c:637 at91sam7_write(): first_page: 0, last_page: 8, count 1996

Debug: arm7_9_common.c:1649 arm7_9_read_memory(): address: 0xfffffc24, size: 0x00000004, count: 0x00000001

Debug: embeddedice.c:157 embeddedice_read_reg_w_check(): 1

Debug: arm7_9_common.c:1649 arm7_9_read_memory(): address: 0xfffffc30, size: 0x00000004, count: 0x00000001

Debug: embeddedice.c:157 embeddedice_read_reg_w_check(): 1

Debug: arm7_9_common.c:1649 arm7_9_read_memory(): address: 0xfffffc2c, size: 0x00000004, count: 0x00000001

Debug: embeddedice.c:157 embeddedice_read_reg_w_check(): 1

Debug: arm7_9_common.c:1649 arm7_9_read_memory(): address: 0xfffffc2c, size: 0x00000004, count: 0x00000001

Debug: embeddedice.c:157 embeddedice_read_reg_w_check(): 1

Debug: at91sam7.c:225 at91sam7_set_flash_mode(): fmcn: 81

Debug: arm7_9_common.c:1795 arm7_9_write_memory(): address: 0xffffff60, size: 0x00000004, count: 0x00000001

Debug: embeddedice.c:253 embeddedice_write_reg(): 0: 0x00000004

Debug: embeddedice.c:157 embeddedice_read_reg_w_check(): 1

Debug: embeddedice.c:253 embeddedice_write_reg(): 0: 0x00000005

Debug: arm7_9_common.c:1795 arm7_9_write_memory(): address: 0x00100000, size: 0x00000004, count: 0x00000040

Debug: embeddedice.c:253 embeddedice_write_reg(): 0: 0x00000004

Debug: embeddedice.c:157 embeddedice_read_reg_w_check(): 1

Debug: embeddedice.c:157 embeddedice_read_reg_w_check(): 1

Debug: embeddedice.c:157 embeddedice_read_reg_w_check(): 1

Debug: embeddedice.c:157 embeddedice_read_reg_w_check(): 1

Debug: embeddedice.c:157 embeddedice_read_reg_w_check(): 1

Debug: embeddedice.c:253 embeddedice_write_reg(): 0: 0x00000005

Debug: arm7_9_common.c:1795 arm7_9_write_memory(): address: 0xffffff64, size: 0x00000004, count: 0x00000001

Debug: embeddedice.c:253 embeddedice_write_reg(): 0: 0x00000004

Debug: embeddedice.c:157 embeddedice_read_reg_w_check(): 1

Debug: embeddedice.c:253 embeddedice_write_reg(): 0: 0x00000005

Debug: at91sam7.c:268 at91sam7_flash_command(): Flash command: 0x5a000001, pagenumber:

Debug: arm7_9_common.c:1649 arm7_9_read_memory(): address: 0xffffff68, size: 0x00000004, count: 0x00000001

Debug: embeddedice.c:157 embeddedice_read_reg_w_check(): 1

Debug: at91sam7.c:239 at91sam7_wait_status_busy(): status: 0x400

Debug: arm7_9_common.c:1649 arm7_9_read_memory(): address: 0xffffff68, size: 0x00000004, count: 0x00000001

Debug: embeddedice.c:157 embeddedice_read_reg_w_check(): 1

Debug: at91sam7.c:243 at91sam7_wait_status_busy(): status: 0x401

Debug: at91sam7.c:660 at91sam7_write(): Flash command: 0x8, pagenumber:

Debug: arm7_9_common.c:1795 arm7_9_write_memory(): address: 0x00100000, size: 0x00000004, count: 0x00000040

Debug: embeddedice.c:253 embeddedice_write_reg(): 0: 0x00000004

Debug: embeddedice.c:157 embeddedice_read_reg_w_check(): 1

Debug: embeddedice.c:157 embeddedice_read_reg_w_check(): 1

Debug: embeddedice.c:157 embeddedice_read_reg_w_check(): 1

Debug: embeddedice.c:157 embeddedice_read_reg_w_check(): 1

Debug: embeddedice.c:157 embeddedice_read_reg_w_check(): 1

Debug: embeddedice.c:253 embeddedice_write_reg(): 0: 0x00000005

Debug: arm7_9_common.c:1795 arm7_9_write_memory(): address: 0xffffff64, size: 0x00000004, count: 0x00000001

Debug: embeddedice.c:253 embeddedice_write_reg(): 0: 0x00000004

Debug: embeddedice.c:157 embeddedice_read_reg_w_check(): 1

Debug: embeddedice.c:253 embeddedice_write_reg(): 0: 0x00000005

Debug: at91sam7.c:268 at91sam7_flash_command(): Flash command: 0x5a000101, pagenumber:

Debug: arm7_9_common.c:1649 arm7_9_read_memory(): address: 0xffffff68, size: 0x00000004, count: 0x00000001

Debug: embeddedice.c:157 embeddedice_read_reg_w_check(): 1

Debug: at91sam7.c:239 at91sam7_wait_status_busy(): status: 0x400

Debug: arm7_9_common.c:1649 arm7_9_read_memory(): address: 0xffffff68, size: 0x00000004, count: 0x00000001

Debug: embeddedice.c:157 embeddedice_read_reg_w_check(): 1

Debug: at91sam7.c:243 at91sam7_wait_status_busy(): status: 0x401

Debug: at91sam7.c:660 at91sam7_write(): Flash command: 0x8, pagenumber:

Debug: arm7_9_common.c:1795 arm7_9_write_memory(): address: 0x00100000, size: 0x00000004, count: 0x00000040

Debug: embeddedice.c:253 embeddedice_write_reg(): 0: 0x00000004

Debug: embeddedice.c:157 embeddedice_read_reg_w_check(): 1

Debug: embeddedice.c:157 embeddedice_read_reg_w_check(): 1

Debug: embeddedice.c:157 embeddedice_read_reg_w_check(): 1

Debug: embeddedice.c:157 embeddedice_read_reg_w_check(): 1

Debug: embeddedice.c:157 embeddedice_read_reg_w_check(): 1

Debug: embeddedice.c:253 embeddedice_write_reg(): 0: 0x00000005

Debug: arm7_9_common.c:1795 arm7_9_write_memory(): address: 0xffffff64, size: 0x00000004, count: 0x00000001

Debug: embeddedice.c:253 embeddedice_write_reg(): 0: 0x00000004

Debug: embeddedice.c:157 embeddedice_read_reg_w_check(): 1

Debug: embeddedice.c:253 embeddedice_write_reg(): 0: 0x00000005

Debug: at91sam7.c:268 at91sam7_flash_command(): Flash command: 0x5a000201, pagenumber:

i did not paste all the rest here.

If I see tings clear, not the flashing itself, but the device initialisation seems to be the problem. and in fact, the backlight blinking code runs during the ‘wait’.

alex

@dominic:

the telnet connection problem arises from the same problems:

using -d, i see that the init ‘hangs’ for a certain amount of time. during this time, the backlight switches on/off → the old code is still running.

some 10 seconds later, the blinking stops, i have some more output fromopenocd and i can connect via telnet…

alex