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.

  • Hi

    I suspect you are out of RAM. Check if the problem goes away if you decrease the amount of services and/or characteristics. One solution is to get a chip with larger RAM, i.e. the nRF51822 QFAC variant which has 32kB of RAM. Another solution, if possible, is to put the application on RAM diet, see this thread.

    Update 4.3.2015 For explanation about RAM space on nRF51, look at the answer here.

    I do not know yet what nRF51 variant you have or what softdevice you are using, but if I assume you are using the S110 softdevice, the RAM usage is as follows:

    • S110: 8kB
    • Stack: 2kB (combined S110 and application)
    • Heap: 2kB
    • Space left for application 4kB

    As you point out, your RAM and ROM usage is

    Code=30484 RO-data=432 RW-data=204 ZI-data=5964 
    

    Your application is consuming 204 + 5964 = 6168 bytes of RAM, which includes the 2048 bytes allocated for the stack. You could remove the heap by configuring the arm_startup_nrf51.s file if you do not have any dynamic memory allocation.

    What softdevice and hardware are you actually using?

    Update 10.3.2015 I suspect now that the NRF_ERROR_NO_MEM error that you see when creating a service is because of limited RAM size for the GATT table in the softdevice. For softdevices prior to version 8.0.0, the size of the GATT table is limited to 0x700 bytes. The maximum size of the GATT table can however be configured in S110 8.0.0, see the release notes that come with S110 8.0.0 and the migration document. Note that increasing the GATT table size will decrease the RAM available for the application.

    So, I suspect the solution to this problem is at least one of the three:

    • Get a nRF51 QFAC chip which has 32kB RAM
    • Decrease the number of services and/or characteristics created by your application
    • Increase the maximum size of the GATT table
  • Hi Stefan, The first steps I have done are to create services and characteristics, so I do not think is a RAM space problem. Please, take a look to summary line that appears after compiling: Program Size: Code=30484 RO-data=432 RW-data=204 ZI-data=5964
    So, I'm far away from RAM limit. As far as I have read, I think it is something related to the 1.5KB space that stack has assigned. Right??

  • I'm using Softdevice S110 v7.1.0 on the nrf51822qfaag0 device. But, what I do not understand is having such RAM consumption: I have started from Heart-Rate demo and, by proceeding in the same way, I have created 5 custem services: 1st one with 3 characteristics, 2nd with 2, 3rd with 2, 4th with 3 and 5th with 1. And I have not implemented more code, yet. A lot of RAM consumption just with 5 services, right?? And the 5964 bytes of RAM, are not included inside the 8KB available for the S110? Furthermore, for the ble_app_hrs demo parameters are quite similar: Program Size: Code=23656 RO-data=360 RW-data=280 ZI-data=5664

  • 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.

  • Thank you RK. But there is anything that does not match here. As a comparison:

    • My App --> ZI-Data:5964
    • ble_app_hrs demo --> ZI-Data: 5664
    • ble_app_lbs demo --> ZI-Data: 5880 So, there is no much difference between them in terms of space... So, where is the key of this subject?
Related