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

NRF_ERROR_NO_MEM

Hi, I have created up to 5 custom services with several characteristics (4 at maximum) each one. They all use the same base UUID. The problem I'm facing now is that when I execute 'services_init' function, the function 'sd_ble_gatts_service_add' gives error 0x000004 (NRF_ERROR_NO_MEM). I have changed services ordes inside 'services_init' function and then the same error is given but now by the 'sd_ble_gatts_characteristic_add' function. (This is maybe due to the fact that not all the services have the same number of characteristics). Do you know which is the reason of this problem? Best regards, Dani.

Parents
  • ok so there are two places using RAM, one is the heap, do you need a heap at all? If you aren't using malloc or anything which uses malloc(), you don't need it, you can turn it to 0Kb, that saves you 2Kb. (Note: in the projects I've tested 0KB heap is the default, but I don't use Keil so perhaps it's different).

    Now that 5964 bytes of RAM, that's a lot. So you need to figure out what it is. First you need to understand what Zi-data is. It's RAM (i.e. it's memory which can be written) which is set to zero by default at the start of program execution. For instance if you had this line of code in your code

    static uint8_t MY_BIG_BUFFER[ 5694 ];
    

    that would generate 5694 bytes of Zi-Data. Why? Because it's a static buffer, it's writable (not constant) and it has no initialisation which means it's initialized to zero.

    Obviously that's not what you have in your code, Zi-data will come from lots of different places and add up to 5694 bytes, but the general point is there is static, writable zero-filled data and if it's of that kind of size, it's probably array data, so have you added any variables with static arrays? You say for instance that you created 5 custom services, do they have static arrays of data in them?

    If I wanted to find out what was generating this I would go and look at the .map file generated by the linker. I don't know how you do that with whatever tools you're using, but if you can generate one and look at it, you should find the names of the symbols taking up space.

    Finally I will add one piece of confusion. This is all static memory allocation. I would have expected the linker to fail if you used more RAM than was on the device, this looks more like something runtime when you're running out of memory. I did wonder if your services were taking up more than the 700 bytes available for service data, only with the very latest softdevice 8.0.0 can you allocate more than that. I don't know how 5 services with a total of 11 characteristics take up 700 bytes but it's possible, that to me seemed more likely to generate this type of runtime error.

  • .. and I wish comments weren't so limited to 900 chars ..

    So I'd try removing a service or characteristic until it doesn't crash, you may be right on the limit and just removing one or two would work.

    The new Softdevice 8.0.0 allows you to change that 0x700 byte limit. You could try that, although there's so many changes in that version and the SDK isn't out yet you may run into other issues, probably better to wait for SDK v8

    I don't have the code for the softdevice else I could look at see exactly in what circumstances NRF_ERROR_NO_MEM is returned from those two calls. Basically that's a controlled error message, so it's an internal check inside the softdevice against its own memory usage.

Reply
  • .. and I wish comments weren't so limited to 900 chars ..

    So I'd try removing a service or characteristic until it doesn't crash, you may be right on the limit and just removing one or two would work.

    The new Softdevice 8.0.0 allows you to change that 0x700 byte limit. You could try that, although there's so many changes in that version and the SDK isn't out yet you may run into other issues, probably better to wait for SDK v8

    I don't have the code for the softdevice else I could look at see exactly in what circumstances NRF_ERROR_NO_MEM is returned from those two calls. Basically that's a controlled error message, so it's an internal check inside the softdevice against its own memory usage.

Children
No Data
Related