Trouble uploading to nrf51-DK with Platformio

I’ve been trying to upload the arduino-ble-led example from the Platformio platform-nordicnrf51 to my nrf51-DK. I’m getting the following error:

Uploading .pioenvs/nrf51_dk/firmware.hex
GNU ARM Eclipse 64-bits Open On-Chip Debugger 0.10.0-00114-g84195369 (2017-04-19-00:49)
Licensed under GNU GPL v2

For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
swd
cortex_m reset_config sysresetreq
adapter speed: 1000 kHz
Info : No device selected, using first device.
Info : J-Link OB-SAM3U128-V2-NordicSemi compiled Aug 28 2015 19:26:24
Info : Hardware version: 1.00
Info : VTarget = 3.300 V
Info : clock speed 1000 kHz
Info : SWD DPIDR 0x0bb11477
Info : nrf51.cpu: hardware has 4 breakpoints, 2 watchpoints
target halted due to debug-request, current mode: Thread
xPSR: 0xc1000000 pc: 0x000006d0 msp: 0x000007c0
** Programming Started **
auto erase enabled
Info : nRF51422-QFAC(build code: A1) 256kB Flash
Info : Padding image section 0 with 2112 bytes
Info : Padding image section 1 with 5864 bytes
Warn : using fast async flash loader. This is currently supported
Warn : only with ST-Link and CMSIS-DAP. If you have issues, add
Warn : "set WORKAREASIZE 0" before sourcing nrf51.cfg to disable it
Info : SWD DPIDR 0x0bb11477
Error: Failed to read memory at 0x20000028
Error: failed to get read pointer
Error: Failed to write to nrf51 flash
Error: error writing to flash at address 0x00000000 at offset 0x00000000
embedded:startup.tcl:476: Error: ** Programming Failed **
in procedure 'program'
in procedure 'program_error' called at file "embedded:startup.tcl", line 532
at file "embedded:startup.tcl", line 476
*** [upload] Error 1
========================== [ERROR] Took 3.86 seconds ==========================

I’ve looked around to see if I can make sense of the errors myself but can’t figure it out. Do I need to configure something with openOCD? I noticed the line about “set WORKAREASIZE 0”, but I don’t know where I would do that. If someone could point me in the right direction for that, that would be great. Or maybe I’m missing some build-flags?

Any help would be greatly appreciated.

OK, I’ve got it working.

Having come across some clues here, in the exchange between ivankravets and fabltd, I modified the file at ~/.platformio/packages/tool-openocd/scripts/target/nrf51.cfg. I replaced line 24 with “set WORKAREASIZE 0”. Upload works now, just a bit slow, but I can live with that.

Thanks! Fixed in

In latest version this issue is back:

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/nordicnrf51/nrf51_dk.html
PLATFORM: Nordic nRF51 4.3.0 > Nordic nRF51X22 Development Kit(PCA1000X)
HARDWARE: NRF51822 32MHz, 32KB RAM, 256KB Flash
DEBUG: Current (cmsis-dap) On-board (cmsis-dap, jlink) External (blackmagic, stlink)
PACKAGES: tool-jlink 1.64607.0 (6.46.7), tool-nrfjprog 1.90702.1 (9.7.2), toolchain-gccarmnoneeabi 1.70201.0 (7.2.1), tool-openocd 2.1000.190422 (10.0), framework-mbed 5.51105.190312 (5.11.5), tool-sreccat 1.164.0 (1.64)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 4 compatible libraries
Scanning dependencies...
No dependencies
Checking size .pio/build/core51822/firmware.elf
Memory Usage -> http://bit.ly/pio-memory-usage
DATA:    [====      ]  38.1% (used 12472 bytes from 32768 bytes)
PROGRAM: [====      ]  42.5% (used 111440 bytes from 262144 bytes)
Configuring upload protocol...
AVAILABLE: blackmagic, cmsis-dap, jlink, mbed, nrfjprog, stlink
CURRENT: upload_protocol = stlink
Uploading .pio/build/core51822/firmware.hex
GNU MCU Eclipse OpenOCD, 64-bitOpen On-Chip Debugger 0.10.0+dev-00593-g23ad80df4 (2019-04-22-20:18)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
0x4000
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
adapter speed: 1000 kHz
Info : clock speed 1000 kHz
Info : STLINK V2J17S4 (API v2) VID:PID 0483:3748
Info : Target voltage: 3.258614
Info : nrf51.cpu: hardware has 4 breakpoints, 2 watchpoints
Info : Listening on port 3333 for gdb connections
target halted due to debug-request, current mode: Thread 
xPSR: 0xc1000000 pc: 0xfffffffe msp: 0xfffffffc
** Programming Started **
auto erase enabled
Info : nRF51822-QFAC(build code: A1) 256kB Flash
Info : Flash write discontinued at 0x000007c0, next section at 0x00001000
Warn : using fast async flash loader. This is currently supported
Warn : only with ST-Link and CMSIS-DAP. If you have issues, add
Warn : "set WORKAREASIZE 0" before sourcing nrf51.cfg/nrf52.cfg to disable it
Error: flash write algorithm aborted by target
Error: timed out while waiting for target halted
Error: error waiting for target flash write algorithm
Error: Failed to write to nrf5 flash
Error: error writing to flash at address 0x00000000 at offset 0x00000000
embedded:startup.tcl:479: Error: ** Programming Failed **
in procedure 'program' 
in procedure 'program_error' called at file "embedded:startup.tcl", line 538
at file "embedded:startup.tcl", line 479
*** [upload] Error 1
========================================================================== [ERROR] Took 26.17 seconds ==========================================================================
The terminal process terminated with exit code: 1

Please report to Issues · platformio/platform-nordicnrf51 · GitHub