ARMmbed / mbed-os

Arm Mbed OS is a platform operating system designed for the internet of things
https://mbed.com
Other
4.67k stars 2.98k forks source link

nRF52 BLE VS UUID Crash #7297

Closed AGlass0fMilk closed 5 years ago

AGlass0fMilk commented 6 years ago

Description

I recently synced my mbed-os fork and now I am experiencing a crash associated with BLE initialization. My BLE profile requires me to exceed the default vendor-specific UUID limit of 4. Before I updated, this limit was set by a macro in the TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_14_2/TARGET_SOFTDEVICE_S132/mbed_lib.json file.

Now the system has been changed to be overwritable by a user's mbed_app.json file. The new limit is set by a configurable macro in features/FEATURE_BLE/targets/TARGET_NORDIC/mbed_lib.json.

I have configured this macro to allow 8 Vendor specific UUIDs (what I had set it to under the previous system). Now, when BLE is initialized, my chip resets with no error information from mbed -- this leads me to believe it is the soft device causing a reset (I am in debug profile).

The strange thing is, if I configure the macro to have less than 8 VS UUIDs (I tried 7), initialization works as expected but of course the VS UUID services/characteristics aren't shown after a 7 have been added. If I go above 8 (I tried 10 and 12) then the chip doesn't reset but it is not visibly broadcasting (I have checked using the Punch Through BLE app and nRF Connect desktop).

So I'm not sure what's going on or what has changed with this configuration system. The most recent stable commit I was building on was 16ece66f950facea0cc06047794afdd0eab39372.

EDIT:

I have also tried varying the NRF_SDH_BLE_GATTS_ATTR_TAB_SIZE parameter for gatt attributes, to no avail.

Issue request type

[ ] Question
[ ] Enhancement
[ X ] Bug

andrewleech commented 6 years ago

So I presume you'll now be setting nordic-ble.uuid_table_max_entries in your mbed_app.json?

When you changed NRF_SDH_BLE_GATTS_ATTR_TAB_SIZE , did you do so via the nordic-ble.gatt_attr_tab_size setting? I would expect that to need increasing if you're using more UUID's, depending on how many services / characteristics you're using. If you increase this though you will also likely need to increase the ram allocation of the softdevice in the linker file.

Are you set up to swd debug your application on board? If so set a breakpoint in btle_init() function, mbed-os\features\FEATURE_BLE\targets\TARGET_NORDIC\TARGET_NRF52\source\btle\btle.cpp and follow it through to err_code = nrf_sdh_ble_enable(&ram_start); The ram_start variable will be set to the current assigned amount in linker before the function call, and then will be updated with the amount the softdevice needs after that call. If it needs more than is assigned you'll need to copy the right linker file out of the mbed-os folder into your project, increase the start ram address (and reduce the length by same amount) then tell the mbed compile command to use that linker file instead.

Also, If you're not already, check the error code returned by all the BLE initialisation calls, eg.

ble_error_t err = BLE_ERROR_NONE;
err = _ble->gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
MBED_ASSERT(err == BLE_ERROR_NONE);
err = _ble->gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS, uint128_services_list, sizeof(uint128_services_list));
MBED_ASSERT(err == BLE_ERROR_NONE);
err = _ble->gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)name, strlen(name));
MBED_ASSERT(err == BLE_ERROR_NONE);
err = _ble->gap().setDeviceName((const uint8_t *)name);
MBED_ASSERT(err == BLE_ERROR_NONE);
err = _ble->gap().startAdvertising();
MBED_ASSERT(err == BLE_ERROR_NONE);

There's a fair chance that one of them is actually returning an error code that'll hopefully point in the right direction for a fix.

[Mirrored to Jira]

AGlass0fMilk commented 6 years ago

Crashing was occuring when nordic-ble.uuid_table_max_entries was set to 8 and the NRF_SDH_BLE_GATTS_ATTR_TAB_SIZE was set to the default of 0x600. I then tried increasing the gatt attribute table size to 0x800. Then I started getting a fatal crash that seemed to be due to main stack corruption.

I figured this was due to the soft device using more RAM than previously so I adjusted the allocation in the linker script which stopped the crashing but the device was still not broadcasting.

I'll do some more debugging tomorrow. I may just switch all my custom services/characteristics to share the same base VS UUID to avoid this problem altogether... [Mirrored to Jira]

adbridge commented 6 years ago

Internal Jira reference: https://jira.arm.com/browse/IOTPAN-215