SparkFun Forums 

Where electronics enthusiasts find answers.

Open source ARM Debugger
By bigcalves
#192222
Attempting to get openocd to clear the reset reason on the STM32F407 processor on my STM32F4 Discovery board, I added this command to my openocd.config file:

# Clear the reset reason
mwb 0x40023877 0x01

This was generating an error and preventing the server from coming up when running openocd -f openocd.config. This same command works fine on a production board with the same microprocessor but with an ftdi adapter. Setting the debug_level to 3 I found that the stlink firmware was trying to verify my write with a read behind the scenes:

Debug: 73 2929 command.c:145 script_debug(): command - ocd_command ocd_command type ocd_mwb 0x40023877 0x01
Debug: 74 2930 command.c:145 script_debug(): command - mwb ocd_mwb 0x40023877 0x01
Debug: 76 2937 hla_target.c:766 adapter_write_memory(): adapter_write_memory 0x40023877 1 1
Debug: 77 2950 stlink_usb.c:399 stlink_usb_error_check(): Verify error
Debug: 78 2951 command.c:628 run_command(): Command failed with error code -4
User : 79 2951 command.c:689 command_run_line():
Debug: 80 2951 hla_interface.c:119 hl_interface_quit(): hl_interface_quit

This fails because that address is STM32F407's RCC_CSR peripheral register and we are attempting to write to the RMVF bit to clear the reset reason. Per the documentation this is a write-only bit and reads back as a zero. Hence the verify error. The same issue was apparently noticed two years ago here http://openocd-devel.narkive.com/c9CrVc ... ess-and-mw but I don't see that it has been addressed. I tried changing the logic that returns an ERROR_FAIL to an ERROR_OK in stlink_usb.c where the STLINK_JTAG_WRITE_VERIF_ERROR is being handled in stlink_usb_error_check(). This works well. Anyone know of a reason why I shouldn't do this? I wouldn't think one would want the server to abort if this unsolicited write-read verification fails. Clearly there is no such write-read verification being done with the ftdi adapter, since no error is thrown in my tests.