connect under reset with st-link v2

I’m using OpenOCD 0.6.1 (2013-03-09-11:15), with an STlink v2 (on an STM32F4Discovery board) to program an STM32F0 on an external PCB. My firmware reconfigures the SWD pins as GPIOs, so connecting to the chip requires using the reset pin. Is this possible with OpenOCD?

I’m using the board/stm32f0discovery.cfg file, and it lists:

...
# use hardware reset, connect under reset
reset_config srst_only srst_nogate

But it is not actually connecting under reset. Using the official stlink Windows utility (in the connect-under-reset mode) works fine and I can flash my STM32F0.

Any ideas or tips?

Thanks,

-Farrell

the text does need updating, however this will work as you expect.

reset_config srst_only srst_nogate connect_assert_srst

Spen

It still isn’t working for me. Here’s what I get:

openocd -f /usr/local/share/openocd/scripts/board/stm32f0discovery.cfg -f ../../stm32f0-discovery-basic-template/extra/stm32f0-openocd.cfg -c "stm_flash `pwd`/firmware.bin" -c shutdown
Open On-Chip Debugger 0.6.1 (2013-03-09-11:15)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.sourceforge.net/doc/doxygen/bugs.html
adapter speed: 1000 kHz
Error: unknown reset_config flag (connect_assert_srst)
reset_config [none|trst_only|srst_only|trst_and_srst]
          [srst_pulls_trst|trst_pulls_srst|combined|separate]
          [srst_gates_jtag|srst_nogate] [trst_push_pull|trst_open_drain]
          [srst_push_pull|srst_open_drain]
Runtime Error: /usr/local/share/openocd/scripts/board/stm32f0discovery.cfg:10: 
in procedure 'script' 
at file "embedded:startup.tcl", line 58
in procedure 'reset_config' called at file "/usr/local/share/openocd/scripts/board/stm32f0discovery.cfg", line 10
make: *** [install] Error 1

stm32f0-openocd.cfg is:

#This file can be used to automatically program the STM32F0-Discovery board's Flash memory from the command line
#After programming, the board must be power-cycled (briefly remove the power) for the program to start running
#This can be done by unpluggin the USB cable, or removing JP2

init

proc stm_flash {IMGFILE} {
	reset halt
	sleep 100
	wait_halt 2
	flash write_image erase $IMGFILE 0x08000000
	sleep 100 
	verify_image $IMGFILE 0x08000000
	sleep 100
	reset run
}

proc stm_erase {} {
	reset halt
	sleep 100
	stm32f1x mass_erase 0
	sleep 100
}

Thanks,

-Farrell

You need to use a newer version of OpenOCD as this change is not part of 0.6.1.

You will have to checkout the git master branch.

Spen

Just tried and get the error below. It mentions JTAG, but iirc the st-link v2 only supports the SWD protocol. I’m not sure if that is part of the problem, or if JTAG is just part of the info tag?

openocd -f /usr/local/share/openocd/scripts/board/stm32f0discovery.cfg -f ../../stm32f0-discovery-basic-template/extra/stm32f0-openocd.cfg -c "stm_flash `pwd`/firmware.bin" -c shutdown
Open On-Chip Debugger 0.7.0-dev-00208-g900f299 (2013-03-31-03:27)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.sourceforge.net/doc/doxygen/bugs.html
srst_only separate srst_nogate srst_open_drain connect_assert_srst
Info : This adapter doesn't support configurable speed
Info : STLINK v2 JTAG v17 API v2 SWIM v0 VID 0x0483 PID 0x3748
Info : Target voltage: 2.891070
Error: init mode failed
in procedure 'transport'
Runtime Error: ../../stm32f0-discovery-basic-template/extra/stm32f0-openocd.cfg:5: 
in procedure 'script' 
at file "embedded:startup.tcl", line 58
in procedure 'init' called at file "../../stm32f0-discovery-basic-template/extra/stm32f0-openocd.cfg", line 5

Thanks for the quick replies! I’m not trying to be a pest, I promise. :slight_smile:

-Farrell

You will have to enable debug logging (-d3) so I can see what your scripts are trying to do.

Spen

Sure:

$ openocd -f /usr/local/share/openocd/scripts/board/stm32f0discovery.cfg -f ../../stm32f0-discovery-basic-template/extra/stm32f0-openocd.cfg -c "stm_flash `pwd`/firmware.bin" -c shutdown -d3
Open On-Chip Debugger 0.7.0-dev-00208-g900f299 (2013-03-31-03:27)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.sourceforge.net/doc/doxygen/bugs.html
User : 13 1 command.c:549 command_print(): debug_level: 3
Debug: 14 2 configuration.c:45 add_script_search_dir(): adding /home/farrellf/.openocd
Debug: 15 2 configuration.c:45 add_script_search_dir(): adding /usr/local/share/openocd/site
Debug: 16 2 configuration.c:45 add_script_search_dir(): adding /usr/local/share/openocd/scripts
Debug: 17 2 configuration.c:86 find_file(): found /usr/local/share/openocd/scripts/board/stm32f0discovery.cfg
Debug: 18 2 configuration.c:86 find_file(): found /usr/local/share/openocd/scripts/interface/stlink-v2.cfg
Debug: 19 2 command.c:145 script_debug(): command - ocd_command ocd_command type ocd_interface hla
Debug: 20 2 command.c:145 script_debug(): command - interface ocd_interface hla
Debug: 22 2 command.c:369 register_command_handler(): registering 'ocd_hla_device_desc'...
Debug: 23 2 command.c:369 register_command_handler(): registering 'ocd_hla_serial'...
Debug: 24 2 command.c:369 register_command_handler(): registering 'ocd_hla_layout'...
Debug: 25 2 command.c:369 register_command_handler(): registering 'ocd_hla_vid_pid'...
Debug: 26 2 command.c:369 register_command_handler(): registering 'ocd_stlink_api'...
Debug: 27 2 command.c:145 script_debug(): command - ocd_command ocd_command type ocd_hla_layout stlink
Debug: 28 2 command.c:145 script_debug(): command - hla_layout ocd_hla_layout stlink
Debug: 30 2 hla_interface.c:161 hl_interface_handle_layout_command(): hl_interface_handle_layout_command
Debug: 31 2 command.c:145 script_debug(): command - ocd_command ocd_command type ocd_hla_device_desc ST-LINK/V2
Debug: 32 2 command.c:145 script_debug(): command - hla_device_desc ocd_hla_device_desc ST-LINK/V2
Debug: 34 2 hla_interface.c:135 hl_interface_handle_device_desc_command(): hl_interface_handle_device_desc_command
Debug: 35 2 command.c:145 script_debug(): command - ocd_command ocd_command type ocd_hla_vid_pid 0x0483 0x3748
Debug: 36 2 command.c:145 script_debug(): command - hla_vid_pid ocd_hla_vid_pid 0x0483 0x3748
Debug: 38 2 hla_interface.c:189 hl_interface_handle_vid_pid_command(): hl_interface_handle_vid_pid_command
Debug: 39 3 configuration.c:86 find_file(): found /usr/local/share/openocd/scripts/target/stm32f0x_stlink.cfg
Debug: 40 3 configuration.c:86 find_file(): found /usr/local/share/openocd/scripts/target/stm32_stlink.cfg
Debug: 41 3 command.c:145 script_debug(): command - ocd_command ocd_command type ocd_transport select hla_swd
Debug: 42 3 command.c:145 script_debug(): command - ocd_transport ocd_transport select hla_swd
Debug: 43 3 hla_transport.c:187 hl_transport_select(): hl_transport_select
Debug: 44 3 command.c:369 register_command_handler(): registering 'ocd_hla'...
Debug: 45 3 command.c:369 register_command_handler(): registering 'ocd_jtag'...
Debug: 46 3 command.c:369 register_command_handler(): registering 'ocd_jtag'...
Debug: 47 3 command.c:369 register_command_handler(): registering 'ocd_jtag'...
Debug: 48 3 command.c:369 register_command_handler(): registering 'ocd_jtag'...
Debug: 49 3 command.c:369 register_command_handler(): registering 'ocd_jtag'...
Debug: 50 3 command.c:369 register_command_handler(): registering 'ocd_jtag'...
Debug: 51 3 command.c:369 register_command_handler(): registering 'ocd_jtag'...
Debug: 52 3 command.c:369 register_command_handler(): registering 'ocd_jtag'...
Debug: 53 3 command.c:369 register_command_handler(): registering 'ocd_jtag'...
Debug: 54 3 command.c:145 script_debug(): command - ocd_command ocd_command type ocd_hla newtap stm32f0x cpu -expected-id 0x0bb11477
Debug: 55 3 command.c:145 script_debug(): command - ocd_hla ocd_hla newtap stm32f0x cpu -expected-id 0x0bb11477
Debug: 56 3 hla_tcl.c:104 jim_hl_newtap_cmd(): Creating New Tap, Chip: stm32f0x, Tap: cpu, Dotted: stm32f0x.cpu, 2 params
Debug: 57 3 hla_tcl.c:114 jim_hl_newtap_cmd(): Processing option: -expected-id
Debug: 58 3 core.c:1323 jtag_tap_init(): Created Tap: stm32f0x.cpu @ abs position 0, irlen 0, capture: 0x0 mask: 0x0
Debug: 59 3 command.c:145 script_debug(): command - ocd_command ocd_command type ocd_target create stm32f0x.cpu hla_target -chain-position stm32f0x.cpu
Debug: 60 3 command.c:145 script_debug(): command - ocd_target ocd_target create stm32f0x.cpu hla_target -chain-position stm32f0x.cpu
Debug: 61 3 target.c:1615 target_free_all_working_areas_restore(): freeing all working areas
Debug: 62 3 command.c:369 register_command_handler(): registering 'ocd_arm'...
Debug: 63 4 command.c:369 register_command_handler(): registering 'ocd_arm'...
Debug: 64 4 command.c:369 register_command_handler(): registering 'ocd_arm'...
Debug: 65 4 command.c:369 register_command_handler(): registering 'ocd_arm'...
Debug: 66 4 command.c:369 register_command_handler(): registering 'ocd_arm'...
Debug: 67 4 command.c:369 register_command_handler(): registering 'ocd_arm'...
Debug: 68 4 hla_target.c:299 adapter_target_create(): adapter_target_create
Debug: 69 4 hla_target.c:272 adapter_init_arch_info(): adapter_init_arch_info
Debug: 70 4 command.c:369 register_command_handler(): registering 'ocd_stm32f0x.cpu'...
Debug: 71 4 command.c:369 register_command_handler(): registering 'ocd_stm32f0x.cpu'...
Debug: 72 4 command.c:369 register_command_handler(): registering 'ocd_stm32f0x.cpu'...
Debug: 73 4 command.c:369 register_command_handler(): registering 'ocd_stm32f0x.cpu'...
Debug: 74 4 command.c:369 register_command_handler(): registering 'ocd_stm32f0x.cpu'...
Debug: 75 4 command.c:369 register_command_handler(): registering 'ocd_stm32f0x.cpu'...
Debug: 76 4 command.c:369 register_command_handler(): registering 'ocd_stm32f0x.cpu'...
Debug: 77 4 command.c:369 register_command_handler(): registering 'ocd_stm32f0x.cpu'...
Debug: 78 4 command.c:369 register_command_handler(): registering 'ocd_stm32f0x.cpu'...
Debug: 79 4 command.c:369 register_command_handler(): registering 'ocd_stm32f0x.cpu'...
Debug: 80 4 command.c:369 register_command_handler(): registering 'ocd_stm32f0x.cpu'...
Debug: 81 4 command.c:369 register_command_handler(): registering 'ocd_stm32f0x.cpu'...
Debug: 82 4 command.c:369 register_command_handler(): registering 'ocd_stm32f0x.cpu'...
Debug: 83 4 command.c:369 register_command_handler(): registering 'ocd_stm32f0x.cpu'...
Debug: 84 4 command.c:369 register_command_handler(): registering 'ocd_stm32f0x.cpu'...
Debug: 85 4 command.c:369 register_command_handler(): registering 'ocd_stm32f0x.cpu'...
Debug: 86 4 command.c:369 register_command_handler(): registering 'ocd_stm32f0x.cpu'...
Debug: 87 4 command.c:369 register_command_handler(): registering 'ocd_stm32f0x.cpu'...
Debug: 88 4 command.c:369 register_command_handler(): registering 'ocd_stm32f0x.cpu'...
Debug: 89 4 command.c:369 register_command_handler(): registering 'ocd_stm32f0x.cpu'...
Debug: 90 4 command.c:369 register_command_handler(): registering 'ocd_stm32f0x.cpu'...
Debug: 91 4 command.c:369 register_command_handler(): registering 'ocd_stm32f0x.cpu'...
Debug: 92 4 command.c:369 register_command_handler(): registering 'ocd_stm32f0x.cpu'...
Debug: 93 4 command.c:369 register_command_handler(): registering 'ocd_stm32f0x.cpu'...
Debug: 94 4 command.c:369 register_command_handler(): registering 'ocd_stm32f0x.cpu'...
Debug: 95 4 command.c:369 register_command_handler(): registering 'ocd_stm32f0x.cpu'...
Debug: 96 4 command.c:145 script_debug(): command - ocd_command ocd_command type ocd_stm32f0x.cpu configure -work-area-phys 0x20000000 -work-area-size 0x2000 -work-area-backup 0
Debug: 97 4 command.c:145 script_debug(): command - ocd_stm32f0x.cpu ocd_stm32f0x.cpu configure -work-area-phys 0x20000000 -work-area-size 0x2000 -work-area-backup 0
Debug: 98 4 target.c:1615 target_free_all_working_areas_restore(): freeing all working areas
Debug: 99 4 target.c:1615 target_free_all_working_areas_restore(): freeing all working areas
Debug: 100 4 target.c:1615 target_free_all_working_areas_restore(): freeing all working areas
Debug: 101 4 command.c:145 script_debug(): command - ocd_command ocd_command type ocd_flash bank stm32f0x.flash stm32f1x 0 0 0 0 stm32f0x.cpu
Debug: 102 4 command.c:145 script_debug(): command - ocd_flash ocd_flash bank stm32f0x.flash stm32f1x 0 0 0 0 stm32f0x.cpu
Debug: 104 4 command.c:369 register_command_handler(): registering 'ocd_stm32f1x'...
Debug: 105 4 command.c:369 register_command_handler(): registering 'ocd_stm32f1x'...
Debug: 106 4 command.c:369 register_command_handler(): registering 'ocd_stm32f1x'...
Debug: 107 4 command.c:369 register_command_handler(): registering 'ocd_stm32f1x'...
Debug: 108 4 command.c:369 register_command_handler(): registering 'ocd_stm32f1x'...
Debug: 109 4 tcl.c:781 handle_flash_bank_command(): 'stm32f1x' driver usage field missing
Debug: 110 4 command.c:145 script_debug(): command - ocd_command ocd_command type ocd_reset_config srst_only srst_nogate connect_assert_srst
Debug: 111 4 command.c:145 script_debug(): command - reset_config ocd_reset_config srst_only srst_nogate connect_assert_srst
User : 113 4 command.c:549 command_print(): srst_only separate srst_nogate srst_open_drain connect_assert_srst
Debug: 114 4 configuration.c:86 find_file(): found ../../stm32f0-discovery-basic-template/extra/stm32f0-openocd.cfg
Debug: 115 4 command.c:145 script_debug(): command - ocd_command ocd_command type ocd_init
Debug: 116 4 command.c:145 script_debug(): command - init ocd_init
Debug: 118 4 command.c:145 script_debug(): command - ocd_command ocd_command type ocd_target init
Debug: 119 4 command.c:145 script_debug(): command - ocd_target ocd_target init
Debug: 121 4 target.c:1178 handle_target_init_command(): Initializing targets...
Debug: 122 4 hla_target.c:289 adapter_init_target(): adapter_init_target
Debug: 123 4 command.c:369 register_command_handler(): registering 'ocd_target_request'...
Debug: 124 4 command.c:369 register_command_handler(): registering 'ocd_trace'...
Debug: 125 4 command.c:369 register_command_handler(): registering 'ocd_trace'...
Debug: 126 4 command.c:369 register_command_handler(): registering 'ocd_fast_load_image'...
Debug: 127 4 command.c:369 register_command_handler(): registering 'ocd_fast_load'...
Debug: 128 4 command.c:369 register_command_handler(): registering 'ocd_profile'...
Debug: 129 4 command.c:369 register_command_handler(): registering 'ocd_virt2phys'...
Debug: 130 4 command.c:369 register_command_handler(): registering 'ocd_reg'...
Debug: 131 4 command.c:369 register_command_handler(): registering 'ocd_poll'...
Debug: 132 4 command.c:369 register_command_handler(): registering 'ocd_wait_halt'...
Debug: 133 4 command.c:369 register_command_handler(): registering 'ocd_halt'...
Debug: 134 4 command.c:369 register_command_handler(): registering 'ocd_resume'...
Debug: 135 4 command.c:369 register_command_handler(): registering 'ocd_reset'...
Debug: 136 4 command.c:369 register_command_handler(): registering 'ocd_soft_reset_halt'...
Debug: 137 4 command.c:369 register_command_handler(): registering 'ocd_step'...
Debug: 138 4 command.c:369 register_command_handler(): registering 'ocd_mdw'...
Debug: 139 4 command.c:369 register_command_handler(): registering 'ocd_mdh'...
Debug: 140 4 command.c:369 register_command_handler(): registering 'ocd_mdb'...
Debug: 141 4 command.c:369 register_command_handler(): registering 'ocd_mww'...
Debug: 142 4 command.c:369 register_command_handler(): registering 'ocd_mwh'...
Debug: 143 4 command.c:369 register_command_handler(): registering 'ocd_mwb'...
Debug: 144 5 command.c:369 register_command_handler(): registering 'ocd_bp'...
Debug: 145 5 command.c:369 register_command_handler(): registering 'ocd_rbp'...
Debug: 146 5 command.c:369 register_command_handler(): registering 'ocd_wp'...
Debug: 147 5 command.c:369 register_command_handler(): registering 'ocd_rwp'...
Debug: 148 5 command.c:369 register_command_handler(): registering 'ocd_load_image'...
Debug: 149 5 command.c:369 register_command_handler(): registering 'ocd_dump_image'...
Debug: 150 5 command.c:369 register_command_handler(): registering 'ocd_verify_image'...
Debug: 151 5 command.c:369 register_command_handler(): registering 'ocd_test_image'...
Debug: 152 5 command.c:369 register_command_handler(): registering 'ocd_reset_nag'...
Debug: 153 5 command.c:369 register_command_handler(): registering 'ocd_ps'...
Debug: 154 5 hla_interface.c:98 hl_interface_init(): hl_interface_init
Debug: 155 5 hla_layout.c:91 hl_layout_init(): hl_layout_init
Info : 156 5 core.c:1375 adapter_init(): This adapter doesn't support configurable speed
Debug: 157 5 openocd.c:132 handle_init_command(): Debug Adapter init complete
Debug: 158 5 command.c:145 script_debug(): command - ocd_command ocd_command type ocd_transport init
Debug: 159 5 command.c:145 script_debug(): command - ocd_transport ocd_transport init
Debug: 161 5 transport.c:240 handle_transport_init(): handle_transport_init
Debug: 162 5 hla_transport.c:148 hl_transport_init(): hl_transport_init
Debug: 163 5 hla_transport.c:165 hl_transport_init(): current transport hla_swd
Debug: 164 5 hla_interface.c:44 hl_interface_open(): hl_interface_open
Debug: 165 5 hla_layout.c:42 hl_layout_open(): hl_layout_open
Debug: 166 5 stlink_usb.c:1225 stlink_usb_open(): stlink_usb_open
Debug: 167 5 stlink_usb.c:1243 stlink_usb_open(): transport: 1 vid: 0x0483 pid: 0x3748
Info : 168 95 stlink_usb.c:423 stlink_usb_version(): STLINK v2 JTAG v17 API v2 SWIM v0 VID 0x0483 PID 0x3748
Debug: 169 98 stlink_usb.c:599 stlink_usb_init_mode(): MODE: 0x02
Info : 170 104 stlink_usb.c:457 stlink_usb_check_voltage(): Target voltage: 2.888495
Debug: 171 104 stlink_usb.c:654 stlink_usb_init_mode(): MODE: 0x01
Debug: 172 106 stlink_usb.c:376 stlink_usb_error_check(): status error: 9 ('unknown')
Error: 173 106 stlink_usb.c:1320 stlink_usb_open(): init mode failed
Debug: 174 106 hla_layout.c:49 hl_layout_open(): failed
Debug: 175 106 command.c:631 run_command(): Command failed with error code -4
User : 176 107 command.c:669 command_run_line(): in procedure 'transport'
Debug: 177 107 command.c:631 run_command(): Command failed with error code -4
User : 178 107 command.c:669 command_run_line(): Runtime Error: ../../stm32f0-discovery-basic-template/extra/stm32f0-openocd.cfg:5: 
in procedure 'script' 
at file "embedded:startup.tcl", line 58
in procedure 'init' called at file "../../stm32f0-discovery-basic-template/extra/stm32f0-openocd.cfg", line 5
Debug: 179 107 hla_interface.c:106 hl_interface_quit(): hl_interface_quit

-Farrell

Do you get this error every time you connect the stlink?

The error being returned means the device id is invalid, normally this means a non ST part.

One other thing i spotted is the version of stlink firmware is newer than i have seen before - JTAG v17. I have only seen v16.

The stlink supports both swd and jtag, swd is the default.

I have archived all the stlink firmware versions i am aware of [here.

Cheers

Spen](stlink - Google Drive)

Yes, it happens every time when working with this PCB that requires connect-under-reset. I updated the firmware through the official stlink Windows program, thinking old firmware might be a problem. OpenOCD didn’t work with the older firmware either, but I don’t remember the version number.

OpenOCD has worked with my F0’s before, I just never needed to connect-under-reset before. Unfortunately I don’t have an F0 with me other than this one that requires connect-under-reset, so I don’t currently have a way to see if the newer stlink firmware is part of the problem.

On the topic of JTAG, maybe we’re thinking of different stlinks? I’m using the stlink v2 built onto the STM32F4Discovery board. According to the STM32F4Discovery User Manual, “The embedded ST-LINK/V2 supports only SWD for STM32 devices.” (page 13)

-Farrell

farrellf:
Yes, it happens every time when working with this PCB that requires connect-under-reset. I updated the firmware through the official stlink Windows program, thinking old firmware might be a problem. OpenOCD didn’t work with the older firmware either, but I don’t remember the version number.

Have you got a link to the updater as the latest i can find on ST’s website is “STLINK v2 JTAG v16 API v2 SWIM v0 VID 0x0483 PID 0x3748” ?

farrellf:
OpenOCD has worked with my F0’s before, I just never needed to connect-under-reset before. Unfortunately I don’t have an F0 with me other than this one that requires connect-under-reset, so I don’t currently have a way to see if the newer stlink firmware is part of the problem.

OpenOCD is working fine for me with F0’s, for some reason the stlink is not detecting your target as valid, have you double checked your connections ?

farrellf:
On the topic of JTAG, maybe we’re thinking of different stlinks? I’m using the stlink v2 built onto the STM32F4Discovery board. According to the STM32F4Discovery User Manual, “The embedded ST-LINK/V2 supports only SWD for STM32 devices.” (page 13)

-Farrell

The stlink supports both JTAG and SWD, just happens the discovery board can only use SWD as that is all they bring out onto CN2.

Spen

The stlink utility advised me to update the firmware, and I updated the firmware through the stlink utility. The software is “STSW-LINK004” from the stlink page:

http://www.st.com/web/catalog/tools/FM1 … 7/PF251168

OpenOCD is not seeing my target because it is not connecting under reset. The official stlink utility will not see my target either unless I tell it to connect under reset.

I have double checked my connections, and currently use the Windows stlink software successfully. Here’s what stlink shows when it connects under reset:

http://farrellf.com/temp/stlink.jpg

Thanks,

-Farrell

Farrell,

Not sure there is anything i can do, unable to reproduce your problems here.

Are you able to send firmware that i can load into a F0 that may help trace the issue ?

Spen

Sure:

http://farrellf.com/temp/firmware.bin

Thanks,

-Farrell

ok i can reproduce and have uploaded a patch to our review server - http://openocd.zylin.com/1315

If possible can you review, to test use the following cmd to checkout this commit

git fetch http://openocd.zylin.com/openocd refs/changes/15/1315/1 && git checkout FETCH_HEAD

you will still need to use the reset_config as follows:

reset_config srst_only srst_nogate connect_assert_srst

Cheers

Spen

I’m getting a “read version failed” error:

openocd -f /usr/local/share/openocd/scripts/board/stm32f0discovery.cfg -f ../../stm32f0-discovery-basic-template/extra/stm32f0-openocd.cfg -c "stm_flash `pwd`/firmware.bin" -c shutdown -d3
Open On-Chip Debugger 0.7.0-dev-00218-g75ab95e (2013-04-11-16:38)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.sourceforge.net/doc/doxygen/bugs.html
User : 13 1 command.c:549 command_print(): debug_level: 3
Debug: 14 1 configuration.c:45 add_script_search_dir(): adding /home/farrellf/.openocd
Debug: 15 1 configuration.c:45 add_script_search_dir(): adding /usr/local/share/openocd/site
Debug: 16 1 configuration.c:45 add_script_search_dir(): adding /usr/local/share/openocd/scripts
Debug: 17 1 configuration.c:86 find_file(): found /usr/local/share/openocd/scripts/board/stm32f0discovery.cfg
Debug: 18 1 configuration.c:86 find_file(): found /usr/local/share/openocd/scripts/interface/stlink-v2.cfg
Debug: 19 1 command.c:145 script_debug(): command - ocd_command ocd_command type ocd_interface hla
Debug: 20 1 command.c:145 script_debug(): command - interface ocd_interface hla
Debug: 22 1 command.c:369 register_command_handler(): registering 'ocd_hla_device_desc'...
Debug: 23 1 command.c:369 register_command_handler(): registering 'ocd_hla_serial'...
Debug: 24 1 command.c:369 register_command_handler(): registering 'ocd_hla_layout'...
Debug: 25 1 command.c:369 register_command_handler(): registering 'ocd_hla_vid_pid'...
Debug: 26 1 command.c:369 register_command_handler(): registering 'ocd_stlink_api'...
Debug: 27 1 command.c:145 script_debug(): command - ocd_command ocd_command type ocd_hla_layout stlink
Debug: 28 1 command.c:145 script_debug(): command - hla_layout ocd_hla_layout stlink
Debug: 30 1 hla_interface.c:167 hl_interface_handle_layout_command(): hl_interface_handle_layout_command
Debug: 31 1 command.c:145 script_debug(): command - ocd_command ocd_command type ocd_hla_device_desc ST-LINK/V2
Debug: 32 1 command.c:145 script_debug(): command - hla_device_desc ocd_hla_device_desc ST-LINK/V2
Debug: 34 1 hla_interface.c:141 hl_interface_handle_device_desc_command(): hl_interface_handle_device_desc_command
Debug: 35 1 command.c:145 script_debug(): command - ocd_command ocd_command type ocd_hla_vid_pid 0x0483 0x3748
Debug: 36 1 command.c:145 script_debug(): command - hla_vid_pid ocd_hla_vid_pid 0x0483 0x3748
Debug: 38 1 hla_interface.c:195 hl_interface_handle_vid_pid_command(): hl_interface_handle_vid_pid_command
Debug: 39 2 configuration.c:86 find_file(): found /usr/local/share/openocd/scripts/target/stm32f0x_stlink.cfg
Debug: 40 2 configuration.c:86 find_file(): found /usr/local/share/openocd/scripts/target/stm32_stlink.cfg
Debug: 41 2 command.c:145 script_debug(): command - ocd_command ocd_command type ocd_transport select hla_swd
Debug: 42 2 command.c:145 script_debug(): command - ocd_transport ocd_transport select hla_swd
Debug: 43 2 hla_transport.c:187 hl_transport_select(): hl_transport_select
Debug: 44 2 command.c:369 register_command_handler(): registering 'ocd_hla'...
Debug: 45 2 command.c:369 register_command_handler(): registering 'ocd_jtag'...
Debug: 46 2 command.c:369 register_command_handler(): registering 'ocd_jtag'...
Debug: 47 2 command.c:369 register_command_handler(): registering 'ocd_jtag'...
Debug: 48 2 command.c:369 register_command_handler(): registering 'ocd_jtag'...
Debug: 49 2 command.c:369 register_command_handler(): registering 'ocd_jtag'...
Debug: 50 2 command.c:369 register_command_handler(): registering 'ocd_jtag'...
Debug: 51 2 command.c:369 register_command_handler(): registering 'ocd_jtag'...
Debug: 52 2 command.c:369 register_command_handler(): registering 'ocd_jtag'...
Debug: 53 2 command.c:369 register_command_handler(): registering 'ocd_jtag'...
Debug: 54 2 command.c:145 script_debug(): command - ocd_command ocd_command type ocd_hla newtap stm32f0x cpu -expected-id 0x0bb11477
Debug: 55 2 command.c:145 script_debug(): command - ocd_hla ocd_hla newtap stm32f0x cpu -expected-id 0x0bb11477
Debug: 56 2 hla_tcl.c:104 jim_hl_newtap_cmd(): Creating New Tap, Chip: stm32f0x, Tap: cpu, Dotted: stm32f0x.cpu, 2 params
Debug: 57 2 hla_tcl.c:114 jim_hl_newtap_cmd(): Processing option: -expected-id
Debug: 58 2 core.c:1323 jtag_tap_init(): Created Tap: stm32f0x.cpu @ abs position 0, irlen 0, capture: 0x0 mask: 0x0
Debug: 59 2 command.c:145 script_debug(): command - ocd_command ocd_command type ocd_target create stm32f0x.cpu hla_target -chain-position stm32f0x.cpu
Debug: 60 2 command.c:145 script_debug(): command - ocd_target ocd_target create stm32f0x.cpu hla_target -chain-position stm32f0x.cpu
Debug: 61 2 target.c:1615 target_free_all_working_areas_restore(): freeing all working areas
Debug: 62 2 command.c:369 register_command_handler(): registering 'ocd_arm'...
Debug: 63 2 command.c:369 register_command_handler(): registering 'ocd_arm'...
Debug: 64 2 command.c:369 register_command_handler(): registering 'ocd_arm'...
Debug: 65 2 command.c:369 register_command_handler(): registering 'ocd_arm'...
Debug: 66 2 command.c:369 register_command_handler(): registering 'ocd_arm'...
Debug: 67 2 command.c:369 register_command_handler(): registering 'ocd_arm'...
Debug: 68 2 hla_target.c:299 adapter_target_create(): adapter_target_create
Debug: 69 2 hla_target.c:272 adapter_init_arch_info(): adapter_init_arch_info
Debug: 70 2 command.c:369 register_command_handler(): registering 'ocd_stm32f0x.cpu'...
Debug: 71 2 command.c:369 register_command_handler(): registering 'ocd_stm32f0x.cpu'...
Debug: 72 2 command.c:369 register_command_handler(): registering 'ocd_stm32f0x.cpu'...
Debug: 73 2 command.c:369 register_command_handler(): registering 'ocd_stm32f0x.cpu'...
Debug: 74 2 command.c:369 register_command_handler(): registering 'ocd_stm32f0x.cpu'...
Debug: 75 2 command.c:369 register_command_handler(): registering 'ocd_stm32f0x.cpu'...
Debug: 76 2 command.c:369 register_command_handler(): registering 'ocd_stm32f0x.cpu'...
Debug: 77 2 command.c:369 register_command_handler(): registering 'ocd_stm32f0x.cpu'...
Debug: 78 2 command.c:369 register_command_handler(): registering 'ocd_stm32f0x.cpu'...
Debug: 79 2 command.c:369 register_command_handler(): registering 'ocd_stm32f0x.cpu'...
Debug: 80 2 command.c:369 register_command_handler(): registering 'ocd_stm32f0x.cpu'...
Debug: 81 2 command.c:369 register_command_handler(): registering 'ocd_stm32f0x.cpu'...
Debug: 82 2 command.c:369 register_command_handler(): registering 'ocd_stm32f0x.cpu'...
Debug: 83 3 command.c:369 register_command_handler(): registering 'ocd_stm32f0x.cpu'...
Debug: 84 3 command.c:369 register_command_handler(): registering 'ocd_stm32f0x.cpu'...
Debug: 85 3 command.c:369 register_command_handler(): registering 'ocd_stm32f0x.cpu'...
Debug: 86 3 command.c:369 register_command_handler(): registering 'ocd_stm32f0x.cpu'...
Debug: 87 3 command.c:369 register_command_handler(): registering 'ocd_stm32f0x.cpu'...
Debug: 88 3 command.c:369 register_command_handler(): registering 'ocd_stm32f0x.cpu'...
Debug: 89 3 command.c:369 register_command_handler(): registering 'ocd_stm32f0x.cpu'...
Debug: 90 3 command.c:369 register_command_handler(): registering 'ocd_stm32f0x.cpu'...
Debug: 91 3 command.c:369 register_command_handler(): registering 'ocd_stm32f0x.cpu'...
Debug: 92 3 command.c:369 register_command_handler(): registering 'ocd_stm32f0x.cpu'...
Debug: 93 3 command.c:369 register_command_handler(): registering 'ocd_stm32f0x.cpu'...
Debug: 94 3 command.c:369 register_command_handler(): registering 'ocd_stm32f0x.cpu'...
Debug: 95 3 command.c:369 register_command_handler(): registering 'ocd_stm32f0x.cpu'...
Debug: 96 3 command.c:145 script_debug(): command - ocd_command ocd_command type ocd_stm32f0x.cpu configure -work-area-phys 0x20000000 -work-area-size 0x2000 -work-area-backup 0
Debug: 97 3 command.c:145 script_debug(): command - ocd_stm32f0x.cpu ocd_stm32f0x.cpu configure -work-area-phys 0x20000000 -work-area-size 0x2000 -work-area-backup 0
Debug: 98 3 target.c:1615 target_free_all_working_areas_restore(): freeing all working areas
Debug: 99 3 target.c:1615 target_free_all_working_areas_restore(): freeing all working areas
Debug: 100 3 target.c:1615 target_free_all_working_areas_restore(): freeing all working areas
Debug: 101 3 command.c:145 script_debug(): command - ocd_command ocd_command type ocd_flash bank stm32f0x.flash stm32f1x 0 0 0 0 stm32f0x.cpu
Debug: 102 3 command.c:145 script_debug(): command - ocd_flash ocd_flash bank stm32f0x.flash stm32f1x 0 0 0 0 stm32f0x.cpu
Debug: 104 3 command.c:369 register_command_handler(): registering 'ocd_stm32f1x'...
Debug: 105 3 command.c:369 register_command_handler(): registering 'ocd_stm32f1x'...
Debug: 106 3 command.c:369 register_command_handler(): registering 'ocd_stm32f1x'...
Debug: 107 3 command.c:369 register_command_handler(): registering 'ocd_stm32f1x'...
Debug: 108 3 command.c:369 register_command_handler(): registering 'ocd_stm32f1x'...
Debug: 109 3 tcl.c:781 handle_flash_bank_command(): 'stm32f1x' driver usage field missing
Debug: 110 3 command.c:145 script_debug(): command - ocd_command ocd_command type ocd_reset_config srst_only srst_nogate connect_assert_srst
Debug: 111 3 command.c:145 script_debug(): command - reset_config ocd_reset_config srst_only srst_nogate connect_assert_srst
User : 113 3 command.c:549 command_print(): srst_only separate srst_nogate srst_open_drain connect_assert_srst
Debug: 114 3 configuration.c:86 find_file(): found ../../stm32f0-discovery-basic-template/extra/stm32f0-openocd.cfg
Debug: 115 3 command.c:145 script_debug(): command - ocd_command ocd_command type ocd_init
Debug: 116 3 command.c:145 script_debug(): command - init ocd_init
Debug: 118 3 command.c:145 script_debug(): command - ocd_command ocd_command type ocd_target init
Debug: 119 3 command.c:145 script_debug(): command - ocd_target ocd_target init
Debug: 121 3 target.c:1178 handle_target_init_command(): Initializing targets...
Debug: 122 3 hla_target.c:289 adapter_init_target(): adapter_init_target
Debug: 123 3 command.c:369 register_command_handler(): registering 'ocd_target_request'...
Debug: 124 3 command.c:369 register_command_handler(): registering 'ocd_trace'...
Debug: 125 3 command.c:369 register_command_handler(): registering 'ocd_trace'...
Debug: 126 3 command.c:369 register_command_handler(): registering 'ocd_fast_load_image'...
Debug: 127 3 command.c:369 register_command_handler(): registering 'ocd_fast_load'...
Debug: 128 3 command.c:369 register_command_handler(): registering 'ocd_profile'...
Debug: 129 3 command.c:369 register_command_handler(): registering 'ocd_virt2phys'...
Debug: 130 3 command.c:369 register_command_handler(): registering 'ocd_reg'...
Debug: 131 3 command.c:369 register_command_handler(): registering 'ocd_poll'...
Debug: 132 3 command.c:369 register_command_handler(): registering 'ocd_wait_halt'...
Debug: 133 3 command.c:369 register_command_handler(): registering 'ocd_halt'...
Debug: 134 3 command.c:369 register_command_handler(): registering 'ocd_resume'...
Debug: 135 3 command.c:369 register_command_handler(): registering 'ocd_reset'...
Debug: 136 3 command.c:369 register_command_handler(): registering 'ocd_soft_reset_halt'...
Debug: 137 3 command.c:369 register_command_handler(): registering 'ocd_step'...
Debug: 138 3 command.c:369 register_command_handler(): registering 'ocd_mdw'...
Debug: 139 3 command.c:369 register_command_handler(): registering 'ocd_mdh'...
Debug: 140 3 command.c:369 register_command_handler(): registering 'ocd_mdb'...
Debug: 141 3 command.c:369 register_command_handler(): registering 'ocd_mww'...
Debug: 142 3 command.c:369 register_command_handler(): registering 'ocd_mwh'...
Debug: 143 3 command.c:369 register_command_handler(): registering 'ocd_mwb'...
Debug: 144 3 command.c:369 register_command_handler(): registering 'ocd_bp'...
Debug: 145 3 command.c:369 register_command_handler(): registering 'ocd_rbp'...
Debug: 146 3 command.c:369 register_command_handler(): registering 'ocd_wp'...
Debug: 147 3 command.c:369 register_command_handler(): registering 'ocd_rwp'...
Debug: 148 3 command.c:369 register_command_handler(): registering 'ocd_load_image'...
Debug: 149 3 command.c:369 register_command_handler(): registering 'ocd_dump_image'...
Debug: 150 3 command.c:369 register_command_handler(): registering 'ocd_verify_image'...
Debug: 151 3 command.c:369 register_command_handler(): registering 'ocd_test_image'...
Debug: 152 3 command.c:369 register_command_handler(): registering 'ocd_reset_nag'...
Debug: 153 3 command.c:369 register_command_handler(): registering 'ocd_ps'...
Debug: 154 3 hla_interface.c:107 hl_interface_init(): hl_interface_init
Debug: 155 3 hla_layout.c:91 hl_layout_init(): hl_layout_init
Info : 156 3 core.c:1375 adapter_init(): This adapter doesn't support configurable speed
Debug: 157 3 openocd.c:132 handle_init_command(): Debug Adapter init complete
Debug: 158 3 command.c:145 script_debug(): command - ocd_command ocd_command type ocd_transport init
Debug: 159 3 command.c:145 script_debug(): command - ocd_transport ocd_transport init
Debug: 161 3 transport.c:240 handle_transport_init(): handle_transport_init
Debug: 162 3 hla_transport.c:148 hl_transport_init(): hl_transport_init
Debug: 163 3 hla_transport.c:165 hl_transport_init(): current transport hla_swd
Debug: 164 3 hla_interface.c:44 hl_interface_open(): hl_interface_open
Debug: 165 3 hla_layout.c:42 hl_layout_open(): hl_layout_open
Debug: 166 3 stlink_usb.c:1233 stlink_usb_open(): stlink_usb_open
Debug: 167 3 stlink_usb.c:1251 stlink_usb_open(): transport: 1 vid: 0x0483 pid: 0x3748
Error: 168 42 stlink_usb.c:1279 stlink_usb_open(): read version failed
Debug: 169 42 hla_layout.c:49 hl_layout_open(): failed
Debug: 170 42 command.c:631 run_command(): Command failed with error code -4
User : 171 42 command.c:669 command_run_line(): in procedure 'transport'
Debug: 172 42 command.c:631 run_command(): Command failed with error code -4
User : 173 42 command.c:669 command_run_line(): Runtime Error: ../../stm32f0-discovery-basic-template/extra/stm32f0-openocd.cfg:5: 
in procedure 'script' 
at file "embedded:startup.tcl", line 58
in procedure 'init' called at file "../../stm32f0-discovery-basic-template/extra/stm32f0-openocd.cfg", line 5
Debug: 174 42 hla_interface.c:115 hl_interface_quit(): hl_interface_quit

Thanks,

-Farrell

It now works except for the final reset (see the code block below.) It seems that I get the “read version failed” error only if I power cycle my target after connecting it to the stlink and then attempt to flash it. Let me elaborate:

The following process does NOT result in a read version failed error:

  1. Connect the target to the stlink, then connect the stlink to the computer via a USB cable. Both the stlink and my target are powered through the USB cable.

  2. Run OpenOCD. This works, but results in the reset error shown in the code block below.

The following process DOES result in the read version failed error shown in my previous post:

  1. Connect the target to the stlink, then connect the stlink to the computer via a USB cable. Both the stlink and my target are powered through the USB cable.

  2. Run OpenOCD. This works, but results in the reset error shown in the code block below.

  3. Disconnect VDD from the target. Reconnect VDD to the target. (Only VDD is disconnected, the other four wires remain connected the entire time.)

  4. Run OpenOCD. This fails with the “read version failed” error as shown in my previous post.

Here’s the reset error I get when OpenOCD works:

...
Debug: 600 1749 hla_target.c:55 adapter_load_core_reg_u32(): adapter_load_core_reg_u32
Debug: 601 1751 hla_target.c:70 adapter_load_core_reg_u32(): load from core reg 12  value 0xffffffff
Debug: 602 1751 hla_target.c:55 adapter_load_core_reg_u32(): adapter_load_core_reg_u32
Debug: 603 1754 hla_target.c:70 adapter_load_core_reg_u32(): load from core reg 13  value 0x20002000
Debug: 604 1754 hla_target.c:55 adapter_load_core_reg_u32(): adapter_load_core_reg_u32
Debug: 605 1756 hla_target.c:70 adapter_load_core_reg_u32(): load from core reg 14  value 0xffffffff
Debug: 606 1756 hla_target.c:55 adapter_load_core_reg_u32(): adapter_load_core_reg_u32
Debug: 607 1758 hla_target.c:70 adapter_load_core_reg_u32(): load from core reg 15  value 0x2000002e
Debug: 608 1758 hla_target.c:55 adapter_load_core_reg_u32(): adapter_load_core_reg_u32
Debug: 609 1761 hla_target.c:70 adapter_load_core_reg_u32(): load from core reg 16  value 0x61000000
Debug: 610 1761 hla_target.c:55 adapter_load_core_reg_u32(): adapter_load_core_reg_u32
Debug: 611 1763 hla_target.c:70 adapter_load_core_reg_u32(): load from core reg 17  value 0x20002000
Debug: 612 1763 hla_target.c:55 adapter_load_core_reg_u32(): adapter_load_core_reg_u32
Debug: 613 1766 hla_target.c:70 adapter_load_core_reg_u32(): load from core reg 18  value 0xfffffffc
Debug: 614 1766 hla_target.c:55 adapter_load_core_reg_u32(): adapter_load_core_reg_u32
Debug: 615 1768 hla_target.c:135 adapter_load_core_reg_u32(): load from special reg 19 value 0x0
Debug: 616 1769 hla_target.c:55 adapter_load_core_reg_u32(): adapter_load_core_reg_u32
Debug: 617 1771 hla_target.c:135 adapter_load_core_reg_u32(): load from special reg 20 value 0x0
Debug: 618 1771 hla_target.c:55 adapter_load_core_reg_u32(): adapter_load_core_reg_u32
Debug: 619 1773 hla_target.c:135 adapter_load_core_reg_u32(): load from special reg 21 value 0x0
Debug: 620 1773 hla_target.c:55 adapter_load_core_reg_u32(): adapter_load_core_reg_u32
Debug: 621 1776 hla_target.c:135 adapter_load_core_reg_u32(): load from special reg 22 value 0x0
Debug: 622 1778 hla_target.c:374 adapter_debug_entry(): entered debug state in core mode: Thread at PC 0x2000002e, target->state: halted
Debug: 623 1778 target.c:1294 target_call_event_callbacks(): target event 19 (debug-halted)
Debug: 624 1778 hla_target.c:412 adapter_poll(): halted: PC: 0x2000002e
Debug: 625 1778 hla_target.c:55 adapter_load_core_reg_u32(): adapter_load_core_reg_u32
Debug: 626 1780 hla_target.c:70 adapter_load_core_reg_u32(): load from core reg 15  value 0x2000002e
Debug: 627 1780 armv7m.c:491 armv7m_wait_algorithm(): restoring register xPSR with value 0xc1000000
Debug: 628 1780 armv7m.c:491 armv7m_wait_algorithm(): restoring register pc with value 0x08000718
Debug: 629 1780 armv7m.c:491 armv7m_wait_algorithm(): restoring register r6 with value 0xffffffff
Debug: 630 1780 armv7m.c:491 armv7m_wait_algorithm(): restoring register r5 with value 0xffffffff
Debug: 631 1780 armv7m.c:491 armv7m_wait_algorithm(): restoring register r4 with value 0xffffffff
Debug: 632 1780 armv7m.c:491 armv7m_wait_algorithm(): restoring register r3 with value 0xffffffff
Debug: 633 1780 armv7m.c:491 armv7m_wait_algorithm(): restoring register r2 with value 0xffffffff
Debug: 634 1780 armv7m.c:491 armv7m_wait_algorithm(): restoring register r1 with value 0xffffffff
Debug: 635 1780 armv7m.c:491 armv7m_wait_algorithm(): restoring register r0 with value 0xffffffff
Debug: 636 1780 target.c:1587 target_free_working_area_restore(): freed 52 bytes of working area at address 0x20000000
Debug: 637 1780 target.c:1381 print_wa_layout():    0x20000000-0x20001fff (8192 bytes)
User : 638 1780 command.c:549 command_print(): verified 1920 bytes in 0.123034s (15.240 KiB/s)
Debug: 639 1780 command.c:145 script_debug(): command - ocd_command ocd_command type ocd_sleep 100
Debug: 640 1780 command.c:145 script_debug(): command - sleep ocd_sleep 100
Debug: 642 1885 command.c:145 script_debug(): command - ocd_command ocd_command type ocd_reset run
Debug: 643 1885 command.c:145 script_debug(): command - reset ocd_reset run
Debug: 645 1887 command.c:145 script_debug(): command - ocd_command ocd_command type ocd_target names
Debug: 646 1887 command.c:145 script_debug(): command - ocd_target ocd_target names
Debug: 647 1887 command.c:145 script_debug(): command - ocd_command ocd_command type ocd_stm32f0x.cpu invoke-event reset-start
Debug: 648 1887 command.c:145 script_debug(): command - ocd_stm32f0x.cpu ocd_stm32f0x.cpu invoke-event reset-start
Debug: 649 1887 command.c:145 script_debug(): command - ocd_command ocd_command type ocd_jtag arp_init-reset
Debug: 650 1887 command.c:145 script_debug(): command - ocd_jtag ocd_jtag arp_init-reset
Debug: 652 1888 hla_interface.c:122 hl_interface_execute_queue(): hl_interface_execute_queue: ignored
Debug: 653 1888 core.c:715 jtag_add_reset(): SRST line asserted
Debug: 654 1890 command.c:145 script_debug(): command - ocd_command ocd_command type ocd_stm32f0x.cpu cget -chain-position
Debug: 655 1890 command.c:145 script_debug(): command - ocd_stm32f0x.cpu ocd_stm32f0x.cpu cget -chain-position
Debug: 656 1890 command.c:145 script_debug(): command - ocd_command ocd_command type ocd_jtag tapisenabled stm32f0x.cpu
Debug: 657 1890 command.c:145 script_debug(): command - ocd_jtag ocd_jtag tapisenabled stm32f0x.cpu
Debug: 658 1890 command.c:145 script_debug(): command - ocd_command ocd_command type ocd_stm32f0x.cpu invoke-event examine-start
Debug: 659 1890 command.c:145 script_debug(): command - ocd_stm32f0x.cpu ocd_stm32f0x.cpu invoke-event examine-start
Debug: 660 1890 command.c:145 script_debug(): command - ocd_command ocd_command type ocd_stm32f0x.cpu arp_examine
Debug: 661 1890 command.c:145 script_debug(): command - ocd_stm32f0x.cpu ocd_stm32f0x.cpu arp_examine
Debug: 662 1890 command.c:145 script_debug(): command - ocd_command ocd_command type ocd_stm32f0x.cpu invoke-event examine-end
Debug: 663 1890 command.c:145 script_debug(): command - ocd_stm32f0x.cpu ocd_stm32f0x.cpu invoke-event examine-end
Debug: 664 1890 command.c:145 script_debug(): command - ocd_command ocd_command type ocd_stm32f0x.cpu invoke-event reset-assert-pre
Debug: 665 1890 command.c:145 script_debug(): command - ocd_stm32f0x.cpu ocd_stm32f0x.cpu invoke-event reset-assert-pre
Debug: 666 1890 command.c:145 script_debug(): command - ocd_command ocd_command type ocd_stm32f0x.cpu cget -chain-position
Debug: 667 1890 command.c:145 script_debug(): command - ocd_stm32f0x.cpu ocd_stm32f0x.cpu cget -chain-position
Debug: 668 1890 command.c:145 script_debug(): command - ocd_command ocd_command type ocd_jtag tapisenabled stm32f0x.cpu
Debug: 669 1890 command.c:145 script_debug(): command - ocd_jtag ocd_jtag tapisenabled stm32f0x.cpu
Debug: 670 1890 command.c:145 script_debug(): command - ocd_command ocd_command type ocd_stm32f0x.cpu arp_reset assert 0
Debug: 671 1890 command.c:145 script_debug(): command - ocd_stm32f0x.cpu ocd_stm32f0x.cpu arp_reset assert 0
Debug: 672 1890 target.c:1615 target_free_all_working_areas_restore(): freeing all working areas
Debug: 673 1890 target.c:1381 print_wa_layout():    0x20000000-0x20001fff (8192 bytes)
Debug: 674 1890 hla_target.c:425 adapter_assert_reset(): adapter_assert_reset
Debug: 675 1899 stlink_usb.c:854 stlink_usb_reset(): RESET: 0x00000080
Debug: 676 1899 command.c:145 script_debug(): command - ocd_command ocd_command type ocd_stm32f0x.cpu invoke-event reset-assert-post
Debug: 677 1899 command.c:145 script_debug(): command - ocd_stm32f0x.cpu ocd_stm32f0x.cpu invoke-event reset-assert-post
Debug: 678 1899 command.c:145 script_debug(): command - ocd_command ocd_command type ocd_stm32f0x.cpu invoke-event reset-deassert-pre
Debug: 679 1899 command.c:145 script_debug(): command - ocd_stm32f0x.cpu ocd_stm32f0x.cpu invoke-event reset-deassert-pre
Debug: 680 1899 command.c:145 script_debug(): command - ocd_command ocd_command type ocd_stm32f0x.cpu cget -chain-position
Debug: 681 1899 command.c:145 script_debug(): command - ocd_stm32f0x.cpu ocd_stm32f0x.cpu cget -chain-position
Debug: 682 1899 command.c:145 script_debug(): command - ocd_command ocd_command type ocd_jtag tapisenabled stm32f0x.cpu
Debug: 683 1899 command.c:145 script_debug(): command - ocd_jtag ocd_jtag tapisenabled stm32f0x.cpu
Debug: 684 1899 command.c:145 script_debug(): command - ocd_command ocd_command type ocd_stm32f0x.cpu arp_reset deassert 0
Debug: 685 1899 command.c:145 script_debug(): command - ocd_stm32f0x.cpu ocd_stm32f0x.cpu arp_reset deassert 0
Debug: 686 1899 target.c:1615 target_free_all_working_areas_restore(): freeing all working areas
Debug: 687 1899 target.c:1381 print_wa_layout():    0x20000000-0x20001fff (8192 bytes)
Debug: 688 1899 hla_target.c:488 adapter_deassert_reset(): adapter_deassert_reset
Debug: 689 1902 hla_interface.c:122 hl_interface_execute_queue(): hl_interface_execute_queue: ignored
Debug: 690 1902 core.c:719 jtag_add_reset(): SRST line released
Debug: 691 1902 target.c:1294 target_call_event_callbacks(): target event 3 (resume-start)
Debug: 692 1902 hla_target.c:551 adapter_resume(): adapter_resume 1 0x00000000 0 0
Debug: 693 1902 target.c:1615 target_free_all_working_areas_restore(): freeing all working areas
Debug: 694 1902 target.c:1381 print_wa_layout():    0x20000000-0x20001fff (8192 bytes)
Debug: 695 1902 hla_target.c:697 adapter_read_memory(): adapter_read_memory 0x08000718 2 1
Debug: 696 1906 target.c:1936 target_read_u16(): address: 0x08000718, value: 0xe002
Debug: 697 1906 target.c:1978 target_write_u32(): address: 0xe000edfc, value: 0x01000000
Debug: 698 1906 hla_target.c:745 adapter_write_memory(): adapter_write_memory 0xe000edfc 4 1
Debug: 699 1911 armv7m.c:140 armv7m_restore_context():  
User : 700 1914 command.c:549 command_print(): 

Debug: 701 1914 command.c:631 run_command(): Command failed with error code -4
User : 702 1914 command.c:669 command_run_line(): Runtime Error: ../../stm32f0-discovery-basic-template/extra/stm32f0-openocd.cfg:15: 
in procedure 'stm_flash' 
in procedure 'reset' called at file "../../stm32f0-discovery-basic-template/extra/stm32f0-openocd.cfg", line 15
Debug: 703 1914 hla_interface.c:115 hl_interface_quit(): hl_interface_quit

farrellf@Farrell-VM ~/stm32/projects/lcd_touch_and_rf $ cat ../../stm32f0-discovery-basic-template/extra/stm32f0-openocd.cfg
#This file can be used to automatically program the STM32F0-Discovery board's Flash memory from the command line
#After programming, the board must be power-cycled (briefly remove the power) for the program to start running
#This can be done by unpluggin the USB cable, or removing JP2

init

proc stm_flash {IMGFILE} {
	reset halt
	sleep 100
	wait_halt 2
	flash write_image erase $IMGFILE 0x08000000
	sleep 100 
	verify_image $IMGFILE 0x08000000
	sleep 100
	reset run
}

proc stm_erase {} {
	reset halt
	sleep 100
	stm32f1x mass_erase 0
	sleep 100
}

farrellf@Farrell-VM ~/stm32/projects/lcd_touch_and_rf $ cat /usr/local/share/openocd/scripts/board/stm32f0discovery.cfg
# This is an STM32F0 discovery board with a single STM32F051R8T6 chip.
# http://www.st.com/internet/evalboard/product/253215.jsp

source [find interface/stlink-v2.cfg]

set WORKAREASIZE 0x2000
source [find target/stm32f0x_stlink.cfg]

# use hardware reset, connect under reset
reset_config srst_only srst_nogate connect_assert_srst

you probably want to turn off polling before the ‘reset run’ - does your code disable the swd/jtag ?

...
poll off
reset run

latest OpenOCD also includes a programming helper, see - http://openocd.sourceforge.net/doc/html … mming.html

Cheers

Spen

Hi Spen,

I’m also getting this same error:

Debug: 154 7 command.c:369 register_command_handler(): registering ‘ocd_ps’…

Debug: 155 7 hla_interface.c:107 hl_interface_init(): hl_interface_init

Debug: 156 7 hla_layout.c:91 hl_layout_init(): hl_layout_init

Info : 157 7 core.c:1377 adapter_init(): This adapter doesn’t support configurable speed

Debug: 158 7 openocd.c:132 handle_init_command(): Debug Adapter init complete

Debug: 159 7 command.c:145 script_debug(): command - ocd_command ocd_command type ocd_transport init

Debug: 160 7 command.c:145 script_debug(): command - ocd_transport ocd_transport init

Debug: 162 8 transport.c:240 handle_transport_init(): handle_transport_init

Debug: 163 8 hla_transport.c:148 hl_transport_init(): hl_transport_init

Debug: 164 8 hla_transport.c:165 hl_transport_init(): current transport hla_swd

Debug: 165 8 hla_interface.c:44 hl_interface_open(): hl_interface_open

Debug: 166 8 hla_layout.c:42 hl_layout_open(): hl_layout_open

Debug: 167 8 stlink_usb.c:1233 stlink_usb_open(): stlink_usb_open

Debug: 168 8 stlink_usb.c:1251 stlink_usb_open(): transport: 1 vid: 0x0483 pid: 0x3748

Info : 169 9 stlink_usb.c:423 stlink_usb_version(): STLINK v2 JTAG v14 API v2 SWIM v0 VID 0x0483 PID 0x3748

Debug: 170 10 stlink_usb.c:601 stlink_usb_init_mode(): MODE: 0x00

Info : 171 11 stlink_usb.c:457 stlink_usb_check_voltage(): Target voltage: 2.913574

Debug: 172 11 stlink_usb.c:656 stlink_usb_init_mode(): MODE: 0x01

Debug: 173 11 stlink_usb.c:376 stlink_usb_error_check(): status error: 9 (‘unknown’)

Error: 174 11 stlink_usb.c:1328 stlink_usb_open(): init mode failed

Debug: 175 12 hla_layout.c:49 hl_layout_open(): failed

Debug: 176 12 command.c:631 run_command(): Command failed with error code -4

User : 177 12 command.c:669 command_run_line(): in procedure ‘transport’

Debug: 178 12 command.c:631 run_command(): Command failed with error code -4

User : 179 12 command.c:669 command_run_line(): Runtime Error: /home/alan/tcl/target/kl25z_hla_flash.cfg:142:

in procedure ‘script’

at file “embedded:startup.tcl”, line 58

in procedure ‘init’ called at file “/home/alan/tcl/target/kl25z_hla_flash.cfg”, line 142

Debug: 180 12 hla_interface.c:115 hl_interface_quit(): hl_interface_quit

Note: I’m using current version from git with your patches applied and with Nemui patch to add support to swd and kinetis:

http://cid-36f4d1230f8a673c.skydrive.li … d_misc.zip

It is very strange, but first time I used it, it flashed the firmware on my Freedom KL25Z board:

$ openocd -s /home/alan/tcl -f interface/stlink-v2.cfg -f target/kl25z_hla_flash.cfg -c “mt_flash main.elf”

Open On-Chip Debugger 0.7.0-dev-00228-g2cb4862-dirty (2013-04-18-09:22)

Licensed under GNU GPL v2

For bug reports, read

http://openocd.sourceforge.net/doc/doxygen/bugs.html

none separate

Info : add flash_bank kinetis pflash

Info : This adapter doesn’t support configurable speed

Info : STLINK v2 JTAG v14 API v2 SWIM v0 VID 0x0483 PID 0x3748

Info : Target voltage: 2.907282

Info : kl25z.cpu: hardware has 2 breakpoints, 2 watchpoints

target state: halted

target halted due to debug-request, current mode: Thread

xPSR: 0x61000000 pc: 0x00000424 msp: 0x1ffffdcc

Rize up to Internal PLLed Clock!

auto erase enabled

Info : Probing flash info for bank 0

Info : Padding image section 0 with 848 bytes

Warn : flash configuration field erased, please reset the device

Warn : Kinetis L Series supports Program Longword execution only.

wrote 2048 bytes from file main.elf in 0.647022s (3.091 KiB/s)

Error: checksum mismatch - attempting binary compare

verified 596 bytes in 0.029051s (20.035 KiB/s)

Runtime Error: /home/alan/tcl/target/kl25z_hla_flash.cfg:92:

in procedure ‘mt_flash’

in procedure ‘reset’ called at file

“/home/alan/tcl/target/kl25z_hla_flash.cfg”, line 92

Even with about error message the binary was flashed correctly.

All wire still soldered the same way on my STM32F4Discovery, also I flashed previous firmware on Freedom, but never got success again.

Do you have same idea to solve this problem? or some test to try to diagnostic this issue? s Alan

I discovered why the problem is happening: I cut the track under J11 of Freedom board to isolate SWD_CLK from OpenSDA programmer (to avoid it interfering with SWD_CLK that come from STLink), then OpenOCD stopped to work.

I was thinking the J11 should isolate the OpenSDA from KL25Z MCU to let other programmer to have direct access to KL25Z microcontroller, but in fact it is just isolating the OpenSDA programmer to let use it as an standalone programmer. I just read the freescale statement in the schematic, just a look at KL25_SWD_CLK signal at schematic should be enough to avoid this mistake :roll:

After putting a jumper at J11 and suppling 3.3V at pin 1 of connector J6 it worked. Unfortunately powering Freedom board over USB doesn’t work because OpenSDA will interfere on SWD_CLK signal coming from STLinkV2.