User Tools

Site Tools


c_cast_32_bit_boundary

rudy_wiki_ultra_lite_header.jpg

C cast to 32-bits Boundary (Customer Contribution)

After investigation, we discovered the issue we had and the LCD is currently working in our embedded environment.

Thanks to the source code you provided, we think we have discovered an issue in your code (see attached ProtoBuffer.c). Our ARM processor (CPU - Marvell 88F6281), it is known that the cast MUST be aligned to a 32-bits boundary. Then, when casting your buffer in ProtoBuffer.c, there is an effect on the data sent or received (which generates some data corruption). I suggest to review this part of code to have a good behaviour for any ARM architecture.

I give you the source code we modified to get the 1RU tutorial working. The toolchain used is gcc-arm-linux-gnueabi (default package provided by ubuntu package).

Original source code

*((RdUWord*) (buffer->ptr + buffer->size)) = input;
      ^^  This cast is not necessarily aligned to a 32-bits boundary and generates some corruption

Replaced by:

 memcpy(buffer->ptr + buffer->size, &input, sizeof(RdUWord));

Here are some link about this known ARM cast-align issue:

https://wiki.debian.org/ArmEabiPort#Struct_packing_and_alignment

http://www.aleph1.co.uk/chapter-10-arm-structured-alignment-faq

https://www.securecoding.cert.org/confluence/display/c/EXP36-C.+Do+not+cast+pointers+into+more+strictly+aligned+pointer+types

Customer Credit: Enensy

rudy_wiki_header_ripdraw_ultra_lite_footer.jpg

Last modified: 2016/04/18 23:10

Page Tools