Skip to content

Commit 18fd367

Browse files
authored
Arduino Nano 33 IoT large transfer fix (MCU hang bug)
uint16_t handle = *(uint16_t*)data hangs Arduino Nano 33 IoT in cases when data pointer is unaligned. This happens when receiving large packets of BLEStringCharacteristic. This doesn't not happen when setting such characteristics from iPhone (iOS) or Android devices, but happens 100% of the time on PC using either Bleak (Python) or QT6 libraries. In those cases data pointer at the time of this call is not two bytes (sizeof(uint16_t)) aligned and dereferencing such pointer hangs the MCU. To resolve the issue we copy that uint16_t handle byte by byte without monkeying with ORs, Shifts or other binary operations to avoid endianness issues on other platforms.
1 parent 675fc91 commit 18fd367

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/utility/ATT.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1246,7 +1246,11 @@ void ATTClass::writeReqOrCmd(uint16_t connectionHandle, uint16_t mtu, uint8_t op
12461246
return;
12471247
}
12481248

1249-
uint16_t handle = *(uint16_t*)data;
1249+
/// uint16_t handle = *(uint16_t*)data; // This hangs Arduino Nano 33 IoT in cases when data is unaligned
1250+
/// mainly when dealing with large packets. Copy the handle byte by byte in endianness independent way.
1251+
uint16_t handle;
1252+
((uint8_t *)&handle)[0] = ((uint8_t*)data)[0];
1253+
((uint8_t *)&handle)[1] = ((uint8_t*)data)[1];
12501254

12511255
if ((uint16_t)(handle - 1) > GATT.attributeCount()) {
12521256
if (withResponse) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy