Dear Folks,

Im currently trying to use OpenOCD together with a STM32VLDiscovery, which 
basically is a STLINK/V1 tied to an STM32F100 via SWD.

Actually, everything works OK, but one thing I can not figure out is how to 
disable the Read Protection.

I wrote a small test application, which would flash an LED on the board. Then I 
tried to load the firmware onto the STM32F100 using STM's STVP-Tool, with the 
STLINK/V1 being installed as a mass-storage device.

This works as expected, after disabling the Read Protection.

Now I am trying to move to OpenOCD. I installed the WinUSB driver using the 
"Zadig" Tool, with no problems. A quick test with OpenOCD shows that everything 
is fine with the STLINK/V1:

----
F:\Apps\openocd\openocd-0.6.0-rc2\openocd-0.6.0-rc2\bin-x64>openocd-x64-0.6.0-rc2.exe
 -f board/stm32vldiscovery.cfg -c init -c "halt" -c "stm32f1x options_read 0" 
-c shutdown
Open On-Chip Debugger 0.6.0-rc2 (2012-08-29-09:26)
Licensed under GNU GPL v2
For bug reports, read
         http://openocd.sourceforge.net/doc/doxygen/bugs.html
adapter speed: 1000 kHz
Info : clock speed 1000 kHz
Info : stm32f1x.cpu: hardware has 6 breakpoints, 4 watchpoints
Warn : target was in unknown state when halt was requested
target state: halted
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0xfffffffe msp: 0xfffffffc
Info : device id = 0x10016420
Info : flash size = 5384kbytes
Option Byte: 0x3fffffe
Readout Protection On
Software Watchdog
Stop: No reset generated
Standby: No reset generated
shutdown command invoked
----

It shows, that the Read Protection is activated.

While this looks rather good, I have noted 3 things:
   - "stm32f1x mass_erase 0" works. Is that correct behaviour? I could not 
erase the device with the STVP tool before disabling the Read Protection.
   - "flash write_image $file" does not produce any errors. It successfully 
writes the bytes to the chip, well, at least it says so. After "reset run", 
nothing happens on the target.
   - "flash write_image erase unlock $file" does produce an error. It complains 
about the Readout Protection

So, how do I disable the Read Protection? I tried using "stm32f1x unlock 0", 
which acknowledges the removal of the Read Protection. But no matter if I use a 
"reset halt" or recycle the power supply afterwards, the Readout Protection 
won't disable.

----
F:\Apps\openocd\openocd-0.6.0-rc2\openocd-0.6.0-rc2\bin-x64>openocd-x64-0.6.0-rc2.exe
 -f board/stm32vldiscovery.cfg -c init -c "halt" -c "stm32f1x options_read 0" 
-c "stm32f1x unlock 0" -c "reset halt" -c "stm32f1x options_read 0" -c shutdown
Open On-Chip Debugger 0.6.0-rc2 (2012-08-29-09:26)
Licensed under GNU GPL v2
For bug reports, read
         http://openocd.sourceforge.net/doc/doxygen/bugs.html
adapter speed: 1000 kHz
Info : clock speed 1000 kHz
Info : stm32f1x.cpu: hardware has 6 breakpoints, 4 watchpoints
Warn : target was in unknown state when halt was requested
target state: halted
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0xfffffffe msp: 0xfffffffc
Info : device id = 0x10016420
Info : flash size = 5384kbytes
Option Byte: 0x3fffffe
Readout Protection On
Software Watchdog
Stop: No reset generated
Standby: No reset generated
Info : Device Security Bit Set
stm32x unlocked.
INFO: a reset or power cycle is required for the new settings to take effect.
target state: halted
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0xfffffffe msp: 0xfffffffc
Option Byte: 0x3fffffe
Readout Protection On
Software Watchdog
Stop: No reset generated
Standby: No reset generated
shutdown command invoked
----


For the record, I include the scripts I have used.

openocd.cfg
----
init

proc program {file} {
     reset halt
     stm32f1x unlock 0
     reset halt

     stm32f1x mass_erase 0
     flash write_image $file
     
     reset run
     shutdown
}
----

My Eclipse External Tool Configuration Parameters:
----
-f board/stm32vldiscovery.cfg
-f ${project_loc}\openocd.cfg
-c "program {${project_loc}\${config_name:${project_name}}\${project_name}.hex}"
----

And this is the result:
----
Open On-Chip Debugger 0.6.0-rc2 (2012-08-29-09:26)
Licensed under GNU GPL v2
For bug reports, read
   http://openocd.sourceforge.net/doc/doxygen/bugs.html
adapter speed: 1000 kHz
Info : clock speed 1000 kHz
Info : stm32f1x.cpu: hardware has 6 breakpoints, 4 watchpoints
program
target state: halted
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x08000850 msp: 0x20002000
Info : device id = 0x10016420
Info : flash size = 128kbytes
stm32x unlocked.
INFO: a reset or power cycle is required for the new settings to take effect.
target state: halted
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x08000850 msp: 0x20002000
stm32x mass erase complete
target state: halted
target halted due to breakpoint, current mode: Thread
xPSR: 0x41000000 pc: 0x2000003a msp: 0x20002000
wrote 2268 bytes from file 
F:\Projekte\_EclipseWorkspaces\STM32\Test\Debug\Test.hex in 0.306641s (7.223 
KiB/s)
shutdown command invoked
----

As you can see, there is no problem (as noted before). But the target won't 
execute the code I wrote, which is definitely working using the STM-STVP Tool 
instead of OpenOCD.

I hope someone of you can help me. I have been made aware, that the combination 
of SWD and STLINK/V1 is a rather tricky one.
If so, can anybody tell me a better hardware to work with OpenOCD? Will the 
STLINK/V2 work better?

Thanks in Advance and let me know if you need some more information, which I 
will be happy to provide.

-- 

Mit freundlichen Grüßen

         Simon Küppers


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
OpenOCD-devel mailing list
OpenOCD-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openocd-devel

Reply via email to