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.

TMS320F28062F: Memory allocation for an array aborts program

Part Number: TMS320F28062F
Other Parts Discussed in Thread: MOTORWARE

Currently I'm trying to save different motor configurations ("profiles") to EEPROM, and for that I have to copy a struct to an array that could be sent via I2C. But when I try to declare the array, the application goes to the abort() function in exit.c.

Here is the function where the problem appears (happens when executing the line "uint16_t rawData8[len];"):

uint16_t EEPROM_saveProfile(HAL_Handle halHandle, Profile *profile, uint16_t profileNumber){
	uint16_t len = sizeof(Profile)*2;
	uint32_t address = profileDataStartAddr + len * profileNumber;
	// Making sure we don't go beyond the avaliable memory.
	if((address+len > EEPROM_SIZE) || (address+len > profileDataStartAddr+profileDataSize)){
		return 0;
	}

	uint16_t rawData8[len];
	convert16_8lsb(profile, rawData8, len);

	return eepromWrite(halHandle->eepromHandle, address, rawData8, len);
}

I verified that len=60 when the line in question is reached, and also tried to set it to a constant 60 rather than calculate it from the size of the profile, but the behavior didn't change. Commenting out the last 2 lines and setting len=1 still causes the program to abort there.

After digging deeper I found that abort() is called from increase_curr_vla_pool_capacity() in vla_alloc.cpp after realloc() returns 0 because curr_vla_pool->capacity * sizeof(a_vla_allocation) is 0. These files aren't part of my project (they are in the lib/src folder of the compiler).

First I thought the problem appears because some section runs out of memory, so I changed the .cmd file so that there is a lot of free space in each memory block by connecting all similarly named consecutive memory blocks in each page, but that didn't solve the problem. Here it is what it currently looks like:

MEMORY
{
PAGE 0 :   /* Program Memory */
           /* Memory (RAM/FLASH/OTP) blocks can be moved to PAGE1 for data allocation */
   RAML0_1       : origin = 0x008000, length = 0x000C00     /* on-chip RAM block L0 and L1 */
   OTP           : origin = 0x3D7800, length = 0x000400     /* on-chip OTP */

   FLASHA_B_C_D  : origin = 0x3E8000, length = 0x00FF80     /* on-chip FLASH */
   CSM_RSVD      : origin = 0x3F7F80, length = 0x000076     /* Part of FLASHA.  Program with all 0x0000 when CSM is in use. */
   BEGIN         : origin = 0x3F7FF6, length = 0x000002     /* Part of FLASHA.  Used for "boot to Flash" bootloader mode. */
   CSM_PWL_P0    : origin = 0x3F7FF8, length = 0x000008     /* Part of FLASHA.  CSM password locations in FLASHA */

   FPUTABLES     : origin = 0x3FD590, length = 0x0006A0	 /* FPU Tables in Boot ROM */
   IQTABLES      : origin = 0x3FDC30, length = 0x000B50    /* IQ Math Tables in Boot ROM */
   IQTABLES2     : origin = 0x3FE780, length = 0x00008C    /* IQ Math Tables in Boot ROM */
   IQTABLES3     : origin = 0x3FE80C, length = 0x0000AA	 /* IQ Math Tables in Boot ROM */

   ROM           : origin = 0x3FF3B0, length = 0x000C10     /* Boot ROM */
   RESET         : origin = 0x3FFFC0, length = 0x000002     /* part of boot ROM  */
   VECTORS       : origin = 0x3FFFC2, length = 0x00003E     /* part of boot ROM  */

PAGE 1 :   /* Data Memory */
           /* Memory (RAM/FLASH/OTP) blocks can be moved to PAGE0 for program allocation */
           /* Registers remain on PAGE1                                                  */

   BOOT_RSVD   : origin = 0x000000, length = 0x000050     /* Part of M0, BOOT rom will use this for stack */
   RAMM0_1     : origin = 0x000050, length = 0x0007B0     /* on-chip RAM block M0 */
   RAML2_3_4_5 : origin = 0x008C00, length = 0x005400
   USB_RAM     : origin = 0x040000, length = 0x000800     /* USB RAM		  */

   ECANA       : origin = 0x006000, length = 0x000040     /* eCAN-A control and status registers */
   ECANA_LAM   : origin = 0x006040, length = 0x000040     /* eCAN-A local acceptance masks */
   ECANA_MOTS  : origin = 0x006080, length = 0x000040     /* eCAN-A message object time stamps */
   ECANA_MOTO  : origin = 0x0060C0, length = 0x000040     /* eCAN-A object time-out registers */
   ECANA_MBOX  : origin = 0x006100, length = 0x000100     /* eCAN-A mailboxes */
}


SECTIONS
{

   /* Allocate program areas: */
   .cio                : > RAML0_1,        PAGE = 0
   .cinit              : > FLASHA_B_C_D,   PAGE = 0
   .pinit              : > FLASHA_B_C_D,   PAGE = 0
   .text               : > FLASHA_B_C_D,   PAGE = 0
   codestart           : > BEGIN,          PAGE = 0
   ramfuncs            : LOAD = FLASHA_B_C_D,
                         RUN = RAML0_1,
                         LOAD_START(_RamfuncsLoadStart),
                         LOAD_END(_RamfuncsLoadEnd),
                         RUN_START(_RamfuncsRunStart),
                         PAGE = 0

   csmpasswds          : > CSM_PWL_P0,       PAGE = 0
   csm_rsvd            : > CSM_RSVD,         PAGE = 0

   /* Allocate uninitalized data sections: */
   .stack              : > RAMM0_1,          PAGE = 1
   .esysmem            : > RAML2_3_4_5,      PAGE = 1
   .ebss               : > RAML2_3_4_5,      PAGE = 1

   /* Initalized sections to go in Flash */
   /* For SDFlash to program these, they must be allocated to page 0 */
   .econst             : > FLASHA_B_C_D,   PAGE = 0
   .switch             : > FLASHA_B_C_D,   PAGE = 0

   /* Allocate IQ math areas: */
   IQmath              : > FLASHA_B_C_D,   PAGE = 0            /* Math Code */
   IQmathTables        : > IQTABLES,       PAGE = 0, TYPE = NOLOAD
   
   /* Allocate FPU math areas: */
   FPUmathTables       : > FPUTABLES,      PAGE = 0, TYPE = NOLOAD

   DMARAML5	           : > RAML2_3_4_5,    PAGE = 1

   .reset              : > RESET,      PAGE = 0, TYPE = DSECT
   vectors             : > VECTORS,    PAGE = 0, TYPE = DSECT

}

Any way to fix that?

P.S. Just in case it's relevant, I'm using proj_lab09 from Motorware 17 as basis for this project, but it was changed a lot already.

  • Hello

    Have you verified you aren't getting a stack overflow? You don't have a lot allocated to ".stack".

    Best Regards
    Chris
  • Increased stack size in project settings from 0x3B0 to 0x600 and heap size from 0x400 to 0x800 and moved the .stack to RAML2_3_4_5. It didin't help, program still behaves the same.
  • I made a macro and created the array directly with that macro. The code works now...

    #define PROFILE_SIZE sizeof(Profile)*2
    
    uint16_t rawData8[PROFILE_SIZE];

  • Dmitri Ranfft said:

    I made a macro and created the array directly with that macro. The code works now...

    #define PROFILE_SIZE sizeof(Profile)*2
    
    uint16_t rawData8[PROFILE_SIZE];

    I've just run into a similar problem... I, at first, fixed it by hard-wiring the array sizes rather than letting them be set by the input parameter... Eventually I moved to global storage...

    Did you happen to find out what was going on? Was it a stack overflow or something else?