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

How do I read my .map file?

I am trying to free up some RAM on my nRF because I am getting Fatal error 0x4, NRF_ERROR_NO_MEM when I try to increase the size of a 2D array. 

I do not understand how to read my map file. This is the file that contains all my symbols, correct? I sorted all the symbols by size and this is what I get: 

Apparently all the ".debug_str" take up 11 MB total? That's a lot but if it's all in flash then I don't care. I want to free up RAM. How do I list only the RAM symbols? Do I just delete the entire ".text" section from the .map file?

I filtered out all the ".debug" symbols and I'm left with this: 

First of all, what is the difference between ".bss.ucHeap" and ."heap"? 

Secondly, I changed my makefile to make the heap size = 0 and my stack size bigger (from 2048 bytes to 3072), but my application STILL Fatal errors with 0x04 when I try to increase the size of a 2D array from [2][75] to [2][140]. I am only using 130 more bytes in the array. Why can't my stack handle it if I just increased its size from 2048 bytes to 3072? I am not using malloc() anywhere. 

New map file after stack/heap modification: 

  

Parents Reply Children
  • Hi,

    I did not follow your calculations and reasoning about why you would expect to fill all the RAM.

    Regarding the physical size, the application can typically not use all the RAM of the device. If you have a SoftDevice, then that will need some RAM as well. In your case the application RAM starts from 0x20002400, which I assume is because the SoftDevice use the RAM from 0x20000000 and upto 0x200023FF. I expect this matches your linker configuration.

    Regarding the original question: Note that there is no direct link between free space on the device and you getting NRF_ERROR_NO_MEM. If there is no more space in the heap, then you cannot allocate any more. That is regardless of if there is available space on the device or not, as long as that is not configured to be used for the heap.

  • I did not know that RAM from 0x20000000-0x20002400 is allocated to the SoftDevice. That would have helped my calculations. 

    I was able to eliminate my NRF_ERR_NO_MEM error by increasing the size of the GATT table by increasing NRF_SDH_BLE_GATTS_ATTR_TAB_SIZE and from 1408 to 3000 and increasing the RAM limits to RAM (rwx) :  ORIGIN = 0x20002A38, LENGTH = 0xD5C8.

    Why do I only get an NRF_ERR_NO_MEM from the char_add() function when I try to increase my array size? My array is allocated with RAM outside of the SoftDevice RAM: address 0x20005f20. Why does an array allocated outside of the SoftDevice RAM affect the Softdevice RAM?

    How do I know if I have unallocated physical RAM left? Do I just add up everything in the memory addresses0x20002A38-0x20010000 and sum up their sizes + 0x2A38 for the SoftDevice RAM?

  • Hi,

    If you get NRF_ERR_NO_MEM returned from a call to sd_ble_gatts_characteristic_add(), then this is because the GATT table is too small as you have noted. In that case you need to increase it and adjust the application start address as you have done. 

    Andrew Ong said:
    Why do I only get an NRF_ERR_NO_MEM from the char_add() function when I try to increase my array size?

     Please always specify from which function you get the error code. That way we can better understand the issue. How do you try to allocate this array, and from where do you get NRF_ERR_NO_MEM in this case?

    Andrew Ong said:
    Why does an array allocated outside of the SoftDevice RAM affect the Softdevice RAM?

    It does not. There is a strict separation between SoftDevice an application RAM, which is why you have to configure the application RAM start address to be after the end of the RAM used by the SoftDevice (which depend on its configuration).

    Andrew Ong said:
    How do I know if I have unallocated physical RAM left? Do I just add up everything in the memory addresses0x20002A38-0x20010000 and sum up their sizes + 0x2A38 for the SoftDevice RAM?

    Yes. However, if you use for instance Segger Embedded Studio (or most other IDEs for that matter) it would present you the memory usage automatically after every build so that you will not have to do the calculations yourself. For that and other reasons I suggest you consider migrating to Segger Embedded Studio unless you have a strong inclination to continue using GCC directly.

Related