From fa0a24ba6e6edc2ccab90cc65b51b9c1c07f5794 Mon Sep 17 00:00:00 2001 From: KMeldgaard Date: Mon, 15 Nov 2021 09:35:29 +0100 Subject: [PATCH 1/9] added support for custom ble app conf --- src/utility/STM32Cube_FW/app_conf.h | 157 +--------------- src/utility/STM32Cube_FW/app_conf_default.h | 188 ++++++++++++++++++++ 2 files changed, 192 insertions(+), 153 deletions(-) create mode 100644 src/utility/STM32Cube_FW/app_conf_default.h diff --git a/src/utility/STM32Cube_FW/app_conf.h b/src/utility/STM32Cube_FW/app_conf.h index 667dbbd4..64349958 100644 --- a/src/utility/STM32Cube_FW/app_conf.h +++ b/src/utility/STM32Cube_FW/app_conf.h @@ -1,158 +1,9 @@ -/** - ****************************************************************************** - * File Name : app_conf.h - * Description : Application configuration file for STM32WPAN Middleware. - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2020 STMicroelectronics. - * All rights reserved.

- * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 - * - ****************************************************************************** - */ - -/* Define to prevent recursive inclusion -------------------------------------*/ #ifndef APP_CONF_H #define APP_CONF_H -#include "hw.h" -#include "ble_bufsize.h" - - -/****************************************************************************** - * Application Config - ******************************************************************************/ - -/**< generic parameters ******************************************************/ -/* HCI related defines */ - -#define ACI_HAL_SET_TX_POWER_LEVEL 0xFC0F -#define ACI_WRITE_CONFIG_DATA_OPCODE 0xFC0C -#define ACI_READ_CONFIG_DATA_OPCODE 0xFC0D -#define MAX_HCI_ACL_PACKET_SIZE (sizeof(TL_PacketHeader_t) + 5 + 251) -#define HCI_RESET 0x0C03 - -#ifndef BLE_SHARED_MEM_BYTE_ORDER - #define BLE_SHARED_MEM_BYTE_ORDER MSBFIRST +#if __has_include("app_conf_custom.h") +#include "app_conf_custom.h" #endif -#define BLE_MODULE_SHARED_MEM_BUFFER_SIZE 128 - -/** - * Define Tx Power - */ -#define CFG_TX_POWER (0x18) /* -0.15dBm */ - -/****************************************************************************** - * BLE Stack - ******************************************************************************/ -/** - * Maximum number of simultaneous connections that the device will support. - * Valid values are from 1 to 8 - */ -#define CFG_BLE_NUM_LINK 8 - -/** - * Maximum number of Services that can be stored in the GATT database. - * Note that the GAP and GATT services are automatically added so this parameter should be 2 plus the number of user services - */ -#define CFG_BLE_NUM_GATT_SERVICES 8 - -/** - * Maximum number of Attributes - * (i.e. the number of characteristic + the number of characteristic values + the number of descriptors, excluding the services) - * that can be stored in the GATT database. - * Note that certain characteristics and relative descriptors are added automatically during device initialization - * so this parameters should be 9 plus the number of user Attributes - */ -#define CFG_BLE_NUM_GATT_ATTRIBUTES 68 - -/** - * Maximum supported ATT_MTU size - */ -#define CFG_BLE_MAX_ATT_MTU (156) - -/** - * Size of the storage area for Attribute values - * This value depends on the number of attributes used by application. In particular the sum of the following quantities (in octets) should be made for each attribute: - * - attribute value length - * - 5, if UUID is 16 bit; 19, if UUID is 128 bit - * - 2, if server configuration descriptor is used - * - 2*DTM_NUM_LINK, if client configuration descriptor is used - * - 2, if extended properties is used - * The total amount of memory needed is the sum of the above quantities for each attribute. - */ -#define CFG_BLE_ATT_VALUE_ARRAY_SIZE (1344) - -/** - * Prepare Write List size in terms of number of packet - */ -//#define CFG_BLE_PREPARE_WRITE_LIST_SIZE BLE_PREP_WRITE_X_ATT(CFG_BLE_MAX_ATT_MTU) -#define CFG_BLE_PREPARE_WRITE_LIST_SIZE (0x3A) - -/** - * Number of allocated memory blocks - */ -//#define CFG_BLE_MBLOCK_COUNT (BLE_MBLOCKS_CALC(CFG_BLE_PREPARE_WRITE_LIST_SIZE, CFG_BLE_MAX_ATT_MTU, CFG_BLE_NUM_LINK)) -#define CFG_BLE_MBLOCK_COUNT (0x79) -/** - * Enable or disable the Extended Packet length feature. Valid values are 0 or 1. - */ -#define CFG_BLE_DATA_LENGTH_EXTENSION 1 - -/** - * Sleep clock accuracy in Slave mode (ppm value) - */ -#define CFG_BLE_SLAVE_SCA 500 - -/** - * Sleep clock accuracy in Master mode - * 0 : 251 ppm to 500 ppm - * 1 : 151 ppm to 250 ppm - * 2 : 101 ppm to 150 ppm - * 3 : 76 ppm to 100 ppm - * 4 : 51 ppm to 75 ppm - * 5 : 31 ppm to 50 ppm - * 6 : 21 ppm to 30 ppm - * 7 : 0 ppm to 20 ppm - */ -#define CFG_BLE_MASTER_SCA 0 - -/** - * Source for the 32 kHz slow speed clock - * 1 : internal RO - * 0 : external crystal ( no calibration ) - */ -#define CFG_BLE_LSE_SOURCE 0 - -/** - * Start up time of the high speed (16 or 32 MHz) crystal oscillator in units of 625/256 us (~2.44 us) - */ -#define CFG_BLE_HSE_STARTUP_TIME 0x148 - -/** - * Maximum duration of the connection event when the device is in Slave mode in units of 625/256 us (~2.44 us) - */ -#define CFG_BLE_MAX_CONN_EVENT_LENGTH ( 0xFFFFFFFF ) - -/** - * Viterbi Mode - * 1 : enabled - * 0 : disabled - */ -#define CFG_BLE_VITERBI_MODE 1 - -/** - * LL Only Mode - * 1 : LL Only - * 0 : LL + Host - */ -#define CFG_BLE_LL_ONLY 1 - -#endif /* APP_CONF_H */ +#include "app_conf_default.h" -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ +#endif /* APP_CONF_H */ \ No newline at end of file diff --git a/src/utility/STM32Cube_FW/app_conf_default.h b/src/utility/STM32Cube_FW/app_conf_default.h new file mode 100644 index 00000000..06e94f7d --- /dev/null +++ b/src/utility/STM32Cube_FW/app_conf_default.h @@ -0,0 +1,188 @@ +/** + ****************************************************************************** + * File Name : app_conf.h + * Description : Application configuration file for STM32WPAN Middleware. + ****************************************************************************** + * @attention + * + *

© Copyright (c) 2020 STMicroelectronics. + * All rights reserved.

+ * + * This software component is licensed by ST under Ultimate Liberty license + * SLA0044, the "License"; You may not use this file except in compliance with + * the License. You may obtain a copy of the License at: + * www.st.com/SLA0044 + * + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef APP_CONF_H +#define APP_CONF_H + +#include "ble_bufsize.h" +#include "hw.h" + +/****************************************************************************** + * Application Config + ******************************************************************************/ + +/**< generic parameters ******************************************************/ +/* HCI related defines */ + +#define ACI_HAL_SET_TX_POWER_LEVEL 0xFC0F +#define ACI_WRITE_CONFIG_DATA_OPCODE 0xFC0C +#define ACI_READ_CONFIG_DATA_OPCODE 0xFC0D +#define MAX_HCI_ACL_PACKET_SIZE (sizeof(TL_PacketHeader_t) + 5 + 251) +#define HCI_RESET 0x0C03 + +#ifndef BLE_SHARED_MEM_BYTE_ORDER +#define BLE_SHARED_MEM_BYTE_ORDER MSBFIRST +#endif +#define BLE_MODULE_SHARED_MEM_BUFFER_SIZE 128 + +/** + * Define Tx Power + */ +#ifndef CFG_TX_POWER +#define CFG_TX_POWER (0x18) /* -0.15dBm */ +#endif + +/****************************************************************************** + * BLE Stack + ******************************************************************************/ +/** + * Maximum number of simultaneous connections that the device will support. + * Valid values are from 1 to 8 + */ +#ifndef CFG_BLE_NUM_LINK +#define CFG_BLE_NUM_LINK 8 +#endif + +/** + * Maximum number of Services that can be stored in the GATT database. + * Note that the GAP and GATT services are automatically added so this parameter should be 2 plus the number of user + * services + */ +#ifndef CFG_BLE_NUM_GATT_SERVICES +#define CFG_BLE_NUM_GATT_SERVICES 8 +#endif + +/** + * Maximum number of Attributes + * (i.e. the number of characteristic + the number of characteristic values + the number of descriptors, excluding the + * services) that can be stored in the GATT database. Note that certain characteristics and relative descriptors are + * added automatically during device initialization so this parameters should be 9 plus the number of user Attributes + */ +#ifndef CFG_BLE_NUM_GATT_ATTRIBUTES +#define CFG_BLE_NUM_GATT_ATTRIBUTES 68 +#endif + +/** + * Maximum supported ATT_MTU size + */ +#ifndef CFG_BLE_MAX_ATT_MTU +#define CFG_BLE_MAX_ATT_MTU (156) +#endif + +/** + * Size of the storage area for Attribute values + * This value depends on the number of attributes used by application. In particular the sum of the following + * quantities (in octets) should be made for each attribute: + * - attribute value length + * - 5, if UUID is 16 bit; 19, if UUID is 128 bit + * - 2, if server configuration descriptor is used + * - 2*DTM_NUM_LINK, if client configuration descriptor is used + * - 2, if extended properties is used + * The total amount of memory needed is the sum of the above quantities for each attribute. + */ +#ifndef CFG_BLE_ATT_VALUE_ARRAY_SIZE +#define CFG_BLE_ATT_VALUE_ARRAY_SIZE (1344) +#endif + +/** + * Prepare Write List size in terms of number of packet + */ +//#define CFG_BLE_PREPARE_WRITE_LIST_SIZE BLE_PREP_WRITE_X_ATT(CFG_BLE_MAX_ATT_MTU) +#ifndef CFG_BLE_PREPARE_WRITE_LIST_SIZE +#define CFG_BLE_PREPARE_WRITE_LIST_SIZE (0x3A) +#endif + +/** + * Number of allocated memory blocks + */ +//#define CFG_BLE_MBLOCK_COUNT (BLE_MBLOCKS_CALC(CFG_BLE_PREPARE_WRITE_LIST_SIZE, CFG_BLE_MAX_ATT_MTU, +// CFG_BLE_NUM_LINK)) +#ifndef CFG_BLE_MBLOCK_COUNT +#define CFG_BLE_MBLOCK_COUNT (0x79) +#endif + +/** + * Enable or disable the Extended Packet length feature. Valid values are 0 or 1. + */ +#ifndef CFG_BLE_DATA_LENGTH_EXTENSION +#define CFG_BLE_DATA_LENGTH_EXTENSION 1 +#endif + +/** + * Sleep clock accuracy in Slave mode (ppm value) + */ +#ifndef CFG_BLE_SLAVE_SCA +#define CFG_BLE_SLAVE_SCA 500 +#endif + +/** + * Sleep clock accuracy in Master mode + * 0 : 251 ppm to 500 ppm + * 1 : 151 ppm to 250 ppm + * 2 : 101 ppm to 150 ppm + * 3 : 76 ppm to 100 ppm + * 4 : 51 ppm to 75 ppm + * 5 : 31 ppm to 50 ppm + * 6 : 21 ppm to 30 ppm + * 7 : 0 ppm to 20 ppm + */ +#ifndef CFG_BLE_MASTER_SCA +#define CFG_BLE_MASTER_SCA 0 +#endif + +/** + * Source for the 32 kHz slow speed clock + * 1 : internal RO + * 0 : external crystal ( no calibration ) + */ +#ifndef CFG_BLE_LSE_SOURCE +#define CFG_BLE_LSE_SOURCE 0 +#endif + +/** + * Start up time of the high speed (16 or 32 MHz) crystal oscillator in units of 625/256 us (~2.44 us) + */ +#ifndef CFG_BLE_HSE_STARTUP_TIME +#define CFG_BLE_HSE_STARTUP_TIME 0x148 +#endif + +/** + * Maximum duration of the connection event when the device is in Slave mode in units of 625/256 us (~2.44 us) + */ +#ifndef CFG_BLE_MAX_CONN_EVENT_LENGTH +#define CFG_BLE_MAX_CONN_EVENT_LENGTH (0xFFFFFFFF) +#endif + +/** + * Viterbi Mode + * 1 : enabled + * 0 : disabled + */ +#define CFG_BLE_VITERBI_MODE 1 + +/** + * LL Only Mode + * 1 : LL Only + * 0 : LL + Host + */ +#define CFG_BLE_LL_ONLY 1 + +#endif /* APP_CONF_H */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ From 975ca4ba9abe85d5f7517380d388ca94d9d9c975 Mon Sep 17 00:00:00 2001 From: KMeldgaard Date: Mon, 15 Nov 2021 09:40:43 +0100 Subject: [PATCH 2/9] added Configuration section to README --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 2fb6e425..b2d48b13 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,11 @@ https://github.com/stm32duino/wiki/wiki/STM32duinoBLE#stm32duinoble-with-x-nucle For more information about ArduinoBLE library please visit the official web page at: https://github.com/arduino-libraries/ArduinoBLE +# Configuration +STM32Cube_WPAN has several configuration options, which are set in the `app_conf.h`. +This package has a default configuration named `app_conf_default.h`. +The user can include the file `app_conf_custom.h` to customize the ble application. Options wrapped in `#ifndef, #endif` in `app_conf_default.h` can be overwritten. Additional options can be added. + ## License ``` From 22807d0c3585de3b75c55819670563f6bd9204c0 Mon Sep 17 00:00:00 2001 From: KMeldgaard Date: Mon, 15 Nov 2021 09:45:41 +0100 Subject: [PATCH 3/9] Added header guards --- src/utility/STM32Cube_FW/app_conf.h | 11 +++++++++++ src/utility/STM32Cube_FW/app_conf_default.h | 9 +++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/utility/STM32Cube_FW/app_conf.h b/src/utility/STM32Cube_FW/app_conf.h index 64349958..888c91a0 100644 --- a/src/utility/STM32Cube_FW/app_conf.h +++ b/src/utility/STM32Cube_FW/app_conf.h @@ -1,6 +1,17 @@ +//----------------------------- +// @file app_conf.h +// @author Kasper Meldgaard +// @brief Wrapper for BLE app configuration based on comment by fpistm +// (https://github.com/stm32duino/STM32duinoBLE/issues/34). +// @date 15-11-2021 +// @copyright Copyright (c) 2021 + #ifndef APP_CONF_H #define APP_CONF_H +#include "ble_bufsize.h" +#include "hw.h" + #if __has_include("app_conf_custom.h") #include "app_conf_custom.h" #endif diff --git a/src/utility/STM32Cube_FW/app_conf_default.h b/src/utility/STM32Cube_FW/app_conf_default.h index 06e94f7d..58effc8a 100644 --- a/src/utility/STM32Cube_FW/app_conf_default.h +++ b/src/utility/STM32Cube_FW/app_conf_default.h @@ -17,11 +17,8 @@ */ /* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef APP_CONF_H -#define APP_CONF_H - -#include "ble_bufsize.h" -#include "hw.h" +#ifndef APP_CONF_DEFAULT_H +#define APP_CONF_DEFAULT_H /****************************************************************************** * Application Config @@ -183,6 +180,6 @@ */ #define CFG_BLE_LL_ONLY 1 -#endif /* APP_CONF_H */ +#endif /* APP_CONF_DEFAULT_H */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ From d89cfdad6d3974bec6ba49ff008ef01e2cf3eb07 Mon Sep 17 00:00:00 2001 From: KMeldgaard <36625114+KMeldgaard@users.noreply.github.com> Date: Mon, 15 Nov 2021 12:08:04 +0100 Subject: [PATCH 4/9] Update src/utility/STM32Cube_FW/app_conf_default.h Co-authored-by: Frederic Pillon --- src/utility/STM32Cube_FW/app_conf_default.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utility/STM32Cube_FW/app_conf_default.h b/src/utility/STM32Cube_FW/app_conf_default.h index 58effc8a..58c9f5bb 100644 --- a/src/utility/STM32Cube_FW/app_conf_default.h +++ b/src/utility/STM32Cube_FW/app_conf_default.h @@ -1,7 +1,7 @@ /** ****************************************************************************** - * File Name : app_conf.h - * Description : Application configuration file for STM32WPAN Middleware. + * File Name : app_conf_default.h + * Description : Default application configuration file for STM32WPAN Middleware. ****************************************************************************** * @attention * From 0490ea33ff86d926f83d07ee28fb100b51ad922c Mon Sep 17 00:00:00 2001 From: KMeldgaard Date: Wed, 24 Nov 2021 16:11:46 +0100 Subject: [PATCH 5/9] added set_data_length --- src/utility/ATT.cpp | 2 ++ src/utility/HCI.cpp | 14 ++++++++++++++ src/utility/HCI.h | 23 +++++++++++++++++++++++ 3 files changed, 39 insertions(+) diff --git a/src/utility/ATT.cpp b/src/utility/ATT.cpp index 6c502068..3bfb76e6 100644 --- a/src/utility/ATT.cpp +++ b/src/utility/ATT.cpp @@ -256,6 +256,8 @@ void ATTClass::addConnection(uint16_t handle, uint8_t role, uint8_t peerBdaddrTy if (_eventHandlers[BLEConnected]) { _eventHandlers[BLEConnected](BLEDevice(peerBdaddrType, peerBdaddr)); } + // TODO (krm) increase speed! + HCI.hciSetDataLength(handle, 251, 2120); } void ATTClass::handleData(uint16_t connectionHandle, uint8_t dlen, uint8_t data[]) diff --git a/src/utility/HCI.cpp b/src/utility/HCI.cpp index 96b42537..86a77b31 100644 --- a/src/utility/HCI.cpp +++ b/src/utility/HCI.cpp @@ -672,6 +672,20 @@ void HCIClass::setTransport(HCITransportInterface *HCITransport) _HCITransport = HCITransport; } +int HCIClass::hciSetDataLength(uint16_t connectionHandle, uint16_t txOctects, uint16_t txTime){ + const uint8_t payload_len = 6; + const uint16_t opcode = 0x2022; + uint8_t cmd_buffer[BLE_CMD_MAX_PARAM_LEN]; + hci_le_set_data_length_cp0 *cp0 = (hci_le_set_data_length_cp0*)(cmd_buffer); + + // create payload + cp0->Connection_Handle = connectionHandle; + cp0->TxOctets = txOctects; + cp0->TxTime = txTime; + + return sendCommand(opcode, payload_len, cmd_buffer); +} + #if !defined(FAKE_HCI) HCIClass HCIObj; HCIClass& HCI = HCIObj; diff --git a/src/utility/HCI.h b/src/utility/HCI.h index 0efd8125..72bab320 100644 --- a/src/utility/HCI.h +++ b/src/utility/HCI.h @@ -23,6 +23,14 @@ #include #include "HCITransport.h" +#define BLE_CMD_MAX_PARAM_LEN 255 + +struct hci_le_set_data_length_cp0{ + uint16_t Connection_Handle; + uint16_t TxOctets; + uint16_t TxTime; +}; + class HCIClass { public: HCIClass(); @@ -74,6 +82,21 @@ class HCIClass { void setTransport(HCITransportInterface *HCITransport); + //----------------------------- + // @brief + // @param connectionHandle Connection_Handle Connection handle for which the command applies. + // Values: 0x0000 ... 0x0EFF + // @param txOctects TxOctets Preferred maximum number of payload octets that the local + // Controller should include in a single Link Layer packet on this + // connection. + // Values: 0x001B ... 0x00FB + // @param txTime TxTime Preferred maximum number of microseconds that the local + // Controller should use to transmit a single Link Layer packet on this + // connection. + // Values: 0x0148 ... 0x4290 + // @return Value indicating success or error code. + int hciSetDataLength(uint16_t connectionHandle, uint16_t txOctects, uint16_t txTime); + private: virtual int sendCommand(uint16_t opcode, uint8_t plen = 0, void* parameters = NULL); From 58c62579961223036cd3ba445ecf0064a6b1ea2c Mon Sep 17 00:00:00 2001 From: KMeldgaard Date: Thu, 25 Nov 2021 09:34:25 +0100 Subject: [PATCH 6/9] added define guard on hci set data length implementation --- README.md | 6 ++++++ src/utility/ATT.cpp | 6 +++++- src/utility/HCI.cpp | 2 ++ src/utility/HCI.h | 6 ++++++ 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b2d48b13..20219efd 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,12 @@ STM32Cube_WPAN has several configuration options, which are set in the `app_conf This package has a default configuration named `app_conf_default.h`. The user can include the file `app_conf_custom.h` to customize the ble application. Options wrapped in `#ifndef, #endif` in `app_conf_default.h` can be overwritten. Additional options can be added. +## HCI data length +By default the data length (max payload per BLE packet) is set to 27 bytes. This can cause fragmentation when tranmitting large characteristics using a large ATT_MTU. +To increase the data length user must define `CFG_BLE_ENABLE_SET_DATA_LENGTH` (in `app_conf_default.h`). Further more, the wanted data length must bbe set in same define - eg: `#define CFG_BLE_ENABLE_SET_DATA_LENGTH 251`. Valid range: 27 --> 251. +**Note: if this is enabled the pheripheral will attempt to increase the HCI data length with every connected device! There is no guarantee all BLE devices support all sizes!** +Please see + ## License ``` diff --git a/src/utility/ATT.cpp b/src/utility/ATT.cpp index 3bfb76e6..05ecf0f8 100644 --- a/src/utility/ATT.cpp +++ b/src/utility/ATT.cpp @@ -257,7 +257,11 @@ void ATTClass::addConnection(uint16_t handle, uint8_t role, uint8_t peerBdaddrTy _eventHandlers[BLEConnected](BLEDevice(peerBdaddrType, peerBdaddr)); } // TODO (krm) increase speed! - HCI.hciSetDataLength(handle, 251, 2120); + #ifdef CFG_BLE_ENABLE_SET_DATA_LENGTH + #if CFG_BLE_ENABLE_SET_DATA_LENGTH < 252 && CFG_BLE_ENABLE_SET_DATA_LENGTH > 26 + HCI.hciSetDataLength(handle, CFG_BLE_ENABLE_SET_DATA_LENGTH, 2120); + #endif // CFG_BLE_ENABLE_SET_DATA_LENGTH < 252 && CFG_BLE_ENABLE_SET_DATA_LENGTH > 26 + #endif // CFG_BLE_ENABLE_SET_DATA_LENGTH } void ATTClass::handleData(uint16_t connectionHandle, uint8_t dlen, uint8_t data[]) diff --git a/src/utility/HCI.cpp b/src/utility/HCI.cpp index 86a77b31..6f9c9737 100644 --- a/src/utility/HCI.cpp +++ b/src/utility/HCI.cpp @@ -672,6 +672,7 @@ void HCIClass::setTransport(HCITransportInterface *HCITransport) _HCITransport = HCITransport; } +#ifdef CFG_BLE_ENABLE_SET_DATA_LENGTH int HCIClass::hciSetDataLength(uint16_t connectionHandle, uint16_t txOctects, uint16_t txTime){ const uint8_t payload_len = 6; const uint16_t opcode = 0x2022; @@ -685,6 +686,7 @@ int HCIClass::hciSetDataLength(uint16_t connectionHandle, uint16_t txOctects, ui return sendCommand(opcode, payload_len, cmd_buffer); } +#endif // CFG_BLE_ENABLE_SET_DATA_LENGTH #if !defined(FAKE_HCI) HCIClass HCIObj; diff --git a/src/utility/HCI.h b/src/utility/HCI.h index 72bab320..034950f8 100644 --- a/src/utility/HCI.h +++ b/src/utility/HCI.h @@ -23,6 +23,10 @@ #include #include "HCITransport.h" +#if __has_include("app_conf_custom.h") +#include "app_conf_custom.h" +#endif + #define BLE_CMD_MAX_PARAM_LEN 255 struct hci_le_set_data_length_cp0{ @@ -82,6 +86,7 @@ class HCIClass { void setTransport(HCITransportInterface *HCITransport); + #ifdef CFG_BLE_ENABLE_SET_DATA_LENGTH //----------------------------- // @brief // @param connectionHandle Connection_Handle Connection handle for which the command applies. @@ -96,6 +101,7 @@ class HCIClass { // Values: 0x0148 ... 0x4290 // @return Value indicating success or error code. int hciSetDataLength(uint16_t connectionHandle, uint16_t txOctects, uint16_t txTime); + #endif // CFG_BLE_ENABLE_SET_DATA_LENGTH private: virtual int sendCommand(uint16_t opcode, uint8_t plen = 0, void* parameters = NULL); From d7787a94ca5cf0e881b31246cac522abe53c35b5 Mon Sep 17 00:00:00 2001 From: KMeldgaard Date: Thu, 25 Nov 2021 09:39:40 +0100 Subject: [PATCH 7/9] rearranged readme --- README.md | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 20219efd..63299586 100644 --- a/README.md +++ b/README.md @@ -15,18 +15,6 @@ https://github.com/stm32duino/wiki/wiki/STM32duinoBLE#stm32duinoble-with-x-nucle For more information about ArduinoBLE library please visit the official web page at: https://github.com/arduino-libraries/ArduinoBLE - -# Configuration -STM32Cube_WPAN has several configuration options, which are set in the `app_conf.h`. -This package has a default configuration named `app_conf_default.h`. -The user can include the file `app_conf_custom.h` to customize the ble application. Options wrapped in `#ifndef, #endif` in `app_conf_default.h` can be overwritten. Additional options can be added. - -## HCI data length -By default the data length (max payload per BLE packet) is set to 27 bytes. This can cause fragmentation when tranmitting large characteristics using a large ATT_MTU. -To increase the data length user must define `CFG_BLE_ENABLE_SET_DATA_LENGTH` (in `app_conf_default.h`). Further more, the wanted data length must bbe set in same define - eg: `#define CFG_BLE_ENABLE_SET_DATA_LENGTH 251`. Valid range: 27 --> 251. -**Note: if this is enabled the pheripheral will attempt to increase the HCI data length with every connected device! There is no guarantee all BLE devices support all sizes!** -Please see - ## License ``` @@ -47,3 +35,12 @@ You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ``` + +# Configuration +STM32Cube_WPAN has several configuration options, which are set in the `app_conf.h`. +This package has a default configuration named `app_conf_default.h`. +The user can include the file `app_conf_custom.h` to customize the ble application. Options wrapped in `#ifndef, #endif` in `app_conf_default.h` can be overwritten. Additional options can be added. +## HCI data length +By default the data length (max payload per BLE packet) is set to 27 bytes. This can cause fragmentation when tranmitting large characteristics using a large ATT_MTU. +To increase the data length user must define `CFG_BLE_ENABLE_SET_DATA_LENGTH` (in `app_conf_default.h`). Further more, the wanted data length must bbe set in same define - eg: `#define CFG_BLE_ENABLE_SET_DATA_LENGTH 251`. Valid range: 27 --> 251. +**Note: if this is enabled the pheripheral will attempt to increase the HCI data length with every connected device! There is no guarantee all BLE devices support all sizes!** From 78b918cb5d799b73935cbfc6c62bd3c3d938096c Mon Sep 17 00:00:00 2001 From: KMeldgaard Date: Thu, 25 Nov 2021 09:48:26 +0100 Subject: [PATCH 8/9] spell check fix --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 63299586..938897c5 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,6 @@ STM32Cube_WPAN has several configuration options, which are set in the `app_conf This package has a default configuration named `app_conf_default.h`. The user can include the file `app_conf_custom.h` to customize the ble application. Options wrapped in `#ifndef, #endif` in `app_conf_default.h` can be overwritten. Additional options can be added. ## HCI data length -By default the data length (max payload per BLE packet) is set to 27 bytes. This can cause fragmentation when tranmitting large characteristics using a large ATT_MTU. +By default the data length (max payload per BLE packet) is set to 27 bytes. This can cause fragmentation when transmitting large characteristics using a large ATT_MTU. To increase the data length user must define `CFG_BLE_ENABLE_SET_DATA_LENGTH` (in `app_conf_default.h`). Further more, the wanted data length must bbe set in same define - eg: `#define CFG_BLE_ENABLE_SET_DATA_LENGTH 251`. Valid range: 27 --> 251. **Note: if this is enabled the pheripheral will attempt to increase the HCI data length with every connected device! There is no guarantee all BLE devices support all sizes!** From a050636c9ead31c5b374e8276fc1f37ea1146920 Mon Sep 17 00:00:00 2001 From: KMeldgaard Date: Thu, 25 Nov 2021 10:01:01 +0100 Subject: [PATCH 9/9] removed TODO comment --- src/utility/ATT.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/utility/ATT.cpp b/src/utility/ATT.cpp index 05ecf0f8..11ac3eb7 100644 --- a/src/utility/ATT.cpp +++ b/src/utility/ATT.cpp @@ -256,7 +256,6 @@ void ATTClass::addConnection(uint16_t handle, uint8_t role, uint8_t peerBdaddrTy if (_eventHandlers[BLEConnected]) { _eventHandlers[BLEConnected](BLEDevice(peerBdaddrType, peerBdaddr)); } - // TODO (krm) increase speed! #ifdef CFG_BLE_ENABLE_SET_DATA_LENGTH #if CFG_BLE_ENABLE_SET_DATA_LENGTH < 252 && CFG_BLE_ENABLE_SET_DATA_LENGTH > 26 HCI.hciSetDataLength(handle, CFG_BLE_ENABLE_SET_DATA_LENGTH, 2120);