• Figuring out how to get Espruino into a blank nRF52832 (ebyte E73 module from Aliexpress) took me quite a lot of time since I couldn't find a single tutorial with all the needed steps.

    I 'm a total beginner in ARM programming and architecture, so words like J-TAG or SWD didn't tell me anything. After some googling I figured I need more than an USB-UART adapter to bring the chip alive. Fortunately, I had a RPi Zero W lying around and it turned out that it's all you need!

    Here are the steps. In the end, the process is very simple.

    1) Use RPi's command line to install openocd:

    cd ~
    sudo apt-get update
    sudo apt-get install git autoconf libtool make pkg-config libusb-1.0-0 libusb-1.0-0-dev
    git clone "http://openocd.zylin.com/openocd"
    cd openocd
    ./bootstrap
    ./configure --enable-sysfsgpio --enable-bcm2835gpio
    make
    sudo make install
    

    2) Create the following script file (rpi1.cfg) (uncomment the RPi v2+ part if you are using RPi v2 or later):

     # FULL ESPRUINO SCRIPT
    
     # 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 espruino_2v01_nrf52832.hex
    reset halt
    targets
    verify_image espruino_2v01_nrf52832.hex
    reset run
    targets
    exit
    
     # END OF SCRIPT
    

    4) Copy the "espruino_2v01_nrf52832.hex" file into the openocd directory and make sure that the "rpi1.cfg" file is also in that directory. The hex file is from "http://www.espruino.com/binaries".

    5) Connect the nRF52832 chip and the Raspberry Pi:

    nRF52832 <-> RPi

    • VCC <-> VCC (3.3V)
    • GND <-> GND
    • SWDIO <-> GPIO 24 (pin header #22)
    • SWDCLK <-> GPIO 25 (pin header #18)

    6) Run this command in the openocd directory:

    sudo openocd -f "rpi1.cfg"
    

    That's it. You should now be able to upload javascript into the nRF52832 with the Espruiono Web UI!

    ps. If you want to execute the openocd commands one by one or execute other commands, comment out the execution portion of the script file. Then run the script, open another terminal and give the command:

    telnet localhost 4444
    

    You can now give the openocd debugger commands one by one through the telnet terminal. Telnet can be installed with

    sudo apt-get install telnet
    

    pps. This tutorial can be used to program other nRF51 and nRF52 chips with minor modifications to the script file. Also other Raspberry Pi boards can be used!

    Most of this tutorial is based on these posts:
    https://iosoft.blog/2019/01/28/raspberry­-pi-openocd/
    https://devzone.nordicsemi.com/f/nordic-­q-a/21650/flashing-nrf51-with-openocd-on­-raspberry-pi


    2 Attachments

  • Nice - thanks for posting this up!

  • Indeed it is poor man's SWD for free if you have the Pi. However when Pi is used also as a desktop the connection is very unreliable. I tried this or Pi 3B+ and when just moving window the opened SWD connections breaks. But when just using already opened terminal window it works fine. Maybe it is also because dynamic CPU scaling as there are some hardcoded numbers expecting specific CPU frequency in the config.

    But I guess Zero as a dedicated device over e.g. serial or USB could be quite reliable in this. In fact just reliable as those <$2 STLINK clones from aliexpress are :-)

  • I used my (headless) Zero W with ssh terminal over WiFi. Worked like a charm. Zero W is cheaper than any of the official programmers and after programming, you'll have a fully working wireless computer to play with. All for 12 €.

  • Very nice, thanks for confirming this. I feared that even wireless and ssh could affect the reliability. BTW, those stlink clones are in fact generic stm32f103c8t6 boards in small usb stick like package so they are also quite versatile but Zero (W) is definitely better and far more flexible.

    Can openocd run as a daemon without attaching to device immediately? Then one could run it on the Zero W automatically at boot time so one would not need to login over ssh to it since it runs as server already. And if it is not possible out of box maybe it can be proxied over inetd so it would try to start and attach each time one opens network connection to openocd port.

  • The ZeroW running OpenOcd should bd able to do a complete "mass erase", which a ST-link v2.x could not, I believe...

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

FULL tutorial for flashing Espruino into nRF52832 with Raspberry Pi (Zero) using OpenOCD and SWD (two wires)

Posted by Avatar for jaolho @jaolho

Actions