Failed to write to nrf5 flash when flash bootloader with openocd and cmsis dap link

I'm building a nrfmicro bluetooth keyboard controller which uses an ebyte E73-2G4M08S1C nrf52840. My programmer is cmsis dap link. Openocd verson is 0.11.0.

Unlock is fine using command nrf52.dap apreg 1 0x04 0x01

openocd -d2 -f interface/cmsis-dap.cfg -f target/nrf52.cfg -c "init" -c "nrf52.dap apreg 1 0x04 0x01" -c "exit"

############## unlock output omitted

openocd -d2 -f interface/cmsis-dap.cfg -f target/nrf52.cfg -c "init" -c "nrf52.dap apreg 1 0x04" -c "exit"               

Open On-Chip Debugger 0.11.0
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
debug_level: 2

Info : auto-selecting first available session transport "swd". To override use 'transport select <transport>'.
Info : CMSIS-DAP: SWD  Supported
Info : CMSIS-DAP: FW Version = 2.0.0
Info : CMSIS-DAP: Serial# = 205526554555
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : SWCLK/TCK = 1 SWDIO/TMS = 1 TDI = 0 TDO = 0 nTRST = 0 nRESET = 1
Info : CMSIS-DAP: Interface ready
Info : clock speed 1000 kHz
Info : SWD DPIDR 0x2ba01477
Info : nrf52.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : starting gdb server for nrf52.cpu on 3333
Info : Listening on port 3333 for gdb connections
0x00000001

When flash nrf bootloader according to nrfmicro wiki, or Adafruit nRF52 Bootloader pca10056_bootloader-0.6.3_s140_6.1.1.hex, got error

openocd -d2 -f interface/cmsis-dap.cfg -f target/nrf52.cfg -c "init" -c "program ./bootloader.hex verify reset exit"

Open On-Chip Debugger 0.11.0
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
debug_level: 2

Info : auto-selecting first available session transport "swd". To override use 'transport select <transport>'.
Info : CMSIS-DAP: SWD  Supported
Info : CMSIS-DAP: FW Version = 2.0.0
Info : CMSIS-DAP: Serial# = 205526554555
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : SWCLK/TCK = 1 SWDIO/TMS = 1 TDI = 0 TDO = 0 nTRST = 0 nRESET = 1
Info : CMSIS-DAP: Interface ready
Info : clock speed 1000 kHz
Info : SWD DPIDR 0x2ba01477
Info : nrf52.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : starting gdb server for nrf52.cpu on 3333
Info : Listening on port 3333 for gdb connections
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x00000a80 msp: 0x20000400
** Programming Started **
Info : nRF52840-xxAA(build code: D0) 1024kB Flash, 256kB RAM
Info : Padding image section 0 at 0x00000b00 with 1280 bytes
Info : Flash write discontinued at 0x00025de8, next section at 0x000f4000
Warn : Adding extra erase range, 0x00025de8 .. 0x00025fff
Info : SWD DPIDR 0x2ba01477
Error: Failed to write memory at 0x20002024
Error: Failed to write to nrf5 flash
Error: error writing to flash at address 0x00000000 at offset 0x00000000
** Programming Failed **
shutdown command invoked

Here is the full debug level 3 log

7774.nrfmicro_bootloader_log.txt

Parents
  • Add set WORKARESIZE 0 to to top of /usr/share/openocd/scripts/target/nrf52.cfg

    #
    # Nordic nRF52 series: ARM Cortex-M4 @ 64 MHz
    #
    set WORKAREASIZE 0
    
    source [find target/swj-dp.tcl]
    
    if { [info exists CHIPNAME] } {
            set _CHIPNAME $CHIPNAME
    } else {
            set _CHIPNAME nrf52
    }
    
    # Work-area is a space in RAM used for flash programming
    # By default use 16kB
    if { [info exists WORKAREASIZE] } {
       set _WORKAREASIZE $WORKAREASIZE
    } else {
       set _WORKAREASIZE 0x4000
    }

    500kb hex file tooks minutes. Slow but seems work.

    openocd -d2 -f interface/cmsis-dap.cfg -f target/nrf52.cfg -c "init" -c "program ./bootloader.hex verify reset exit"
    
    Open On-Chip Debugger 0.11.0
    Licensed under GNU GPL v2
    For bug reports, read
            http://openocd.org/doc/doxygen/bugs.html
    debug_level: 2
    
    Info : auto-selecting first available session transport "swd". To override use 'transport select <transport>'.
    Info : CMSIS-DAP: SWD  Supported
    Info : CMSIS-DAP: FW Version = 2.0.0
    Info : CMSIS-DAP: Serial# = 205526554555
    Info : CMSIS-DAP: Interface Initialised (SWD)
    Info : SWCLK/TCK = 1 SWDIO/TMS = 1 TDI = 0 TDO = 0 nTRST = 0 nRESET = 1
    Info : CMSIS-DAP: Interface ready
    Info : clock speed 1000 kHz
    Info : SWD DPIDR 0x2ba01477
    Info : nrf52.cpu: hardware has 6 breakpoints, 4 watchpoints
    Error: nrf52.cpu -- clearing lockup after double fault
    Polling target nrf52.cpu failed, trying to reexamine
    Info : nrf52.cpu: hardware has 6 breakpoints, 4 watchpoints
    Info : starting gdb server for nrf52.cpu on 3333
    Info : Listening on port 3333 for gdb connections
    target halted due to debug-request, current mode: Thread 
    xPSR: 0x01000000 pc: 0xfffffffe msp: 0xfffffffc
    ** Programming Started **
    Info : nRF52840-xxAA(build code: D0) 1024kB Flash, 256kB RAM
    Info : Padding image section 0 at 0x00000b00 with 1280 bytes
    Info : Flash write discontinued at 0x00025de8, next section at 0x000f4000
    Warn : Adding extra erase range, 0x00025de8 .. 0x00025fff
    Warn : not enough working area available(requested 34)
    Warn : no working area available, falling back to slow memory writes
    Info : Padding image section 2 at 0x000fca9c with 3428 bytes
    Warn : Adding extra erase range, 0x000fd858 .. 0x000fdfff
    Warn : not enough working area available(requested 34)
    Warn : no working area available, falling back to slow memory writes
    Warn : Adding extra erase range, 0x10001000 .. 0x10001013
    Warn : Adding extra erase range, 0x1000101c .. 0x10001fff
    Warn : not enough working area available(requested 34)
    Warn : no working area available, falling back to slow memory writes
    ** Programming Finished **
    ** Verify Started **
    Warn : not enough working area available(requested 52)
    Warn : not enough working area available(requested 52)
    Warn : not enough working area available(requested 52)
    Warn : not enough working area available(requested 52)
    Warn : not enough working area available(requested 52)
    ** Verified OK **
    ** Resetting Target **
    shutdown command invoked
    

Reply
  • Add set WORKARESIZE 0 to to top of /usr/share/openocd/scripts/target/nrf52.cfg

    #
    # Nordic nRF52 series: ARM Cortex-M4 @ 64 MHz
    #
    set WORKAREASIZE 0
    
    source [find target/swj-dp.tcl]
    
    if { [info exists CHIPNAME] } {
            set _CHIPNAME $CHIPNAME
    } else {
            set _CHIPNAME nrf52
    }
    
    # Work-area is a space in RAM used for flash programming
    # By default use 16kB
    if { [info exists WORKAREASIZE] } {
       set _WORKAREASIZE $WORKAREASIZE
    } else {
       set _WORKAREASIZE 0x4000
    }

    500kb hex file tooks minutes. Slow but seems work.

    openocd -d2 -f interface/cmsis-dap.cfg -f target/nrf52.cfg -c "init" -c "program ./bootloader.hex verify reset exit"
    
    Open On-Chip Debugger 0.11.0
    Licensed under GNU GPL v2
    For bug reports, read
            http://openocd.org/doc/doxygen/bugs.html
    debug_level: 2
    
    Info : auto-selecting first available session transport "swd". To override use 'transport select <transport>'.
    Info : CMSIS-DAP: SWD  Supported
    Info : CMSIS-DAP: FW Version = 2.0.0
    Info : CMSIS-DAP: Serial# = 205526554555
    Info : CMSIS-DAP: Interface Initialised (SWD)
    Info : SWCLK/TCK = 1 SWDIO/TMS = 1 TDI = 0 TDO = 0 nTRST = 0 nRESET = 1
    Info : CMSIS-DAP: Interface ready
    Info : clock speed 1000 kHz
    Info : SWD DPIDR 0x2ba01477
    Info : nrf52.cpu: hardware has 6 breakpoints, 4 watchpoints
    Error: nrf52.cpu -- clearing lockup after double fault
    Polling target nrf52.cpu failed, trying to reexamine
    Info : nrf52.cpu: hardware has 6 breakpoints, 4 watchpoints
    Info : starting gdb server for nrf52.cpu on 3333
    Info : Listening on port 3333 for gdb connections
    target halted due to debug-request, current mode: Thread 
    xPSR: 0x01000000 pc: 0xfffffffe msp: 0xfffffffc
    ** Programming Started **
    Info : nRF52840-xxAA(build code: D0) 1024kB Flash, 256kB RAM
    Info : Padding image section 0 at 0x00000b00 with 1280 bytes
    Info : Flash write discontinued at 0x00025de8, next section at 0x000f4000
    Warn : Adding extra erase range, 0x00025de8 .. 0x00025fff
    Warn : not enough working area available(requested 34)
    Warn : no working area available, falling back to slow memory writes
    Info : Padding image section 2 at 0x000fca9c with 3428 bytes
    Warn : Adding extra erase range, 0x000fd858 .. 0x000fdfff
    Warn : not enough working area available(requested 34)
    Warn : no working area available, falling back to slow memory writes
    Warn : Adding extra erase range, 0x10001000 .. 0x10001013
    Warn : Adding extra erase range, 0x1000101c .. 0x10001fff
    Warn : not enough working area available(requested 34)
    Warn : no working area available, falling back to slow memory writes
    ** Programming Finished **
    ** Verify Started **
    Warn : not enough working area available(requested 52)
    Warn : not enough working area available(requested 52)
    Warn : not enough working area available(requested 52)
    Warn : not enough working area available(requested 52)
    Warn : not enough working area available(requested 52)
    ** Verified OK **
    ** Resetting Target **
    shutdown command invoked
    

Children
No Data
Related