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.

Compiler/TM4C1290NCPDT: initializing memory

Part Number: TM4C1290NCPDT

Tool/software: TI C/C++ Compiler

TI v16.9.3.LTS

CCS 9.3

I have a unsigned integer pointer UINT8 *m_ucArcnetInputBuffer;

Structures of different sizes are used with this pointer to make assignments.

e.g., ARCNET_MSG_01_t * pRecvMessage = (ARCNET_MSG_01_t *)&(m_ucArcnetInputBuffer[0]);

In some places memory is dynamically allotted and freed to this buffer using free RTOS 

e.g., m_ucArcnetInputBuffer = (UINT8*)pvPortMalloc(ucNumMsgs*MAX_USB_MESSAGE_SIZE);

vPortFree(m_ucArcnetInputBuffer);

The problem I am running into is:

Soon after I flash the application, and halt at the first structure assignment (shown above),

there are values written into the memory that are non-zero. This is causing problems in the application. 

If I try malloc and freeing space, the processor is running into hard fault.

What can I do about this? Upgrading to a newer compiler didn't help.

Thanks,

Priya

  • When you cast an address to a pointer of a different type, such as ...

    Priya Nadathur70 said:
    ARCNET_MSG_01_t * pRecvMessage = (ARCNET_MSG_01_t *)&(m_ucArcnetInputBuffer[0]);

    ... it is your responsibility to insure the alignment constraints of the new type are met.  In this particular case, the new type is ARCNET_MSG_01_t.

    Priya Nadathur70 said:

    Soon after I flash the application, and halt at the first structure assignment (shown above),

    there are values written into the memory that are non-zero

    Where do these unexpected non-zero values appear?  In the source, or the destination?  If in the destination, do you inspect it after the structure assignment is complete?

    Thanks and regards,

    -George

  • I am halting prior to the assignment of the structure. The non-zero values are in locations following &m_ucArcnetInputBuffer[0]. I need these to be zero.

    Thanks,

    Priya

  • I am halting prior to the structure assignment is in effect. This is after UINT8 *m_ucArcnetInputBuffer; has been declared.

    Locations following &(m_ucArcnetInputBuffer[0] are non-zero and I need these to be zero.

    Thanks,

    Priya

  • Priya Nadathur70 said:
    Locations following &(m_ucArcnetInputBuffer[0] are non-zero and I need these to be zero.

    How is the memory associated with this variable allocated?  Is it a global variable?  Or allocated dynamically?

    If it is a global variable ...  Such variables are set to zero by the startup code.  In particular, the boot routine supplied in the compiler RTS library performs this task.  Please set a breakpoint at the beginning of main and inspect this variable.  Is everything zero then?

    If it is allocated dynamically ... If you use a FreeRTOS routine to allocate it, then consult the documentation for that routine.  If you use the malloc function supplied with the compiler, that memory is not guaranteed to be set to zero.  You have to either call calloc instead, or use memset to clear it after getting it from malloc.

    Thanks and regards,

    -George