This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Programming nRF52 using nrfjprog for use in Arduino

I want to get started with nRF52832 in Arduino. I have a Ebyte development board with E73 module containing the NRF chip.

The hardware is quite similar to Adafruit NRF52 Feather.

But for use in Arduino with serial interface I have to program the boot loader once.

What I have is a STM Nucleo board with ST-Link Interface. The Arduino already has nrfjprog.exe, which interfaces to a J-Link from Segger.

I found that I can update the ST-Link to J-Link and did that.

I connected VCC, GND, SWCLK, SWDIO, RESET and tried:

nrfjprog --program bl.hex  -f nrf52  --reset
ERROR: The operation attempted is unavailable due to readback protection in
ERROR: your device. Please use --recover to unlock the device.

nrfjprog --recover
Recovering device. This operation might take 30s.
ERROR: Recover failed. Please make sure that the correct device family is given
ERROR: and try again.

nrfjprog --program bl.hex  -f nrf52  --reset
ERROR: Cannot connect to any nRF device. Please make sure a device is
ERROR: connected to the debugger and supplied.

It seems that something has changed, but to the worse, the interface can not talk to the chip anymore.

Is this problem related to the STM based interface which should only be used with ST chips ?

Do I have a chance using openOCD and ST-Link for this?

As a fallback I also have a Raspberry Pi, I heard that it can be used without interface. But I need info about installation and connection.

Thanks for help....

  • Solved it in the meantime. The solution is to follow the decription below and use a raspberry Pi to avoid any interface.

    http://forum.espruino.com/conversations/335722/

    But this description is missing the recovery for protected boards. Funny that this worked with upgraded St-Link 2.1, but nrfjprog could not program the chip after recovery. Maybe this is blocked by Segger.

    It would be better if Nordic would support an openOCD workflow with tutorials for new users, to have an easy start and avoid initial frustration.

    Script for openOCD to replace nrfjprog -f NRF52 --recover :

    # Read APPROTECTSTATUS
    # (0x0 Access port protection enabled - 0x1 APP disabled)
    nrf52832.dap apreg 1 0x0c 0x00000000
    # Write ERASEALL register
    nrf52832.dap apreg 1 0x04 0x01
    reset

    Script for openOCD to program after recover:

    # RPi Zero/v1 interface

    interface bcm2835gpio

    bcm2835gpio_peripheral_base 0x20000000

    bcm2835gpio_speed_coeffs 113714 28

    # RPi v2+ interface

    # bcm2835gpio_peripheral_base 0x3F000000

    # bcm2835gpio_speed_coeffs 146203 36

    # Pins

    bcm2835gpio_swd_nums 25 24

    bcm2835gpio_srst_num 18

    reset_config srst_only srst_push_pull

    # Transport

    transport select swd

    # Target

    set WORKAREASIZE 0

    set CHIPNAME nrf52832

    source [find target/nrf52.cfg]

    reset_config srst_only srst_nogate

    adapter_nsrst_delay 100

    adapter_nsrst_assert_width 100

    # Execution

    init

    targets

    halt

    nrf52832.dap apreg 1 0x04 0x01

    flash write_image bootloader_nrf52832.hex

    reset halt

    targets

    verify_image bootloader_nrf52832.hex

    reset run

    targets

    exit

    # END OF SCRIPT

Related