<?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>S32KのトピックRe: S32K358 + FreeRTOS: Random HardFault during PendSV_Handler</title>
    <link>https://community.nxp.com/t5/S32K/S32K358-FreeRTOS-Random-HardFault-during-PendSV-Handler/m-p/2397098#M59961</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/233316"&gt;@nirmal_masilamani&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;It looks like the task context saved during the FreeRTOS context switch has been corrupted.&lt;BR /&gt;PendSV is used by FreeRTOS for context switching, therefore, if the HardFault occurs inside PendSV_Handler(), it often means the scheduler is attempting to restore an invalid task context.&lt;BR /&gt;One possible root cause is a task stack overflow. I would recommend increasing the stack size of the tasks and enabling FreeRTOS stack overflow detection:&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;configCHECK_FOR_STACK_OVERFLOW&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Implement:&amp;nbsp;&lt;/SPAN&gt;vApplicationStackOverflowHook().&lt;/P&gt;
&lt;P&gt;Additionally, you can periodically monitor the remaining stack space of each task using uxTaskGetStackHighWaterMark(). This can help identify tasks that are running close to their stack limits before the fault occurs.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Daniel&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 21 Jul 2026 08:08:13 GMT</pubDate>
    <dc:creator>danielmartynek</dc:creator>
    <dc:date>2026-07-21T08:08:13Z</dc:date>
    <item>
      <title>S32K358 + FreeRTOS: Random HardFault during PendSV_Handler</title>
      <link>https://community.nxp.com/t5/S32K/S32K358-FreeRTOS-Random-HardFault-during-PendSV-Handler/m-p/2396864#M59949</link>
      <description>&lt;P class=""&gt;Hi Team,&lt;/P&gt;&lt;P&gt;I am facing a random HardFault issue on an &lt;STRONG&gt;S32K358&lt;/STRONG&gt; running &lt;STRONG&gt;FreeRTOS.&lt;/STRONG&gt;&lt;/P&gt;&lt;P class=""&gt;The application runs normally for a long duration and then suddenly hangs. After the system stops executing, the Software Watchdog (SWT) is not serviced and eventually resets the controller.&lt;/P&gt;&lt;P&gt;The failure is not immediate—it occurs after approximately &lt;STRONG&gt;1 to 2 hours&lt;/STRONG&gt; of continuous execution&lt;/P&gt;&lt;P class=""&gt;When halted after the failure, the call stack shows:&lt;/P&gt;&lt;P class=""&gt;&lt;STRONG&gt;PendSV_Handler() &lt;/STRONG&gt;&lt;/P&gt;&lt;P class=""&gt;&lt;STRONG&gt;↓ &lt;/STRONG&gt;&lt;/P&gt;&lt;P class=""&gt;&lt;STRONG&gt;HardFault_Handler()&lt;/STRONG&gt;&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN&gt;Register values:&lt;/SPAN&gt;&lt;/P&gt;&lt;P class=""&gt;&lt;STRONG&gt;LR = 0xA5A5A5A5 &lt;/STRONG&gt;&lt;/P&gt;&lt;P class=""&gt;&lt;STRONG&gt;PC = 0x00407BD9&lt;/STRONG&gt;&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;LR = 0xA5A5A5A5&lt;SPAN&gt; looks like a memory initialization pattern rather than a valid return address.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;Other registers:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;R0 = 0x204011A8 &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;R3 = 0x2040012C &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;R12 = 0x20400010&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Any suggestions or debugging recommendations would be greatly appreciated.&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jul 2026 15:55:32 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S32K/S32K358-FreeRTOS-Random-HardFault-during-PendSV-Handler/m-p/2396864#M59949</guid>
      <dc:creator>nirmal_masilamani</dc:creator>
      <dc:date>2026-07-20T15:55:32Z</dc:date>
    </item>
    <item>
      <title>Re: S32K358 + FreeRTOS: Random HardFault during PendSV_Handler</title>
      <link>https://community.nxp.com/t5/S32K/S32K358-FreeRTOS-Random-HardFault-during-PendSV-Handler/m-p/2397098#M59961</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/233316"&gt;@nirmal_masilamani&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;It looks like the task context saved during the FreeRTOS context switch has been corrupted.&lt;BR /&gt;PendSV is used by FreeRTOS for context switching, therefore, if the HardFault occurs inside PendSV_Handler(), it often means the scheduler is attempting to restore an invalid task context.&lt;BR /&gt;One possible root cause is a task stack overflow. I would recommend increasing the stack size of the tasks and enabling FreeRTOS stack overflow detection:&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;configCHECK_FOR_STACK_OVERFLOW&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Implement:&amp;nbsp;&lt;/SPAN&gt;vApplicationStackOverflowHook().&lt;/P&gt;
&lt;P&gt;Additionally, you can periodically monitor the remaining stack space of each task using uxTaskGetStackHighWaterMark(). This can help identify tasks that are running close to their stack limits before the fault occurs.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Daniel&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jul 2026 08:08:13 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S32K/S32K358-FreeRTOS-Random-HardFault-during-PendSV-Handler/m-p/2397098#M59961</guid>
      <dc:creator>danielmartynek</dc:creator>
      <dc:date>2026-07-21T08:08:13Z</dc:date>
    </item>
    <item>
      <title>Re: S32K358 + FreeRTOS: Random HardFault during PendSV_Handler</title>
      <link>https://community.nxp.com/t5/S32K/S32K358-FreeRTOS-Random-HardFault-during-PendSV-Handler/m-p/2397124#M59966</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/160001"&gt;@danielmartynek&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;Thank you for response,&lt;/P&gt;&lt;P&gt;I already tried increased stack size, enabled stack overflow hook.&lt;/P&gt;&lt;P&gt;Added debug CAN msg in overflow hook, I am not receiving that message when fault occur.&lt;/P&gt;&lt;P&gt;Also monitoring&amp;nbsp;&lt;SPAN&gt;uxTaskGetStackHighWaterMark(), when fault occur&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Task 1 : 1977 × 4 ≈ 7908 bytes free&lt;/P&gt;&lt;P&gt;Task 2: 1971 × 4 ≈ 7884 bytes free&lt;/P&gt;&lt;P&gt;Task 3: 3988 × 4 ≈ 15952 bytes free&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jul 2026 09:04:02 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S32K/S32K358-FreeRTOS-Random-HardFault-during-PendSV-Handler/m-p/2397124#M59966</guid>
      <dc:creator>nirmal_masilamani</dc:creator>
      <dc:date>2026-07-21T09:04:02Z</dc:date>
    </item>
    <item>
      <title>Re: S32K358 + FreeRTOS: Random HardFault during PendSV_Handler</title>
      <link>https://community.nxp.com/t5/S32K/S32K358-FreeRTOS-Random-HardFault-during-PendSV-Handler/m-p/2397654#M59994</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/233316"&gt;@nirmal_masilamani&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;So we can probably exclude a stack overflow as the root cause.&lt;BR /&gt;However, the task context is still getting corrupted. The processor is restoring LR = 0xA5A5A5A5, which results in a UsageFault.&amp;nbsp;0xA5A5A5A5 is the pattern generated from tskSTACK_FILL_BYTE (0xA5U) and is used by FreeRTOS to fill task stacks when they are created.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="danielmartynek_0-1784709240297.png" style="width: 659px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/392889iE8FA12C058EF82EA/image-dimensions/659x119?v=v2" width="659" height="119" role="button" title="danielmartynek_0-1784709240297.png" alt="danielmartynek_0-1784709240297.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Therefore, if LR becomes 0xA5A5A5A5, the context is restored from a location that still contains the original stack fill pattern rather than a valid register value.&lt;/P&gt;
&lt;P&gt;This could happen if the SP gets corrupted. In that case, PendSV_Handler() would restore the task context from a wrong location in RAM.&lt;/P&gt;
&lt;P&gt;You should be able to identify the SRAM region from the stack pointer address.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would recommend that you properly protect the region by MPUs and XRDC.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, are any interrupts calling FreeRTOS APIs? If so, are they using the FromISR() variants, and are their priorities configured correctly with respect to configMAX_SYSCALL_INTERRUPT_PRIORITY?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Daniel&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jul 2026 09:30:15 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S32K/S32K358-FreeRTOS-Random-HardFault-during-PendSV-Handler/m-p/2397654#M59994</guid>
      <dc:creator>danielmartynek</dc:creator>
      <dc:date>2026-07-22T09:30:15Z</dc:date>
    </item>
  </channel>
</rss>

