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

Advertising does not start with S140 6.1.0, same hex run without issue with S140 6.0.0

Hi,

I am working for Adafruit on the bootloader for the upcoming feather nRF52840. Currently testing using the nrf52840DK pc10056. Everything is OK with S140 6.0.0 . Today I tried to upgrade the SD to 6.1.0 but the BLE won't start ( advertising cannot be discovered ). The very same code/hex is running fine with S140 6.0.0. I have tried to change settings here and there but couldn't figure out how. This is weird since 6.1.0 is supposed to be binary compatible with 6.0.0, maybe I am doing something wrong but could get away with 6.0.0 ???

I am really appreciated if you guys could help to shed some light, the code repo is here: 

https://github.com/adafruit/Adafruit_nRF52_Bootloader 

you should compile and flash it with 

make BOARD=pca10056 all flash

https://github.com/hathach/nrf52_6.1.0_test

The code is very minial, all contains in a single main.c file, it only advertise and does not do any other thing. except blinky led1, and turn on led2 if there is an error with sd-* call

github.com/.../main.c

You can compile and flash with 

make all flash

To flash S140 6.1.0

make sd610

to flash S140 v 6.0.0

make sd600

If I flashed S140 6.0.0 first and run above command, it will show up as "AdaDFU", but if S140 6.1.0 is flashed nothing ~.~

I attached the compressed hex file for your convenience.

Update: I create a seperated repo with minimal amount of code that can demonstrate  S140 v6.1.0 is not binary compatible with S140 v6.0.0

bootloader.hex.zip

Parents
  • Hi,

    It turns out, starting from SoftDevice versions 6.0.0, the GAP advertising data buffers (ble_gap_adv_data_t structures) must be kept alive for the full duration of advertising with that data. See the ble_gap_adv_data_t Struct Reference for details.

    For your minimal example, this means in advertising_start() adv_buf and gap_adv needs to live longer than the scope of advertising_start(). For that example, declaring both of these static solves the issue:

    void advertising_start(void)
    {
      uint8_t _adv_handle = BLE_GAP_ADV_SET_HANDLE_NOT_SET;
    
      static uint8_t adv_buf[BLE_GAP_ADV_SET_DATA_SIZE_MAX];
      static ble_gap_adv_data_t gap_adv =
      {
          .adv_data = { .p_data = adv_buf, .len = 0 }
      };
    
    // (...)
    
    }

    The lifetime requirement for ble_gap_adv_data_t is also stated in the s140 v6.0.0 migration guide.

    Admittedly, there should have been a note in the documentation for sd_ble_gap_adv_set_configure() as well, stating there are lifetime requirements for the data pointed to by the p_adv_data parameter and referring to the ble_gap_adv_data_t documentation for details. Currently the requirements are not mentioned in the context where it is most important for developers to know about them. I consider this to be a documentation bug, and the SoftDevice team is notified of this documentation bug.

    The reason why your application did work with s140 v6.0.0, is that although those lifetime requirements follows from the intended implementation within the SoftDevices, they are not needed with the actual implementation for versions 6.0.0. For SoftDevice versions 6.1.0, however, they are. (Failing to meet the lifetime requirements leads to undefined behavior.)

    We still consider versions 6.0.0 and 6.1.0 compatible, provided that you follow the API documentation thoroughly.

    Regards,
    Terje

Reply
  • Hi,

    It turns out, starting from SoftDevice versions 6.0.0, the GAP advertising data buffers (ble_gap_adv_data_t structures) must be kept alive for the full duration of advertising with that data. See the ble_gap_adv_data_t Struct Reference for details.

    For your minimal example, this means in advertising_start() adv_buf and gap_adv needs to live longer than the scope of advertising_start(). For that example, declaring both of these static solves the issue:

    void advertising_start(void)
    {
      uint8_t _adv_handle = BLE_GAP_ADV_SET_HANDLE_NOT_SET;
    
      static uint8_t adv_buf[BLE_GAP_ADV_SET_DATA_SIZE_MAX];
      static ble_gap_adv_data_t gap_adv =
      {
          .adv_data = { .p_data = adv_buf, .len = 0 }
      };
    
    // (...)
    
    }

    The lifetime requirement for ble_gap_adv_data_t is also stated in the s140 v6.0.0 migration guide.

    Admittedly, there should have been a note in the documentation for sd_ble_gap_adv_set_configure() as well, stating there are lifetime requirements for the data pointed to by the p_adv_data parameter and referring to the ble_gap_adv_data_t documentation for details. Currently the requirements are not mentioned in the context where it is most important for developers to know about them. I consider this to be a documentation bug, and the SoftDevice team is notified of this documentation bug.

    The reason why your application did work with s140 v6.0.0, is that although those lifetime requirements follows from the intended implementation within the SoftDevices, they are not needed with the actual implementation for versions 6.0.0. For SoftDevice versions 6.1.0, however, they are. (Failing to meet the lifetime requirements leads to undefined behavior.)

    We still consider versions 6.0.0 and 6.1.0 compatible, provided that you follow the API documentation thoroughly.

    Regards,
    Terje

Children
Related