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.

TMS570LS3137: How to set the endianness of the scalar fields of C structures to little-endian ?

Part Number: TMS570LS3137

Hello,

I'm working on a project where I need to port a huge C software module from Windows platform (Little Endian architecture) to TMS570LS3137 (Big Endian)

The software module basically receives some data from an external chip, process them and sends back the response.

Data received or sent to the external chip should be little endian but TMS570LS3137 is big endian.

The Software module uses a lot of type casting to convert from 8bits data buffer to specific internal structure type.

E.g.:

myStructure = (MY_STRUCTURE_TYPE *)pData //pData of type (uint8_t *)

When the software runs on windows platform, it works fine as data in 'myStructure' is in right order but when run on TMS570, everything is the wrong way round because of the change in endianness.

1/ I saw the pragma <#pragma scalar_storage_order little-endian> that could be used whenever such structure is defined but it is not supported by TI compiler (TI v20.2.5.LTS)

2/ I tried to compile the code in little endian and changed the device type to little endian in CCS but then I'm having an issue flashing the code to the target with the error coming from CCS "File.elf does not match the target endianness, not loaded"

3/ I was having a look at changing compiler to gcc (in order to use the scalar_storage_order pragma) but this process would involve building the whole GNU toolchain. However that process doesn't seem well documented.

The only dirty hacky way I can see is to manually create functions to reverse necessary bytes whenever such type cast is used. However, this is error prone and high effort adaptation because there are hundreds of structure and type casting like the above.

What do you think is the best way to handle this issue ? I'm literally open to any solution. 

Thanks