[chbot] Any ARM savvy people?

Peter Harris petes.username at gmail.com
Tue Oct 11 21:15:11 BST 2016


Hi Robin
That is a weird one, my only thought is word alignment of the RAM you are
copying data too.
I have just sorted a data alignment issue where I was reserving space in
RAM to instantiate classes in. The classes contain uint64_t attributes and
the wheels would fall off whenever a 64 bit value was accessed. The problem
turned out to be with the declaration of the RAM space:

uint8_t space_for_instance[sizeof(required_class)];

This block of RAM is not necessarily aligned on a word boundary so when the
class is created like this:
pointer_to_instance  = new(&space_for_instance[0]) required_class();
the 64 bit data can be misaligned.

The fix is to force the reserved RAM to be word aligned like this:

uint32_t space_for_instance[(sizeof(required_class) +3)/4];  // Q'pla!

This is the quick fix, I will likely end up with something like:
union
{
  uint32_t dummy_to_force_alignment;
  uint8_t space_for_instance[sizeof(required_class)];
} space_for_instance;

  Peter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ourshack.com/pipermail/chchrobotics/attachments/20161012/71c41701/attachment.html>


More information about the Chchrobotics mailing list