<?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>LPC MicrocontrollersのトピックRe: Facing stack corruption in LPC55S28</title>
    <link>https://community.nxp.com/t5/LPC-Microcontrollers/Facing-stack-corruption-in-LPC55S28/m-p/1443223#M48477</link>
    <description>&lt;P&gt;I have no experience with the LPC55xx as such, only other LPC MCUs, and those of other vendors.&lt;/P&gt;&lt;P&gt;First, many toolchains support a watermarking, and many RTOSs support a runtime stack check. Watermarking is pre-filling the stack with specific values to detect it's usage (watermark) afterwards. Famous watermarking values are 0xDDDDDDDD, or 0xDEADBEEF.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Both methods seem not very promising in your case, though.&lt;/P&gt;&lt;P&gt;The second option are data breakpoints. All proper toolchains (debugger) support such data breakpoints, which do not stop execution based on PC value, but on a reference (read) or change (write) to a certain data location.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 13 Apr 2022 07:47:15 GMT</pubDate>
    <dc:creator>frank_m</dc:creator>
    <dc:date>2022-04-13T07:47:15Z</dc:date>
    <item>
      <title>Facing stack corruption in LPC55S28</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/Facing-stack-corruption-in-LPC55S28/m-p/1443195#M48475</link>
      <description>&lt;P&gt;Hi NXP,&lt;/P&gt;&lt;P&gt;We are using hashscrypt driver from SDK-2.10.1. In that in function&amp;nbsp;hashcrypt_get_data we are seeing first 8 bytes of&amp;nbsp;digest variable&amp;nbsp; are corrupted. Below is the code snippet.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;/*!
 * @brief Read OUTDATA registers.
 *
 * This function copies OUTDATA to output buffer.
 *
 * &lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/197964"&gt;@Param&lt;/a&gt; base Hachcrypt peripheral base address.
 * &lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/197964"&gt;@Param&lt;/a&gt;[out] output Output buffer.
 * &lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/197964"&gt;@Param&lt;/a&gt; Number of bytes to copy.
 */
static void hashcrypt_get_data(HASHCRYPT_Type *base, uint32_t *output, size_t outputSize)
{
    uint32_t digest[8];

    while (0U == (base-&amp;gt;STATUS &amp;amp; HASHCRYPT_STATUS_DIGEST_MASK))
    {
    }

    for (int i = 0; i &amp;lt; 8; i++)
    {
        digest[i] = swap_bytes(base-&amp;gt;DIGEST0[i]);
    }

    if (outputSize &amp;gt; sizeof(digest))
    {
        outputSize = sizeof(digest);
    }
    (void)hashcrypt_memcpy(output, digest, outputSize);
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Digest have proper value in&amp;nbsp;DIGEST0 HW register, but after swapping somehow digest have not proper value.&amp;nbsp;&lt;/P&gt;&lt;P&gt;If we Disable global interrupt before copying to digest variable&amp;nbsp; &lt;STRONG&gt;digest[i] = swap_bytes(base-&amp;gt;DIGEST0[i]);, &lt;/STRONG&gt;then issue is not happen and if i initialize local digest variable to 0&amp;nbsp; &lt;STRONG&gt;uint32_t digest[8] = {0}; &lt;/STRONG&gt;then also issue not happens. It indicates somehow stack is corrupted.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there any way to observe Stack corruption in LPC55S28. Also MTB &amp;amp; ETM is not supported in LPC55S28 ,so i cannot enable trace debugging to identify who is modifying digest variable.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please suggest good way to debug this issue.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Rahul Shah&lt;/P&gt;</description>
      <pubDate>Wed, 13 Apr 2022 07:11:51 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/Facing-stack-corruption-in-LPC55S28/m-p/1443195#M48475</guid>
      <dc:creator>rahulshah</dc:creator>
      <dc:date>2022-04-13T07:11:51Z</dc:date>
    </item>
    <item>
      <title>Re: Facing stack corruption in LPC55S28</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/Facing-stack-corruption-in-LPC55S28/m-p/1443223#M48477</link>
      <description>&lt;P&gt;I have no experience with the LPC55xx as such, only other LPC MCUs, and those of other vendors.&lt;/P&gt;&lt;P&gt;First, many toolchains support a watermarking, and many RTOSs support a runtime stack check. Watermarking is pre-filling the stack with specific values to detect it's usage (watermark) afterwards. Famous watermarking values are 0xDDDDDDDD, or 0xDEADBEEF.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Both methods seem not very promising in your case, though.&lt;/P&gt;&lt;P&gt;The second option are data breakpoints. All proper toolchains (debugger) support such data breakpoints, which do not stop execution based on PC value, but on a reference (read) or change (write) to a certain data location.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Apr 2022 07:47:15 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/Facing-stack-corruption-in-LPC55S28/m-p/1443223#M48477</guid>
      <dc:creator>frank_m</dc:creator>
      <dc:date>2022-04-13T07:47:15Z</dc:date>
    </item>
    <item>
      <title>Re: Facing stack corruption in LPC55S28</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/Facing-stack-corruption-in-LPC55S28/m-p/1447066#M48526</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;No still issue is not resolved.&amp;nbsp;Also as you mentioned about breakpoint where there is read /write. That is called Watchpoint, But that is only applicable for Global variables. In my case digest[] is local variable which is corrupted.&lt;/P&gt;&lt;P&gt;Still no clue how to debug.&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Rahul Shah&lt;/P&gt;</description>
      <pubDate>Thu, 21 Apr 2022 08:38:28 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/Facing-stack-corruption-in-LPC55S28/m-p/1447066#M48526</guid>
      <dc:creator>rahulshah</dc:creator>
      <dc:date>2022-04-21T08:38:28Z</dc:date>
    </item>
    <item>
      <title>Re: Facing stack corruption in LPC55S28</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/Facing-stack-corruption-in-LPC55S28/m-p/1447165#M48529</link>
      <description>&lt;P&gt;&lt;EM&gt;&amp;gt; But that is only applicable for Global variables. In my case digest[] is local variable which is corrupted.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;In my experience this depends on the toolchain (and the debugger). Usually, data watchpoints are basically related to addresses.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Perhaps your issues are triggered by an interrupt handler, or another communication-based handler.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I had debugged such a problem last year, and it turned out the main (RT-OS) thread had passed a buffer on the stack to communication handler. This buffer address was (re-)used much later in the next OS cycle when the response from the remote device was processed, corrupting the stack.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Perhaps the values on the stack itself can give you a clue. They are either addresses or data values, which might help you identify the offender.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;When you disable interrupts for the runtime of the routine, does the stack corruption still happen ?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;As mentioned, I have no experience with LPC55S devices. And I'm no NXP employee, for all intents and purposes.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Apr 2022 10:15:55 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/Facing-stack-corruption-in-LPC55S28/m-p/1447165#M48529</guid>
      <dc:creator>frank_m</dc:creator>
      <dc:date>2022-04-21T10:15:55Z</dc:date>
    </item>
    <item>
      <title>Re: Facing stack corruption in LPC55S28</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/Facing-stack-corruption-in-LPC55S28/m-p/1447212#M48531</link>
      <description>&lt;P&gt;Yes, if i disable interrupts then everything works ok and not seen any corruption. But may be issue happens at other places later on . So i am searching exact root cause like who is corrupting the stack.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Apr 2022 11:25:31 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/Facing-stack-corruption-in-LPC55S28/m-p/1447212#M48531</guid>
      <dc:creator>rahulshah</dc:creator>
      <dc:date>2022-04-21T11:25:31Z</dc:date>
    </item>
    <item>
      <title>Re: Facing stack corruption in LPC55S28</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/Facing-stack-corruption-in-LPC55S28/m-p/1447226#M48532</link>
      <description>&lt;P&gt;Unless you have an immediate idea what causes it, I would disable individual interrupts one by one now and try again. Thus single out the handler that triggers the stack corruption.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Apr 2022 11:42:01 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/Facing-stack-corruption-in-LPC55S28/m-p/1447226#M48532</guid>
      <dc:creator>frank_m</dc:creator>
      <dc:date>2022-04-21T11:42:01Z</dc:date>
    </item>
    <item>
      <title>Re: Facing stack corruption in LPC55S28</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/Facing-stack-corruption-in-LPC55S28/m-p/1447231#M48533</link>
      <description>&lt;P&gt;So after all exercise if i disable SPI &amp;amp; UART interrupt then issue not happen. But if i keep them enabled then interrupt routine for SPI &amp;amp; UART not called at all during and around this issue.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Apr 2022 11:52:47 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/Facing-stack-corruption-in-LPC55S28/m-p/1447231#M48533</guid>
      <dc:creator>rahulshah</dc:creator>
      <dc:date>2022-04-21T11:52:47Z</dc:date>
    </item>
    <item>
      <title>Re: Facing stack corruption in LPC55S28</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/Facing-stack-corruption-in-LPC55S28/m-p/1447258#M48534</link>
      <description>&lt;P&gt;&lt;EM&gt;&amp;gt; But if i keep them enabled then interrupt routine for SPI &amp;amp; UART not called at all during and around this issue.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;Not sure what you mean by that.&lt;/P&gt;&lt;P&gt;But interrupts are not called, they are asynchronous events caused by external sources, especially in the case of UART. A character reception or a "FIFO full" event usually trigger an interrupt.&lt;/P&gt;&lt;P&gt;In case of SPI (and if your MCU is the master), this happens more or less synchronously to a transmission.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Check how you deal with received character(s), and closely guard buffer indices used inside this handlers.&amp;nbsp;By the way, this includes &lt;STRONG&gt;ALL&lt;/STRONG&gt; callback functions called from within interrupt context.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Apr 2022 12:59:17 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/Facing-stack-corruption-in-LPC55S28/m-p/1447258#M48534</guid>
      <dc:creator>frank_m</dc:creator>
      <dc:date>2022-04-21T12:59:17Z</dc:date>
    </item>
  </channel>
</rss>

