If you set multiple 128bit UUIDs, error 4 will occur in "sd_ble_uuid_vs_add" during operation.

OS in development environment :Windows10
HARD :(Taiyo Yuden)EBSHSN Series Evaluation Board : Central / Peripherals
CPU :(Nordic) nRF52832 / ARMR Cortex-M4F 32 bit processor 28-pin Land Grid Array / 15GPIOs / SWD
builder :SEGGER Embedded Studio for ARM Release 3.34a Build 2018022300.35192 Windows x64
Copyright 2014-2018 SEGGER Microcontroller GmbH & Co. KG
Copyright 1997-2018 Rowley Associates Ltd.
GCC/BINUTILS: Built using the GNU ARM Embedded Toolchain version 6-2017-q2-update source distribution
Clang/LLVM: Built using the version 5.0.0 source distribution
Soft Ver:nRF5_SDK_15.3.0_59ac345

If you set multiple 128bit UUIDs, error 4 will occur in "sd_ble_uuid_vs_add" during operation.
I referred to related questions and others, but I couldn't solve it.
Please tell me how to resolve

<< extract program source >>
[ble_cus.h]
/-*< 2 custom service instance definition >*-/
 #define BLE_CUS1_DEF(_name) static ble_cus_t _name; NRF_SDH_BLE_OBSERVER(_name ## _obs, BLE_HRS_BLE_OBSERVER_PRIO, ble_cus1_on_evt, &_name) /* Item1 */
 #define BLE_CUS2_DEF(_name) static ble_cus_t _name; NRF_SDH_BLE_OBSERVER(_name ## _obs, BLE_HRS_BLE_OBSERVER_PRIO, ble_cus2_on_evt, &_name) /* Item1 */
/-*< 2 custom service instance reservation >*-/
 BLE_CUS1_DEF(m_cus1); /*< 1st custom service instance */
 BLE_CUS2_DEF(m_cus2); /*< 2nd custom service instance */

[ble_cus1.c]
 ble_cus_init1(ble_cus_t * p_cus, const ble_cus_init_t * p_cus_init)
    :
    :
 /*-< Add Custom Service UUID >-*/
  ble_uuid128_t base_uuid = {CUSTOM_SERVICE1_UUID_BASE};
  err_code = sd_ble_uuid_vs_add(&base_uuid, &p_cus->uuid_type);
  VERIFY_SUCCESS(err_code);

[ble_cus2.c]
  ble_cus_init2(ble_cus_t * p_cus, const ble_cus_init_t * p_cus_init)
    :
    :
 /*-< Add Custom Service UUID >-*/
  ble_uuid128_t base_uuid = {CUSTOM_SERVICE2_UUID_BASE};
  err_code = sd_ble_uuid_vs_add(&base_uuid, &p_cus->uuid_type);
  VERIFY_SUCCESS(err_code);    <======  error4

<<---------->>

thank you
  • Hello,

    If you take a look in ble.h line 512 -> 538, you can see that the reason that NRF_ERROR_NO_MEM is returned by this softdevice call is when there are no more free slots for VS (Vendor specific / custom) UUIDs. To reserve more slots, you need to increase NRF_SDH_BLE_VS_UUID_CNT in sdk_config.h by one, to be able to add one extra Vendor Specific UUID. 

    Please note that when you increase this, the log will probably say something about adjusting RAM start and size when you initialize the BLE stack, so please adjust the settings accordingly in the project settings.

    Best regards,

    Edvin

  • If you connect to BLE, it will stop without any error. Please tell me the possible causes.
    1) Build is OK
    2) Independent operation is OK
    3) Stops without error when connecting (220804-1.png)
    Thank you very much.

  • That looks like a hardfault. Perhaps you have a callback handler that is not populated properly. Is there some way for me to reproduce what you are seeing? Is it possible to zip the project folder that you are using, so that I can unzip it into an unmodified SDK and reproduce it following a few steps that you describe?

    Best regards,

    Edvin

  • I will send you the environment where the error occurred.
    
    Do you understand?
    
    Thank you
    CUS_2item_220805.zip
  • Edvin said:
    Perhaps you have a callback handler that is not populated properly

    That seems to be it. When you call ble_cus_2_init() in services_init(), your cus2_init.evt_handler = NULL. Inside ble_cus_2_init() you still set p_cus->evt_handler = p_cus_init->evt_handler, and later, you call this event handler. When you call a handler function like this, but the handler is a NULL pointer, then the behavior is not defined, and typically you get caught up in the hardfault handler. This is because when you call a function, it goes to the address where this function is located in flash, and executes at that place. But when you send it directly to 0x00000000, there is no function there to tell the processor what to do next, so basically it starts to execute something that is not set up to be a function.

    So the takeaway is to uncomment line 439 in main.c:

    //        cus2_init.evt_handler                = on_cus_evt;

    And you should be good to go.

    Best regards,

    Edvin

Related