<?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>Hard fault after uart printf</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/74602/hard-fault-after-uart-printf</link><description>Hello , 
 On NRF52840 DK my logger works fine and I get no problem with printf(). However, on my custom board the program goes into hard fault with the following : 
 0x4001 
 0x2003 FF14 
 Matter of fact, for my init function 
 
 And I added retarget</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 05 May 2021 08:50:19 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/74602/hard-fault-after-uart-printf" /><item><title>RE: Hard fault after uart printf</title><link>https://devzone.nordicsemi.com/thread/308305?ContentTypeID=1</link><pubDate>Wed, 05 May 2021 08:50:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3c702af3-7988-4410-a676-9d39c0a04d7c</guid><dc:creator>Mouss</dc:creator><description>&lt;p&gt;Hello Jorgen,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thank you for your help ! This has solved my problem&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Hard fault after uart printf</title><link>https://devzone.nordicsemi.com/thread/307687?ContentTypeID=1</link><pubDate>Fri, 30 Apr 2021 13:54:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:20fe2647-634e-465c-88d8-f7fe704216ee</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;As you can read from the UARTE peripheral documentation about &lt;a title="Error conditions" href="https://infocenter.nordicsemi.com/topic/ps_nrf52840/uarte.html#concept_fpm_qcm_wr"&gt;Error conditions&lt;/a&gt;:&lt;/p&gt;
&lt;p&gt;&amp;quot;&lt;span&gt;&lt;em&gt;An ERROR event, in the form of a framing error, will be generated if a valid stop bit is not detected in a frame. Another ERROR event, in the form of a break condition, will be generated if the RXD line is held active low for longer than the length of a data frame. Effectively, a framing error is always generated before a break condition occurs.&lt;/em&gt;&amp;quot;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;These errors will not generate hardfault, but the app_uart library will report an event, APP_UART_COMMUNICATION_ERROR, which by default is passed to the APP_ERROR_CHECK() in the event handler. This check will put the application in the error handler if the error code is not zero (NRF_SUCCESS):&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;void uart_error_handle(app_uart_evt_t * p_event)
{
    if (p_event-&amp;gt;evt_type == APP_UART_COMMUNICATION_ERROR)
    {
        APP_ERROR_HANDLER(p_event-&amp;gt;data.error_communication);
    }
    else if (p_event-&amp;gt;evt_type == APP_UART_FIFO_ERROR)
    {
        APP_ERROR_HANDLER(p_event-&amp;gt;data.error_code);
    }
}&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Try pulling the RX pin to VDD, or remove the APP_ERROR_CHECK in the UART event handler in your application.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Hard fault after uart printf</title><link>https://devzone.nordicsemi.com/thread/307655?ContentTypeID=1</link><pubDate>Fri, 30 Apr 2021 12:03:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f3b4902a-61dd-4a0d-80e2-af4e925780fe</guid><dc:creator>Mouss</dc:creator><description>&lt;p&gt;Hi,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The hardfault happen &lt;strong&gt;&lt;span style="text-decoration:underline;"&gt;right after a call to printf&lt;/span&gt; &lt;/strong&gt;but only on the custom board (not on nrf52840 DK) .&lt;/p&gt;
&lt;p&gt;Yes indeed, I have enabled the&amp;nbsp;&lt;span&gt;retarget functions on my sdk_config.h and like I said everything works fine on&amp;nbsp;nrf52840 DK.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;When I was testing my code on the DK I used the VCOM pins.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#define RX_PIN_NUMBER  8
#define TX_PIN_NUMBER  6
#define CTS_PIN_NUMBER 7
#define RTS_PIN_NUMBER 5
#define HWFC           true&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Can you tell me what do you mean by &amp;quot;pins connected/pulled to a given state on the custom board&amp;quot;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;On my custom board, these pins are exposed to an external connector .&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I also switched to other pin ( RX P0.3 and TX P0.4 which are also exposed for testing purposes) .&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Could you explain to me why do I need my pins&amp;nbsp;pulled / connected to a specific state in order to avoid hardfault ?&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Kind regards ,&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Moussaab&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Hard fault after uart printf</title><link>https://devzone.nordicsemi.com/thread/307642?ContentTypeID=1</link><pubDate>Fri, 30 Apr 2021 10:57:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:71baa196-ec27-40c1-9700-cd6baa665ea0</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Do the hardfault happen after a call to printf, or once it runs on the custom board?&lt;/p&gt;
&lt;p&gt;Have you enabled the retarget functions in your sdk_config.h file?&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;// &amp;lt;q&amp;gt; RETARGET_ENABLED  - retarget - Retargeting stdio functions
 

#ifndef RETARGET_ENABLED
#define RETARGET_ENABLED 1
#endif&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Which pins are you using for the UART peripheral? Are these pins connected/pulled to a given state on the custom board? If not, you may get an error on the RX line, putting your application in the error handler.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;br /&gt;Jørgen&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>