Skip to content

Bluetooth

Andrea Barisani edited this page Mar 16, 2022 · 17 revisions

The Mk II includes a u-blox ANNA-B112 Bluetooth module for out-of-band (in relation to USB interfaces) interaction with a wireless client (e.g. mobile application).

The module SoC is a Nordic Semiconductor nRF52832, supporting low energy (BLE) Bluetooth 5 and Bluetooth mesh.

Documentation

Mobile apps

The following mobile applications are provided by u-blox for module evaluation:

Control tool

The armoryctl can be used to perform some of the procedures illustrated below.

Serial connection

All serial AT commands can be issued with your favorite terminal program against device /dev/ttymxc0 and baud rate 115200, example:

minicom -b 115200 -D /dev/ttymxc0

Initial configuration

A one-time configuration, to force the internal RC oscillator as low frequency clock source, must be performed through the following AT commands:

AT+UPROD=1
AT+UPRODLFCLK=0,16,2

This can also be accomplished with armoryctl ble rc_lfck (flash|at) command.

Toggling visibility

The following AT commands set BLE as non discoverable, non pairable, non connectable and disable any role (central or peripheral).

AT+UBTDM=1
AT+UBTPM=1
AT+UBTCM=1
AT+UBTLE=0

The following commands allow permanently store the configuration

AT&W
AT+CPWROFF

This can also be accomplished with armoryctl ble (enable|disable) commands.

Firmware update

The following procedure allows to update the u-blox connectivity software (u-connect).

This can also be accomplished with armoryctl ble update command.

Check the running firmware version

AT+GMR

Download firmware updates

The ANNA-B112 firmware is available on the module product page.

The firmware zip archive contains the following files under the uart subdirectory, which are used during the update:

  • Nordic Semiconductors Bluetooth stack: s132_nrf52_x.x.x_softdevice.bin
  • u-connect application: ANNA-B112-SW-x.x.x.bin
  • update metadata: ANNA-B112-Configuration-x.x.x.json

Enter bootloader mode

# configure GPIOs
echo "9" > /sys/class/gpio/export
echo "26" > /sys/class/gpio/export
echo "27" > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio9/direction
echo "out" > /sys/class/gpio/gpio26/direction
echo "out" > /sys/class/gpio/gpio27/direction
# set SWITCH_1 and SWITCH_2 to low
echo "0" > /sys/class/gpio/gpio27/value
echo "0" > /sys/class/gpio/gpio26/value
# toggle RESET_N
echo "0" > /sys/class/gpio/gpio9/value
echo "1" > /sys/class/gpio/gpio9/value

Update the Nordic Semiconductors Bluetooth stack

The SoftDevice section of the update metadata contains the Address, Size, and Crc32 values to be used in the following commands:

  1. Set the bootloader in xmodem erase+program mode at the relevant address:
x <Address>
  1. Send the file s132_nrf52_x.x.x_softdevice.bin using xmodem transfer mode, with minicom this can be done using shortcut Ctrl+a+S.

  2. Finalize the update by verifying size and checksum values:

c SOFTDEVICE <Size> <Crc32>

Update the u-connect application

The ConnectivitySoftware section of the update metadata contains the Address value to be used in the following commands:

  1. Set the bootloader in xmodem erase+program mode at the relevant address:
x <Address>
  1. Send the file ANNA-B112-SW-x.x.x.bin using xmodem transfer mode, with minicom this can be done using shortcut Ctrl+a+S.

Exit bootloader mode

# set SWITCH_1 and SWITCH_2 to high
echo "1" > /sys/class/gpio/gpio27/value
echo "1" > /sys/class/gpio/gpio26/value
# toggle RESET_N
echo "0" > /sys/class/gpio/gpio9/value
echo "1" > /sys/class/gpio/gpio9/value

OpenCPU mode

The ANNA-B112 module supports an "OpenCPU" option to allow arbitrary firmware, replacing the built-in u-blox one, on its Nordic Semiconductor nRF52832 SoC. This allows provisioning of the SoC with Nordic SDK, Wirepas mesh, ARM Mbed or arbitrary user firmware. The nRF52832 SoC features an ARM Cortex-M4 CPU with 512 kB of internal Flash and 64 kB of RAM.

Using OpenOCD for JTAG access

The following instructions have been tested on the USB armory Mk II using its standard Debian image.

  1. Install the following dependencies:
apt-get install git build-essential autotools automake libtool pkg-config
  1. Download and compile OpenOCD from its github repository:
git clone https://github.com/ntfreak/openocd
cd openocd
./bootstrap
./configure --disable-internal-libjaylink --disable-jlink --enable-imx_gpio
make
  1. Create the ANNA-B112.cfg configuration file with the following contents:
transport select swd
source [find target/nrf52.cfg]
  1. Create the interface file as follows:
cp ./tcl/interface/imx-native.cfg usbarmory-mark-two.cfg
sed -i -e 's/imx_gpio_swd_nums 1 6/imx_gpio_swd_nums 4 6/' usbarmory-mark-two.cfg
  1. Launch OpenOCD
sudo ./src/openocd --search ./tcl -f usbarmory-mark-two.cfg -f ANNA-B112.cfg

The output should be similar to the following one:

Open On-Chip Debugger 0.10.0+dev-00924-g16496488 (2019-08-09-12:39)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : imx_gpio GPIO JTAG/SWD bitbang driver
Info : SWD only mode enabled (specify tck, tms, tdi and tdo gpios to add JTAG mode)
Info : imx_gpio mmap: pagesize: 4096, regionsize: 131072
Info : clock speed 1000 kHz
Info : SWD DPIDR 0x2ba01477
Info : nrf52.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : Listening on port 3333 for gdb connections
Info : accepting 'telnet' connection on tcp/4444
  1. Test OpenOCD

Now GDB (port 3333) and the interactive console (port 4444) can be used for full access to the SoC ARM Cortex-M4 CPU and flash memory.

The following example shows how to read the SoC CPU state:

telnet 127.0.0.1 4444
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
Open On-Chip Debugger
> init
> nrf52.cpu curstate
running

Type help for all available commands.

Clone this wiki locally