• 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:

    1. cd ~
    2. sudo apt-get update
    3. sudo apt-get install git autoconf libtool make pkg-config libusb-1.0-0 libusb-1.0-0-dev
    4. git clone "http://openocd.zylin.com/openocd"
    5. cd openocd
    6. ./bootstrap
    7. ./configure --enable-sysfsgpio --enable-bcm2835gpio
    8. make
    9. sudo make install

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

    1. # FULL ESPRUINO SCRIPT
    2. # RPi Zero/v1 interface
    3. interface bcm2835gpio
    4. bcm2835gpio_peripheral_base 0x20000000
    5. bcm2835gpio_speed_coeffs 113714 28
    6. # RPi v2+ interface
    7. # bcm2835gpio_peripheral_base 0x3F000000
    8. # bcm2835gpio_speed_coeffs 146203 36
    9. # Pins
    10. bcm2835gpio_swd_nums 25 24
    11. bcm2835gpio_srst_num 18
    12. reset_config srst_only srst_push_pull
    13. # Transport
    14. transport select swd
    15. # Target
    16. set WORKAREASIZE 0
    17. set CHIPNAME nrf52832
    18. source [find target/nrf52.cfg]
    19. reset_config srst_only srst_nogate
    20. adapter_nsrst_delay 100
    21. adapter_nsrst_assert_width 100
    22. # Execution
    23. init
    24. targets
    25. halt
    26. nrf52832.dap apreg 1 0x04 0x01
    27. flash write_image espruino_2v01_nrf52832.hex
    28. reset halt
    29. targets
    30. verify_image espruino_2v01_nrf52832.hex
    31. reset run
    32. targets
    33. exit
    34. # 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:

    1. 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:

    1. telnet localhost 4444

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

    1. 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

About

Avatar for jaolho @jaolho started