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

testing tutorial example ble custom service , the program stops on NRF_BREAKPOINT_COND and the console says

Hi, I take the tutorial here: https://github.com/NordicPlayground/nRF5x-custom-ble-service-tutorial

Because I have the SDK16 I made same mofification.

1) I comment all inside the static void sleep_mode_enter(void) function

2)  I comment :  err_code = bsp_btn_ble_init(NULL, &startup_event);    APP_ERROR_CHECK(err_code); in the buttons_leds_init function

3) I delete the btn config in the buttons_leds_init function , like that ---->  err_code = bsp_init(BSP_INIT_LEDS, bsp_event_handler); because I use the feather nrf52840, of course I have a custom_board.h file with the right LED.

With that, It  works with a timer sending notification each second. I don't try more than one minute.

Then I make some change, inthe main.c file :


#define MIN_CONN_INTERVAL               MSEC_TO_UNITS(10, UNIT_1_25_MS)        /**< Minimum acceptable connection interval (0.1 seconds). */
#define MAX_CONN_INTERVAL               MSEC_TO_UNITS(100, UNIT_1_25_MS) 

and


#define NOTIFICATION_INTERVAL           APP_TIMER_TICKS(50)     

In the ble_cus.c  in the ble_cus_custom_value_update function I had

 uint8_t cu[80];
    memset(cu, 0, sizeof(uint8_t));
    cu[0]=custom_value;

and you wil reconize these modified lines:

 gatts_value.len     = 80*sizeof(uint8_t);
    gatts_value.offset  = 0;
    gatts_value.p_value = cu;

of course I modified these lines too in the custom_value_char_add function

 attr_char_value.init_len  = 80*sizeof(uint8_t);
    attr_char_value.init_offs = 0;
    attr_char_value.max_len   = 80*sizeof(uint8_t);

You have guessed I want to increase the data rate.

I tryed the program , It runs during  some seconds and finishes with NRF_BREAKPOINT_COND and the console says <info> app: sd_ble_gatts_hvx result: 13. 

Have you an idea of my mistake ?

  • I progress in my research.

    The bug does not happen every time, but often.

    I catch the event BLE_GATTS_EVT_HVN_TX_COMPLETE, I can see that before the crash the sd_ble_gatts_hvx is called many time without any BLE_GATTS_EVT_HVN_TX_COMPLETE event . It seems that the softdevice has a buffer to memorise the packets to send, may be 4 or 5 packets maximum.

    So I program my own buffer with 16 packets size. I call sd_ble_gatts_hvx only if I receive a BLE_GATTS_EVT_HVN_TX_COMPLETE event. And it works,,,, but the speed is low, I don't have a packet send each 50ms. So I presume that the softdevice loses speed if its buffer is empty,

    So my second modification is: I call sd_ble_gatts_hvx if it miss less than 3 BLE_GATTS_EVT_HVN_TX_COMPLETE event to keep the softdevice buffer not empty, but not full too. And it works, An average of 50ms between each packet is respected.

    I don't know if there is a configuration for the softdevice knowing that  I can see  my buffer has never more than 8 packets to memorise.

  • HI Jrt, 

    Apologies for the late reply. 

    Error code 0x13 is NRF_ERROR_RESOURCES. 

    As stated in the sd_ble_gatts_hvx documentation you will get NRF_ERROR_RESOURCES if  too many notifications queued and you should wait for a BLE_GATTS_EVT_HVN_TX_COMPLETE event and retry. Which you have done. 

    The number of Notifications you will be able to send per connection event will depend on the connection interval and the GAP event length as well as the MTU size, see the NRF_SDH_BLE_GAP_EVENT_LENGTH and NRF_SDH_BLE_GATT_MAX_MTU_SIZE defines in the sdk_config.h file

    Best regards

    Bjørn

Related