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

Writing characteristics longer than 20 bytes

I know there are multiple different questions/answers relating to this topic but none exactly solved my issue. Further, some of the questions are many years old so it's not clear to me if some of that information is perfectly relevant. So here goes...

I am trying to create a characteristic that is up to 512 bytes which I believe I read is a BLE maximum. 

During the setup of the characteristic I set the following variables:

        attr_char_value.max_len  = VECTOR_DATA_SIZE;
        attr_char_value.init_len    = VECTOR_DATA_SIZE;

Where VECTOR_DATA_SIZE is programmable. As an experiment I set it to 64 (decimal).

I then initialize the value in the peripheral characteristic to 0,1,2,3,...63

So far so good.

If I then open up nRF Connect and attempt to READ this characteristic I see that the size of the characteristic is correct and the proper data is returned.

If I try to WRITE that data however, I get a BLE_GATT_STATUS_ATTERR_APP_BEGIN error.

As you might expect, I see this same error if the size (ie: VECTOR_DATA_SIZE) is set to any value greater than 20.

What am I missing?

Parents
  • You need to initialize the softdevice with a max mtu value require otherwise the default is 20.  look for MTU somewhere in sdk_config.h

  • I assume you mean the following #defines:

    // <o> NRF_SDH_BLE_GATT_MAX_MTU_SIZE - Static maximum MTU size.
    #ifndef NRF_SDH_BLE_GATT_MAX_MTU_SIZE
    #define NRF_SDH_BLE_GATT_MAX_MTU_SIZE 24   // Default = 23
    #endif

    If I change the size greater to anything than the default value of 23, I wind up in the app_err_fault_handler() routine in app_error_weak.c.

    Debug terminal warning messages include:

    <warning> nrf_sdh_ble: Insufficient RAM allocated for the SoftDevice.
    <warning> nrf_sdh_ble: Change the RAM start location from 0x20002220 to 0x20002228.
    <warning> nrf_sdh_ble: Maximum RAM size for application is 0xDDD8.
    <error> nrf_sdh_ble: sd_ble_enable() returned NRF_ERROR_NO_MEM.
    <error> app: Fatal error

    Note that I am using SDK 15.0.0 with the nRF52 development kit (if that is helpful).

    Thoughts?

Reply
  • I assume you mean the following #defines:

    // <o> NRF_SDH_BLE_GATT_MAX_MTU_SIZE - Static maximum MTU size.
    #ifndef NRF_SDH_BLE_GATT_MAX_MTU_SIZE
    #define NRF_SDH_BLE_GATT_MAX_MTU_SIZE 24   // Default = 23
    #endif

    If I change the size greater to anything than the default value of 23, I wind up in the app_err_fault_handler() routine in app_error_weak.c.

    Debug terminal warning messages include:

    <warning> nrf_sdh_ble: Insufficient RAM allocated for the SoftDevice.
    <warning> nrf_sdh_ble: Change the RAM start location from 0x20002220 to 0x20002228.
    <warning> nrf_sdh_ble: Maximum RAM size for application is 0xDDD8.
    <error> nrf_sdh_ble: sd_ble_enable() returned NRF_ERROR_NO_MEM.
    <error> app: Fatal error

    Note that I am using SDK 15.0.0 with the nRF52 development kit (if that is helpful).

    Thoughts?

Children
  • Hi, 

    TCdeveloper said:
    <warning> nrf_sdh_ble: Change the RAM start location from 0x20002220 to 0x20002228.
    <warning> nrf_sdh_ble: Maximum RAM size for application is 0xDDD8.

     You need to modify the RAM start location and Maximum RAM size in the project option -> Linker -> Section Placement Marcos as the log indicates. 

  • When you increase the MTU size, softdevice will requires more ram space for that matter.  You need to readjust the reserve ram for softdevice as indicated in the log in the linker script.

  • This was helpful, thanks. It did fix my immediate problem. A couple of follow up questions.

    1) How large can I make the MTU size?

    2) Is there a preferred way to write larger amounts of data (from central to peripheral)?

    For example, others on devzone have mentioned queued (or long) writes. I tried this out by instantiating the "ble_app_queued_writes" example and it also seems to work.

  • Thanks . This is indeed what I needed to do. Any thoughts on the follow-up questions I asked Amanda?

  • 251-3 for ble 4.2

    512-3 for ble 5