<?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 Re: using c++ exceptions with freertos in Kinetis Microcontrollers</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/using-c-exceptions-with-freertos/m-p/615772#M36628</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;By fault, most of your exceptions will execute the default handler, so the first thing you need to do is determine which exception is actually executing. You can see the "Determining Which Exception Handler is Executing" section on the following page: &lt;A href="http://www.freertos.org/Debugging-Hard-Faults-On-Cortex-M-Microcontrollers.html"&gt;http://www.freertos.org/Debugging-Hard-Faults-On-Cortex-M-Microcontrollers.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would guess, since you are not using a peripheral in your code, that it will be a fault handler, probably the hard fault. The same page (see link above) gives instructions on debugging that too.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Other than that - ensure you do the normal FreeRTOS debug things, like ensure you have configASSERT() defined, and that you have stack overflow checking on. Info on those topics is found on this page: &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://community.nxp.com/external-link.jspa?url=http%3A%2F%2Fwww.freertos.org%2FFAQHelp.html" rel="nofollow" target="_blank"&gt;http://www.freertos.org/FAQHelp.html&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 13 Sep 2016 16:42:50 GMT</pubDate>
    <dc:creator>FreeRTOS_org</dc:creator>
    <dc:date>2016-09-13T16:42:50Z</dc:date>
    <item>
      <title>using c++ exceptions with freertos</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/using-c-exceptions-with-freertos/m-p/615771#M36627</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm using a ARM Cortex M4 with freertos using freescales freedom Kinetis IDE (gnu arm toolchain). Problem is that&lt;/P&gt;&lt;P&gt;try {&lt;BR /&gt; throw std::runtime_error("wut");&lt;BR /&gt; } catch (...) {&lt;BR /&gt; }&lt;BR /&gt;results in a halted CPU and code after the try or (when some is added) in the catch handler is not executed.&lt;/P&gt;&lt;P&gt;I ASSUMED that this results in an SVC interrupt, I'm sorry I got that wrong, Freertos tricked me into this, because when I throw something it halts in DefaultISR.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;The throw indeeds jump to **__cxa_throw then from there to ___Unwind_RaiseException __gnu_Unwind_RaiseException __cxa_begin_catch&amp;gt;&lt;BR /&gt; &amp;lt;_ZSt9terminatev&amp;gt;**&lt;BR /&gt;So it looks like `std::terminate` is called, but the catch all block should not allow this. Or is my assumption wrong and this behavior is because the gcc C++ runtime exception support is a stub which always calls terminate?!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;we are using&lt;BR /&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;Kinetis Design Studio 3.2.0. with the &lt;/SPAN&gt;&lt;BR style="color: #51626f; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;GNU ARM C/C++ Cross Compiler&lt;/SPAN&gt;&lt;BR style="color: #51626f; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;Version: 1.12.1.201502281154&lt;/SPAN&gt;&lt;BR style="color: #51626f; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;for our &lt;/SPAN&gt;&lt;BR style="color: #51626f; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;FRDM-KV31F&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Sep 2016 10:54:17 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/using-c-exceptions-with-freertos/m-p/615771#M36627</guid>
      <dc:creator>markusklemm</dc:creator>
      <dc:date>2016-09-13T10:54:17Z</dc:date>
    </item>
    <item>
      <title>Re: using c++ exceptions with freertos</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/using-c-exceptions-with-freertos/m-p/615772#M36628</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;By fault, most of your exceptions will execute the default handler, so the first thing you need to do is determine which exception is actually executing. You can see the "Determining Which Exception Handler is Executing" section on the following page: &lt;A href="http://www.freertos.org/Debugging-Hard-Faults-On-Cortex-M-Microcontrollers.html"&gt;http://www.freertos.org/Debugging-Hard-Faults-On-Cortex-M-Microcontrollers.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would guess, since you are not using a peripheral in your code, that it will be a fault handler, probably the hard fault. The same page (see link above) gives instructions on debugging that too.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Other than that - ensure you do the normal FreeRTOS debug things, like ensure you have configASSERT() defined, and that you have stack overflow checking on. Info on those topics is found on this page: &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://community.nxp.com/external-link.jspa?url=http%3A%2F%2Fwww.freertos.org%2FFAQHelp.html" rel="nofollow" target="_blank"&gt;http://www.freertos.org/FAQHelp.html&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Sep 2016 16:42:50 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/using-c-exceptions-with-freertos/m-p/615772#M36628</guid>
      <dc:creator>FreeRTOS_org</dc:creator>
      <dc:date>2016-09-13T16:42:50Z</dc:date>
    </item>
    <item>
      <title>Re: using c++ exceptions with freertos</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/using-c-exceptions-with-freertos/m-p/615773#M36629</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It's the hard fault, since it stops there after throwing after I define an own HardFault_Handler. &lt;BR /&gt;My biggest question at the moment is: I&lt;STRONG&gt;s C++ exception handling supposed to work out of the box, with freeRTOS or without an OS?!&lt;/STRONG&gt; I'm asking since this is a brown field project I have been thrown into, and if you say "Yeah it should work, so it looks like wrong interrupt management" I know where to look.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 Sep 2016 13:30:36 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/using-c-exceptions-with-freertos/m-p/615773#M36629</guid>
      <dc:creator>markusklemm</dc:creator>
      <dc:date>2016-09-15T13:30:36Z</dc:date>
    </item>
    <item>
      <title>Re: using c++ exceptions with freertos</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/using-c-exceptions-with-freertos/m-p/615774#M36630</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Because I saw that rand() tries to use malloc(), I also defined a working malloc()/freeRTOS function and et voilà: &amp;nbsp;__cxa_allocate_exception uses malloc (I wonder how the toolchain expects me to handle a bad_alloc case).&lt;/P&gt;&lt;P&gt;So now, it still crashes, but after exception allocation (I think):&lt;/P&gt;&lt;P&gt;The excecution path is :&amp;nbsp;&lt;/P&gt;&lt;P&gt;(throwing function after exception allocation)&lt;/P&gt;&lt;P&gt;__cxa_throw&lt;/P&gt;&lt;P&gt;&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;//(some intructions in __cxa_throw)&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;__cxa_begin_catch &amp;nbsp;//I guess something went wrong here&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;_ZSt9terminatev // Immediately after&amp;nbsp;&lt;SPAN&gt;__cxa_begin_catch&lt;/SPAN&gt;&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;_ZN10__cxxabiv111__terminateEPFvvE:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;00016dfc: push {r3, lr}&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;00016dfe: blx r0 &amp;nbsp;//Goes directly to&amp;nbsp;WDOG_EWM_IRQHandler or hard fault handler&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;00016e00: bl 0x194ac &amp;lt;abort&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you wonder or it might help: My debuggers say its the&amp;nbsp;&lt;SPAN&gt;WDOG_EWM_IRQHandler I crash into, if I not define the hard_fault handler and an own default handler.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;So I guess something went wrong in the stack unwinding, because I go thru some symbols with "finished stack unwinding" in the name in _throw, but I didn't catched the break point I set in a destructor of an object which should have been cleaned up. And that seems to motivate&amp;nbsp;__cxa_begin_catch to call abort or something.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 19 Sep 2016 15:59:50 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/using-c-exceptions-with-freertos/m-p/615774#M36630</guid>
      <dc:creator>markusklemm</dc:creator>
      <dc:date>2016-09-19T15:59:50Z</dc:date>
    </item>
    <item>
      <title>Re: using c++ exceptions with freertos</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/using-c-exceptions-with-freertos/m-p/615775#M36631</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Problem solved :&amp;nbsp;&lt;A href="https://community.nxp.com/thread/441354"&gt;Throw ends in abort on new blank frdm22f project (+ malloc/new )&lt;/A&gt;&amp;nbsp;&lt;BR /&gt;Remove&amp;nbsp;-specs=nano.specs in the linking options.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Jan 2017 13:10:02 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/using-c-exceptions-with-freertos/m-p/615775#M36631</guid>
      <dc:creator>markusklemm</dc:creator>
      <dc:date>2017-01-03T13:10:02Z</dc:date>
    </item>
  </channel>
</rss>

