This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC2640R2L: BT

Part Number: CC2640R2L
Other Parts Discussed in Thread: CC2640

Hi,

We had a requirement where the TI bt chip CC2640 needed to be controlled from the host CPU and the TI bt chip CC2640 needed to act both as a peripheral and central, based on the need. We figured out that running "Host Test sample application" on CC2640 and write a application code which will send HCI/GAP/GAAT messages.

  • Central:  We are clear on this and were able to verify the same with the "btool" using a launchpad. 
  • Peripheral :  We have 2 options to get this working
    • Compile with GATT_DB_OFF_CHIP and have the gatt server controlled from the external application. The problem with this is 
      • We could not find an example where the same is implememted.
      • Forums discourage going this route.
      • Not sure what are pit falls we may encounter. For example after we add a service using GATT_AddService (0xFDFC), while adding an attribute using GATT_AddAttribute (0xFDFE) could not figure out how to enable NOTIFY ( looking at doc TI BLE Vendor Specific HCI Reference Guide Version 3.0.0) . 
      • Unfortunately btool also dose not support to validate this mode
    • Reading in the forum , we see advice as to add a service in the firmware it self and use the same example (https://e2e.ti.com/support/wireless-connectivity/bluetooth-group/bluetooth/f/bluetooth-forum/1096805/cc2652r-how-to-use-gatt-server-from-btool-host_test-app) . Wanted to know what is the best way to achieve the following two ( assuming service is added in the firmware itself)
      • Our requirement was that what ever data that is written to this Peripheral should be sent to the application processor.
      • Our requirement was that the application processor will send the data to the connected central device using notify.

Can you guide us with the approach to take to get the Peripheral implemented?

Regards,

Sumanth N

  • Hi Sumanth ,

    I believe both options should be possible to implement the functionality you are looking for. I think option 2 may be better in the long run as it means you wont have to recreate the service through HCI commands every time the device boots. You should be able to add the service/profile code to the project. I would recommend referencing the Custom Profile SimpleLink Academy lab for information on creating your own custom profile. I would also suggest referencing the simple_peripheral project to see how a service can be added to an existing project.

    Best Regards,

    Jan

  • Hi Jan,

    Thanks for the reply.

    While choosing option 2 wanted to know how written to this Peripheral can be sent to the application processor ?  to be more specific will the application processor receive ATT_HandleValueInd (Command = 0xFD1D, Event = 0x051D) ? so that the application processor can know the value that was written ?

    If we choose option 2 to send a notification to the connected central device from the application processor what commands need to be sent from application processor ?

    Regards,

    Sumanth N

  • HI Sumanth,

    To enable notifications, you will need to write the proper data to the CCCD to enable/disable notifications. This can be done via a GATT write operation. For more information on this, please reference the Custom Profile SLA lab.

    Best Regards,

    Jan

  • Hi Jan,

    We have gone through this example, but still we still are not able to get answers for the questions that I had asked. Can you help me with this ?

    "wanted to know how the data written to this Peripheral can be sent to the application processor ?  Assume that I have added a profile in host_test as shown in the above example and it has an attribute that can be written. Now Lets assume that I write to this attribute from an external central device. This will come and land in the host_test firmware of the cc2640 chip. Now how can the same be sent to the application processor from the firmware ?"

    Regards,

    Sumanth N

  • Sumanth, 

    Jan is currently out of office and will not be able to give a response until early next week. Feel free to open a new thread if this is a high priority issue and you are unable to resolve this issue in the meantime. 

    Thanks,

    Luke

  • Hi Sumanth,

    A profile may be provided with a read/write callback that executes whenever a read/write occurs on a specific characteristic. This will likely be the best way to capture data written to the characteristic and pass it along to the application.

    Best Regards,

    Jan

  • Hi Jan,

    From the call back in the firmware how do we relay the data that is written to to the external Application processor ? Should we add a custom event for it ? Is there an example for the same ? Any reference code or any pointers as to how to send it ?

    Regards,

    Sumanth N

  • So, basically you want to echo back the data you sent from host application?

    The peripheral cc2640 will echo back the data?

    I suggest to use IOS LightBlue App or Android nRF Connect as host application.

    -kel

  • In our case  CC2640 needed to be controlled from the host CPU i.e in our setup the host CPU is an ARM processor which runs Linux and CC2640 is a device which needs to be controlled by this ARM processor. The host CPU is the master. It will decide it the BT has to be used in peripheral mode or as a central mode. If it wants CC2640 as a central, it will decide whom to connect to and the operations that need to be done. If it decides if the mode needs to be peripheral It will configure a few services which will expose write and notify. Looking at all the requirements I believe the best way to go about is having "Host Test sample application" on CC2640 and write a application code on the HOST CPU which will send HCI/GAP/GAAT messages to do the same.

    With out experiments ( just as a POC)  with "host test" and "btool" we are clear on the work for central mode. What we wanted was help with peripheral part.

    As discussed above I did add a service in the "host test firmware " like explained in the https://e2e.ti.com/support/wireless-connectivity/bluetooth-group/bluetooth/f/bluetooth-forum/1096805/cc2652r-how-to-use-gatt-server-from-btool-host_test-app.

    Now when ever an external mobile application will connect to the service and does a write , the data will land on CC2640 chip. What we wanted was a way to rely this data to the HOST CPU so that it can process the data. Can you help me with a way to do the same ?

    Regards,

    Sumanth N

  • This will work with multi role example program. But you are limited to the number of devices you can connect due to memory limitation. So, I suggest to use BLE MCU with bigger flash and ram.

    -kel

  • We have looked at two approaches and specifically worked on approach 1. 
    Approach 1:
    We have invested many months of development effort on getting the problem solved by using the "host test firmware" . We have solved the following things 
    • Central Profile.
    • Peripheral Profile - Where we have added a service and have a mobile connected to the chip. We only need to solve 2 small pieces of the puzzle.i.e

      [*A] Send the data that mobile has sent to the chip to the host CPU. We believe that write can have a callback in the firmware and from this callback we can have a custom event to send the data to the Host CPU. Want to understand if this is the proper approach, if so want to know how we can add the custom event.
      [*B] Send data from the host CPU to chip so that it can use the existing capability to send it to mobile. This may require us to add a custom GATT command. Want to know if this is the proper approach, if so we want to know how we can add the same.
    So we have solved having dual mode + communication with the host CPU. Only missing part is probably having a couple of custom commands. 
    Approach 2: 
    Moving our development effort to multi role means we will have to throw away the work so far without a clear path to completion with multi role either due to the reasons below.
    We don't mind restarting if Approach 1 is completely infeasible according to your experts.
    The problem with muti role that we see is as follows :
    Given this, I would highly appreciate it if you can unblock us with *specifically* with respect to *A and *B, unless you think this is completely unfeasible. 
  • Sorry, I thought your host MCU is connected to the CC2640 wirelessly using Bluetooth connection.

    So, the CC2640 is connected to your host CPU using wired connection maybe UART.

    CC2640 should be programmed with network processor example program. Your ARM based host CPU will send HCI commands. Am I correct?

    Mostly this is heavy coding at host CPU side to implement your requirements.

    -kel

  • Yes its connected to host CPU using UART. CC2640 i believe should be programmed with "host test" firmware. Yes Host CPU will be sending HCI/GAP/GAAT messages. 

    Yes the work on the host is more. We believe if we get answer to these two questions we will be able to solve our issues.

  • Hi Sumanth,

    Here are my thoughts regarding your two questions:

    [*A] Send the data that mobile has sent to the chip to the host CPU. We believe that write can have a callback in the firmware and from this callback we can have a custom event to send the data to the Host CPU. Want to understand if this is the proper approach, if so want to know how we can add the custom event.

    I believe this would be the proper approach here. What I would suggest is to add a characteristic that the mobile device can write to and enable the write callback functionality. Within the write callback, you can add additional logic to enqueue a custom event in order to do some additional processing (such as sending the received data to a host MCU via NPI, UART, SPI or some other communication protocol.

    The custom profile SLA contains information on how to implement your own custom profile as well as a helpful service generator. There is also a discussion included on read/write callbacks.

    https://dev.ti.com/tirex/content/simplelink_academy_cc2640r2sdk_5_30_01_00/modules/blestack/ble_01_custom_profile/ble_01_custom_profile.html

    In the simple_peripheral example, there is already an event posting system through the use of the SimplePeripheral_enqueueMsg() function and the write callback is configured to call the SimplePeripheral_charValueChangeCB(). These would be very helpful references to start with in order to implement the same in host_test

    [*B] Send data from the host CPU to chip so that it can use the existing capability to send it to mobile. This may require us to add a custom GATT command. Want to know if this is the proper approach, if so we want to know how we can add the same.

    Should be possible to implement custom NPI commands to do some additional functionality, but you will need to ensure this is implemented in the host_test side properly as well as the CPU side.

    Best Regards,

    Jan

  • Hi Jan,

    Had a look at SimplePeripheral_enqueueMsg() and SimplePeripheral_charValueChangeCB(). From my understating  SimplePeripheral_enqueueMsg() will enqueue an event from ble stack to the application stack on the firmware and in the context of application stack we will use SimpleProfile_GetParameter() to get the value that has been written. My question is from here how is the data that is fetched can be sent to the host CPU ?

    1. Should we send an custom event to host CPU from the context of the application stack of firmware.
    2. Is there an example of how to do the same ?
    3. If there is no example can you help us with how to achieve the same ?

    Regards,

    Sumanth N

  • Hi,

    Your understanding of how the data flows is correct. The exact method of how you would communicate data from the CC2640R2 device to another device is up to you. You may add another custom HCI event/call to the host_test project and to the host CPU and use that. This will allow you to take advantage of the already existing NPI setup. You could setup a separate UART/SPI/I2C/etc connection between the CC2640R2 and the host CPU to send application data. The path to follow here would depend on your system architecture and your preferences.

    We do not have an example available to specifically showcases this, but we do  have the host_test examples as mentioned before and some I2C,SPI,UART examples that may be helpful as well.

    Best Regards,

    Jan

  • Hi Jan,

    Thanks for the guidance. We are trying to implement the same. We will get back to you with more queries if we get stuck.

    Regards,

    Sumanth N

  • Hi Sumanth,

    No problem! Sounds good! I will close this thread for now, but if you have any questions, then feel free to reply to this message and I will get back to you as soon as possible. If the thread has locked, then please open a related question and we will support you in the new thread.

    Best Regards,

    Jan