Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs

Device reset when memory is full

Hello,

We use nRF5 SDK v17.1.0 (soft device S140 v7.2.0) and it works well except that when receiving many message over bluetooth the device reset due to memory being full so the SDK was not able to allocate more memory for incoming message. I have 16kb of heap size and 4kb of stack.
The message flow is as is:

- SDK receive message, allocate the memory for it, then call the callback registered through gatt_factory_reg_callback_write

- the callback treat the message and send answer through gatt_factory_update_value

- SDK frees the memory for this message

So the issue is that the callback can take more time to handle some messages than time to receive message so many message accumulates in the memory to the point where the SDK detect a memory full and call the error_handler which reset the device.

Questions are:

1/ can I remove the reset from the error_handler and then SDK will just discard message until there is free memory ? Any potential problem from removing the reset ?

2/ is there a way to tell the SDK to discard message when memory is full instead of calling the error_handler ? Or should I write another error_handler which do not reset when memory is full but it goes with 1/ any risks to not reset device ?

3/ Since my callback can takes some time should I write a new callback which post messages into a queue and when queue is full I just discard the message ? Does SDK release immediately the memory at the end of the callback or there is something else which release memory ? Like a garbage collector which I need to run ?

Thank you for your time.

Best regards.

  • I reread my ticket and I saw I was a bit too deep in our code, we register our own obserser for ble event with

    NRF_SDH_BLE_OBSERVER(m_ble_observer, APP_BLE_OBSERVER_PRIO, ble_drv_evt_dispatch, NULL);

    So this ble_drv_evt_dispatch calls the callback when there is a BLE_GATTS_EVT_WRITE event from soft device I hope it is more clear

  • Hi!

    So the issue is that the callback can take more time to handle some messages than time to receive message so many message accumulates in the memory to the point where the SDK detect a memory full and call the error_handler which reset the device.

    So a function returned an error-code, that was passed to APP_ERROR_CHECK(), and the error_handler reset the device.

    What function returned the error code? And what error-code was returned?

Related