This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

RTOS/CC2642R: Heap Size when using Memory_alloc()

Part Number: CC2642R
Other Parts Discussed in Thread: CC2640,

Tool/software: TI-RTOS

Hello TI Experts,

I am currently porting code from the CC2640 to a new device running on the CC2642R1 and I'm running into some heap related issues.

In our CC2640 Build, heap sized was defined as "BIOS.heapSize = 512*5" in the .cfg file and worked with the following code:

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//                      NUM_SEQUENCE calculation:
//
//                    [ (BIOS_HEAP_SIZE - 20)/2 ]
//                  ------------------------------
//                         SD_SEQUENCE_SIZE
// WHERE:
// BIOS_HEAP_SIZE -  size of system default heap in units of BYTES
//                  defined in settings.h
//                  it is a manual reference to BIOS.heapSize which is defined in .cfg
//
//                  NOTE:   haven't found a way to read this variable out of the .cfg file
//                          #include <xdc/cfg/global.h> was included in settings.h to faciliate
//                          this functionality, but was not successfully integrated.
//                          Therefore the BIOS.heapSize must be manually checked and assigned to
//                          BIOS_HEAP_SIZE in settings.h
//                  (uses HeapMem Module - described in detail in:
//                  SYS/BIOS (TI-RTOS Kernel) v6.46.01 USER'S GUIDE chap. 7)
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#define NUM_SEQUENCE ((((BIOS_HEAP_SIZE) - 28)/2)/(SD_SEQUENCE_SIZE)) // UNITS in bytes #define BUFFER_SIZE (((SD_SEQUENCE_SIZE)*(NUM_SEQUENCE))) // UNITS in bytes // for each buffer write #define AFE_ELEMENTS (AFE4404_SAMPLE_RATE/ADXL345_SAMPLE_RATE) * (SAMPLE_INFARED+SAMPLE_RED+SAMPLE_GREEN) static int timestamp_start; static int timestamp_end; long long int timestamp = 999; typedef struct SDBuffer { bool address; // value to pick one of two allocated buffer SD_addresses, either sdbuffer or tempsdbuffer int size; // size of memory allocated for each buffer int index; // value to keep track of which memory element is being accessed and to signify when // buffer is full bool full; // signifies when buffer is full, when index == size -1 and all memory elements store // data to be written to sd card }SDBuffer; uint32_t *SD_Buffer; uint32_t *tempSD_Buffer; struct SDBuffer SDbuffer; uint32_t *SD_addresses[2]; bool heap_set_up(){ /* initialize SDBuffer structure members */ SDbuffer.address = 0; SDbuffer.size = ((BUFFER_SIZE)/4); // DIVIDE by 4 to get in units of uint32_t which is 4 bytes, This is number of elements SDbuffer.index = 0; SDbuffer.full = false; System_printf("Buffer1 size before alloc: %d\n",BUFFER_SIZE);System_flush(); SD_Buffer = (uint32_t *)Memory_alloc(NULL, (BUFFER_SIZE), 0, NULL);//multiply by datasize SIZE_DATA_TYPE_ADXL345 if(!SD_Buffer){ System_printf("Memory not allocated for memory storage, aborting...!\n");System_flush(); return false; } tempSD_Buffer = (uint32_t *)Memory_alloc(NULL, (BUFFER_SIZE), 0, NULL);//multiply by datasize SIZE_DATA_TYPE_AFE4404 if(!tempSD_Buffer){ System_printf("Memory not allocated for memory storage, aborting...!\n");System_flush(); return false; } SD_addresses[0] = SD_Buffer; SD_addresses[1] = tempSD_Buffer; System_printf("Buffer size: %d\n",BUFFER_SIZE);System_flush(); System_printf("Num sequence: %d\n",NUM_SEQUENCE);System_flush(); return true; }

When adding this same code to the new CC2642R1 build, the program freezes at the Memory_alloc() call from what appears to be a lack of available heap space.  This new code currently uses on 16% of 360K for FLASH and 23% of the 81,920K for SRAM. 

Is there some modification to the .cfg file or any other modules that should be doing to make this build work?

Thanks.

- Stephen P.