Setup UART BLE using Nordic nrf52832
Published at September 16, 2021 · Last Modified at April 9, 2022 · 4 min read · Tags: ble iot zephyr
Setup UART BLE using Nordic nrf52832
Published at September 16, 2021 · Last Modified at April 9, 2022 · 4 min read · Tags: ble iot zephyr
I have played with Murata’s MBN52832 module BLE module. This module is based on a Nordic chipset (nRF52832), it has BLE and NFC capabilities and MCU with cortex-m4 to manage the radio operation. The module comes with a demo firmware without an AT Command interface, and the user has to write its application. However, the SW flexibility allows creating a standalone application with BLE and NFC without using a host device like a PC to operate the BLE radio. BLE devices that are connected to PC are usually controlled by HCI interface.
The MBN52832 have full support from Nordic, which uses Zephyr RTOS and can also be used for a standalone application that manages sensors and can handle BLE communication to a PC or tablet. I have used this target board which matched to the this board which given by Nordic.
I have used a modified Zephyr environment from Nordic. It also contains a pre-compiled libraries for the link layer. Refer for sdc.h as begging to explore this subject. I just had to follow the instruction in this link.
In short, after the west utility is ready for use, just type:
mkdir ncs
cd ncs
west init -m https://github.com/nrfconnect/sdk-nrf --mr v1.6.1
west update
west zephyr-export
Both, west command and the file west.yml are functioning in a similar way as repo utility does in embedded Linux.
I have used the peripheral UART demo application for testing the BLE. This basic example setup a peripheral UART service on the Nordic device. A peripheral UART means that the BLE will pair with BLE central devices, which exist on devices like smartphones and PCs. I have used An iPhone application named BluefruitConnect to serve as a UART console. The input data for the Nordic is received from its UART. It sends the data using its BLE stack, and from there, it is transmitted over the air into the iPhone BLE. The iPhone UART application obtained the RX value from the relevant service characteristic and displayed it to the user. When the iPhone application sends data, it places a character into the appropriate service, and the BLE transmits it over the air. At the same time, the Nordic BLE stack receives the data, extracts the TX value from the same service, and sends it to UART. The build and compile the project, just type :
cd ncs/nrf/samples/bluetooth/peripheral_uart
west build -b nrf52dk_nrf52832
This sample application is based on Nordic UART Service (NUS), and the service definition can be found here:
BT_GATT_SERVICE_DEFINE(nus_svc,
BT_GATT_PRIMARY_SERVICE(BT_UUID_NUS_SERVICE),
BT_GATT_CHARACTERISTIC(BT_UUID_NUS_TX,
BT_GATT_CHRC_NOTIFY,
BT_GATT_PERM_READ,
NULL, NULL, NULL),
BT_GATT_CCC(nus_ccc_cfg_changed, BT_GATT_PERM_READ | BT_GATT_PERM_WRITE),
BT_GATT_CHARACTERISTIC(BT_UUID_NUS_RX,
BT_GATT_CHRC_WRITE |
BT_GATT_CHRC_WRITE_WITHOUT_RESP,
BT_GATT_PERM_READ | BT_GATT_PERM_WRITE,
NULL, on_receive, NULL),
);
This file under subsys/bluetooth/shell/gatt.c provids better view for service definition.
To display the graphical interface of the configuration file, change to the project directory and run the following command:
cd samples/bluetooth/peripheral_uart
west build -b nrf52dk_nrf52832 --target guiconfig
I have tried two options:
sudo ~/zephyr-sdk-0.11.3/./sysroots/x86_64-pokysdk-linux/usr/bin/openocd -f interface/jlink.cfg -f target/nrf52.cfg
The follwoing patch was applied to nrf52.cfg to fix some problems:
x c29adbdd6..9ce81ec4c 100644
--- a/tcl/target/nrf52.cfg
+++ b/tcl/target/nrf52.cfg
@@ -24,7 +24,9 @@ if { [info exists CPUTAPID] } {
set _CPUTAPID 0x2ba01477
}
-swj_newdap $_CHIPNAME cpu -expected-id $_CPUTAPID
+#swj_newdap $_CHIPNAME cpu -expected-id $_CPUTAPID
+swj_newdap $_CHIPNAME cpu -irlen 4 -expected-id $_CPUTAPID
+
dap create $_CHIPNAME.dap -chain-position $_CHIPNAME.cpu
set _TARGETNAME $_CHIPNAME.cpu
@@ -40,3 +42,11 @@ if { ![using_hla] } {
flash bank $_CHIPNAME.flash nrf5 0x00000000 0 1 1 $_TARGETNAME
flash bank $_CHIPNAME.uicr nrf5 0x10001000 0 1 1 $_TARGETNAME
+$_TARGETNAME configure -rtos Zephyr
And to change the interface to SWD, add this line to jlink.cfg
transport select swd
cd ~/BLE/nRF-Command-Line-Tools_10_13_0_Linux64/JLink_Linux_V750a_x86_64
sudo ./JLinkGDBServerExe -select USB -device nRF52832_xxAB -endian little -if SWD -speed 4000 -noir -noLocalhostOnly
It can use gdb for both methods using the target remote command, where OpenOcd usually uses port 333 and Jlink uses port 2331.
Developing Bluetooth application evolves with some technical details that have to define:
CONFIG_BT_L2CAP_TX_MTU=384
CONFIG_BT_BUF_ACL_RX_SIZE=400
[1] getting-started-with-ble
[2] Getting Started with Bluetooth Low Energy
[3] architecture-of-bluetooth-low-energy
[[4] pp-bt_conn_get_info-function-examples] (https://cpp.hotexamples.com/examples/-/-/bt_conn_get_info/cpp-bt_conn_get_info-function-examples.html)
https://devzone.nordicsemi.com/f/nordic-q-a/35927/max-data-length-over-ble https://devzone.nordicsemi.com/f/nordic-q-a/1105/how-do-i-calculate-throughput-for-a-ble-link