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.

CCS/AM5726: Wrong memory alignment

Part Number: AM5726


Tool/software: Code Composer Studio

Hello,

The following problem is one of the outcomes related to a previous post, where a data transfer via DMA to/from the UART FIFOs is not working properly.

e2e.ti.com/.../754190

One of the problems that UART DMA transfer is not working as expected is due to the fact, that the buffers that receives the data and holds the data that is being transmitted are not 128[byte] aligned although we added the __attribute__ ((aligned (128))) instruction as shown in the below picture.

The situation is as follows:

1) The structure SafetyCardOutputBuffer is a member variable of a C++ class.
2) The structure SafetyCardOutputBuffer is not 128[byte] aligned.
3) The instance of the class is being created on the system heap as follows:
        UartCyclicChannel* cUartCyclicChannel = {NULL};
        cUartCyclicChannel = new UartCyclicChannel(0);
4) I use CCS version  7.4.0.00015 with GNU v6.3.1(Linaro) compiler

Please let me know if you need further details.

Thanks,

Andreas

  • The problem is this new call ...

    Andreas Halbe said:
            cUartCyclicChannel = new UartCyclicChannel(0);

    I was unable to find any documentation which clearly states the alignment of the memory address returned by new.  But it is very unlikely to be 128 bytes.  It is probably the maximum alignment of the the largest built-in type, which is 8 bytes.  

    I recommend you implement a memory allocation routine which returns memory addresses aligned to 128 bytes, and call it instead of new.

    Thanks and regards,

    -George

  • George,

    The customer don’t want to align the whole class, they simply want to align member variables, which are part of the class instance. So the __attribute__ keyword is not working. Why is that? Do you have more insight for this?

    Regards, Eric
  • The only way to establish the alignment of a field inside a structure is to first align the whole structure to that same alignment.  This is true in general.  For instance, suppose a structure contains a field of type double.  That type requires an alignment of 8-bytes.  Therefore the compiler has to align the entire structure to 8-bytes.  With that established, then the compiler aligns the double within the structure.

    Your customer has a similar situation, though with an alignment constraint of 128 bytes.  As expensive as it is, the only way to align a field inside a structure to 128-bytes is to first align the whole structure to 128-bytes.  Since new does not return addresses aligned to 128-bytes, a custom allocation routine must be implemented and used instead.

    Thanks and regards,

    -George