Skip to content
Tristan edited this page Sep 12, 2020 · 30 revisions

nRF52832

Use with Arduino IDE: https://github.com/sandeepmistry/arduino-nRF5

E73-2G4M04S1B

Get the bare module from AliExpress

(not labeled) 36 P0.21 Input/Output/RST

The bare module has no LEDs and it is difficult to find out if the board is actually powered. The easiest way to know si to use a BT5.0 enabled phone and scan for bluetooth devices. The bare module advertises itself as Ebyte_UART and you can use one of the Nordic nRF tools (you can get them from the playstore or app store) like nRF Connect to see if the board responds.

Get the breakout board (easier to prototype with) from AliExpress

Connections: https://pastebin.com/PTWDBn5T

NRF52832 E73-2G4M04S1B Connected to
P0.05 21 CH340G CTS
P0.06 22 CH340G RX
P0.07 23 CH340G RTS
P0.08 24 CH340G TX
P0.13 29 SW2 (act. low)
P0.14 30 SW1 (act. low)
P0.17 33 LED1 (act. low)
P0.18 34 LED2 (act. low)

The breakout board advertises itself as Nordic_UART and has LEDs three LEDs: one to indicate power, and two user LEDs.

Espruino nrf52832DK firmware can be flashed on the breakout. The breakout's two LEDs and two switches are similar to the first two LEDs and switches of the nrf52832DK; hence the firmware maps them correctly to LED1 LED2 BTN1 and BTN2. However note that the silkscreen identifies BTN1 as SW2 and BTN2 as SW1.

There's also https://github.com/parasquid/mcu-iot-sensors/blob/master/espruino-boards/E73TRM01.py derived from @AkosLukacs

Removing Access Port (Flash) Protection using Raspberry Pi

The modules seem to have their flash access protection enabled; normally you can use nrfjprog to recover and erase the flash, but that requires a Segger J-Link which is quite expensive. There are ways to use openocd and a Raspberry Pi to debug and remove the the flash access protection, though.

Flashing with ST-LinkV2

After the flash access protection has been disabled, an ST-LinkV2 can be used to program the module.

Flashing with the Pi

OpenOCD flashing (via stlink):

First get the latest OpenOCD and build it

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
make
sudo make install

Then make a file for the configuration (I call mine ebyte.cfg):

#
# Nordic Semiconductor NRF52 Development Kit (nRF52832)
#
source [find interface/stlink-v2.cfg]

transport select hla_swd

source [find target/nrf52.cfg]

Then openocd -f ebyte.cfg On another terminal, telnet localhost 4444 When you are dropped in the OpenOCD prompt, you can now reprogram the device:

halt
nrf5 mass_erase
program espruino_2v04.300_e73trm01.hex verify

Note that the ST-Link cannot remove protection; you'll need to use the raspberry pi or a jlink for that.

Access Protection

Also see https://devzone.nordicsemi.com/f/nordic-q-a/17015/how-do-i-disable-control-access-port-protection-on-nrf52-using-openocd

This will check if access protection is enabled:

nrf52.dap apreg 1 0x0c

0x0 means protection is enabled and you can't use jtag (to dump memory for example).

To disable protection (and erase the program that's currently installed)

nrf52.dap apreg 1 0x04 0x01

Example programming via OpenOCD:

sudo openocd -d2 -f interface/jlink.cfg -c "transport select swd" -f target/nrf52.cfg -c "init; halt; nrf5 mass_erase; program /home/tristan/parasquid/Espruino/builds/espruino_2v06.48_mdbt42q.hex; reset; exit"

For the nrf52840 module: https://psqd.pw/ebyte-nrf52840 see http://openocd.zylin.com/#/c/5522/

So after nrf5 mass_erase which will then show a bogus error message

Flash protection of this nRF device is not supported
Failed to check chip's write protection 

you can use flash erase_check 0 to check if the flash has indeed been erased

More debug info here as well https://github.com/netik/dc27_badge/blob/master/hardware/programming/debug.txt

Also see https://devzone.nordicsemi.com/f/nordic-q-a/38205/flashing-pca10059

Dumping the flash

See also https://gist.github.com/fanoush/06eee6344a2e59f7b12707b25d87edda

sudo openocd -d2 -f interface/jlink.cfg -c "transport select swd" -f target/nrf52.cfg -c "init; halt;"
> flash banks
#0 : nrf52.flash (nrf5) at 0x00000000, size 0x00000000, buswidth 1, chipwidth 1
#1 : nrf52.uicr (nrf5) at 0x10001000, size 0x00000000, buswidth 1, chipwidth 1

> flash read_bank 0 flash-bank0.bin
nRF52832-QFAA(build code: E1) 512kB Flash, 64kB RAM
wrote 524288 bytes to file flash-bank0.bin from flash bank 0 at offset 0x00000000 in 17.059698s (30.012 KiB/s)

> flash read_bank 1 flash-bank1.bin
wrote 4096 bytes to file flash-bank1.bin from flash bank 1 at offset 0x00000000 in 0.139697s (28.633 KiB/s)