STM32WB Bluetooth® LE – AT command server Project

Revision as of 08:14, 21 April 2022 by Registered User (→‎Auxiliary packet introduction)

1. STM32WB - Extended advertising configuration for applications

M0: stm32wb5x_BLE_Satck_full_extended_fw.bin @0x080c7000 (CubeWB package v1.14.0)

M4: M4: BLE_p2pServer_Ext and BLE_p2pClient_Ext v1.14.0

The BLE_p2pServer_Ext and BLE_p2pClient_Ext application are available by downloading STM32CubeWB[1] release.

Application is compiled with following options in app_conf.h:  CFG_BLE_OPTIONS: default flags + SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV SHCI_C2_BLE_INIT_OPTIONS_CS_ALGO2 (mandatory in Extended Advertising PDUs) New parameters are defined in v1.14.0: CFG_BLE_MAX_ADV_SET_NBR and CFG_BLE_MAX_ADV_DATA_LEN. They are transmitted to the stack through ble_init_cmd_packet. 


New Scatter file to use (provided in M4 projects): Shared RAM for M4 has been reduced Part of SRAM2B is now used for M4, mailbox buffers


2. Applications description


3. Auxiliary packet introduction

The PDU payload of primary advertising channels can vary in length from 6 to 37 bytes. (6 bytes for addresses, remaining 31 bytes for data)
In Extended Advertising, secondary advertising channels are used to offload data

  • Up to 1650 bytes
  • Multiple and agnostic adverting sets

The advertising packets on primary channels contain the information in which secondary advertising channel and the offset to the start time the auxiliary data will be transmitted

Aux packet


4. Adv Extended NoConn_NoScan

Primary and auxiliary segments-NO SCANNABLE/NO CONNECTABLE
Segments timing implementation:

  • Both primary/auxiliary segments belong to the same scheduled slot for all fragmentations policy (length depends on data size)
  • Channel of AUX_ADV_IND (+request and response) are randomly selected when set is ACTIVATED
  • Chained channels follow a hopping of 1 increment
Example of no scannable/no connectable set


5. Adv Extended Scannable

Primary and auxiliary segments-SCANNABLE
The scannable undirected event type using the ADV_EXT_IND PDU allows any scanner to respond with a scan request to receive scan response data on the secondary advertising physical channel

  • Only Auxiliary segment could be scanned, and Data could only be contained in the scan response.
  • A scanner may send a scan request using the AUX_SCAN_REQ PDU on the same secondary advertising channel index as the received AUX_ADV_IND
Example of scannable set


5.1. General commands

Initialization commands:

GAP Command Description Comments
BLE_RST Reset the Link Layer
BLE_PUB_ADDR Initializes public address If needed, to be done before BLE_INIT
BLE_CFG_RAND_ADDR Uses the default random address (defined in application) If needed, to be done before BLE_INIT
BLE_RAND_ADDR Initializes random address If needed, to be done before BLE_INIT
BLE_NAME Sets the name of the device If needed, to be done before BLE_INIT
BLE_RF_POWER Sets the TX power level of the device Entered in dBm. See available values
BLE_INIT Initializes public and random addresses, TX power level, name of the device: default values are used if not defined with previous AT commands. Sets default init values for the security Default security values can be modified with BLE_IO_CAPA and BLE_SET_AUTHEN_REQ
BLE_IO_CAPA Sets IO capability Can be done before or after BLE_INIT
BLE_SET_AUTHEN_REQ Sets authentication requirement of the device Can be done before or after BLE_INIT
BLE_SVC Initializes a predefined service (P2P server or Heart Rate) BLE_SVC=1 creates service and characteristics for P2P_server service and starts advertising. BLE_SVC=2 creates service and characteristics for Heart_Rate service and starts advertising.


GAP commands:

GAP Command Description Comments
BLE_ADV_PARAM Sets advertising parameters
BLE_ADV Starts, stops advertising If no new defined advertising parameter, use of default parameters
BLE_CONN_INT Updates the connection interval To send after link establishment if needed
BLE_CLEAR_DB Clears the security database
BLE_PERIPH_SEC_REQ Sends a peripheral security request to the central To send after link establishment if needed
BLE_PAIRING_CONFIRM Allows the user to confirm or the numeric comparison value showed through BLE_EVT_VALUE_CONFIRM Used to answer BLE_EVT_VALUE_CONFIRM event
BLE_PASSKEY_RESP Sends the passkey to use during the pairing process, in response to BLE_EVT_PASSKEY_REQ Used to answer BLE_EVT_PASSKEY_REQ event


GATT commands:

GAP Command Description Comments
BLE_SVC Initialize a service BLE_SVC=3 to 5 creates a custom service
BLE_CHAR_ADD Add a characteristic Applicable to a custom service
BLE_NOTIF_VAL Sets the characteristic value to be notified value sent from the server to the client
BLE_INDIC_VAL Sets the characteristic value to be indicated value sent from the server to the client


GAP events:

GAP Command Description Comments
BLE_EVT_CONN After connection/disconnection
BLE_EVT_UPD_CONN After connection update
BLE_EVT_PASSKEY_REQ After pairing request (legacy pairing) Needs to be answered with BLE_PASSKEY_RESP
BLE_EVT_VALUE_CONFIRM After pairing request (secure connection) Needs to be answered with BLE_PAIRING_CONFIRM
BLE_EVT_PAIRING AT the end of pairing process Returns status and reason parameters


GATT events:

GAP Command Description Comments
BLE_EVT_WRITE After characteristic write Sent when a client writes a characteristic


6. Initialization commands

6.1. Initialization - reset - BLE_RST

SET operation: <1>

AT+BLE_RST=1
OK

QUERY operation: no query for this command, it returns an error.

6.2. Initialization - public address - BLE_PUB_ADDR

Public address is 6 bytes address.
SET operation: <address>

AT+BLE_PUB_ADDR=0x112233445566
OK

QUERY operation: <public address>

AT+BLE_PUB_ADDR?
+ BLE_PUB_ADDR: 0x112233445566
OK

6.3. Initialization - use of default random address – BLE_CFG_RAND_ADDR

SET operation: <1>

AT+BLE_CFG_RAND_ADDR=1
OK

QUERY operation: <config random address>

AT+BLE_CFG_RAND_ADDR?
+BLE_CFG_RAND_ADDR=1
OK

6.4. Initialization - random address – BLE_RAND_ADDR

Random address is 6 bytes address.
SET operation: <address>

AT+BLE_RAND_ADDR=0xFF11223344CC
OK

QUERY operation: <random address>

AT+BLE_RAND_ADDR?
+ BLE_RAND_ADDR: 0xFF11223344CC
OK

6.5. Initialization - name – BLE_NAME

Device name is a string of characters (maximum of 19 characters)
SET operation: <name>

AT+BLE_NAME=WB_ATCMD
OK

QUERY operation: <name>

AT+BLE_NAME?
+BLE_NAME=WB_ATCMD
OK

6.6. Initialization - Tx power – BLE_RF_POWER

Tx power value is between -40 dBm to 6 dBm (IC level). List of supported values in dBm:

-40	
-20,85	
-19,75	
-18,85	
-17,6	
-16,5	
-15,25	
-14,1	
-13,15	
-12,05	
-10,9
-9,9	
-8,85	
-7,8	
-6,9	
-5,9	
-4,95	
-4	
-3,15	
-2,45	
-1,8	
-1,3
-0,85	
-0,5	
-0,15	
0	
1	
2	
3	
4	
5	
6	

SET operation: <tx power>

AT+BLE_RF_POWER=1
OK

QUERY operation: <tx power>

AT+BLE_RF_POWER?
+ BLE_RF_POWER:1
OK

6.7. Initialization - BLE_INIT

BLE_INIT to be used in case of custom application. If AT+BLE_INIT=1 is the first sent command, initialization of the following parameters is done:
Public address, random address, device name, RF Tx power, security parameters.
The default values applied in this case are:

  • Public address: based on the company ID, the device ID and the Unique Device Number (UDN)
    • bit[47:24] : 24bits (OUI) equal to the company ID
    • bit[23:16] : Device ID.
    • bit[15:0] : The last 16bits from the UDN
  • Random address: based on the UDN and a defined value (0x0000ED6E) to fit the requirements of a random address.
  • Device name: AT SERVER
  • RF Tx power: -0.15 dBm
  • IO Capability: IO_CAP_KEYBOARD_DISPLAY (4)
  • Authentication requirements: no bonding mode (0), MITM (1), SC support supported but optional (1), no use of fixed pin (1), fixed pin (111111), public address (0)

If the public address, the random address, the name or the tx output power needs to be changed, send associated AT commands, BLE_PUB_ADDR, BLE_RAND_ADDR, BLE_NAME, BLE_RF_POWER before BLE_INIT.

If IO capability, authentication requirements parameters need to be changed, send BLE_IO_CAPA, BLE_SET_AUTHEN_REQ before or after BLE_INIT out of any link establishment.

SET operation: <1>
Use default BD address, default name, default Tx Power if no new parameter has been defined. Default initialization in case security (pairing) is started after link establishment. These values can be changed when no link is established with BLE_IO_CAPA and BLE_SET_AUTHEN_REQ (commands described later).If BLE_PUB_ADDR, BLE_RAND_ADDR, BLE_NAME or BLE_RF_POWER have been sent previously, the new parameters are taken into account.

AT+BLE_INIT=1
OK

QUERY operation: <public_addr>, <name>, <tx power>

AT+BLE_INIT?
+BLE_INIT:0x0080e12600c2,AT server,-0.15
OK

6.8. Initialization - IO capability - BLE_IO_CAPA

IO capability values :

  • 0: IO_CAP_DISPLAY_ONLY
  • 1: IO_CAP_DISPLAY_YES_NO
  • 2: IO_CAP_KEYBOARD_ONLY
  • 3: IO_CAP_NO_INPUT_NO_OUTPUT
  • 4: IO_CAP_KEYBOARD_DISPLAY


SET operation: <io_capability>

AT+BLE_IO_CAPA=1
OK

QUERY operation: <io_capability>

AT+BLE_IO_CAPA?
+BLE_IO_CAPA:1
OK

6.9. Initialization - authentication requirement - BLE_SET_AUTHEN_REQ

Sets authentification requirement of the device :

bonding_mode:
  • 0: no bonding mode’
  • 1: bonding mode
mitm:
  • 0: no MITM
  • 1: MITM
sc_support:
  • 0: SC pairing not supported
  • 1: SC pairing supported but optional
  • 2: SC pairing mandatory
use_fixed_pin:
  • 0: use a fixed pin
  • 1: do not use a fixed pin
fixed_pin:
  • 0 to 999999

SET operation: <bonding_mode>, <mitm>, <sc_support>, <use_fixed_pin>, <fixed_pin>

AT+BLE_SET_AUTHEN_REQ=0,0,1,1,0000
OK

QUERY operation: <bonding_mode>, <mitm>, <sc_support>, <use_fixed_pin>, <fixed_pin>,<identity_address_type>

AT+BLE_SET_AUTHEN_REQ?
+BLE_SET_AUTHEN_REQ:0,0,1,1,0x0,0
OK

6.10. Initialization commands – P2P_server or heart rate service creation – BLE_SVC

If BLE_SVC=1 or BLE_SVC=2 is sent, no need to send BLE_INIT.
BLE_SVC=1 creates service and characteristics for P2P_server service and starts advertising.
BLE_SVC=2 creates service and characteristics for Heart_Rate service and starts advertising.
Use a phone with ST BLE Sensor application to connect to P2P server or Heart rate application.
Services available:

  • 0: no service
  • 1: P2P service
  • 2: Heart Rate


SET operation: <svc_id>

  • Creates P2P_server service and starts advertising
AT+BLE_SVC=1
OK
  • Creates heart rate service and starts advertising
AT+BLE_SVC=2
OK

QUERY operation: <svc_id> Returns the active service.

AT+BLE_SVC? 
+BLE_SVC:2
 OK

7. GAP commands

7.1. GAP command - advertising set parameters – BLE_ADV_PARAM

Sets advertising parameters of the device:

entry_nb:
  • 1: 0,20ms,30ms,0
  • 2: 0,180ms,200ms,0
  • 3: 0,1s,2.5s,0
  • 0, <adv_type>, <adv_int_min>, <adv_int_max>
adv_type:
  • 0: connectable undirected advertising
  • 1: connectable directed advertising
  • 2: scannable undirected advertising
  • 3: not connectable undirected advertising
adv_int_min:
  • From 20 ms to 10240 ms (must be multiple of 0.625 ms)
adv_int_max:
  • From 20 ms to 10240 ms (must be multiple of 0.625 ms)

SET operation: <entry_nb>

AT+BLE_ADV_PARAM=2
OK
AT+BLE_ADV_PARAM=0,0,32,48
OK

QUERY operation: <entry_nb> <adv_type>, <adv_int_min>, <adv_int_max>, <own_addr_type>

AT+BLE_ADV_PARAM?
+BLE_ADV_PARAM:2,0,180.0,200.0,0
OK
AT+BLE_ADV_PARAM?
+BLE_ADV_PARAM:0,0,32.0,48.0,0
OK

7.2. GAP command - start/stop advertising – BLE_ADV

Start/stop advertising:

  • 0: stop advertising
  • 1: start advertising

If no param entered, use default values (config 1)
If predefined config, use (1,2 or 3)
If param entered, use the new parameters

SET operation: <enable>

AT+BLE_ADV=1
OK

QUERY operation: <enable>

AT+BLE_ADV?
+BLE_ADV:1
OK

7.3. GAP command - connection update – BLE_CONN_INT

Connection interval values:

conn_int_min: From 7,5 ms to 4000 ms (must be multiple of 1.25 ms)
conn_int_max: From 7,5 ms to 4000 ms (must be multiple of 1.25 ms) 

SET operation: <conn_int_min>,<conn_int_max>

AT+BLE_CONN_INT=125,150 
OK

QUERY operation: <conn_int_min>,<conn_int_max>

AT+BLE_CONN_INT?	 
+BLE_CONN_INT:125.00,150.00
OK

7.4. GAP command - clear the security database – BLE_CLEAR_DB

SET operation: <1>

AT+BLE_CLEAR_DB = 1
OK	

QUERY operation: no query for this command, it returns an error.

7.5. GAP command - sends a peripheral security request to the central – BLE_PERIPH_SEC_REQ

SET operation: <1>

AT+BLE_PERIPH_SEC_REQ = 1
OK

QUERY operation: No query for this command, it returns an error.

7.6. GAP command - confirms or not the numeric comparison value in secure Connection - BLE_PAIRING_CONFIRM

Confirms or not the numeric comparison value in secure connection:

  • 0: to not confirm the numeric comparison value
  • 1: to confirm the numeric comparison value

SET operation: <confirm_yes_no>

AT+BLE_PAIRING_CONFIRM=1
OK

QUERY operation: no query for this command, it returns an error.

On reception of BLE_EVT_VALUE_CONFIRM event, send AT+BLE_PAIRING_CONFIRM=<confirm_yes_no>, see example here.

7.7. GAP command - sends the passkey to use during the pairing process in legacy pairing - BLE_PASSKEY_RESP

Passkey value is between 0 and 999999.
SET operation: <passkey>

AT+BLE_PASSKEY_RESP=0000
OK

QUERY operation: no query for this command, it returns an error.

On reception of BLE_EVT_PASSKEY_REQ, send AT+BLE_PASSKEY_RESP=<passkey>, see example here.

When the pairing is complete, reception of BLE_EVT_PAIRING event with two parameters: status, reason.

Status:
  • 0: pairing status success
  • 1: pairing status timeout
  • 2: pairing failed
  • 3: encryption failed
Reason:
  • 1: passkey entry failed
  • 2: OOB not available
  • 3: authentication request cannot be met
  • 4: confirm value failed
  • 5: pairing not supported
  • 6: insufficient encryption key size
  • 7: command not supported
  • 8: unspecified reason
  • 9: very early next attempt
  • 10: invalid parameters
  • 11: SC DHKEY check failed
  • 12: SC numeric comparison failed

8. GATT commands

8.1. GATT command - custom service creation - BLE_SVC

For the creation of a custom service, the command BLE_INIT is mandatory. Use a phone with ST BLE ToolBox to connect with WB55 and a custom service.
Custom service parameters:

svc_id:
  • 0: no service
  • 3 to 5: custom service
svc_uuid_type:
  • 1: 16 bits
  • 2: 128 bits
uuid_16b: 
  • 16 bits service uuid
max_attr_record: 
  • 2 * nb_of_char + 1

SET operation: <svc_id>, <svc_uuid_type>, <uuid_16b>, <max_attr_record>

AT+BLE_SVC=3,1,0xAABB,10
OK

QUERY operation: <svc_id>

AT+BLE_SVC?
+BLE_SVC:3
OK

If svc_uuid_type = 1, a range of UUID values has been pre-allocated, it is the Bluetooth base UUID and it has the value 00000000-0000-1000-8000- 00805F9B34FB.
If svc_uuid_type = 2, the user enters 16 bits service uuid. The 128 bits service uuid is completed in BLE_AT_SERVER application with the following value 00000000-CC7A-482A-984A-7F2ED5B3E58F.

Example 1:

AT+BLE_INIT=1
OK
AT+BLE_SVC=3,1,0xAABB,10
AT+BLE_ADV=1
OK
Custom service creation 1
Connectivity Custom service1.png

Example 2:

AT+BLE_INIT=1
OK
AT+BLE_SVC=3,2,0xAABB,10
AT+BLE_ADV=1
OK
Custom service creation 2
Connectivity Custom service2.png
AT_SERVER: default complete local name
00:80:E1:26:F6:5B: default public BD address

Up to three custom services can be defined.

8.2. GATT command - characteristic creation - BLE_CHAR_ADD

Characteristic parameters:

svc_id: 
  • 3: service id on which characteristic is added
char_id: 
  • 1 to 5: characteristic id
char_uuid_type:
  • 1: 16 bits
  • 2: 128 bits
char_uuid_16b:
  • 16 bits char uuid
char_value_len:
  • 1 to 245
char_prop:
  • 0x00: CHAR_PROP_NONE
  • 0x01: CHAR_PROP_BROADCAST
  • 0x02: CHAR_PROP_READ
  • 0x04: CHAR_PROP_WRITE_WITHOUT_RESP
  • 0x08: CHAR_PROP_WRITE
  • 0x10: CHAR_PROP_NOTIFY
  • 0x20: CHAR_PROP_INDICATE
  • 0x40: CHAR_PROP_SIGNED_WRITE
  • 0x80: CHAR_PROP_EXT
sec_permission:
  • 0x00: None
  • 0x01: AUTHEN_READ
  • 0x02: AUTHOR_READ
  • 0x04: ENCRY_READ
  • 0x08: AUTHEN_WRITE
  • 0x10: AUTHOR_WRITE
  • 0x20: ENCRY_WRITE
gatt_evt_mask:
  • 0x00: GATT_DONT_NOTIFY_EVENTS
  • 0x01: GATT_NOTIFY_ATTRIBUTE_WRITE
  • 0x02: GATT_NOTIFY_WRITE_REQ_AND_WAIT_FOR_APPL_RESP
  • 0x04: GATT_NOTIFY_READ_REQ_AND_WAIT_FOR_APPL_RESP

SET operation: <svc_id>, <char_id>, <char_uuid_type>, <char_uuid_16b>, <char_value_len>, <char_prop>, <sec_permission>, <gatt_evt_mask>

AT+BLE_CHAR_ADD=3,1,1,0x3344,2,26,0,1
OK
	

QUERY operation: no query for this command, it returns an error.

If char_uuid_type = 1, a range of UUID values has been pre-allocated, it is the Bluetooth Base UUID and has the value 00000000-0000-1000-8000- 00805F9B34FB

If char_uuid_type = 2, the user enters 16 bits characteristic uuid. The 128 bits service uuid is completed in BLE_AT_SERVER application with the following value 00000000-8E22-4541-9D4C-21EDAE82ED19.

Example 1:

AT+BLE_CHAR_ADD=3,1,1,0x3344,2,26,0,1
OK
Custom characteristic example 1
Connectivity Custom char1.png

Example 2:

AT+BLE_CHAR_ADD=3,1,2,0x3344,2,10,0,1
OK
Custom characteristic example 2
Connectivity Custom char2.png

8.3. GATT command - setting of the characteristic value to notify - BLE_NOTIF_VAL

Parameters of BLE_NOTIF_VAL command:

svc_id: 
  • 1 to 5: service id corresponding to the characteristic to be notified
char_id: 
  • 1 to 5: characteristic id to be notified
char_val:
  • value to be notified

SET operation: <svc_id>, <char_id>, <char_val>

  • Sets heart rate measurement characteristic value to 70 for heart rate service:
AT+BLE_NOTIF_VAL=2,1,70
OK

By default, energy expended value is set to 0, it is not displayed on the phone.

  • Sets button control characteristic status, 0 and 1 are displayed alternatively (char_val = 0 has no effect) for P2P service:
AT+BLE_NOTIF_VAL=1,2,1
OK	

QUERY operation: no query for this command, it returns an error.

8.4. GATT command - setting of the characteristic value to indicate - BLE_INDIC_VAL

Parameters of BLE_INDIC_VAL command:

svc_id: 
  • 1 to 5: service id corresponding to the characteristic to be notified
char_id: 
  • 1 to 5: characteristic id to be notified
char_val:
  • value to be notified

SET operation: <svc_id>, <char_id>, <char_val>

AT+BLE_INDIC_VAL=3,1,10
OK	

QUERY operation: no query for this command, it returns an error.

9. Events generation

An event is an information received either from the remote device or from the local device to inform the application about the status change or the data received.

Events description
Connectivity Events generation.png

10. Security

The BLE security model includes five security features:

  • Pairing: process for creating one or more shared secret keys.
  • Bonding: act of storing the keys created during pairing for use in subsequent connections in order to form a trusted device pair.
  • Device authentication: verification that the two devices have the same keys.
  • Encryption: provides message confidentiality.
  • Message integrity: protects against fake messages.(4 bytes message integrity check MIC)

BLE uses two security levels:

  • Legacy pairing – short temporary key (STK). STK is created to encrypt connection. Then, if bonding, LTK is used for subsequent connections.
  • Secure connection – long term key (LTK). LTK is created to encrypt connection.

10.1. Legacy pairing and no fixed pin (initiated by the central)

Default initialization values can be changed when no link is established with:

BLE_IO_CAPA=4
BLE_SET_AUTHEN_REQ=0,1,0,1,111111 (fixed pin is not used)
Legacy pairing with no fixed pin exchange sequence
Connectivity LP nofixedpin1.png
Connectivity LP nofixedpin2.png

10.2. Legacy pairing and fixed pin (111111) (initiated by the central)

Default initialization values can be changed when no link is established with:

BLE_IO_CAPA=0
BLE_SET_AUTHEN_REQ=0,0,0,0,111111 (fixed pin = 111111 is used)
Legacy pairing with fixed pin exchange sequence
Connectivity LP fixedpin1.png
Connectivity LP fixedpin2.png

10.3. Secure connection (initiated by the central)

Use of default values when BLE_INIT is sent:

io_capability = 4
bonding_mode = 0
mitm = 1
sc_support = 1
use_fixed_pin = 1
fixed_pin = 111111
identity_address_type = 0
Secure connection (initiated by the central) exchange sequence
Connectivity SecureConnection1.png
Connectivity SecureConnection2.png

11. Flow sequences for examples

11.1. First demonstration using predefined applications

11.1.1. BLE_SVC=1 P2P_server

Steps to use P2P_server application:

  • Power on your board running BLE_AT_Server application
  • Open a terminal emulator to send data to STM32WB LPUART1 interface.
  • Send AT+BLE_SVC=1 command : creates P2P_server service and starts advertising. OK is received
  • Then, open ST BLE Sensor smartphone application and connect to P2PSRV1 device
  • Events are received over LPUART:
    • BLE_EVT_CONN=1
    • BLE_EVT_UPD_CONN=1
    • BLE_EVT_UPD_CONN=1
  • Play with the light on the smartphone, events are received over LPUART:
    • BLE_EVT_WRITE=1,2,x with x = 0 led off, x = 1 led on
  • Send over the LPUART AT+BLE_NOTIF_VAL=1,2,1 command – toggles button characteristic status, (AT+BLE_NOTIF_VAL=1,2,0 has no effect), on the smartphone "Button pressed: hh:mm:ss {status}" is displayed. OK is received


P2P Server exchange sequence
Connectivity P2P server.png
Connectivity P2P sequence debug trace.png

11.1.2. BLE_SVC=2 heart rate

Steps to use the heart rate application:

  • Power on your board running BLE_AT_Server application
  • Open a terminal emulator to send data to STM32WB LPUART1 interface
  • Send AT+BLE_SVC=2 command : creates Heart Rate service and starts advertising. OK is received
  • Then, open ST BLE Sensor smartphone application and connect to HRSTM device
  • Events are received over LPUART:
    • BLE_EVT_CONN=1
    • BLE_EVT_UPD_CONN=1
    • BLE_EVT_UPD_CONN=1
  • Send over the LPUART AT+BLE_NOTIF_VAL=2,1,70 command – sets heart rate measurement characteristic value to 70. OK is received
Heart Rate exchange sequence
Connectivity HeartRate.png
Connectivity HR sequence debug trace.png

11.2. Second demonstration: creating a custom service

11.2.1. BLE_SVC=3 Custom service

Steps to create custom service:

  • Power on your board running BLE_AT_Server application
  • Open a terminal emulator to send data to STM32WB LPUART1 interface
  • Send AT+BLE_INIT=1 command, initialization. OK is received
  • Send AT+BLE_SVC=3,2,0xaabb,10 command, creation of a custom service. OK is received
  • Send AT+BLE_CHAR_ADD=3,1,1,0x3344,2,26,0,1 command, creation of a characteristic with properties: read, write, notify. OK is received
  • Send AT+BLE_CHAR_ADD=3,2,1,0x5566,2,40,0,1 command, creation of a second characteristic with properties: write, indicate. OK is received
  • Send AT+BLE_ADV=1, starts advertising. OK is received
  • Then, open ST BLE ToolBox smartphone application and connect to AT_SERVER device, discover service and characteristics.
  • Events are received over LPUART:
    • <BLE_EVT_CONN=1
    • <BLE_EVT_UPD_CONN=1
    • <BLE_EVT_UPD_CONN=1
Creation of custom service exchange sequence
Connectivity newcustom.png
ST BLE ToolBox Custom service
Connectivity ST BLE ToolBox Custom Service.jpg

Write characteristics, enable notification and indication:

  • On the first writable characteristic, click on the write button, enter the value to write for example 0x1122 and click on send. Value is written on service 3, characteristic 1.
  • Event is received over LPUART:
    • <BLE_EVT_WRITE=3,1,0x1122
  • Same thing on the second writable characteristic, write 0x3344 value.
  • Event is received over LPUART:
    • <BLE_EVT_WRITE=3,2,0x3344
  • On notifiable characteristics, click on Notify for characteristic 1 to enable notification and click on Indicate for characteristic 2 to enable indication.
  • Send AT+BLE_NOTIF_VAL=3,1,1 command, OK is received. Notification received on the smartphone.
  • Send AT+ BLE_INDIC_VAL=3,2,1 command, OK is received. Indication received on the smartphone.
Characteristic management exchange sequence
Connectivity writechar1.png
Connectivity writechar2.png

Initialization sequence with specific parameters, change of connection interval:

  • Send AT+BLE_PUB_ADDR=0x112233445566 command, configuration of public address. OK is received
  • Send AT+BLE_INIT=1 command, initialization. OK is received
  • Send AT+BLE_ADV_PARAM=0,0,20,25 command, configuration of advertising parameters. OK is received
  • Send AT+BLE_ADV_PARAM? command to check advertising parameters.
    • +BLE_ADV_PARAM:0,0,20.0,25.0,0 is received
    • OK is received
  • Send AT+BLE_ADV=1 command, starts advertising. OK is received
  • Then, open ST BLE ToolBox smartphone application and connect to AT_SERVER device, discover service and characteristics.
  • Events are received over LPUART:
    • <BLE_EVT_CONN=1
    • <BLE_EVT_UPD_CONN=1
    • <BLE_EVT_UPD_CONN=1
  • Send AT+BLE_CONN_INT=125,150 command, change connection interval. OK is received
  • Events are received over LPUART:
    • <BLE_EVT_UPD_CONN=1
  • Send AT+BLE_CONN_INT? command to check connection interval.
    • +BLE_CONN_INT:150.00,150.00 is received
    • OK is received
Initialization sequence with specific parameters, change of connection interval
Connectivity conninterval1.png
Connectivity conninterval2.png

Initialization sequence with random address defined by the user:

  • Send AT+BLE_RAND_ADDR=0xee2233445566 command, configuration of random address. OK is received
  • Send AT+BLE_RAND_ADDR? command to check random address.
    • +BLE_RAND_ADDR:0xee2233445566 is received
    • OK is received
  • Send AT+BLE_INIT=1 command, initialization. OK is received
  • Send AT+BLE_ADV_PARAM=0,0,20,25 command, configuration of advertising parameters. OK is received
  • Send AT+BLE_ADV_PARAM? command to check advertising parameters.
    • +BLE_ADV_PARAM:0,0,20.0,25.0,0 is received
    • OK is received
  • Send AT+BLE_ADV=1 command, starts advertising. OK is received
  • Then, open ST BLE ToolBox smartphone application and connect to AT_SERVER device, discover service and characteristics.
  • Events are received over LPUART :
    • <BLE_EVT_CONN=1
    • <BLE_EVT_UPD_CONN=1
    • <BLE_EVT_UPD_CONN=1
Initialization sequence with random address defined by the user
Connectivity random addr1 1.png
Connectivity random addr1 2.png

Initialization sequence with default random address (CFG_STATIC_RANDOM_ADDRESS defined in app_conf.h):

  • Send AT+BLE_CFG_RAND_ADDR=1 command, configuration of random address. OK is received
  • Send AT+BLE_RAND_ADDR? command to check random address.
    • +BLE_RAND_ADDR:0x000000000000 is received
    • OK is received
  • Send AT+BLE_INIT=1 command, initialization. OK is received
  • Send AT+BLE_RAND_ADDR? command to check random address.
    • +BLE_RAND_ADDR:0xc122aabbccdd is received
    • OK is received
  • Send AT+BLE_ADV_PARAM? command to check advertising parameters.
    • +BLE_ADV_PARAM:0,0,20.0,30.0,0 is received
    • OK is received
  • Send AT+BLE_ADV=1 command, starts advertising. OK is received
  • Then, open ST BLE ToolBox smartphone application and connect to AT_SERVER device, discover service and characteristics.
  • Events are received over LPUART:
    • <BLE_EVT_CONN=1
    • <BLE_EVT_UPD_CONN=1
    • <BLE_EVT_UPD_CONN=1
Initialization sequence with default random address
Connectivity random addr2 1.png
Connectivity random addr2 2.png

Initialization sequence with default random address generated with random generator (CFG_STATIC_RANDOM_ADDRESS not defined in app_conf.h):

  • Send AT+BLE_CFG_RAND_ADDR=1 command, configuration of random address. OK is received
  • Send AT+BLE_RAND_ADDR? command to check random address.
    • +BLE_RAND_ADDR:0x000000000000 is received
    • OK is received
  • Send AT+BLE_INIT=1 command, initialization. OK is received
  • Send AT+BLE_RAND_ADDR? command to check random address.
    • +BLE_RAND_ADDR:0xe7257d5fd350 is received
    • OK is received
  • Send AT+BLE_ADV=1 command, starts advertising. OK is received
  • Send AT+BLE_ADV_PARAM? command to check advertising parameters.
    • +BLE_ADV_PARAM:0,0,20.0,30.0,1 is received
    • OK is received
  • Then, open ST BLE ToolBox smartphone application and connect to AT_SERVER device, discover service and characteristics.
  • Events are received over LPUART :
    • <BLE_EVT_CONN=1
    • <BLE_EVT_UPD_CONN=1
    • <BLE_EVT_UPD_CONN=1
Initialization sequence with default random address
Connectivity random addr3 1.png
Connectivity random addr3 2.png

Initialization sequence with a new name:

  • Send AT+BLE_NAME=WB_ATCMD command, configuration of device name. OK is received
  • Send AT+BLE_NAME? command to check random address.
    • +BLE_NAME:WB_ATCMD is received
    • OK is received
  • Send AT+BLE_INIT=1 command, initialization. OK is received
  • Send AT+BLE_ADV=1 command, starts advertising. OK is received
  • Then, open ST BLE ToolBox smartphone application and connect to WB_ATCMD device, discover service and characteristics.
  • Events are received over LPUART :
    • <BLE_EVT_CONN=1
    • <BLE_EVT_UPD_CONN=1
    • <BLE_EVT_UPD_CONN=1
Initialization sequence with a new name
Connectivity name1.png
Connectivity name2.png

12. References