<?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 Software Development Kit中的主题 Strange hard fault</title>
    <link>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/Strange-hard-fault/m-p/621161#M6478</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In the code below, I am trying to read the flash memory and store it in a buffer.&lt;/P&gt;&lt;P&gt;When I read and assign to a buffer, I get a hard fault. When I only read and print it to UART, there is no problem and it prints all the addresses with the data I expect to be there.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can someone please help me? (refer to the in-line comments to understand the problematic statements).&lt;/P&gt;&lt;P&gt;If there is no direct hint, could you please give me a&amp;nbsp;HardFault_Handler implementation which will help me get more information of this problem?&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;======snip start=======&lt;/P&gt;&lt;P&gt;void read_session_from_flash()&lt;BR /&gt;{&lt;BR /&gt; uint32_t read_buffer[(destAdrss - zeroAdrss)/4];&lt;BR /&gt; uint32_t *flash_ptr;&lt;/P&gt;&lt;P&gt;PRINTF("\r\nNUMBER OF TIMESTAMPS IN FLASH = %d\r\n",(destAdrss - zeroAdrss)/4);&lt;BR /&gt; &lt;BR /&gt; flash_ptr = (uint32_t*)zeroAdrss;&lt;BR /&gt; for (uint8_t i = 0; i &amp;lt; (destAdrss - zeroAdrss)/4; i++)&lt;BR /&gt; { &lt;BR /&gt; //read_buffer[i] = *(flash_ptr++); GBA: Something crazy here!! Enable this code and it leads to a hard fault&lt;BR /&gt; //PRINTF("FLASH_READ[%d] = 0x%x\r\n", i, read_buffer[i]); // should be enabled when the line above is enabled&lt;BR /&gt; PRINTF("FLASH_READ[%d] = 0x%x\r\n", i, *(flash_ptr++)); //This works like a charm!!!&lt;BR /&gt; }&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;======snip end=======&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 24 Nov 2016 14:53:25 GMT</pubDate>
    <dc:creator>gauravbanyal</dc:creator>
    <dc:date>2016-11-24T14:53:25Z</dc:date>
    <item>
      <title>Strange hard fault</title>
      <link>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/Strange-hard-fault/m-p/621161#M6478</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In the code below, I am trying to read the flash memory and store it in a buffer.&lt;/P&gt;&lt;P&gt;When I read and assign to a buffer, I get a hard fault. When I only read and print it to UART, there is no problem and it prints all the addresses with the data I expect to be there.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can someone please help me? (refer to the in-line comments to understand the problematic statements).&lt;/P&gt;&lt;P&gt;If there is no direct hint, could you please give me a&amp;nbsp;HardFault_Handler implementation which will help me get more information of this problem?&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;======snip start=======&lt;/P&gt;&lt;P&gt;void read_session_from_flash()&lt;BR /&gt;{&lt;BR /&gt; uint32_t read_buffer[(destAdrss - zeroAdrss)/4];&lt;BR /&gt; uint32_t *flash_ptr;&lt;/P&gt;&lt;P&gt;PRINTF("\r\nNUMBER OF TIMESTAMPS IN FLASH = %d\r\n",(destAdrss - zeroAdrss)/4);&lt;BR /&gt; &lt;BR /&gt; flash_ptr = (uint32_t*)zeroAdrss;&lt;BR /&gt; for (uint8_t i = 0; i &amp;lt; (destAdrss - zeroAdrss)/4; i++)&lt;BR /&gt; { &lt;BR /&gt; //read_buffer[i] = *(flash_ptr++); GBA: Something crazy here!! Enable this code and it leads to a hard fault&lt;BR /&gt; //PRINTF("FLASH_READ[%d] = 0x%x\r\n", i, read_buffer[i]); // should be enabled when the line above is enabled&lt;BR /&gt; PRINTF("FLASH_READ[%d] = 0x%x\r\n", i, *(flash_ptr++)); //This works like a charm!!!&lt;BR /&gt; }&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;======snip end=======&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 Nov 2016 14:53:25 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/Strange-hard-fault/m-p/621161#M6478</guid>
      <dc:creator>gauravbanyal</dc:creator>
      <dc:date>2016-11-24T14:53:25Z</dc:date>
    </item>
    <item>
      <title>Re: Strange hard fault</title>
      <link>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/Strange-hard-fault/m-p/621162#M6479</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, &lt;/P&gt;&lt;P&gt;Regarding the pointer uint32_t *flash_ptr; if you assign an immediate value to it, you have to guarantee that the immediate value ranges in RAM space. If the immediate value is not in RAM space, a hardware fault will be triggered.&lt;/P&gt;&lt;P&gt;Secondly, I suggest you define a global variables for the two variables:&lt;/P&gt;&lt;P&gt;uint32_t read_buffer[(destAdrss - zeroAdrss)/4];&lt;BR /&gt; uint32_t *flash_ptr;&lt;/P&gt;&lt;P&gt;As you know that if you define an array as local variables(the array is defined inside of a function), they are saved in stack, if the array size exceeds the stack size, there is error.&lt;/P&gt;&lt;P&gt;How about using the code:&lt;/P&gt;&lt;P&gt;uint32_t read_buffer[(destAdrss - zeroAdrss)/4];&lt;/P&gt;&lt;P&gt;uint32_t write_buffer[(destAdrss - zeroAdrss)/4];&lt;BR /&gt; uint32_t *flash_ptr;&lt;/P&gt;&lt;P&gt;flash_ptr=write_buffer;&lt;/P&gt;&lt;P&gt;....................&lt;/P&gt;&lt;P&gt;Hope it can help you&lt;/P&gt;&lt;P&gt;BR&lt;/P&gt;&lt;P&gt;Xiangjun Rong&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Nov 2016 08:23:03 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/Strange-hard-fault/m-p/621162#M6479</guid>
      <dc:creator>xiangjun_rong</dc:creator>
      <dc:date>2016-11-28T08:23:03Z</dc:date>
    </item>
  </channel>
</rss>

