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.

TMS320F280039C: How many bits does memcpy copy the data at a time

Part Number: TMS320F280039C

Hi Champ,

I am asking for my customer.

They are trying to copy the data from some else in the memory with calling the function memcpy.

May I confirm that the data alignment for memcpy is doing with uint32_t at a time ?

Since we tried to force by writing with uint16_t data alignment with the function memcpy(uint16_t *)&dataRunStart, (uint16_t *)&dataLoadStart, (uint16_t *)&dataSize.

After compiled, we still get data alignment with 32 bits at a time. Couldn't we align with 16 bits at a time ?

Also, where could I find the body source code for memcpy ? Is it in the RTS library ?

Thanks and regards,

Johnny.

  • Hi Johnny,

    Please take a look at this e2e thread on same topic. This was answered by compiler team.

    https://e2e.ti.com/support/microcontrollers/c2000-microcontrollers-group/c2000/f/c2000-microcontrollers-forum/1085141/tms320f280049-introduction-to-memcpy-function

    The source code for rts library is located here:

    C:/ti/ccs1110/ccs/tools/compiler/ti-cgt-c2000_21.6.0.LTS/lib/src/memcpy.c

    Thanks & Regards,

    Santosh

  • Hi Santosh,

    I read the thread commented by George before, while it doesn't explicitly tell that the memcpy always do with a 32-bit at a time ?

    Not sure the place where it tells the 32-bit, is it said in the chapter Using Linker Symbols in C/C++ Applications in C28x assembly tools manual in below screenshot ?

    Thanks and regards, 

    Johnny

  • I need to separate this into two different questions.  1) What is the alignment required of uint16_t and uint32_t type variables, arrays, etc?  2) How is memcpy typically implemented?

    On the C28x CPU, each address corresponds to one 16-bit word.  It is not possible for any address to correspond to an 8-bit byte.  So the alignment of uint16_t variables, arrays, etc. is 1.  The alignment of uint32_t variables, arrays, etc. is 2.  This is always the case, without regard for whether memcpy is used.

    Every time I have inspected code generated by the compiler for a call to memcpy, inline or out-of-line, that code copies 1 16-bit word at a time.  This is true without regard to what is being copied, or how it may be aligned.  That said, it is possible that a future version of the compiler could copy 2 16-bit words at a time, which means those words must be aligned on a 2-word address.  The interface to memcpy remains the same, but the underlying code generated by the compiler could be different.

    Thanks and regards,

    -George

  • Hi expert,

    I looked up the source code for memcpy in rts library. While it seems like there is no restriction with the memcpy function to align with uint16_t(unsigned int) or uint32_t(unsigned long). Am I misunderstanding ?

    The another reason for asking this is because the copy the program and constants from FLASH to RAM before configuring the CPU and CLA are different So, I get confused about how many bits does memcpy copy the data at a time. 

    Would the expert kindly explain more for helping me to get an answer to my question ?

    Thanks and regards,

    Johnny

  • George is current away and will reply after he returns on Tuesday. Thank you for your patience.

  • it seems like there is no restriction with the memcpy function to align with uint16_t(unsigned int) or uint32_t(unsigned long)

    That is correct.  Because it is part of the published interface of memcpy, it will never change.  But that is not what I am talking about.  I am talking about the question of how memcpy is implemented.  Does it always copy 1 16-bit word at a time?  Or 2 16-bit words at a time?  Presently, it is always 1 16-bit word at a time.  But it remains possible that, in a future release, the implementation could change to 2 16-bits words at a time.  

    the copy the program and constants from FLASH to RAM before configuring the CPU and CLA are different

    The key thing to understand is that the parameters passed to to memcpy are always the addresses of those symbols.  That's all that ever happens with those symbols.  Since that is the case, the type used to declare the symbol, or the type used to cast it to a pointer, doesn't matter.  That the type is different in these two cases is of no concern.  For more background on this general topic, please search the C28x assembly tools manual for the sub-chapter titled Using Linker Symbols in C/C++ Applications.

    Thanks and regards,

    -George