Unsolved DFU bootloader for BLE nordics nrf51
-
Hello everyone,
I am working on DFU (for nrf51 DK) application for android and iOS (using Qt C++).
For android everything works fine, but for iOS I have problems.
In order to enter DFU mode I need to write 0x0104 to control point dfu characteristic and after this device is reset in DFU mode.
After this my app doing next steps: connect to device again > discover services (there is only DFU service now) > write descriptor for CP characteristic (to enable notifications) > after this step there is the problem: The delegate for CBPeripheral does not implement -[peripheral:didModifyServices:].
(this is happening in xcode)I tried to increment MAC address (device uuid) when enter in DFU mode because I read that devices may be cached by the phone and if they change services list while connected that could cause the problem, but the problem is still there.
Has anyone had a similar problem/experience?
Thanks in advance.
-
Hi,
I think that problem is in the function void QLowEnergyService::writeDescriptor(const QLowEnergyDescriptor &descriptor, const QByteArray &newValue).
I've tried to run my application directly from Qt on mac desktop and application crashes after second call of writeDescriptor function.
These are the steps in my app:-connect to device (peripheral)
-discover all services and characteristics
-write descriptor for DFU control point characteristic => write value 0100 (in order to enable notifications)
(next step starts DFU process)
-write value 0104 to DFU control point characteristic (00001531-1212-efde-1523-785feabcd123)-peripheral is disconnected after this and my application automatically reconnect device
-discover all services and characteristics (now only DFU service is present)
-write descriptor for DFU control point characteristic (0100)
****** my app is crashed here *******
Note: On android everything works fine.
Thanks!
-
Hi,
Do you have a stack trace that shows exactly where that happens ?
-
Hi SGaist,
Do you mean something like this:
-
Do you have multiple threads running ?
-
I am not sure...I did not explicitly create any threads.
I am using Qt's example Bluetooth Low Energy Scanner and I just added part for descriptor write. -
The OS might be creating some when running an application (that's however not due to Qt but OS specific implementation)
On the same height as "Debugger" you have a thread list, you should inspect them all, the one you are showing doesn't seem to be the one that crashed.
-
I'm not able to identify if there is any problem in threads.
These are all threads:
-
I found which thread is crashed. This is MAC's report:
What should I do in order to avoid this crash?
-
The macOS report gives you the thread number that crashed, which is it ?
-
I'm not sure which number you mean.
This is complete macOS log:Process: lowenergyscanner [794]
Path: /Users/USER/*/lowenergyscanner.app/Contents/MacOS/lowenergyscanner
Identifier: M.lowenergyscanner
Version: 0
Code Type: X86-64 (Native)
Parent Process: Qt Creator [608]
Responsible: lowenergyscanner [794]
User ID: 501Date/Time: 2018-05-30 12:21:33.747 +0200
OS Version: Mac OS X 10.13.4 (17E202)
Report Version: 12
Anonymous UUID: 14C3F395-7323-E24B-A8AC-99381B861AE0Time Awake Since Boot: 6700 seconds
System Integrity Protection: enabled
Crashed Thread: 1 Dispatch queue: qt-bluetooth-LE-queue
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x0000000000000018
Exception Note: EXC_CORPSE_NOTIFYTermination Signal: Segmentation fault: 11
Termination Reason: Namespace SIGNAL, Code 0xb
Terminating Process: exc handler [0]VM Regions Near 0x18:
-->
__TEXT 000000010a406000-000000010a424000 [ 120K] r-x/rwx SM=COW [/Users/zs/Qt/Examples/Qt-5.9.1/bluetooth/build-lowenergyscanner-Desktop_Qt_5_9_1_clang_64bit-Debug/lowenergyscanner.app/Contents/MacOS/lowenergyscanner]Application Specific Information:
objc_msgSend() selector name: descriptorsThread 0:: Dispatch queue: com.apple.main-thread
0 libsystem_kernel.dylib 0x00007fff5f05a20a mach_msg_trap + 10
1 libsystem_kernel.dylib 0x00007fff5f059724 mach_msg + 60
2 com.apple.CoreFoundation 0x00007fff36bfa7d5 __CFRunLoopServiceMachPort + 341
3 com.apple.CoreFoundation 0x00007fff36bf9b27 __CFRunLoopRun + 1783
4 com.apple.CoreFoundation 0x00007fff36bf91a3 CFRunLoopRunSpecific + 483
5 com.apple.HIToolbox 0x00007fff35ee1d96 RunCurrentEventLoopInMode + 286
6 com.apple.HIToolbox 0x00007fff35ee1b06 ReceiveNextEventCommon + 613
7 com.apple.HIToolbox 0x00007fff35ee1884 _BlockUntilNextEventMatchingListInModeWithFilter + 64
8 com.apple.AppKit 0x00007fff34194a73 _DPSNextEvent + 2085
9 com.apple.AppKit 0x00007fff3492ae34 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 3044
10 com.apple.AppKit 0x00007fff34189885 -[NSApplication run] + 764
11 libqcocoa.dylib 0x000000010dbb09bf QCocoaEventDispatcher::processEvents(QFlagsQEventLoop::ProcessEventsFlag) + 2143
12 org.qt-project.QtCore 0x000000010aeb4631 QEventLoop::exec(QFlagsQEventLoop::ProcessEventsFlag) + 401
13 org.qt-project.QtCore 0x000000010aeb9099 QCoreApplication::exec() + 393
14 M.lowenergyscanner 0x000000010a40af6b main + 523 (main.cpp:66)
15 libdyld.dylib 0x00007fff5ef13015 start + 1Thread 1 Crashed:: Dispatch queue: qt-bluetooth-LE-queue
0 libobjc.A.dylib 0x00007fff5e2ebe9d objc_msgSend + 29
1 org.qt-project.QtBluetooth 0x000000010b783010 -[OSXBTCentralManager descriptor:forCharacteristic:] + 96
2 org.qt-project.QtBluetooth 0x000000010b7818a6 -[OSXBTCentralManager setNotifyValue:forCharacteristic:onService:] + 198
3 libdispatch.dylib 0x00007fff5eee164a _dispatch_call_block_and_release + 12
4 libdispatch.dylib 0x00007fff5eed9e08 _dispatch_client_callout + 8
5 libdispatch.dylib 0x00007fff5eeee267 _dispatch_queue_serial_drain + 635
6 libdispatch.dylib 0x00007fff5eee11b6 _dispatch_queue_invoke + 373
7 libdispatch.dylib 0x00007fff5eeeef5d _dispatch_root_queue_drain_deferred_wlh + 332
8 libdispatch.dylib 0x00007fff5eef2d71 _dispatch_workloop_worker_thread + 880
9 libsystem_pthread.dylib 0x00007fff5f22afd2 _pthread_wqthread + 980
10 libsystem_pthread.dylib 0x00007fff5f22abe9 start_wqthread + 13Thread 2:
0 libsystem_kernel.dylib 0x00007fff5f064292 __workq_kernreturn + 10
1 libsystem_pthread.dylib 0x00007fff5f22b009 _pthread_wqthread + 1035
2 libsystem_pthread.dylib 0x00007fff5f22abe9 start_wqthread + 13Thread 3:
0 libsystem_kernel.dylib 0x00007fff5f064292 __workq_kernreturn + 10
1 libsystem_pthread.dylib 0x00007fff5f22b009 _pthread_wqthread + 1035
2 libsystem_pthread.dylib 0x00007fff5f22abe9 start_wqthread + 13Thread 4:: QQmlThread
0 libsystem_kernel.dylib 0x00007fff5f0650a2 poll + 10
1 org.qt-project.QtCore 0x000000010af0d380 qt_safe_poll(pollfd*, unsigned int, timespec const*) + 544
2 org.qt-project.QtCore 0x000000010af0e845 QEventDispatcherUNIX::processEvents(QFlagsQEventLoop::ProcessEventsFlag) + 885
3 org.qt-project.QtCore 0x000000010aeb4631 QEventLoop::exec(QFlagsQEventLoop::ProcessEventsFlag) + 401
4 org.qt-project.QtCore 0x000000010aced19e QThread::exec() + 110
5 org.qt-project.QtQml 0x000000010aa3f1c9 QQmlThreadPrivate::run() + 57
6 org.qt-project.QtCore 0x000000010acf0e7f QThreadPrivate::start(void*) + 367
7 libsystem_pthread.dylib 0x00007fff5f22b661 _pthread_body + 340
8 libsystem_pthread.dylib 0x00007fff5f22b50d _pthread_start + 377
9 libsystem_pthread.dylib 0x00007fff5f22abf9 thread_start + 13Thread 5:: QSGRenderThread
0 GLEngine 0x00007fff41167e34 setProgramUniformInner + 5380
1 GLEngine 0x00007fff4115afcb setUniform + 187
2 org.qt-project.QtQuick 0x000000010a507efd QSGDistanceFieldTextMaterialShader::updateState(QSGMaterialShader::RenderState const&, QSGMaterial*, QSGMaterial*) + 445
3 org.qt-project.QtQuick 0x000000010a509662 QSGHiQSubPixelDistanceFieldTextMaterialShader::updateState(QSGMaterialShader::RenderState const&, QSGMaterial*, QSGMaterial*) + 450
4 org.qt-project.QtQuick 0x000000010a4d9146 QSGBatchRenderer::Renderer::renderMergedBatch(QSGBatchRenderer::Batch const*) + 614
5 org.qt-project.QtQuick 0x000000010a4db0b5 QSGBatchRenderer::Renderer::renderBatches() + 1077
6 org.qt-project.QtQuick 0x000000010a4dc4e3 QSGBatchRenderer::Renderer::render() + 1859
7 org.qt-project.QtQuick 0x000000010a4cc9e9 QSGRenderer::renderScene(QSGBindable const&) + 537
8 org.qt-project.QtQuick 0x000000010a4cc7c4 QSGRenderer::renderScene(unsigned int) + 52
9 org.qt-project.QtQuick 0x000000010a50af54 QSGDefaultRenderContext::renderNextFrame(QSGRenderer*, unsigned int) + 68
10 org.qt-project.QtQuick 0x000000010a562fed QQuickWindowPrivate::renderSceneGraph(QSize const&) + 781
11 org.qt-project.QtQuick 0x000000010a51417e QSGRenderThread::syncAndRender() + 1998
12 org.qt-project.QtQuick 0x000000010a515088 QSGRenderThread::run() + 504
13 org.qt-project.QtCore 0x000000010acf0e7f QThreadPrivate::start(void*) + 367
14 libsystem_pthread.dylib 0x00007fff5f22b661 _pthread_body + 340
15 libsystem_pthread.dylib 0x00007fff5f22b50d _pthread_start + 377
16 libsystem_pthread.dylib 0x00007fff5f22abf9 thread_start + 13Thread 6:: com.apple.NSEventThread
0 libsystem_kernel.dylib 0x00007fff5f05a20a mach_msg_trap + 10
1 libsystem_kernel.dylib 0x00007fff5f059724 mach_msg + 60
2 com.apple.CoreFoundation 0x00007fff36bfa7d5 __CFRunLoopServiceMachPort + 341
3 com.apple.CoreFoundation 0x00007fff36bf9b27 __CFRunLoopRun + 1783
4 com.apple.CoreFoundation 0x00007fff36bf91a3 CFRunLoopRunSpecific + 483
5 com.apple.AppKit 0x00007fff342d1fc4 _NSEventThread + 184
6 libsystem_pthread.dylib 0x00007fff5f22b661 _pthread_body + 340
7 libsystem_pthread.dylib 0x00007fff5f22b50d _pthread_start + 377
8 libsystem_pthread.dylib 0x00007fff5f22abf9 thread_start + 13Thread 1 crashed with X86 Thread State (64-bit):
rax: 0x00007fab4440fd60 rbx: 0xcc5371475ebe0086 rcx: 0x0000000000000008 rdx: 0x0000000000000000
rdi: 0x00007fab46877fd0 rsi: 0x00007fff5badd279 rbp: 0x000070000a8d6720 rsp: 0x000070000a8d6608
r8: 0x0000000000000000 r9: 0x00007fab4440fd60 r10: 0x0000000000000000 r11: 0x00007fff5badd279
r12: 0x00007fab46881338 r13: 0x0000000000000000 r14: 0x00007fab46877fd0 r15: 0x000070000a8d67b0
rip: 0x00007fff5e2ebe9d rfl: 0x0000000000010246 cr2: 0x0000000000000018Logical CPU: 0
Error Code: 0x00000004
Trap Number: 14 -
Here is the interesting information:
@Zivojin said in DFU bootloader for BLE nordics nrf51:
Crashed Thread: 1 Dispatch queue: qt-bluetooth-LE-queue
Can you check whether using a more recent version of Qt goes better ?
-
Tried with updated version of Qt Creator (Qt 5.10.1) and the problem is still there.
What do you think about adding native code? To call somehow setNotify function from Qt instead of writing descriptor?
How can I pass (cast) some Qt BLE object to objective-c BLE object (i.e. QLowEnergyCharacteristic - CBCharacteristic)?
-
I’d take a look at the module sources.
Because from the looks of it, the crash seems to happen in the macOS code.
-
Ok, thanks for your time and help.
-
Hello Zivojin ,
I'm also working dfu fro nrf device for android and windows .
I'm using Qt platform for making android and desktop application.
could you please help me out in how to dfu in QT for nrf device?
Thank in advance