Initially I follow this process: ran openocd in a terminal window:
$ openocd -f board/moto_mdk_muc.cfg Open On-Chip Debugger 0.10.0-dev-00346-gd3d86cc (2017-11-09-18:31) Licensed under GNU GPL v2 For bug reports, read http://openocd.org/doc/doxygen/bugs.html Info : FTDI SWD mode enabled srst_only separate srst_nogate srst_push_pull connect_deassert_srst srst_only separate srst_nogate srst_push_pull connect_deassert_srst adapter speed: 500 kHz adapter_nsrst_delay: 100 srst_only separate srst_nogate srst_push_pull connect_deassert_srst cortex_m reset_config sysresetreq Info : clock speed 500 kHz Info : SWD DPIDR 0x2ba01477 Info : stm32l4x.cpu: hardware has 6 breakpoints, 4 watchpoints
Then in another terminal window I ran:
$ telnet localhost 4444 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. Open On-Chip Debugger > halt stm32l4x.cpu: target state: halted target halted due to debug-request, current mode: Thread xPSR: 0x61000000 pc: 0x080154e0 msp: 0x20001ec0 > flash write_image erase unlock nuttx.bin 0x08000000 auto erase enabled auto unlock enabled device id = 0x10076415 flash size = 1024kbytes timeout waiting for algorithm, a target reset is recommended error executing stm32l4 flash write algorithm flash memory write protected flash write failed = 00000050 at address 08000000 block write failed error writing to flash at address 0x08000000 at offset 0x00000000
This command failed to flash the firmware. Then I disconnected the board and cable and tried again, this time unlock the whole bank:
$ telnet localhost 4444 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. Open On-Chip Debugger > halt > stm32l4x unlock 0 device id = 0x10076415 flash size = 1024kbytes stm32l4x unlocked. INFO: a reset or power cycle is required for the new settings to take effect. > flash write_image erase unlock nuttx.bin 0x08000000 auto erase enabled auto unlock enabled block write succeeded wrote 69632 bytes from file nuttx.bin in 2.863238s (23.749 KiB/s) >
Now it worked fine!