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

What is the maximum MTU size supported on nRF52840

I am bothered by the fact I have to ask this question at all. It should be easily found in the documentation but I cannot find it for the life of me.

I am trying to increase the size of the MTU from the default 23. Somewhere there should be a table that shows the maximum MTU size one can use as a function of SoftDevice version (if that makes a difference) and hardware platform (nRF51822, nRF52840, etc.). There might be one but the search function in the documentation is for all practical purposes useless.

My server works fine on the nRF52840 DK if I set NRF_SDH_BLE_GATT_MAX_MTU_SIZE to 23. But when I start changing that value I am running into errors. I don't know whether I am incorrectly implementing the mtu request on my Android client or messing up on the Nordic size by using an unsupported value or initializing the value incorrectly. So it would be nice to know what the maximum size is because the Nordic support may not yet be up to the spec defined limits.

So I did something simple. Changed NRF_SDH_BLE_GATT_MAX_MTU_SIZE to 24 and did nothing else. The application failed on the first sd_* call after the ble_stack_init(). Note I am using SoftDevice only for BTLE functionality. There must be something fundamental that I am doing wrong here.

Here is a log

<debug> app: Main start GHS
<info> app_timer: RTC: initialized.
<debug> app: Could not set the Bluetooth Address. Error code 12289
<error> app: ERROR 12289 [Unknown error code] at E:\projects\utech\nRF5_SDK_17.0.2_d674dde\examples\bl e_peripheral\ble_app_ghs_header\main.c:2229
PC at: 0x0002FEC1
<error> app: End of error report

Good luck trying to find out what the error code 12289 is!  The call giving rise to the error is 

    // Set device address
    ble_gap_addr_t addrStruct;
    addrStruct.addr_type = BLE_GAP_ADDR_TYPE_PUBLIC;
    memcpy(addrStruct.addr, bluetoothAddress, 6);
    err_code = sd_ble_gap_addr_set(&addrStruct);
    if (err_code != NRF_SUCCESS)
    {
        NRF_LOG_DEBUG("Could not set the Bluetooth Address. Error code %d", err_code);
        APP_ERROR_CHECK(err_code);
    }

Works fine with MTU set to 23. Gives the above when MTU is set to 24. Is there some memory overwrite going on that is not documented?

Parents Reply Children
  • There is no limit per the spec on how high the ATT MTU value can be, but the maximum length of an attribute value is per spec 512 octets. The Softdevice supports this value.

    When you configure the SoftDevice. i.e. you configure how many connections it should support, connections roles, GAP event length, maximum ATT MTU, number of custom UUIDS, size of GATTS attribute table, etc. this is passed to the SoftDevice when you enable it, and it will return the RAM requirements for the configuration. If you have not configured enough RAM, you will not be able to enable the SoftDevice (sd_ble_enable() will return NRF_ERROR_NO_MEM.)

    brianreinhold said:
    It looks like a new MTU requires a new memory size which has to be hard-configured pre-build. There does not appear to be a way to do this dynamically.

     Correct.

    <debug> app: Could not set the Bluetooth Address. Error code 12289

     12289 in hex is 0x3001. ie. NRF_ERROR_STK_BASE_NUM (0x3000) +1 , this is the same as BLE_ERROR_NOT_ENABLED

    What I believe happened here is that the sd_ble_enable() returned NRF_ERROR_NO_MEM, i.e. the SoftDevice was not enabled, then you later called sd_ble_gap_addr_set(), and it returned BLE_ERROR_NOT_ENABLED because sd_ble_enable() had failed/the SoftDevice was not enabled.

  • Sigurd,

    I sort of figured this out by trial and error. However, I will say trying t find the error codes is very difficult because of the way they are defined. There needs to be a place where they are all listed by value.

Related