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

  • Hi,

    I tried to follow this tutorial but without success.
    So, I'm suspicous about my soldered wires.
    To test at least power wires, I was wondering if I only connect 3v3 and GND pins of my raspberry pi
    3 B+ to the nRF52832 chip, I guess it should be visible from my smarphone using a BLE app (like nRF Toolbox). Could you confirm? (because currently I don't see it...)

  • Only if the firmware on your nrf52832 chip is set to advertise on powerup. Bare chips usually would have a factory firmware that don't do anything (at least the ones I've had).

    You should connect the four wires (swd + power) and see if openocd will show the chip as a target. This setup is very sensitive to movement/interference so try to keep things as stable as possible, without any background programs running on the pi.

  • This setup is very sensitive to movement/interference so try to keep things as stable as possible, without any background programs running on the pi.

    It might help to disable cpu frequency scaling as there is hardcoded number in openocd config specific to cpu clock. by default e.g pi zero runs at 700MHz and scales to 1GHz when cpu is more busy. For faster Pis this difference is even larger like 600 idle vs 1600 busy for Pi4 so this is probably what breaks it as some timing loops may run 3x faster when something else runs too. see e.g https://wiki.archlinux.org/index.php/CPU­_frequency_scaling#Scaling_governors

  • Thank you for details and advices.
    I checked my wires and they're well soldered. I'll keep investigating... (probably try an another Pi or chip)

  • Update for "rpi1.cfg" if not using the Raspi Zero like me having a Raspi3

          interface bcm2835gpio
         # RPi Zero/v1 interface
         [#bcm2835gpio_peripheral_base](http://fo­rum.espruino.com/search/?q=%23bcm2835gpi­o_peripheral_base) 0x20000000
         [#bcm2835gpio_speed_coeffs](http://forum­.espruino.com/search/?q=%23bcm2835gpio_s­peed_coeffs) 113714 28
    
       # Raspi1 BCM2835: (700Mhz)
       [#bcm2835gpio_peripheral_base](http://fo­rum.espruino.com/search/?q=%23bcm2835gpi­o_peripheral_base) 0x20000000
       [#bcm2835gpio_speed_coeffs](http://forum­.espruino.com/search/?q=%23bcm2835gpio_s­peed_coeffs) 113714 28
    
       # Raspi2 BCM2836 (900Mhz):
       [#bcm2835gpio_peripheral_base](http://fo­rum.espruino.com/search/?q=%23bcm2835gpi­o_peripheral_base) 0x3F000000
       [#bcm2835gpio_speed_coeffs](http://forum­.espruino.com/search/?q=%23bcm2835gpio_s­peed_coeffs) 146203 36
    
       # Raspi3 BCM2837 (1200Mhz):
        bcm2835gpio_peripheral_base 0x3F000000
        bcm2835gpio_speed_coeffs 194938 48
    
    

    Thanks to @jaolho and @fanoush

    OpenOCD fails to connect with cortex processor

  • Wow it look's horrible - preview look fine but the result after "Post reply" is ugly....

  • Here it is... just follow 'old conventions': make the line comment char a token by letting if follow by a blank:

     # FULL ESPRUINO SCRIPT
    
    interface bcm2835gpio
     # RPi Zero/v1 interface
     # bcm2835gpio_peripheral_base 0x20000000
     # bcm2835gpio_speed_coeffs 113714 28
    
     # Raspi1 BCM2835: (700Mhz)
     # bcm2835gpio_peripheral_base 0x20000000
     # bcm2835gpio_speed_coeffs 113714 28
    
     # Raspi2 BCM2836 (900Mhz):
     # bcm2835gpio_peripheral_base 0x3F000000
     # bcm2835gpio_speed_coeffs 146203 36
    
     # Raspi3 BCM2837 (1200Mhz):
    bcm2835gpio_peripheral_base 0x3F000000
    bcm2835gpio_speed_coeffs 194938 48
    
     # 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
    

    (I assume that a # immediately followed by something is considered kind of an anchor thing for post/conversation/document internal navigation.)

  • so let's just upload the extended version as text file :)


    1 Attachment

  • The forum source parsing and rendering system is very particular when it comes to special characters and more so what the character after the special character is. Simple mark-up - avoiding a real mark-up - has a price... though pretty smart: in 'old fashioned' language syntax / tokenizing blanks after a symbol was required to keep the parsing simple... so do it here too:

    Add a blank *after* the comment (#) sign.

    (Escaping with a leading backslash works some times too... as after between single asterisks does, even within a triple-asterisks streak... ;-\ )

    (IMNSHO anyway a good and gentle practice... for the - human - code reader... we may be nerds, but we are not machines after all. - If I'm not in resource constraints, I write code so I and other humans can read the code easily and grok it right away... and leave the crappy work to the machine, that's for what I have them for.)

    And if you want to get rid of the 'random' syntax coloring pack the stuff into a multi-line js string , like this:

    `
     # FULL ESPRUINO SCRIPT
    interface bcm2835gpio
     # RPi Zero/v1 interface
     # bcm2835gpio_peripheral_base 0x20000000
     # bcm2835gpio_speed_coeffs 113714 28
     # Raspi1 BCM2835: (700Mhz)
     # bcm2835gpio_peripheral_base 0x20000000
     # bcm2835gpio_speed_coeffs 113714 28
     # Raspi2 BCM2836 (900Mhz):
     # bcm2835gpio_peripheral_base 0x3F000000
     # bcm2835gpio_speed_coeffs 146203 36
     # Raspi3 BCM2837 (1200Mhz):
    bcm2835gpio_peripheral_base 0x3F000000
    bcm2835gpio_speed_coeffs 194938 48
     # Pins
    bcm2835gpio_swd_nums 25 24
    bcm2835gpio_srst_num 18
    reset_config srst_only srst_push_pull
    .....
    ...
    .
    `
    

    (Sorry, my bad,... it - color coding - is not random, it follows the rules... But: I wish the triple back tick - ``` - would have something to tell what semantics should be applied for what is triple back ticked... may be there is something possible, but I just don't know about; for example, ` ` ` js or ` ` ` text as standalone line after a blank line - of course, all without blanks between the individual chars - would tell the rendering what rules to apply... and being no rules -just plain, pre-formatted text - would just be good enough. JS (js) could be default with no need to say something; text or plain or pre for 'just leave it alone' would do just great... additional attributes could be about font: fixed, size, color,... like css short specs: fixed 1.0 blue on grey. - 1.0em rather than 11px).

  • 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