<?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 Problems with shared memory in Release mode in LPC Microcontrollers</title>
    <link>https://community.nxp.com/t5/LPC-Microcontrollers/Problems-with-shared-memory-in-Release-mode/m-p/833810#M33271</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I have developed a multicore application on a LPC4357 on a Embedded Artists OEM Board (&lt;A class="link-titled" href="http://www.embeddedartists.com/products/oem/lpc4357_oem.php" title="http://www.embeddedartists.com/products/oem/lpc4357_oem.php"&gt;LPC4357 OEM Board | Embedded Artists AB&lt;/A&gt;&amp;nbsp;).&lt;/P&gt;&lt;P&gt;The Programm works perfect if I run it in Debug mode with a LPC-Link2. But if I change to Release I get problems with the shared memory for the interprocess communication.&lt;/P&gt;&lt;P&gt;The OEM Board provides a 32Mbyte SDRAM wich I use succesfully and I have defined four memory locations for the interprocess communication. !The locations are in both cores the same.&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;#define IPC_M0_CMD&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (uint32_t *)0x28000000&lt;BR /&gt;#define IPC_M0_CMD_PARAM&amp;nbsp;&amp;nbsp; &amp;nbsp;(uint32_t *)0x28000004&lt;BR /&gt;#define IPC_M4_CMD&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (uint32_t *)0x28000008&lt;BR /&gt;#define IPC_M4_CMD_PARAM&amp;nbsp;&amp;nbsp; &amp;nbsp;(uint32_t *)0x2800000C&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;uint32_t *m0_cmd &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = IPC_M0_CMD;&lt;BR /&gt;uint32_t *m0_cmd_param &amp;nbsp;&amp;nbsp; &amp;nbsp;= IPC_M0_CMD_PARAM;&lt;BR /&gt;uint32_t *m4_cmd &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; = IPC_M4_CMD;&lt;BR /&gt;uint32_t *m4_cmd_param &amp;nbsp;&amp;nbsp; &amp;nbsp;= IPC_M4_CMD_PARAM;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;typedef enum{&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;M4_NOP &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = 0,&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;M4_M0upAndRunning &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; = 1,&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;M4_Err &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; = 2,&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;M4_SetInSyncBaseAddr&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = 3,&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;M4_SetBufferReadFinishBaseAddr = 4,&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;M4_SetBufferIndexToReadBaseAddr = 5,&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;M4_ReadMeasureData&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = 6,&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;M4_SkippedCycle&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; = 7,&lt;BR /&gt;} M4_CMD;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;If the M4 core reaches the point to start the M0 core, the M4 core waits after the start till the M0 core responds with a UpAndRunning command:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;// Start M0APP slave processor&lt;BR /&gt;DEBUGOUT("&amp;nbsp; - start M0 core ... ");&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; cr_start_m0(SLAVE_M0APP,&amp;amp;__core_m0app_START__);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; while((*m4_cmd) != M4_M0upAndRunning){}&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; DEBUGOUT("\n&amp;nbsp;&amp;nbsp;&amp;nbsp; M0 responds: M0upAndRunning\n");&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; *m4_cmd = M4_NOP;&lt;BR /&gt;DEBUGOUT("&amp;nbsp;&amp;nbsp;&amp;nbsp; done\n");&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;And the M0 core set the command if the initialization is done and waits till the command is cleared:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;DEBUGOUT("&amp;nbsp; - send upAndRunning back to M4 core ... ");&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; *m4_cmd = M4_M0upAndRunning;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; while(*m4_cmd != M4_NOP){}&lt;BR /&gt;DEBUGOUT("done.\n");&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As written above in Debug mode all worked perfect but in Release mode both cores stay forever in their while loops...&lt;/P&gt;&lt;P&gt;I'm happy if anybody have an idea what the problem could be.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kind regards&lt;BR /&gt;Michael&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 29 Jun 2018 09:41:44 GMT</pubDate>
    <dc:creator>michaelschuehle</dc:creator>
    <dc:date>2018-06-29T09:41:44Z</dc:date>
    <item>
      <title>Problems with shared memory in Release mode</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/Problems-with-shared-memory-in-Release-mode/m-p/833810#M33271</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I have developed a multicore application on a LPC4357 on a Embedded Artists OEM Board (&lt;A class="link-titled" href="http://www.embeddedartists.com/products/oem/lpc4357_oem.php" title="http://www.embeddedartists.com/products/oem/lpc4357_oem.php"&gt;LPC4357 OEM Board | Embedded Artists AB&lt;/A&gt;&amp;nbsp;).&lt;/P&gt;&lt;P&gt;The Programm works perfect if I run it in Debug mode with a LPC-Link2. But if I change to Release I get problems with the shared memory for the interprocess communication.&lt;/P&gt;&lt;P&gt;The OEM Board provides a 32Mbyte SDRAM wich I use succesfully and I have defined four memory locations for the interprocess communication. !The locations are in both cores the same.&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;#define IPC_M0_CMD&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (uint32_t *)0x28000000&lt;BR /&gt;#define IPC_M0_CMD_PARAM&amp;nbsp;&amp;nbsp; &amp;nbsp;(uint32_t *)0x28000004&lt;BR /&gt;#define IPC_M4_CMD&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (uint32_t *)0x28000008&lt;BR /&gt;#define IPC_M4_CMD_PARAM&amp;nbsp;&amp;nbsp; &amp;nbsp;(uint32_t *)0x2800000C&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;uint32_t *m0_cmd &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = IPC_M0_CMD;&lt;BR /&gt;uint32_t *m0_cmd_param &amp;nbsp;&amp;nbsp; &amp;nbsp;= IPC_M0_CMD_PARAM;&lt;BR /&gt;uint32_t *m4_cmd &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; = IPC_M4_CMD;&lt;BR /&gt;uint32_t *m4_cmd_param &amp;nbsp;&amp;nbsp; &amp;nbsp;= IPC_M4_CMD_PARAM;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;typedef enum{&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;M4_NOP &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = 0,&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;M4_M0upAndRunning &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; = 1,&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;M4_Err &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; = 2,&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;M4_SetInSyncBaseAddr&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = 3,&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;M4_SetBufferReadFinishBaseAddr = 4,&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;M4_SetBufferIndexToReadBaseAddr = 5,&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;M4_ReadMeasureData&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = 6,&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;M4_SkippedCycle&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; = 7,&lt;BR /&gt;} M4_CMD;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;If the M4 core reaches the point to start the M0 core, the M4 core waits after the start till the M0 core responds with a UpAndRunning command:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;// Start M0APP slave processor&lt;BR /&gt;DEBUGOUT("&amp;nbsp; - start M0 core ... ");&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; cr_start_m0(SLAVE_M0APP,&amp;amp;__core_m0app_START__);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; while((*m4_cmd) != M4_M0upAndRunning){}&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; DEBUGOUT("\n&amp;nbsp;&amp;nbsp;&amp;nbsp; M0 responds: M0upAndRunning\n");&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; *m4_cmd = M4_NOP;&lt;BR /&gt;DEBUGOUT("&amp;nbsp;&amp;nbsp;&amp;nbsp; done\n");&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;And the M0 core set the command if the initialization is done and waits till the command is cleared:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;DEBUGOUT("&amp;nbsp; - send upAndRunning back to M4 core ... ");&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; *m4_cmd = M4_M0upAndRunning;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; while(*m4_cmd != M4_NOP){}&lt;BR /&gt;DEBUGOUT("done.\n");&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As written above in Debug mode all worked perfect but in Release mode both cores stay forever in their while loops...&lt;/P&gt;&lt;P&gt;I'm happy if anybody have an idea what the problem could be.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kind regards&lt;BR /&gt;Michael&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 29 Jun 2018 09:41:44 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/Problems-with-shared-memory-in-Release-mode/m-p/833810#M33271</guid>
      <dc:creator>michaelschuehle</dc:creator>
      <dc:date>2018-06-29T09:41:44Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with shared memory in Release mode</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/Problems-with-shared-memory-in-Release-mode/m-p/833811#M33272</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In release mode, the compiler optimizes away accesses to main memory and keeps the variables in registers, so the change in memory done by one core is not seen by the other. The compiler can also reorder accesses, which can mess up your data structures.&lt;/P&gt;&lt;P&gt;You can prevent this by declaring the variables which are accessed concurrently `volatile`, then all accesses to these variables go to main memory and are also not reordered.&lt;/P&gt;&lt;P&gt;A more efficient but also more complicated solution is to use memory barriers, which only force accesses and prevent reordering where it matters.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 30 Jun 2018 13:57:55 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/Problems-with-shared-memory-in-Release-mode/m-p/833811#M33272</guid>
      <dc:creator>starblue</dc:creator>
      <dc:date>2018-06-30T13:57:55Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with shared memory in Release mode</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/Problems-with-shared-memory-in-Release-mode/m-p/833812#M33273</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You need to declare the variables in shared memory as ‘volatile‘.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ser this for more info&lt;/P&gt;&lt;P&gt;&lt;A class="link-titled" href="https://barrgroup.com/Embedded-Systems/How-To/C-Volatile-Keyword" title="https://barrgroup.com/Embedded-Systems/How-To/C-Volatile-Keyword"&gt;How to Use C’s Volatile Keyword&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 30 Jun 2018 19:22:44 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/Problems-with-shared-memory-in-Release-mode/m-p/833812#M33273</guid>
      <dc:creator>converse</dc:creator>
      <dc:date>2018-06-30T19:22:44Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with shared memory in Release mode</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/Problems-with-shared-memory-in-Release-mode/m-p/833813#M33274</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks, that was the solution!!!!&lt;/P&gt;&lt;P&gt;Now I know the detailed function of volatile.&lt;/P&gt;&lt;P&gt;But it's confusing that the problem dont show up in debug mode. However it works now.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Jul 2018 13:34:19 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/Problems-with-shared-memory-in-Release-mode/m-p/833813#M33274</guid>
      <dc:creator>michaelschuehle</dc:creator>
      <dc:date>2018-07-02T13:34:19Z</dc:date>
    </item>
  </channel>
</rss>

