Skip to content
This repository was archived by the owner on Jan 17, 2023. It is now read-only.

Commit aa033ad

Browse files
authored
Add data_length_update to BLE DFU (#293)
* Add data length update for ble dfu Data length update needs to be called explicitly in SD v5, it's not automatically adjusted with ATT MTU exchange as in SD v3 * Update required version for pc_ble_driver_py Need pc_ble_driver_py 0.14.1 to get data_length_update feature
1 parent 7b3627d commit aa033ad

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

nordicsemi/dfu/dfu_transport_ble.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
from pc_ble_driver_py.exceptions import NordicSemiException, IllegalStateException
4848
from pc_ble_driver_py.ble_driver import BLEDriver, BLEDriverObserver, BLEEnableParams, BLEUUIDBase, BLEGapSecKDist, BLEGapSecParams, \
4949
BLEGapIOCaps, BLEUUID, BLEAdvData, BLEGapConnParams, NordicSemiErrorCheck, BLEGapSecStatus, driver
50-
from pc_ble_driver_py.ble_driver import ATT_MTU_DEFAULT, BLEConfig, BLEConfigConnGatt
50+
from pc_ble_driver_py.ble_driver import ATT_MTU_DEFAULT, BLEConfig, BLEConfigConnGatt, BLEConfigConnGap
5151
from pc_ble_driver_py.ble_adapter import BLEAdapter, BLEAdapterObserver, EvtSync
5252

5353
logger = logging.getLogger(__name__)
@@ -120,6 +120,9 @@ def open(self):
120120
BLEConfig.conn_gatt,
121121
BLEConfigConnGatt(att_mtu=DFUAdapter.LOCAL_ATT_MTU),
122122
)
123+
self.adapter.driver.ble_cfg_set(
124+
BLEConfig.conn_gap,
125+
BLEConfigConnGap(event_length=5)) # Event length 5 is required for max data length
123126
self.adapter.driver.ble_enable()
124127

125128
self.adapter.driver.ble_vs_uuid_add(DFUAdapter.BASE_UUID)
@@ -168,6 +171,13 @@ def connect(self, target_device_name, target_device_addr):
168171
if DFUAdapter.LOCAL_ATT_MTU > ATT_MTU_DEFAULT:
169172
logger.info('BLE: Enabling longer ATT MTUs')
170173
self.att_mtu = self.adapter.att_mtu_exchange(self.conn_handle, DFUAdapter.LOCAL_ATT_MTU)
174+
175+
logger.info('BLE: Enabling longer Data Length')
176+
max_data_length = 251 # Max data length for SD v5
177+
data_length = self.att_mtu + 4 # ATT PDU overhead is 4
178+
if data_length > max_data_length:
179+
data_length = max_data_length
180+
self.adapter.data_length_update(self.conn_handle, data_length)
171181
else:
172182
logger.info('BLE: Using default ATT MTU')
173183

requirements-frozen.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ ecdsa==0.13.3
55
intelhex==2.2.1
66
ipaddress==1.0.22
77
libusb1==1.7.1
8-
pc-ble-driver-py==0.14.0
8+
pc-ble-driver-py==0.14.1
99
piccata==2.0.1
1010
protobuf==3.10.0
1111
pyserial==3.4

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ crcmod
44
ecdsa
55
intelhex
66
libusb1
7-
pc_ble_driver_py >= 0.14.0
7+
pc_ble_driver_py >= 0.14.1
88
piccata
99
protobuf
1010
pyserial

0 commit comments

Comments
 (0)