<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Problem with volatile struct - I get hard fault in LPCXpresso IDE</title>
    <link>https://community.nxp.com/t5/LPCXpresso-IDE/Problem-with-volatile-struct-I-get-hard-fault/m-p/547978#M10331</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by CodeRedSupport on Mon Oct 10 07:50:20 MST 2011&lt;/STRONG&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: klatecki&lt;/STRONG&gt;&lt;BR /&gt;and at line colored red I get HardFault,&lt;BR /&gt;but when test variable isn't volatile that code works.&lt;BR /&gt;&lt;BR /&gt;Problem occurs with both processors M0 and M3, with and without optimization&lt;BR /&gt;&lt;BR /&gt;I have LPCXpresso 4.0.7.&lt;BR /&gt;If I remember correctly this code works with LPCXpresso 3.x.x&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So with LPCXpresso 3.6.3, you get the following warning....&lt;/SPAN&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;
../src/main.c:1: warning: #pragma pack(push[, id], &amp;lt;n&amp;gt;) is not supported on this target&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;SPAN&gt;which would explain why you&amp;nbsp; saw different behaviour - as you weren't packing anything with the earlier tools!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It is also worth saying that using your original test code on LPCXpresso 4.1.0, I don't see any hard fault running the code here on Cortex-M3 (on an LPC1768), though I do get the hard fault on Cortex-M0 (on an LPC1114). This matches with what I might expect, as Cortex-M3 can do unaligned accesses, whereas Cortex-M0 can't.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I suspect that it might be worth looking at using [FONT=Courier New][SIZE=2] [FONT=monospace][/FONT]__attribute__ ((packed))[/SIZE][/FONT] rather than the pragmas you are currently using.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://" rel="nofollow noopener noreferrer" target="_blank"&gt;http://support.code-red-tech.com/CodeRedWiki/PackedStructs&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I suspect that you might be hitting some subtle difference in behaviour between these two ways of packing structures.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Regards,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;CodeRedSupport&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 15 Jun 2016 23:23:50 GMT</pubDate>
    <dc:creator>lpcware</dc:creator>
    <dc:date>2016-06-15T23:23:50Z</dc:date>
    <item>
      <title>Problem with volatile struct - I get hard fault</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Problem-with-volatile-struct-I-get-hard-fault/m-p/547966#M10319</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by klatecki on Fri Oct 07 06:14:35 MST 2011&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;I have simple code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;
#pragma pack(push,1)
typedefstruct
{
char char1;
short short1;
} test_struct_t;
#pragma pack(pop)

volatile char char1;
volatile short short1;
volatile test_struct_t test;

int main(void) {

char1 = 1;
short1 = 256;

test.char1 = char1;
test.short1 = short1;

char1 = test.char1;
[COLOR=Red]short1 = test.short1;[/COLOR]

for(;;);

return 0 ;
}
&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;and at line colored red I get HardFault,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;but when test variable isn't volatile that code works.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Problem occurs with both processors M0 and M3, with and without optimization&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have LPCXpresso 4.0.7.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;If I remember correctly this code works with LPCXpresso 3.x.x&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 23:23:43 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Problem-with-volatile-struct-I-get-hard-fault/m-p/547966#M10319</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T23:23:43Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with volatile struct - I get hard fault</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Problem-with-volatile-struct-I-get-hard-fault/m-p/547967#M10320</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by Ex-Zero on Fri Oct 07 06:49:15 MST 2011&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Do you understand that :confused:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: &lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;../src/main.c:47:15: warning: mis-aligned access used for structure member&lt;BR /&gt;../src/main.c:47:15: note: When a volatile object spans multiple type-sized locations, the compiler must choose between using a single mis-aligned access to preserve the volatility, or using multiple aligned accesses to avoid runtime faults.&amp;nbsp; This code may fail at runtime if the hardware does not allow this access.&lt;BR /&gt;&lt;/SPAN&gt;&lt;HR /&gt;&lt;SPAN&gt;So your compiler isn't very happy with your struct :mad:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Changing it to...&lt;/SPAN&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;
typedef&amp;nbsp;&amp;nbsp;&amp;nbsp; struct
{
 short short1;
 char char1;
} test_struct_t;
&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;SPAN&gt;...could help &lt;SPAN class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;&lt;LI-EMOJI id="lia_slightly-smiling-face" title=":slightly_smiling_face:"&gt;&lt;/LI-EMOJI&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 23:23:44 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Problem-with-volatile-struct-I-get-hard-fault/m-p/547967#M10320</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T23:23:44Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with volatile struct - I get hard fault</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Problem-with-volatile-struct-I-get-hard-fault/m-p/547968#M10321</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by klatecki on Fri Oct 07 10:01:39 MST 2011&lt;/STRONG&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: Zero&lt;/STRONG&gt;&lt;BR /&gt;Do you understand that :confused:&lt;BR /&gt;&lt;BR /&gt;So your compiler isn't very happy with your struct :mad:&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I understand this but I think compiler should knows that Cortex M0 don't support mis-aligned read and should use multiple reads instead of use incorrect instruction that cause Hard Fault&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: Zero&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;Changing it to...&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;
typedef&amp;nbsp;&amp;nbsp;&amp;nbsp; struct
{
 short short1;
 char char1;
} test_struct_t;
&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;...could help &lt;SPAN class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;&lt;LI-EMOJI id="lia_slightly-smiling-face" title=":slightly_smiling_face:"&gt;&lt;/LI-EMOJI&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Unfortunately I can't reorder fields in the structure &lt;SPAN class="lia-unicode-emoji" title=":disappointed_face:"&gt;&lt;LI-EMOJI id="lia_disappointed-face" title=":disappointed_face:"&gt;&lt;/LI-EMOJI&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;OK, I agree with the fact that the compiler warns against the mistake but this is just an example that I created to illustrate the problem.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;In the specific (more complex) situations (eg, casting the raw data buffer on the structure), the compiler does not report warning. I will try to create such an example in which the compiler will not warn you and still be an issue.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 23:23:44 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Problem-with-volatile-struct-I-get-hard-fault/m-p/547968#M10321</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T23:23:44Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with volatile struct - I get hard fault</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Problem-with-volatile-struct-I-get-hard-fault/m-p/547969#M10322</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by klatecki on Fri Oct 07 10:24:55 MST 2011&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;What do you say to that?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;#include &amp;lt;stdint.h&amp;gt;

#pragma pack(push,1)

typedef struct {
uint8_t DLE;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Data Link Escape = 0x10
uint8_t PID;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Packet ID
uint8_t SIZE;&amp;nbsp;&amp;nbsp; //Size of packet
uint16_t FMPID;
uint8_t&amp;nbsp; FMPDATA[251];
}GARMIN_DATA;

#pragma pack(pop)

typedef struct {

&amp;nbsp;&amp;nbsp;&amp;nbsp; uint32_t&amp;nbsp; origination_time;
&amp;nbsp;&amp;nbsp;&amp;nbsp; int32_t&amp;nbsp;&amp;nbsp; lat;
&amp;nbsp;&amp;nbsp;&amp;nbsp; int32_t&amp;nbsp;&amp;nbsp; lon;
&amp;nbsp;&amp;nbsp;&amp;nbsp; uint32_t&amp;nbsp; unique_id;
&amp;nbsp;&amp;nbsp;&amp;nbsp; uint8_t&amp;nbsp; id_size;
&amp;nbsp;&amp;nbsp;&amp;nbsp; uint8_t&amp;nbsp; reserved[3]; /* set to 0 */
&amp;nbsp;&amp;nbsp;&amp;nbsp; uint8_t&amp;nbsp; id[16];
&amp;nbsp;&amp;nbsp;&amp;nbsp; uint8_t&amp;nbsp; text_message[200];

}CToS_Text;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Client to Server Text


GARMIN_DATA garmin;

int main(void) {

uint32_t id = 0;

id = ((CToS_Text *)garmin.FMPDATA)-&amp;gt;unique_id;

for(;;);

return 0 ;
}&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 23:23:45 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Problem-with-volatile-struct-I-get-hard-fault/m-p/547969#M10322</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T23:23:45Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with volatile struct - I get hard fault</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Problem-with-volatile-struct-I-get-hard-fault/m-p/547970#M10323</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by Ex-Zero on Fri Oct 07 11:56:01 MST 2011&lt;/STRONG&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: klatecki&lt;/STRONG&gt;&lt;BR /&gt;What do you say to that?&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hello?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What else should I say to that? What are you trying to do?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Kidding a compiler or reading a structure in a structure?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 23:23:45 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Problem-with-volatile-struct-I-get-hard-fault/m-p/547970#M10323</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T23:23:45Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with volatile struct - I get hard fault</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Problem-with-volatile-struct-I-get-hard-fault/m-p/547971#M10324</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by klatecki on Fri Oct 07 12:16:14 MST 2011&lt;/STRONG&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: Zero&lt;/STRONG&gt;&lt;BR /&gt;Hello?&lt;BR /&gt;&lt;BR /&gt;What else should I say to that? What are you trying to do?&lt;BR /&gt;Kidding a compiler or reading a structure in a structure?&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;GARMIN_DATA is the main structure. Depending on FMPID meaning of FMPDATA is different. I want to cast FMPDATA to other structure like CToS_Text (I have tens this like sub structures) and read information.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Compiler should know what is the address of each field and correctly read data. I do not care or do it with a single command or a few readings of individual bytes. The result will be correct and the operation should not cause exceptions.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I think the compiler is doing it wrong :(&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Is there any way to force the compiler to generate the correct code? Any flag, directive or something.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 23:23:46 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Problem-with-volatile-struct-I-get-hard-fault/m-p/547971#M10324</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T23:23:46Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with volatile struct - I get hard fault</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Problem-with-volatile-struct-I-get-hard-fault/m-p/547972#M10325</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by Ex-Zero on Fri Oct 07 12:17:34 MST 2011&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;What's wrong with using unions :confused:&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 23:23:46 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Problem-with-volatile-struct-I-get-hard-fault/m-p/547972#M10325</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T23:23:46Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with volatile struct - I get hard fault</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Problem-with-volatile-struct-I-get-hard-fault/m-p/547973#M10326</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by klatecki on Fri Oct 07 12:31:08 MST 2011&lt;/STRONG&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: Zero&lt;/STRONG&gt;&lt;BR /&gt;What's wrong with using unions :confused:&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Nothing is wrong, but if I throw all the structures to the union I get big creature long to 500 lines or more difficult to comprehend.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 23:23:47 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Problem-with-volatile-struct-I-get-hard-fault/m-p/547973#M10326</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T23:23:47Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with volatile struct - I get hard fault</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Problem-with-volatile-struct-I-get-hard-fault/m-p/547974#M10327</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by Ex-Zero on Fri Oct 07 12:39:11 MST 2011&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Don't think so :)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I would bet 1000€ a simple structured access to your unique_id could be programmed within 5 minutes :eek:&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 23:23:48 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Problem-with-volatile-struct-I-get-hard-fault/m-p/547974#M10327</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T23:23:48Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with volatile struct - I get hard fault</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Problem-with-volatile-struct-I-get-hard-fault/m-p/547975#M10328</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by TheFallGuy on Fri Oct 07 15:26:01 MST 2011&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Can't you disable the unaligned access fault in the cortex-m3 confit register?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 23:23:48 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Problem-with-volatile-struct-I-get-hard-fault/m-p/547975#M10328</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T23:23:48Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with volatile struct - I get hard fault</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Problem-with-volatile-struct-I-get-hard-fault/m-p/547976#M10329</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by klatecki on Fri Oct 07 22:54:07 MST 2011&lt;/STRONG&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: TheFallGuy&lt;/STRONG&gt;&lt;BR /&gt;Can't you disable the unaligned access fault in the cortex-m3 confit register?&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Unaligned accesses with LDM, STM, LDRD, and STRD instructions always generate a Hard Fault even when UNALIGN_TRP is set to 0.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 23:23:49 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Problem-with-volatile-struct-I-get-hard-fault/m-p/547976#M10329</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T23:23:49Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with volatile struct - I get hard fault</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Problem-with-volatile-struct-I-get-hard-fault/m-p/547977#M10330</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by igorsk on Mon Oct 10 04:26:54 MST 2011&lt;/STRONG&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: klatecki&lt;/STRONG&gt;&lt;BR /&gt;I understand this but I think compiler should knows that Cortex M0 don't support mis-aligned read and should use multiple reads instead of use incorrect instruction that cause Hard Fault&lt;BR /&gt;&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The compiler can't know what you intend. Since the structure is volatile, it [I]probably[/I] means that field accesses should be atomic, and that's what it's trying to do here.&lt;/SPAN&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: klatecki&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;In the specific (more complex) situations (eg, casting the raw data buffer on the structure), the compiler does not report warning. I will try to create such an example in which the compiler will not warn you and still be an issue.&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Use memcpy to a local variable if you're not sure of the original alignment.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 23:23:49 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Problem-with-volatile-struct-I-get-hard-fault/m-p/547977#M10330</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T23:23:49Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with volatile struct - I get hard fault</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Problem-with-volatile-struct-I-get-hard-fault/m-p/547978#M10331</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by CodeRedSupport on Mon Oct 10 07:50:20 MST 2011&lt;/STRONG&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: klatecki&lt;/STRONG&gt;&lt;BR /&gt;and at line colored red I get HardFault,&lt;BR /&gt;but when test variable isn't volatile that code works.&lt;BR /&gt;&lt;BR /&gt;Problem occurs with both processors M0 and M3, with and without optimization&lt;BR /&gt;&lt;BR /&gt;I have LPCXpresso 4.0.7.&lt;BR /&gt;If I remember correctly this code works with LPCXpresso 3.x.x&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So with LPCXpresso 3.6.3, you get the following warning....&lt;/SPAN&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;
../src/main.c:1: warning: #pragma pack(push[, id], &amp;lt;n&amp;gt;) is not supported on this target&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;SPAN&gt;which would explain why you&amp;nbsp; saw different behaviour - as you weren't packing anything with the earlier tools!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It is also worth saying that using your original test code on LPCXpresso 4.1.0, I don't see any hard fault running the code here on Cortex-M3 (on an LPC1768), though I do get the hard fault on Cortex-M0 (on an LPC1114). This matches with what I might expect, as Cortex-M3 can do unaligned accesses, whereas Cortex-M0 can't.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I suspect that it might be worth looking at using [FONT=Courier New][SIZE=2] [FONT=monospace][/FONT]__attribute__ ((packed))[/SIZE][/FONT] rather than the pragmas you are currently using.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://" rel="nofollow noopener noreferrer" target="_blank"&gt;http://support.code-red-tech.com/CodeRedWiki/PackedStructs&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I suspect that you might be hitting some subtle difference in behaviour between these two ways of packing structures.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Regards,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;CodeRedSupport&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 23:23:50 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Problem-with-volatile-struct-I-get-hard-fault/m-p/547978#M10331</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T23:23:50Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with volatile struct - I get hard fault</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Problem-with-volatile-struct-I-get-hard-fault/m-p/547979#M10332</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by ToBeFrank on Mon Oct 10 11:15:38 MST 2011&lt;/STRONG&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: CodeRedSupport&lt;/STRONG&gt;&lt;BR /&gt;I suspect that you might be hitting some subtle difference in behaviour between these two ways of packing structures.&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I don't agree. The compiler was nice enough to point out his problem. Since the struct is packed, an access to the field is unaligned and thus requires more than one memory access to get it's value. Since he marked it volatile, the compiler has to make a choice between accessing it with one unaligned memory access or two aligned memory accesseses. It has informed him that it chose to honor his volatile and do one unaligned memory access. Thus, hard fault.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 23:23:51 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Problem-with-volatile-struct-I-get-hard-fault/m-p/547979#M10332</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T23:23:51Z</dc:date>
    </item>
  </channel>
</rss>

