Errors updating firmware Pi4+BrickPi3

From a fresh install of the experimental image of buster for Pi4, I have run sudo apt upgrade and then the DI Software Update, and rebooted. After that, an attempt to update the firmware stops with errors. See below for transcript.

pi@pi4:~ $ sudo bash /home/pi/Dexter/BrickPi3/Firmware/brickpi3samd_flash_firmware.sh
Found +RPI4
Using interface file ‘rpi4.cfg’ for RPi version ‘RPI4’.
** Updating the BrickPi3 Firmware with ‘/home/pi/Dexter/BrickPi3/Firmware/brickpi3_firmware.bin’
Open On-Chip Debugger 0.10.0-dev (2016-12-16-18:07)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
BCM2835 GPIO nums: swclk = 25, swdio = 24
BCM2835 GPIO config: srst = 18
srst_only separate srst_gates_jtag srst_push_pull connect_deassert_srst
srst_only separate srst_gates_jtag srst_push_pull connect_deassert_srst
adapter speed: 400 kHz
cortex_m reset_config sysresetreq
adapter speed: 50 kHz
adapter_nsrst_delay: 100
adapter_nsrst_assert_width: 100
Info : BCM2835 GPIO JTAG/SWD bitbang driver
Info : SWD only mode enabled (specify tck, tms, tdi and tdo gpios to add JTAG mode)
Info : clock speed 50 kHz
Info : SWD DPIDR 0x0bc11477
Info : at91samd21j18.cpu: hardware has 4 breakpoints, 2 watchpoints
Polling target at91samd21j18.cpu failed, trying to reexamine
Info : SWD DPIDR 0x0bc11477
Info : SWD DPIDR 0x0bc11477
Error: Failed to read memory at 0xe000ed04
Examination failed, GDB will be halted. Polling again in 100ms
Error: at91samd21j18.cpu – clearing lockup after double fault
Polling target at91samd21j18.cpu failed, trying to reexamine
Info : SWD DPIDR 0x0bc11477
Error: Failed to write memory at 0xe000ed04
Examination failed, GDB will be halted. Polling again in 300ms
TargetName Type Endian TapName State


0* at91samd21j18.cpu cortex_m little at91samd21j18.cpu halted
Info : SWD DPIDR 0x0bc11477
Error: at91samd21j18.cpu – clearing lockup after double fault
at91samd21j18.cpu: target state: halted
target halted due to debug-request, current mode: Handler HardFault
xPSR: 0x71000003 pc: 0xfffffffe msp: 0xffffffd8
Polling target at91samd21j18.cpu failed, trying to reexamine
Info : at91samd21j18.cpu: hardware has 4 breakpoints, 2 watchpoints
Info : SWD DPIDR 0x0bc11477
Info : SWD DPIDR 0x0bc11477
Error: at91samd21j18.cpu – clearing lockup after double fault
at91samd21j18.cpu: target state: halted
target halted due to debug-request, current mode: Handler HardFault
xPSR: 0x71000003 pc: 0xfffffffe msp: 0xffffffd8
** Programming Started **
auto erase enabled
Info : SAMD MCU: SAMD21J18A (256KB Flash, 32KB RAM)
Info : SWD DPIDR 0x0bc11477
Error: Failed to write memory at 0x4100401a
Error: Can’t clear NVM error conditions
Info : SWD DPIDR 0x0bc11477
Error: Failed to write memory at 0x00001598
Error: samd_write: 777
Error: error writing to flash at address 0x00000000 at offset 0x00000000
embedded:startup.tcl:21: Error: auto erase enabled
SAMD MCU: SAMD21J18A (256KB Flash, 32KB RAM)
SWD DPIDR 0x0bc11477
Failed to write memory at 0x4100401a
Can’t clear NVM error conditions
SWD DPIDR 0x0bc11477
Failed to write memory at 0x00001598
samd_write: 777
error writing to flash at address 0x00000000 at offset 0x00000000

in procedure ‘at91samd21j18.cpu’ called at file “embedded:startup.tcl”, line 297
in procedure ‘ocd_bouncer’
at file “embedded:startup.tcl”, line 21

if you see ** Verified OK ** then all is good. If not, please try again. Sometimes it can take a few tries before it works.

Keep on trying. We’re still fighting a timing issue that makes no sense (to us).
Eventually the firmware will get flashed without a problem. It may take up to 4 or 5 attemps.

Yes, eventually it worked.

pi@pi4:~ $ sudo bash /home/pi/Dexter/BrickPi3/Firmware/brickpi3samd_flash_firmware.sh
Found +RPI4
Using interface file ‘rpi4.cfg’ for RPi version ‘RPI4’.
** Updating the BrickPi3 Firmware with ‘/home/pi/Dexter/BrickPi3/Firmware/brickpi3_firmware.bin’
Open On-Chip Debugger 0.10.0-dev (2016-12-16-18:07)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
BCM2835 GPIO nums: swclk = 25, swdio = 24
BCM2835 GPIO config: srst = 18
srst_only separate srst_gates_jtag srst_push_pull connect_deassert_srst
srst_only separate srst_gates_jtag srst_push_pull connect_deassert_srst
adapter speed: 400 kHz
cortex_m reset_config sysresetreq
adapter speed: 50 kHz
adapter_nsrst_delay: 100
adapter_nsrst_assert_width: 100
Info : BCM2835 GPIO JTAG/SWD bitbang driver
Info : SWD only mode enabled (specify tck, tms, tdi and tdo gpios to add JTAG mode)
Info : clock speed 50 kHz
Info : SWD DPIDR 0x0bc11477
Info : at91samd21j18.cpu: hardware has 4 breakpoints, 2 watchpoints
Error: at91samd21j18.cpu – clearing lockup after double fault
Polling target at91samd21j18.cpu failed, trying to reexamine
Info : at91samd21j18.cpu: hardware has 4 breakpoints, 2 watchpoints
TargetName Type Endian TapName State


0* at91samd21j18.cpu cortex_m little at91samd21j18.cpu halted
Info : SWD DPIDR 0x0bc11477
Error: at91samd21j18.cpu – clearing lockup after double fault
at91samd21j18.cpu: target state: halted
target halted due to debug-request, current mode: Handler HardFault
xPSR: 0x71000003 pc: 0xfffffffe msp: 0x20005638
Info : SWD DPIDR 0x0bc11477
Error: at91samd21j18.cpu – clearing lockup after double fault
at91samd21j18.cpu: target state: halted
target halted due to debug-request, current mode: Handler HardFault
xPSR: 0x71000003 pc: 0xfffffffe msp: 0x20005638
** Programming Started **
auto erase enabled
Info : SAMD MCU: SAMD21J18A (256KB Flash, 32KB RAM)
wrote 49152 bytes from file /home/pi/Dexter/BrickPi3/Firmware/brickpi3_firmware.bin in 14.323562s (3.351 KiB/s)
** Programming Finished **
** Verify Started **
verified 43208 bytes in 3.535925s (11.933 KiB/s)
** Verified OK **
Info : SWD DPIDR 0x0bc11477
shutdown command invoked