nRF5 SDK is not maintained anymore
More Info: Consider nRF Connect SDK for new designs
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Define a BLE service instance on the header file

Hi, 

I'm currently development firmware for a application using a Nordic chip. This application will use some drivers allowing the communication with sensors and for the transmission of the sensor data I will use the BLE. So this application is expected to use 4 BLE services, but right now I only have implemented 3 (BAS, NUS and LLS). For the Battery and Nordic UART Service, I have define the each instance on a header file and everything work as expected. When I implement the Link Loss Service, I have done the same thing (define service macro on the header file) but, for some reason, I can't connect to the BLE. When I define the Link Loss Service instance on the .c file, the BLE work perfectly with the 3 Services. 

There is something special with the Link Loss Service that restrict the instance definition to the .c file?

Thanks in advance!

Parents
  • Have you tried it with just LLS and BAS, or LLS and NUS, or perhaps LLS alone?  I vaguely recall that I had problems when defining too many services.

  • Hi! Thanks for your reply. Yes, I have tried with the LLS alone and with only one more service. 

  • Hi,

    Regarding nrf_sdh_ble BLE event 0x10, you can take a look at \headers\ble_ranges.h. This corresponds to the BLE_GAP_EVT_CONNECTED in the ble_gap.h. BLE_GAP_EVT_CONNECTED is one of the events that are coming from the stack to the application.

    Best regards,
    Dejan

  • But the BLE event 0x10 happen in both examples. But for some reason, when declaring the instance in the .h file, the code block after going to the lls_handler_evt. And for that reason the firmware never goes to the ble_handler_evt

  • jpedroliveira said:
    But for some reason, when declaring the instance in the .h file

    I guess maybe you have this .h file included in different .c files? In that case, you will end up with multiple instances of the link loss service structure, but only one will be correctly initialized. This means your program will end up executing a null pointer when processing the connection event and trigger a hardfault exception.

    Edit: just to be clear, the function pointer I'm referring to is '.evt_handler'. I realize the arrow I drew in the picture above can be misleading.

  • Hi! Sorry for the late answer. Regarding your question, after doing some tests I believe that you are correct. The .h file are been called in different .c files. 

    But I have some questions, the others instances are also defined there, why for them there is no problem? And also, can I do something to define the LLS instance one time only (on the .h file)? 

    Thanks

  • Hi, no worries.

    jpedroliveira said:
    But I have some questions, the others instances are also defined there, why for them there is no problem?

    It is problematic to have multiple instances of the service structs even you don't notice any problems right away. The reason the others don't cause a crash in their respective on_connect() implementations is that they happen to include additional checks that will prevent the program from calling the zero-initialized function pointer.

    e.g. here is the on_connect() implementation in ble_nus.c:

    jpedroliveira said:
    And also, can I do something to define the LLS instance one time only (on the .h file)? 

    Then you have to declared the variable as "extern" in your header file.

Reply
  • Hi, no worries.

    jpedroliveira said:
    But I have some questions, the others instances are also defined there, why for them there is no problem?

    It is problematic to have multiple instances of the service structs even you don't notice any problems right away. The reason the others don't cause a crash in their respective on_connect() implementations is that they happen to include additional checks that will prevent the program from calling the zero-initialized function pointer.

    e.g. here is the on_connect() implementation in ble_nus.c:

    jpedroliveira said:
    And also, can I do something to define the LLS instance one time only (on the .h file)? 

    Then you have to declared the variable as "extern" in your header file.

Children
Related