Middleware for the Bluetooth peripheral on RA MCUs. This module implements the BLE ABS Interface.
Overview
This module provides BLE GAP functionality that complies with the Bluetooth Core Specification version 5.0 specified by the Bluetooth SIG. This module is configured via the QE for BLE. QE for BLE provides standard and custom services defined by the user.
The module supports the Renesas Electronics DA14531 and DA14535 Bluetooth® Low Energy 5 Modules. The rm_ble_abs_gtl driver interfaces with the DA14531/DA14535 module over UART.
Features
The Bluetooth® Low Energy Abstraction module with GTL supports the following features:
- Common functionality
- Boot from host or DA14531/DA14535 flash.
- Use 1-wire (default) or 2-wire UART for booting.
- Open/Close the BLE protocol stack.
- The following GAP Role support
- Peripheral: The device that accepts a connection request from Central and establishes a connection.
- Central: The device that initiates a connection with a peripheral.
- All roles: The device may act as a central and peripheral the same time.
- GAP functionality
- Initialize the Host stack.
- Setting address.
- Start/Stop Advertising.
- Connect/Disconnect a link.
- Scan
- GATT Common functionality
- GATT Server functionality
- Initialization of GATT Server.
- Loading of Profile definition.
- Notifications and Indications.
- Read/Write of GATT Profile from host.
- Optionally the application and not the device may handle the attributes (Read Indication).
- Gatt Client functionality
- Discover Peripheral Services/Characteristics.
- Read/Write Peripheral Characteristics.
- Receive Notifications and Indications.
- Security functionality (DA14531/DA14535 module acting as Peripheral)
- Legacy Pairing supporting Just works functionality.
- Legacy Pairing supporting Passkey functionality.
- Initiate security request procedure from Peripheral as well.
- Secure connection with Numeric Comparison
- Support security for both roles (Central - Peripheral).
- Store bonding data to flash.
- Enable security configuration.
- Delete all bonding data.
- Delete bonding data with specific BD address.
- DA1453x Sleep support
- Three sleep modes are supported with UART HW flow control.
Configuration
Pin Configuration
Pins used by the BLE driver to control the DA14531/DA14535 module:
- Reset Pin : Active low reset line for DA14531/DA14535 module.
- UART Interface : RX/TX/RTS Pins. The PMOD DA1453x modules require manually setting CTS GPIO as input. PMOD2_SS should be Input and PMOD2_CLK Output Low.
Usage Notes
Getting Started Guide
The below guide walks users through building a fully working solution that allows booting from the host via 1-wire UART in order to run a BLE application from the RA MCU using the GTL interface.
https://lpccs-docs.renesas.com/DA1453x-FSP_BLE_Framework/UM-B-172/index.html
Addresses
- A public BD address the address pre-programmed into the DA14531/DA14535 and will be used as default.
- A random BD address can be set by calling the R_BLE_VS_SetBdAddr function before the R_BLE_GAP_Init function is called.
- A public BD address can be set by calling the R_BLE_GTL_VS_SetPublicBdAddress() after R_BLE_GAP_Init function is called.
Heap Requirements
Ensure the BSP heap size is set to at least 2K bytes.
When using FreeRTOS ensure the heap 4 size is set to a minimum of 2K bytes.
Module Firmware Compatibility
This middleware module is compatible with GTL binary version 6.0.23.1451 and later. You must ensure that the DA14531/DA14535 Module (or PMOD) you are using contains this version (or later) firmware or that you use the boot from host feature and have the host MCU load the binary into the DA14531/DA14535. Note that DA14531 and DA14535 are not firmware compatible even though the GTL API is the same.
Instructions detailing how to upgrade the firmware in a DA14531 Module can be found here:
https://lpccs-docs.renesas.com/US159-DA14531EVZ_Firmware_Upgrade/index.html
The GTL binary file can be downloaded using the tool described in the above instructions, or by using the following link:
https://www.renesas.com/us/en/document/swo/fsp-gtl-binary-us159-da14531evz-pmod-programming?r=1564826
Limitations
Developers should be aware of the following limitations when using the BLE_ABS:
Following a power on reset, the R_BLE_VS_GetRand function always returns the same number. Subsequent calls to this function produce random numbers.
Up to 3 concurrent connections are supported.
For DA1453x Sleep mode CTSRTS0 (EK-RA6M4) should be set to P413. Flow Control CTS/RTS Selection should be set to Hardware CTS. If RA is required to wake-up from DA453x P413 and P414 should be shorted and P414 should be se to interrupt mode.
For bonded devices Client Characteristic Configuration (CCC) values are not saved to flash memory. They are kept to RAM as long as reset does not take place. If the user wishes to save the CCC values to non-volatile memory, he should handle it from the application layer by marking them as Read Indicated (RI, please find the description bellow).
The CCC values are not kept per connection, the value of a CCC is the value of the last modification by a GATT Client. If the user wishes to keep CCC values per connection, he should handle it from the application layer by marking them as Read Indicated (RI, please find the description bellow).
Maximum bonded devices are limited to seven (7). Application must delete an entry before bonding with a new device. Saving bond data is supported with devices that use HP_Flash and boards RA6M4_EK, RA6M5_EK, RA4M3_EK, RA4M2_EK.
Role switching between Central and Peripheral is not supported after the devices have been bonded.
Out Of Band (OOB) paring is not supported.
GAP operations cannot overlap, e.g. you cannot initiate two connections concurrently
The boot from host feature currently supports 1-wire and 2-wire UART operation. If using a 1-wire boot from host the UART RX and TX pins on the host RA MCU must be tied together using a 1K ohm resistor in order to boot the DA14531/DA14535 - this resistor can remain in place after the boot operation has been completed. Boot from host using 2-wire UART is not supported when using a DA14531MOD module because not all the required pins are exposed. Boot from host using 2-wire UART is supported when a DA14535PMOD with SmartBoot (UM-B-171) is already flashed in DA14535. In this case the same pins used for GTL communication are also used for 2-wire boot.
The RI feature of attributes (values are not stored in DA1453x database) is controlled from the flag Enable Characteristic Value Read Callback of QE Tool. In case of a write request the local data base is automatically updated. The app will be notified by an BLE_GATTS_OP_PEER_XXX_WRITE_REQ. In case of a read request and Value Read Callback is enabled (read indication) the local data base is not automatically accessed to get the value. The user is responsible to provide the reply value from gatts_cb by using R_BLE_GTL_GATTS_ReadCfm after a BLE_GATTS_EVENT_DB_ACCESS_IND with BLE_GATTS_OP_PEER_XXX_READ_REQ. The Client Characteristic Configuration (CCC) values are always treated as RI values. If the attribute is CCC and it is not marked as read_notify, then r_ble_gtl automatically handles it by using a cached value.
Service and characteristic write callback functions, are not generated by the QE Tool. Thus, R_BLE_GTL_GATTC_WRITE_REQ_IND always confirms with R_BLE_GTL_GAP_ERR_NO_ERROR. No value check is provided for incorrect value/range etc
R_BLE_GTL_GAP_StartScan supports only :
- Passive Scan (R_BLE_GTL_GAPM_OP_SCAN_PASSIVE)
- General Discovery Mode (R_BLE_GTL_GAP_GEN_DISCOVERY)
- No White Listing (R_BLE_GTL_SCAN_ALLOW_ADV_ALL)
- Static own address (R_BLE_GTL_GAPM_STATIC_ADDR)
- Slow Scan input
- 1M Phy
- Timeout of 7.7 Seconds restricted by DA145xx ROM.
R_BLE_GTL_GAP_CreateConn supports only :
- Static own address (R_BLE_GTL_GAPM_STATIC_ADDR)
- Automatic connection operation (R_BLE_GTL_GAPM_OP_CONNECTION_AUTO)
Currently supported rm_ble_abs_gtl interface functions:
- RM_BLE_ABS_Open
- RM_BLE_ABS_Close
- RM_BLE_ABS_StartLegacyAdvertising
- RM_BLE_ABS_CreateConnection
- RM_BLE_ABS_StartScanning
Currently supported r_ble_api interface functions:
- R_BLE_Open
- R_BLE_Close
- R_BLE_Execute
- R_BLE_IsTaskFree
- R_BLE_GetVersion
- R_BLE_GAP_Init
- R_BLE_GAP_Terminate
- R_BLE_GAP_UpdConn
- R_BLE_GAP_SetDataLen
- R_BLE_GAP_Disconnect
- R_BLE_GAP_ConfWhiteList
- R_BLE_GAP_GetVerInfo
- R_BLE_GAP_ReadRssi
- R_BLE_GAP_ReadChMap
- R_BLE_GAP_SetAdvParam
- R_BLE_GAP_SetAdvSresData
- R_BLE_GAP_StartAdv
- R_BLE_GAP_StopAdv
- R_BLE_GAP_GetRemainAdvBufSize
- R_BLE_GAP_GetRemDevInfo
- R_BLE_GAP_CreateConn
- R_BLE_GAP_CancelCreateConn
- R_BLE_GAP_StartScan
- R_BLE_GAP_StopScan
- R_BLE_GATTS_SetDbInst
- R_BLE_GATT_GetMtu
- R_BLE_GATTS_RegisterCb
- R_BLE_GATTS_DeregisterCb
- R_BLE_GATTS_Notification
- R_BLE_GATTS_Indication
- R_BLE_GATTS_GetAttr
- R_BLE_GATTS_SetAttr
- R_BLE_GATTC_DiscAllPrimServ
- R_BLE_GATTC_DiscPrimServ
- R_BLE_GATTC_DiscCharByUuid
- R_BLE_GATTC_DiscIncServ
- R_BLE_GATTC_DiscAllChar
- R_BLE_GATTC_DiscAllCharDesc
- R_BLE_GATTC_RegisterCb
- R_BLE_GATTC_DeregisterCb
- R_BLE_GATTC_ReqExMtu
- R_BLE_GATTC_ReadChar
- R_BLE_GATTC_ReadCharUsingUuid
- R_BLE_GATTC_ReadLongChar
- R_BLE_GATTC_ReadMultiChar
- R_BLE_GATTC_WriteCharWithoutRsp
- R_BLE_GATTC_WriteChar
- R_BLE_GATTC_WriteLongChar
- R_BLE_GATTC_ReliableWrites
- R_BLE_GATTC_ExecWrite
- R_BLE_VS_Init
- R_BLE_VS_GetBdAddr
- R_BLE_VS_SetBdAddr
- R_BLE_VS_GetRand
- R_BLE_VS_SetTxPower
- R_BLE_VS_GetTxPower
- R_BLE_VS_SetSleepMode
- R_BLE_VS_SetPublicBdAddress
- R_BLE_GAP_SetPairingParams
- R_BLE_GAP_ReplyPairing
- R_BLE_GAP_ReplyLtkReq
- R_BLE_GAP_ReplyExKeyInfoReq
- R_BLE_GAP_StartPairing
- R_BLE_GAP_ReplyNumComp
- R_BLE_GAP_ReplyPasskeyEntry
- R_BLE_GAP_StartEnc
- R_BLE_GAP_GetDevSecInfo
Currently supported callback events:
- BLE_GAP_EVENT_STACK_ON
- BLE_GAP_EVENT_STACK_OFF
- BLE_GAP_EVENT_CONN_IND
- BLE_GAP_EVENT_DISCONN_IND
- BLE_GAP_EVENT_DATA_LEN_CHG
- BLE_GAP_EVENT_CONN_PARAM_UPD_COMP
- BLE_GAP_EVENT_ADV_ON
- BLE_GAP_EVENT_ADV_OFF
- BLE_GAP_EVENT_ADV_REPT_IND
- BLE_GAP_EVENT_SET_DATA_LEN_COMP
- BLE_GAP_EVENT_LOC_VER_INFO
- BLE_GAP_EVENT_RSSI_RD_COMP
- BLE_GAP_EVENT_CH_MAP_RD_COMP
- BLE_GAP_EVENT_GET_REM_DEV_INFO
- BLE_GAP_EVENT_CONN_CANCEL_COMP
- BLE_GAP_EVENT_CONN_PARAM_UPD_REQ
- BLE_GATTS_EVENT_WRITE_RSP_COMP
- BLE_GATTS_EVENT_HDL_VAL_CNF
- BLE_GATTS_EVENT_DB_ACCESS_IND
- BLE_GATTC_EVENT_EX_MTU_RSP
- BLE_GATTC_EVENT_PRIM_SERV_16_DISC_IND
- BLE_GATTC_EVENT_PRIM_SERV_128_DISC_IND
- BLE_GATTC_EVENT_ALL_PRIM_SERV_DISC_COMP
- BLE_GATTC_EVENT_CHAR_READ_BY_UUID_RSP
- BLE_GATTC_EVENT_CHAR_READ_RSP
- BLE_GATTC_EVENT_CONN_IND
- BLE_GATTC_EVENT_CHAR_WRITE_RSP
- BLE_GATTC_EVENT_CHAR_WRITE_WITHOUT_RSP
- BLE_GATTC_EVENT_CHAR_DISC_COMP
- BLE_GATTC_EVENT_CHAR_128_DISC_IND
- BLE_GATTC_EVENT_HDL_VAL_IND
- BLE_GATTC_EVENT_HDL_VAL_NTF
- BLE_GATTC_EVENT_EXECUTE_WRITE_COMP
- BLE_GATTC_EVENT_ATT_INFO_REQ_IND
- BLE_GATTC_EVENT_HDL_VAL_SVC_CHNG
- BLE_GAP_EVENT_EX_KEY_REQ
- BLE_GAP_EVENT_PASSKEY_ENTRY_REQ
- BLE_GAP_EVENT_PEER_KEY_INFO
- BLE_GAP_EVENT_PAIRING_COMP
- BLE_GAP_EVENT_LTK_REQ
- BLE_GAP_EVENT_ENC_CHG
- BLE_GAP_EVENT_LTK_RSP_COMP
Examples
BLE_ABS_GTL Basic Example
This is a basic example of minimal use of the BLE_ABS_GTL in an application.
void gap_peripheral_cb (uint16_t type, ble_status_t result,
st_ble_evt_data_t * p_data)
{
switch (type)
{
{
g_ble_event_flag = g_ble_event_flag | BLE_ABS_EVENT_FLAG_STACK_ON;
break;
}
{
g_advertising_handle = p_gap_adv_set_evt_param->
adv_hdl;
g_ble_event_flag |= BLE_ABS_EVENT_FLAG_ADV_ON;
break;
}
{
g_ble_event_flag |= BLE_ABS_EVENT_FLAG_ADV_OFF;
break;
}
{
g_ble_event_flag |= BLE_ABS_EVENT_FLAG_CONN_IND;
break;
}
{
break;
}
default:
break;
}
}
#define BLE_ABS_EVENT_FLAG_STACK_ON (0x01 << 0)
#define BLE_ABS_EVENT_FLAG_CONN_IND (0x01 << 1)
#define BLE_ABS_EVENT_FLAG_ADV_ON (0x01 << 2)
#define BLE_ABS_EVENT_FLAG_ADV_OFF (0x01 << 3)
#define BLE_ABS_EVENT_FLAG_DISCONN_IND (0x01 << 4)
#define BLE_ABS_EVENT_FLAG_RSLV_LIST_CONF_COMP (0x01 << 5)
#define BLE_ABS_EXAMPLE_SHORTENED_LOCAL_NAME 'E', 'x', 'a', 'm', 'p', 'l', 'e'
#define BLE_ABS_EXAMPLE_COMPLETE_LOCAL_NAME 'T', 'E', 'S', 'T', '_', 'E', 'x', 'a', 'm', 'p', 'l', 'e'
#define BLE_ABS_EXAMPLE_SLOW_ADVERTISING_INTERVAL (0x00000640)
void ble_abs_peripheral_example (void)
{
volatile uint32_t timeout = UINT16_MAX * UINT8_MAX * 8;
uint8_t advertising_data[] =
{
0x02,
0x01,
(0x1a),
0x08,
0x08,
BLE_ABS_EXAMPLE_SHORTENED_LOCAL_NAME,
};
uint8_t scan_response_data[] =
{
0x0D,
0x09,
BLE_ABS_EXAMPLE_COMPLETE_LOCAL_NAME,
};
{
.slow_advertising_interval = BLE_ABS_EXAMPLE_SLOW_ADVERTISING_INTERVAL,
.slow_advertising_period = 0x0000,
.p_advertising_data = advertising_data,
.advertising_data_length = sizeof(advertising_data),
.p_scan_response_data = scan_response_data,
.scan_response_data_length = sizeof(scan_response_data),
.own_bluetooth_address = {0},
};
g_ble_event_flag = 0;
assert(FSP_SUCCESS == err);
assert(FSP_SUCCESS == err);
while (!(BLE_ABS_EVENT_FLAG_STACK_ON & g_ble_event_flag) && (--timeout > 0U))
{
}
time_out_handle_error(timeout);
g_ble_event_flag = 0;
timeout = UINT16_MAX * UINT8_MAX * 8;
assert(FSP_SUCCESS == err);
while (!(BLE_ABS_EVENT_FLAG_CONN_IND & g_ble_event_flag) && (--timeout > 0U))
{
if (BLE_ABS_EVENT_FLAG_ADV_OFF & g_ble_event_flag)
{
if (FSP_SUCCESS == err)
{
g_ble_event_flag &= (uint16_t) ~BLE_ABS_EVENT_FLAG_ADV_OFF;
}
{
;
}
else
{
assert(FSP_SUCCESS == err);
}
}
else if ((timeout % BLE_ABS_RETRY_INTERVAL) == 0U)
{
}
else
{
;
}
}
time_out_handle_error(timeout);
g_ble_event_flag = 0;
assert(FSP_SUCCESS == err);
}