Other Parts Discussed in Thread: UNIFLASH, HALCOGEN
My project has RAM comprising both the internal RAM and 16MB SDRAM with the configuration as shown below.
I found out (test source code at the end) that:
- malloc(63) and memset region works
- malloc(64) and memset locks processor
- malloc(1), malloc(64), memset(64), free(64), and finally free(1) works
- malloc(1), malloc(4096), memset(4096), free(4096, and finally(1) works too
I tried various variations, and as long as at I do one malloc of any size and do absolutely nothing with that malloc aside from holding onto that malloc I can make any number of additional malloc/use/free operations. The problem comes in, when I have no malloc regions and I want to allocate an initial 64 bytes or larger region. That fails. If I malloc(63), free(63), and then malloc(64)/memset(64), then that will fail, because I freed the initial malloc region, so the second malloc of 64 bytes becomes the new initial malloc region.
Processor: RM48L952ZWT Hercules
Board: My own, NOT the Hercules HDK
Development Tool Chain: Halcogen, CCS (Code Composer Studio), and UniFlash
I am using the TI C/C++. All code below placed in sys_main.c
CCS Memory Map:
MEMORY
{
VECTORS (X) : origin=0x00000000 length=0x00000020
FLASH0 (RX) : origin=0x00000020 length=0x0017FFE0
FLASH1 (RX) : origin=0x00180000 length=0x00180000
STACKS (RW) : origin=0x08000000 length=0x00021000
RAM (RW) : origin=0x08021000 length=0x0001f000
/* USER CODE BEGIN (2) */
RAM2 (RW) : origin=0x80000000 length=0x01000000
/* USER CODE END */
}
/* USER CODE BEGIN (3) */
/* Use the entire 16MB SDRAM for the heap */
--heap_size=0x01000000
#if 0
/* USER CODE END */
/*----------------------------------------------------------------------------*/
/* Section Configuration */
SECTIONS
{
.intvecs : {} > VECTORS
.text : {} > FLASH0 | FLASH1
.const : {} > FLASH0 | FLASH1
.cinit : {} > FLASH0 | FLASH1
.pinit : {} > FLASH0 | FLASH1
.bss : {} > RAM
.data : {} > RAM
.sysmem : {} > RAM
FEE_TEXT_SECTION : {} > FLASH0 | FLASH1
FEE_CONST_SECTION : {} > FLASH0 | FLASH1
FEE_DATA_SECTION : {} > RAM
/* USER CODE BEGIN (4) */
#else
SECTIONS
{
.intvecs : {} > VECTORS
.text : {} > FLASH0 | FLASH1
.const : {} > FLASH0 | FLASH1
.cinit : {} > FLASH0 | FLASH1
.pinit : {} > FLASH0 | FLASH1
.bss : {} > RAM
.data : {} > RAM
.sysmem : {} > RAM2
FEE_TEXT_SECTION : {} > FLASH0 | FLASH1
FEE_CONST_SECTION : {} > FLASH0 | FLASH1
FEE_DATA_SECTION : {} > RAM
#endif
/* USER CODE END */
}
Hercules RAM:
Here is test code:
boolean testMalloc()
{
sciDisplayTextExAll("testMalloc v3e:\r\n");
uint32 uSize2 = 62; // 62 worked
void * lpSize2 = malloc(uSize2);
sciDisplayTextExAll(" => after malloc uSize2\r\n");
memset(lpSize2, 0, uSize2);
sciDisplayTextExAll(" => after memset uSize2\r\n");
free(lpSize2);
sciDisplayTextExAll(" => Success 1!\r\n");
uSize2 = 63;
lpSize2 = malloc(uSize2);
sciDisplayTextExAll(" => after malloc uSize2\r\n");
memset(lpSize2, 0, uSize2);
sciDisplayTextExAll(" => after memset uSize2\r\n");
free(lpSize2);
sciDisplayTextExAll(" => Success 2!\r\n");
uint32 uSize1 = 1;
uSize2 = 4096;
void * lpSize1 = malloc(uSize1);
sciDisplayTextExAll(" => after malloc uSize1\r\n");
lpSize2 = malloc(uSize2);
sciDisplayTextExAll(" => after malloc uSize2\r\n");
memset(lpSize2, 0, uSize2);
sciDisplayTextExAll(" => after memset uSize2\r\n");
free(lpSize1);
free(lpSize2);
sciDisplayTextExAll(" => Success 3!\r\n");
uSize1 = 1;
uSize2 = 256;
lpSize1 = malloc(uSize1);
sciDisplayTextExAll(" => after malloc uSize1\r\n");
lpSize2 = malloc(uSize2);
sciDisplayTextExAll(" => after malloc uSize2\r\n");
memset(lpSize2, 0, uSize2);
sciDisplayTextExAll(" => after memset uSize2\r\n");
free(lpSize1);
free(lpSize2);
sciDisplayTextExAll(" => Success 4!\r\n");
uSize1 = 1;
uSize2 = 64;
lpSize1 = malloc(uSize1);
sciDisplayTextExAll(" => after malloc uSize1\r\n");
lpSize2 = malloc(uSize2);
sciDisplayTextExAll(" => after malloc uSize2\r\n");
memset(lpSize2, 0, uSize2);
sciDisplayTextExAll(" => after memset uSize2\r\n");
free(lpSize1);
free(lpSize2);
sciDisplayTextExAll(" => Success 5!\r\n");
uSize2 = 64;
lpSize2 = malloc(uSize2);
sciDisplayTextExAll(" => after malloc uSize2\r\n");
memset(lpSize2, 0, uSize2);
sciDisplayTextExAll(" => after memset uSize2\r\n");
free(lpSize2);
sciDisplayTextExAll(" => Success 6!\r\n");
return TRUE;
}
When I execute the above function, I see through Success 5 and through "after malloc uSize2" of Success 6, but no after and obviously no Success 6. Success 6 fails, because in my configuration one cannot allocate an initial block of memory that is 64-bytes or larger. Obviously, there is something that I did not configure properly.
What is wrong with my Halcogen/CCS map configuration, either singularly or both? Is it something else, possibly the linker?

