<?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>Kinetis MicrocontrollersのトピックRe: why MCU reset after execute the code?</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/why-MCU-reset-after-execute-the-code/m-p/710825#M43622</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear Mark,&lt;/P&gt;&lt;P&gt;Thanks for your reply.&lt;/P&gt;&lt;P&gt;If this is aligned problem, do you have any method can force the array is aligned.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 25 Sep 2017 00:45:10 GMT</pubDate>
    <dc:creator>allenhuang1</dc:creator>
    <dc:date>2017-09-25T00:45:10Z</dc:date>
    <item>
      <title>why MCU reset after execute the code?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/why-MCU-reset-after-execute-the-code/m-p/710823#M43620</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear Sir,&lt;/P&gt;&lt;P&gt;I have simulated the below code in IAR.&lt;/P&gt;&lt;P&gt;And it worked!&lt;/P&gt;&lt;P&gt;But I run this code in real KE02.&lt;/P&gt;&lt;P&gt;this code will cause KE02 reset.&lt;/P&gt;&lt;P&gt;could you help find out root cause?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have changed the macro as below. this macro worked normally.&lt;/P&gt;&lt;P&gt;#define Set16Int(p,d) &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;*(p)=d&amp;amp;0xff; *(p+1)=d&amp;gt;&amp;gt;8&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;====================================================&lt;/P&gt;&lt;P&gt;#define Get16Int(p) *((uint16*)(p))&lt;BR /&gt;#define Set16Int(p,d) *((uint16*)(p)) = d&lt;/P&gt;&lt;P&gt;uint16 u16gT=0;&lt;/P&gt;&lt;P&gt;uint8 u8gRxBuff[16];&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;u8gRxBuff[0]=0x12;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;u8gRxBuff[1]=0x34;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;u16gT =&amp;nbsp;Get16Int(u8gRxBuff);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;u16gT=0x1234;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Set16Int(&lt;SPAN&gt;u8gRxBuff,u16gT);&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 22 Sep 2017 03:48:42 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/why-MCU-reset-after-execute-the-code/m-p/710823#M43620</guid>
      <dc:creator>allenhuang1</dc:creator>
      <dc:date>2017-09-22T03:48:42Z</dc:date>
    </item>
    <item>
      <title>Re: why MCU reset after execute the code?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/why-MCU-reset-after-execute-the-code/m-p/710824#M43621</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Allen&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The KE02 has a Cortex-m0+ core and this can only access aligned words.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your code may or may not work, depending on the alignment of uint8 u8gRxBuff[16];&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Take a look in the map file and you will presumably find that this is aligned on an odd address, which will cause&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;u16gT =&amp;nbsp;Get16Int(u8gRxBuff);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;to hard fault.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;You either need to align you arrays (eg. use uint16 u8gRxBuff[16/sizeof(unsigned short)]; to force it) instead or else use macros which are core independent: eg. #define Get16Int(x) ((*(uint8*)x &amp;lt;&amp;lt; 8) | (*(uint8*)((uint8 *)(x + 1))))&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The IAR simulation may have been OK if you luckily had an even address, or possibly the IAR simulator is not checking correctly (test by passing u8gRxBuff + 1 instead to see whether it flags an illegal access).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Regards&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Mark&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;A class="jive-link-external-small" href="https://community.nxp.com/external-link.jspa?url=http%3A%2F%2Fwww.utasker.com%2Fkinetis.html" rel="nofollow" target="_blank"&gt;http://www.utasker.com/kinetis.html&lt;/A&gt;&lt;BR /&gt;&lt;A class="jive-link-external-small" href="https://community.nxp.com/external-link.jspa?url=http%3A%2F%2Fwww.utasker.com%2Fkinetis%2FFRDM-KE02Z.html" rel="nofollow" target="_blank"&gt;http://www.utasker.com/kinetis/FRDM-KE02Z.html&lt;/A&gt;&lt;BR /&gt;&lt;A class="jive-link-external-small" href="https://community.nxp.com/external-link.jspa?url=http%3A%2F%2Fwww.utasker.com%2Fkinetis%2FFRDM-KE02Z40M.html" rel="nofollow" target="_blank"&gt;http://www.utasker.com/kinetis/FRDM-KE02Z40M.html&lt;/A&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 22 Sep 2017 10:29:43 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/why-MCU-reset-after-execute-the-code/m-p/710824#M43621</guid>
      <dc:creator>mjbcswitzerland</dc:creator>
      <dc:date>2017-09-22T10:29:43Z</dc:date>
    </item>
    <item>
      <title>Re: why MCU reset after execute the code?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/why-MCU-reset-after-execute-the-code/m-p/710825#M43622</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear Mark,&lt;/P&gt;&lt;P&gt;Thanks for your reply.&lt;/P&gt;&lt;P&gt;If this is aligned problem, do you have any method can force the array is aligned.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 25 Sep 2017 00:45:10 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/why-MCU-reset-after-execute-the-code/m-p/710825#M43622</guid>
      <dc:creator>allenhuang1</dc:creator>
      <dc:date>2017-09-25T00:45:10Z</dc:date>
    </item>
    <item>
      <title>Re: why MCU reset after execute the code?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/why-MCU-reset-after-execute-the-code/m-p/710826#M43623</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Allen&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I gave this possibility in the previous post (although it may not be respected by all compilers):&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;uint16 u8gRxBuff[16/sizeof(unsigned short)];&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Others are&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;uint8 u8gRxBuff[16 + 1];&lt;BR /&gt;uint8 *ptru8gRxBuff = u8gRxBuff;&lt;BR /&gt;if (((unsigned long)ptru8gRxBuff&amp;nbsp; &amp;amp; 0x1) != 0) { // if not short word aligned&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ptru8gRxBuff ++; // skip the first byte so that it is aligned&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;// Use ptru8gRxBuff&amp;nbsp; for all operations (it is aligned memory)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;uint8 *ptru8gRxBuff = malloc(16); // assuming a version of malloc() that always returns long word aligned memory&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Regards&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Mark&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 25 Sep 2017 10:44:57 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/why-MCU-reset-after-execute-the-code/m-p/710826#M43623</guid>
      <dc:creator>mjbcswitzerland</dc:creator>
      <dc:date>2017-09-25T10:44:57Z</dc:date>
    </item>
  </channel>
</rss>

