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.

Compiler/MSP430FR69891: Question about whether alignment is necessary on the MSP430 for 16-bit values

Part Number: MSP430FR69891

Tool/software: TI C/C++ Compiler

Hello,

I'm experiencing a problem with the design I'm working on which feels like an alignment problem.

Basically, it looks like a global 16-bit value, which is in a structure isn't being written to or read from properly.  I'm wondering if there's an issue with alignment in general, requiring that all variables be aligned on an even address.  I have trouble believing this, and I have yet to find any TI documentation, for the compiler or for the MSP430 which states that alignment is necessary.  The only things aligned to an even address in the MSP430 is the Program Counter and the Stack Pointer.

If anyone knows of any documentation from TI which talks about alignment requirements in the compiler and/or the MSP430 (specifically the MSP430FR6xx Family), I would be very appreciative.  I have googled far and wide, and so far I haven't seen anything from TI yet.

Thank you in advance for any help that anyone can provide.

Adam

  • In section 6.2.1 "Data Type Storage" of the MSP430 Compiler User's Guide (processors.wiki.ti.com/.../TI_Compiler_Information) is a table which shows the size and alignment of each fundamental data type. This table shows that 16-bit alignment is required for all fundamental types of size 16 or greater.

  • Hello,

    Thanks very much for the link. I somehow missed this in the compiler manual. Very helpful.

    Do you know why this alignment needs to be enforced? I'm assuming there's an architectural requirement in the MSP430 that needs this alignment? If you know of a TI document that discusses this, I would be most appreciative.

    Additionally, the reason for my post is that I'm seeing the global 16-bit data in the MSP430 based firmware that I'm working on be put on an odd address. And when this happens, the value written or read isn't correct. Something in the firmware has caused this to change, I'm not sure exactly when, but that is what I'm trying to figure out. I'm trying to put together some very simple test cases, with structure definitions to show where they are placed in the map file. So far, my simple testing has shown the structures to always be placed at an even address.

    Thanks again for your help!

    Adam
  • Hello,

    The fundamental reason for the problem I was seeing was due to a #pragma pack( push, 1 ) that was never popped. The reason for the lack of the pop isn't immediately obvious when looking at the code, since it is done in a platform independent manner. The pop for the MSP430 case was somehow forgotten several months ago. And, this problem only mysteriously started to be an issue now. The lack of the packing being popped caused problems with other structures, since they were being packed to 1-byte alignment, when they shouldn't have been.

    So, in summary, I've solved the issue with alignment that I was seeing. Your answer about alignment requirements documented in the Compiler User's Guide, was very helpful.

    If you know where any additional TI documentation describing why the alignment is necessary, that would be very helpful as well.

    Thanks very much for your help.

    Adam