<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>C++ exception</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/45733/c-exception</link><description>Hi, 
 I&amp;#39;m using Segger Embedded Studio (with gcc naturally). The standard C++ exception handling doesn&amp;#39;t work: exceptions are not caught by exception handler. Is there a way to enable normal C++ behaviour? 
 Thanks, 
 Daniel</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Sat, 06 Apr 2019 07:22:11 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/45733/c-exception" /><item><title>RE: C++ exception</title><link>https://devzone.nordicsemi.com/thread/180579?ContentTypeID=1</link><pubDate>Sat, 06 Apr 2019 07:22:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a26c9bdd-3ef9-4251-af0b-69c087affa8a</guid><dc:creator>Daniel Reisfeld</dc:creator><description>&lt;p&gt;&lt;span&gt;&amp;Oslash;yvind,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Thanks for your most helpful answer,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Daniel&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: C++ exception</title><link>https://devzone.nordicsemi.com/thread/180484?ContentTypeID=1</link><pubDate>Fri, 05 Apr 2019 12:05:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b3c0df45-305e-4872-87b7-2df81aabf934</guid><dc:creator>&amp;#216;yvind</dc:creator><description>&lt;p&gt;The Hard Fault handler is based on ARM &amp;#39;s&amp;nbsp;own exception handler:&amp;nbsp;&lt;a href="https://developer.arm.com/docs/dui0553/latest/the-cortex-m4-processor/exception-model/exception-handlers"&gt;https://developer.arm.com/docs/dui0553/latest/the-cortex-m4-processor/exception-model/exception-handlers&lt;/a&gt;&amp;nbsp;and this handles all CPU specific faults that can occur, but should not. ARM describes these faults here:&amp;nbsp;&lt;a href="https://developer.arm.com/docs/dui0553/latest/the-cortex-m4-processor/fault-handling"&gt;https://developer.arm.com/docs/dui0553/latest/the-cortex-m4-processor/fault-handling&amp;nbsp;&lt;/a&gt;&amp;nbsp;To learn more about the ARM Instruction set (Assembly) please see &lt;a href="https://developer.arm.com/docs/dui0553/latest/the-cortex-m4-instruction-set"&gt;this link&lt;/a&gt;.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://developer.arm.com/docs/dui0553/latest/the-cortex-m4-processor/fault-handling"&gt;&lt;br /&gt;T&lt;/a&gt;he Error Module handles application specific errors, it uses the&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href="https://www.nordicsemi.com/DocLib/Content/SDK_Doc/nRF5_SDK/v15-3-0/group__app__error#ga99cd7671f5eca2fdd40980d3ebe5b84a"&gt;app_error_fault_handler&lt;/a&gt;&lt;span&gt;&amp;nbsp;for handling application and SoftDevice errors and is the default in our SDK.&lt;/span&gt;&lt;/p&gt;
[quote user="danielReisfeld"]1. Do I need to compile this as part of&amp;nbsp;my project?[/quote]
&lt;p&gt;No, you do not need to implement it, but we highly recommend it.&lt;/p&gt;
[quote user="danielReisfeld"]2. Does implementing&amp;nbsp;&amp;nbsp;HardFault_c_handler interfere with softdevice?[/quote]
&lt;p&gt;&lt;span&gt;When certain unrecoverable errors occur within the application or SoftDevice, the fault handler will be called. This fault handler function is passed to the SoftDevice during initialization (&lt;/span&gt;&lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.s130.api.v1.0.0/group___n_r_f___s_d_m___f_u_n_c_t_i_o_n_s.html?cp=2_7_2_1_1_2_5_4_1#ga26ecfde6eee7363f88bed8a8b711122a"&gt;sd_softdevice_enable()&lt;/a&gt;)&lt;br /&gt;&lt;br /&gt;&lt;span&gt;HardFault should never happen; it might happen because of a code error, electromagnetic interference (EMI) near the device, or glitches on power lines. In this case, the microcontroller will hang in an endless loop until the next reset, unless a&amp;nbsp;&lt;/span&gt;&lt;a href="https://www.nordicsemi.com/DocLib/Content/SDK_Doc/nRF5_SDK/v15-3-0/hardware_driver_wdt"&gt;watchdog&lt;/a&gt;&lt;span&gt;&amp;nbsp;is used in the code.&lt;/span&gt;&lt;/p&gt;
[quote user="danielReisfeld"]3. What is the&amp;nbsp;uint32_t * parameter passed to&amp;nbsp;HardFault_c_handler?[/quote]
&lt;p&gt;&amp;nbsp;This is the &lt;a href="https://developer.arm.com/docs/dui0553/latest/the-cortex-m4-processor/programmers-model/core-registers#BABJJHGA"&gt;program stack pointer&lt;/a&gt; address, used in the HardFault_C_handler to indicate what caused the error:&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;        [0]  = &amp;quot;The processor has attempted to execute an undefined instruction&amp;quot;,
        [1]  = &amp;quot;The processor attempted a load or store at a location that does not permit the operation&amp;quot;,
        [2]  = NULL,
        [3]  = &amp;quot;Unstack for an exception return has caused one or more access violations&amp;quot;,
        [4]  = &amp;quot;Stacking for an exception entry has caused one or more access violations&amp;quot;,
        [5]  = &amp;quot;A MemManage fault occurred during floating-point lazy state preservation&amp;quot;,
        [6]  = NULL,
        [7]  = NULL,
        [8]  = &amp;quot;Instruction bus error&amp;quot;,
        [9]  = &amp;quot;Data bus error (PC value stacked for the exception return points to the instruction that caused the fault)&amp;quot;,
        [10] = &amp;quot;Data bus error (return address in the stack frame is not related to the instruction that caused the error)&amp;quot;,
        [11] = &amp;quot;Unstack for an exception return has caused one or more BusFaults&amp;quot;,
        [12] = &amp;quot;Stacking for an exception entry has caused one or more BusFaults&amp;quot;,
        [13] = &amp;quot;A bus fault occurred during floating-point lazy state preservation&amp;quot;,
        [14] = NULL,
        [15] = NULL,
        [16] = &amp;quot;The processor has attempted to execute an undefined instruction&amp;quot;,
        [17] = &amp;quot;The processor has attempted to execute an instruction that makes illegal use of the EPSR&amp;quot;,
        [18] = &amp;quot;The processor has attempted an illegal load of EXC_RETURN to the PC, as a result of an invalid context, or an invalid EXC_RETURN value&amp;quot;,
        [19] = &amp;quot;The processor has attempted to access a coprocessor&amp;quot;,
        [20] = NULL,
        [21] = NULL,
        [22] = NULL,
        [23] = NULL,
        [24] = &amp;quot;The processor has made an unaligned memory access&amp;quot;,
        [25] = &amp;quot;The processor has executed an SDIV or UDIV instruction with a divisor of 0&amp;quot;,&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Kind regards,&lt;br /&gt;Øyvind&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: C++ exception</title><link>https://devzone.nordicsemi.com/thread/180368?ContentTypeID=1</link><pubDate>Thu, 04 Apr 2019 15:59:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1a95ea19-d453-4807-a8fc-2f9afc7dbd74</guid><dc:creator>Nguyen Hoan Hoang</dc:creator><description>&lt;p&gt;I don&amp;#39;t know about SES but it might disabled it by default. &amp;nbsp;The GCC flag to disable exceptions is -fno-exceptions. &amp;nbsp;Look to see if it compiles with this flag. &amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: C++ exception</title><link>https://devzone.nordicsemi.com/thread/180348?ContentTypeID=1</link><pubDate>Thu, 04 Apr 2019 14:15:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b2855bdf-1b37-4717-a6a8-922984f5ec17</guid><dc:creator>Daniel Reisfeld</dc:creator><description>&lt;p&gt;&lt;span&gt;&amp;Oslash;yvind,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;From browsing the links you sent it appears that there is a function&amp;nbsp;HardFault_Handler which in turn calls&amp;nbsp;HardFault_c_handler. Furthermore, I see that there is an assembly implementation of&amp;nbsp;&amp;nbsp;HardFault_Handler in&amp;nbsp;\nRF5_SDK_15.3.0_59ac345\components\libraries\hardfault\nrf52\handler\hardfault_handler_gcc.c&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;My questions:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;1. Do I need to compile this as part of&amp;nbsp;my project?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;2. Does implementing&amp;nbsp;&amp;nbsp;HardFault_c_handler interfere with softdevice?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;3. What is the&amp;nbsp;uint32_t * parameter passed to&amp;nbsp;HardFault_c_handler?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Best,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Daniel&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: C++ exception</title><link>https://devzone.nordicsemi.com/thread/180325?ContentTypeID=1</link><pubDate>Thu, 04 Apr 2019 13:04:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fdfaf4ae-8daf-498e-a364-4d0d541625db</guid><dc:creator>&amp;#216;yvind</dc:creator><description>&lt;p&gt;Daniel,&amp;nbsp;&lt;br /&gt;&lt;br /&gt;The nRF SDK has built-in error handling, see&amp;nbsp;&lt;a href="https://www.nordicsemi.com/DocLib/Content/SDK_Doc/nRF5_SDK/v15-3-0/lib_hardfault"&gt;HardFault handling library&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://www.nordicsemi.com/DocLib/Content/SDK_Doc/nRF5_SDK/v15-3-0/lib_error"&gt;Error module&lt;/a&gt;&amp;nbsp; in the &lt;a href="https://www.nordicsemi.com/DocLib/Content/SDK_Doc/nRF5_SDK/v15-3-0/index"&gt;SDK v15.3 documentation&lt;/a&gt;. &lt;a href="https://devzone.nordicsemi.com/b/blog/posts/an-introduction-to-error-handling-in-nrf5-projects"&gt;This tutorial&lt;/a&gt;&amp;nbsp;is also a good read to learn about the&amp;nbsp;error handling in nRF5 projects.&lt;br /&gt;&lt;br /&gt;Hope this answers your question.&lt;br /&gt;&lt;br /&gt;Kind regards,&lt;br /&gt;Øyvind&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: C++ exception</title><link>https://devzone.nordicsemi.com/thread/180310?ContentTypeID=1</link><pubDate>Thu, 04 Apr 2019 12:19:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f6360d7a-bb91-4fe6-95ed-532efe9d0117</guid><dc:creator>Daniel Reisfeld</dc:creator><description>&lt;p&gt;&lt;span&gt;&amp;Oslash;yvind,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;OK, C then: since unlike C++, C doesn&amp;#39;t have a mechanism for systematic exception handling, can you recommend the Nordicsemi preferred way (in C) to recover from HW faults?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Best,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Daniel&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: C++ exception</title><link>https://devzone.nordicsemi.com/thread/180303?ContentTypeID=1</link><pubDate>Thu, 04 Apr 2019 12:06:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ba850a08-bb03-4f90-97eb-108ed836c9df</guid><dc:creator>&amp;#216;yvind</dc:creator><description>&lt;p&gt;Not directly connected to your question, but since you are asking in our forum I would like to inform you that&amp;nbsp;&lt;span&gt;Nordic Semiconductor doesn&amp;#39;t have any official support for C++ in SES (or any other compiler) so you will have to do some of the error searching here yourself.&lt;br /&gt;&lt;br /&gt;Kind regards,&lt;br /&gt;Øyvind&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: C++ exception</title><link>https://devzone.nordicsemi.com/thread/180296?ContentTypeID=1</link><pubDate>Thu, 04 Apr 2019 11:51:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4cf863a7-3af4-4846-824c-709c1ccfd0af</guid><dc:creator>Daniel Reisfeld</dc:creator><description>&lt;p&gt;&lt;span&gt;&amp;Oslash;yvind,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Sorry but I don&amp;#39;t get it - can you elaborate why these links are relevant to my question?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Best,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Daniel&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: C++ exception</title><link>https://devzone.nordicsemi.com/thread/180293?ContentTypeID=1</link><pubDate>Thu, 04 Apr 2019 11:39:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2b124f6c-6a69-48e2-87fb-cdbf92796cef</guid><dc:creator>&amp;#216;yvind</dc:creator><description>&lt;p&gt;Hello Daniel,&amp;nbsp;&lt;br /&gt;&lt;br /&gt;For questions regarding Segger Embedded Studio, I would recommend asking the Segger Forum e.g.&amp;nbsp;&lt;a href="https://forum.segger.com/index.php/Thread/4448-Have-to-import-cpp-files-to-run-code/"&gt;https://forum.segger.com/index.php/Thread/4448-Have-to-import-cpp-files-to-run-code/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Similar questions regarding the nRF SDK and C++ usage have been asked before, have a look &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/33615/segger-embedded-studio-c-and-the-standard-library"&gt;here&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/25134/using-c-standard-libraries"&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Kind regards,&lt;br /&gt;Øyvind&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>