This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nRF52840 Dongle programming for Windows

I need to write a Windows program that talks to the nRF52840 Dongle.  Is there a .dll or .lib or source code for communicating with the Dongle?  I have programmed the dongle with s140_nrf52_6.1.0_softdevice.hex.  I can not find any documentation of the actual interface that is seen on the PC.  Is it just operated via commands over the COM port?  Are these commands documented?  Where can I find this documentation?

I also need an application to use the nRF52840 Dongle in a pass-through UART mode.  Do I need to load a different hex file into it for that?  Where can I get that?  Is there documentation of the GATT service and characteristic UUIDs for this code?

Thanks!

  • OK, I would like to use the pc-ble-driver approach.  I choose sd_api_v5, which seems to have four choices for hex file.  I chose connectivity_2.0.1_1m_with_s132_5.0.hex to load onto the dongle.  I don't understand your answer about --sd-req.  Am I not programming the dongle with a new SoftDevice when I program this hex file into it?  And isn't this hex file the SoftDevice for s132 nRF52 5.0.x as the filename implies?  Why does the --sd-req option need to be 0x8C instead of 0x9D?  After I program this file, even if I do it again, I still need 0x8C, not 0x9D.  Does this mean I have not programmed the desired SoftDevice into the dongle?  Is there another step I'm missing?  Also, I don't understand what you mean by this: "so assuming it is version 3, then you should state that your app requires it."

    Also, I still have the problem that when I program the dongle, it does not expose any COM ports.  I must not have the correct procedure for programming the SoftDevice into the dongle.  Please explain how to do it.

    I did run the Bluetooth Low Energy app from nRF Connect and it works.  It downloads code into the dongle.  Can you tell me exactly what hex file and/or what version is loaded into the dongle by this program?  I understand need my PC app to match this if I am to interface to it.  Also what baud rate does it use?

    I thought I would start by modifying the example heart rate monitor hrm_v5.  First I compiled and ran it with the dongle as programmed by nRF Connect.  It gives this output:

    Serial port used: COM7
    Baud rate used: 1000000
    Info: Successfully opened COM7. Baud rate: 1000000. Flow control: none. Parity: none.

    Status: 6, message: Target Reset performed
    Status: 7, message: Connection active
    Warning: Failed to receive response for command
    Status: 4, message: Error sending packet to target. Code #3
    sd_ble_cfg_set() failed when attempting to set BLE_GAP_CFG_ROLE_COUNT. Error code: 0x03

    I looked at the code around the call to sd_ble_cfg_set() and the online API documentation.  The docs show this function as having 3 arguments, but the example code gives it 4 arguments.  I looked specifically at the docs for S132 SoftDevice v5.0.0 API, which the example supposedly links with. (It is linking with pc_ble_driver_static_sd_api_v5.lib.)  Can you explain this?

    I see there is a file in the hex folder called sdk150_add_sd_v3v5_support.patch.  What do I do with this file?

    I downloaded s140_nrf52_6.1.0.zip.  Is that the latest version of SoftDevice?  There is no .lib file in that .zip.  Where can I find something like pc_ble_driver_static_sd_api_v?.lib for s140?

    Thank you for your help with this.

  • Hi,

    There is a lot of different topics in this thread, and I fear a few misunderstandings. I will try to answer most one by one:

    • The bootloader is originally made as for using Bluetooth as a transport layer, and there you should normally not combine the SoftDevice and application in a single hex and use that for DFU in the bootloader (It is typically too large, and the SoftDevice is needed for upgrade over BLE). When you provide the application with --application <hex>, this typically needs that a specific SoftDevice is present in the flash in order to run, and the bootloader will check the version number provided with the --sd-req and only provide the option if it matches. This check may not be needed for the USB bootloader, as the app and bootloader may not depend on the SoftDevice. I suspect that the reason you need to repeatedly use the version number for a older SoftDevice is that the previous upgrade did not complete, so that the existing SoftDevice in flash has not changed. You can check the flash using e.g. nrfjprog to verify this. Note that you can also skip SoftDevice version checking using --sd-req 0x00 (0x00 meaning any SoftDevice version)
    • You should not expect the nRF52840 dongle to show up as a UART device without firmware that implements it. The connectivity_2.0.1_1m_with_s132_5.0.hex firmware that you used is made for the nRF52832 DK, which does not have onboard USB. (It uses the UART peripheral, and the onboard Segger debugger to bridge UART <-> USB.
    • If you get nRF Connect to work with the Bluetooth Low Energy app, then it means that the connectivity firmware is in place in the nRF52840 so all should be good there. nRF Connect use a modified version of the connectivity firmware in the SDK. You can find the needed patches to the SDK project here.
    • You can check all details of the connectivity firmware and adapt it to your needs by looking at the project for it under <SDK 15>\examples\connectivity\ble_connectivity\pca10059\ser_s140_usb_hci\.
    • It seems sd_ble_cfg_set() returned NRF_ERROR_INTERNAL (0x03). The function takes three parameters in S140 version 6.0.0, as you can see from the API documentation. Where do you see four parameters used?
    • The patch file you mention sdk150_add_sd_v3v5_support.patch is to adapt the SDK example connectivity firmware to the needs of nRF Connect. I do not know the details of this. I suggest you create a separate thread if you want to know the reasoning behind the changes.
    • Yes, S140 version 6.1.0 is the latest SoftDevice for the nRF52840. What kind of lib or zip are you after? Currently, the S140 version 6.1.0 is not used by any other released distributions, but you can adapt existing projects to it (there is no API changes so it should be fast). The next SDK, version 15.1.0, will include eS140 version 6.1.0.
  • Thank you for answering many of my questions.  Sorry, I still have some:

    Yes, nRF connect loads Bluetooth Low energy.  My question is exactly what hex file is loaded when I do that?  What version of SoftDevice and what application code?  I would be happy to interface my PC code to that code if I knew what it was and had documentation on how to interface to it.

    I tried to compile the project in nRF5_SDK_15.0.0_a53641a\nRF5_SDK_15.0.0_a53641a\examples\connectivity\ble_connectivity\pca10059\ser_s140_usb_hci\arm4 and I get the error

    cannot open source input file "core_cm4.h"

    from many files.  It seems this project isn't set up correctly.  I am able to compile the project in ...\ser_s140_usb_hci\arm5_no_packs, but I cannot link with the fre version of Keil I am using.  Do I need to buy a license for Keil (over $1500) to get this hex file?  Can you send the hex file to me?  Also, do I need the arm4 version or the arm5_no_packs version or will either work with the nRF52840 dongle?

    sd_ble_cfg_set() is called with four arguments on line 322 of main.c in the project hrm_v5 which is in pc-ble-driver-master\examples\heart_rate_monitor.  This program compiles, so I am confused as to the discrepancy between the code and the documentation.

    The heart rate monitor example hrm_v5 is a PC program that links with pc_ble_driver_static_sd_api_v5.lib, which should talk to the dongle running the app connectivity_2.0.1_1m_with_s132_5.0.hex and presumably a SoftDevice s132.  I understand that I cannot use this code with the dongle because it uses the UART, not the USB port.  The application that I have seen work is the Bluetooth Low Energy, but I do not have any source code for that.  Do you have source code for that?  I would expect a hex file for the version of the SoftDevice used (perhaps s140_nrf52_6.1.0_softdevice.hex which I have), another hex file for the application, a .lib file and some .h files for the PC application to link to the API which is documented online except for how to link to it or where these files are, and some code for the actual Bluetooth Low Energy application.  If I had that, I could write the code that I need for my application.

    My question about the .patch file is how does one use it?  I don't know if I need it.  I don't see any documentation.

    You say I can use nrfjprog with the dongle.  Is that the only way to write a new SoftDevice into the dongle, using nrfjprog (or segger, etc.) through p1?

    Maybe you have an answer for this: What is the quickest way for me to write PC code that will talk to the nRF 52840 dongle?  Can I do it without compiling new code for the dongle (since Bluetooth Low Energy already does this)?  How do I get the needed hex code into the dongle?

    Thank you so much for your help with this.  Unfortunately, my client need this functioning in a very short time frame, so your help is greatly appreciated.

  • Hi,

    Perhaps it would be better to separate this thread into multiple threads with fewer questions when continuing this? It would make it easier to get an overview. 

    • I expect that the .hex file used by the nRF Connect BLE app is the SDK 15 connectivity example project patched with the patch files from pc-ble-driver, probably from the v6-upgrade branch (I have not been able to verify that, though).
    • You can see the details of how to apply the patch in the pc-ble-driver documentation section Compiling the connectivity .hex files.
    • Regarding the sd_ble_cfg_set() I misunderstood and though you were building using SDK 15 for running locally on the nRF. You should refer to the relevant pc-ble-driver API documentation in the relevant header files (ble.h) if you are building a PC side app. Generally, the serialization API has an additional parameter which is the adapter.
    • I am not sure why you are getting the cannot open source input file "core_cm4.h" error. However, I do not recommend using the old arm4 project (this are for the outdated Keil 4). As you do not have a Keil license I recommend you to use GCC ("armgcc" folder) or Segger Embedded Studio ("ses" folder) instead.
    • You cannot use the connectivity_2.0.1_1m_with_s132_5.0.hex example app out of the box. As mentioned, due to the lack of a debugger on the nRF52840 dongle there are a few significant differences. You need to make changes to accompany those.
    • If you want something that works out of the box as a debug/test too, then buying a DK is a better approach. That solution is more mature and simpler due to the onboard debugger. The nrf52840 dongle is just released and software support is not yet fully in place.
    • You can use the connectivity firmware with the patch files from the pc-ble-driver for the nRF52840 dongle directly (), so that you do not have to write any firmware yourself. But you must make sure to use the proper connectivity firmware as indicated above, and you must use the corresponding pc-ble-driver version. You cannot mix and match different versions as there are API differences between the SoftDevice versions, and HW differences between the various nRF boards (particularly the lack of a debugger means that the nRF52840 dongle is a bit tedious to work with).
    • I mentioned nrfjprog, but you will have to connect an external debugger in order to use it (as there i no onboard debugger).

     

  • Really, my one question, which I don't yet seem to have an answer to, is exactly how do I write a PC program to use the nRF dongle?

    Here's what I think I understand.  Please verify if I have this correct.

    1. Since nrfutil seems to require sd-req code 0x8C, it appears I have SoftDevice s132_nrf52_3.0.0 loaded into my dongle by nRF Connect when I run Bluetooth Low Energy.  nRF Connect also loads a ble_connectivity app, but I don't know the exact source code or hex file for it.

    2. To put a different version of SoftDevice into the dongle, I need to use the dev board or a segger to program it through P1.  I cannot use DFU for this.

    3. The directory nRF5_SDK_15.0.0_a53641a\examples\connectivity\ble_connectivity\hex contains only this one hex file for the pca10059 (the nRF52840 dongle I have): ble_connectivity_s140_usb_hci_pca10059.hex

    4. The PC code to interface to the connectivity app is pc-ble-driver-master, which only has versions to link with s130 v2.0.1 and s132 v5.0.0.  I need to modify this code to link with s140 to use it with the dongle and the above hex file.  Or, I need to modify it to use s132 3.0.0 instead of s132 5.0.x and hope it is compatible with the connectivity application loaded by the Bluetooth Low Energy app.

    5. I am able to compile ble_connectivity with SD_API_VER  and NRF_SD_BLE_API_VERSION set to 5.  If I set these to 3, the code has compilation errors.

    6. I could not find a file for download named s132_nrf52_5.0.0_softdevice.hex.  I did find s132_nrf52_5.1.0_softdevice.hex.  I don't know if this is compatible with 5.0.0.

    7. If I manage to load connectivity_2.0.1_1m_with_s132_5.0.hex along with s132_nrf52_5.1.0_softdevice.hex maybe I can expect the hrm_v5 application to function?

    8. Instead, I could try to modify the hrm_v5 example to sork with s140, and program the dongle through P1.  I am not sure if this programming procedure is dont twice (once for SoftDevice and once for the app), or if I use mergehex to make one hex file to program.  Or, if I also need to include some code for MBR.

    9. I compiled the source code for

    nRF5_SDK_15.0.0_a53641a\examples\connectivity\ble_connectivity\pca10059\ser_s140_usb_hci

    which produced nrf52840_xxaa.hex, 193 kb.  That distribution also included s140_nrf52_6.1.0_softdevice.hex, 423 kb.  If I use mergehex to combine these, the combined file is 615 kb, but the included hex file ble_connectivity_s140_usb_hci_pca10059.hex is only 607 kb.  I think this means that the code I compiled is different from the distributed hex file.  Any idea why?

Related