Login

Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

ARM websites use two types of cookie: (1) those that enable the site to function and perform as required; and (2) analytical cookies which anonymously track visitors only while using the site. If you are not happy with this use of these cookies please review our Privacy Policy to learn how they can be disabled. By disabling cookies some features of the site will not work.

ARM Community: Alignment of variables for Cortex-M0 - ARM Community

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Alignment of variables for Cortex-M0 Rate Topic: **--- 1 Votes

#1 User is offline   Scribe 

  • Member
  • Pip
  • Group: Members
  • Posts: 3
  • Joined: 31-August 12

Posted 12 October 2012 - 07:59 AM

Hi guys,

I'm currently working with a Cortex-M0 (using armcc), which is incapable of unaligned reads.

I have a byte array which is storing a received packet in a certain protocol, the first lot of information to come in is 1 byte, followed by two 16-bit half-words.

This is leading to misalignment and preventing me from performing any direct casting/pointer access to these values; I can't space the data out as it's being placed in the array by DMA.

I know with a structure it can be packed, however I've had no such luck with pointers and access to my array.

Is it possible to ask the compiler to align the start of my byte array on the edge of a word (3 bytes), so that the rest of my data is aligned? And if so how?

Any other suggestions?

Many thanks for any help and advice.


0

#2 User is offline   ttfn 

  • Super Contributor
  • PipPipPipPip
  • Group: Members
  • Posts: 576
  • Joined: 29-September 06

Posted 12 October 2012 - 08:29 AM

You can mark a pointer as being packed:

__packed short* pUnalignedHalfWord = (__packed short*) xyz;


So if you had a structure:

__packed struct MyStruct_t
{
  char a;
  short b;
};

MyStruct_t foo;

__packed short* pUnalignedHalfWord = (__packed short*) &(foo.B);



1

#3 User is offline   Scribe 

  • Member
  • Pip
  • Group: Members
  • Posts: 3
  • Joined: 31-August 12

Posted 14 October 2012 - 03:04 PM

View Postttfn, on 12 October 2012 - 08:29 AM, said:

You can mark a pointer as being packed:

__packed short* pUnalignedHalfWord = (__packed short*) xyz;


So if you had a structure:

__packed struct MyStruct_t
{
  char a;
  short b;
};

MyStruct_t foo;

__packed short* pUnalignedHalfWord = (__packed short*) &(foo.B);





Thank you for the feedback. I had actually tried this though with no luck, I will explore further and see if I can make this work, else return with some sample code/errors for some useful debugging!
1

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic