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.
- GAP functionality
- Initialize the Host stack.
- Setting address.
- Start/Stop Advertising.
- Connect/Disconnect a link.
- GATT Common functionality
- GATT Server functionality
- Initialization of GATT Server.
- Loading of Profile definition.
- Notification of characteristics modification.
- Read/Write of GATT Profile from host.
- 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
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 Pins
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
When using a public BD address the address pre-programmed into the DA14531/DA14535 will be used and can't be overridden.
A random address can be set by calling the R_BLE_VS_SetBdAddr function before the 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.22 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.
Service and characteristic write callback functions, created when using the QE Tool are not supported
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.
Legacy pairing functionality currently works with the DA14531/DA14535 module acting as a Peripheral. Bonding data supports only one connection. Bonding data is stored in RAM and not in Flash. Data will be lost after a reset.
The RI feature of attributes is controlled from the flag read_notify = 1. 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 read_notify==1 (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 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.
Currently supported rm_ble_abs_gtl interface functions:
- RM_BLE_ABS_Open
- RM_BLE_ABS_Close
- RM_BLE_ABS_StartLegacyAdvertising
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_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_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_RegisterCb
- R_BLE_GATTC_DeregisterCb
- R_BLE_GATTC_ReqExMtu
- R_BLE_GATTC_DiscAllPrimServ
- R_BLE_GATTC_DiscIncServ
- R_BLE_GATTC_ReadChar
- R_BLE_GATTC_WriteCharWithoutRsp
- R_BLE_GATTC_SignedWriteChar
- R_BLE_GATTC_WriteChar
- R_BLE_GATTC_WriteLongChar
- R_BLE_GATTC_ExecWrite
- R_BLE_VS_Init
- R_BLE_VS_GetBdAddr
- R_BLE_VS_SetBdAddr
- R_BLE_VS_GetRand
- R_BLE_GAP_SetPairingParams
- R_BLE_GAP_ReplyPairing
- R_BLE_GAP_ReplyLtkReq
- R_BLE_GAP_ReplyExKeyInfoReq
- R_BLE_GAP_StartPairing
- R_BLE_GAP_ReplyNumComp
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_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_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_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);
}