<?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>Reset reason to safely delete bonds of nRF52832</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/113341/reset-reason-to-safely-delete-bonds-of-nrf52832</link><description>Hello, 
 We have a product which is a custom nRF52832 board, nRF5 SDK (didn&amp;#39;t have time to upgrade to nRF Connect SDK), s132, BLE. 
 We used to call delete_bonds() function in security failure event. This fault on our behalf of course, caused many problems</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 29 Aug 2024 10:52:47 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/113341/reset-reason-to-safely-delete-bonds-of-nrf52832" /><item><title>RE: Reset reason to safely delete bonds of nRF52832</title><link>https://devzone.nordicsemi.com/thread/500405?ContentTypeID=1</link><pubDate>Thu, 29 Aug 2024 10:52:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d6b39ef9-1dde-4671-a758-760747fa601e</guid><dc:creator>DimitraN</dc:creator><description>&lt;p&gt;As I said here:&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
[quote userid="128023" url="~/f/nordic-q-a/113341/reset-reason-to-safely-delete-bonds-of-nrf52832/497154"]&lt;p&gt;&lt;span&gt;&lt;strong&gt;EDIT 2&lt;/strong&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;After more tests, I find out that when my board is powered by a battery, it works as expected!! (reset register gives 1 for pin reset)&lt;br /&gt;When it is powered by the Power Profiler Kit II (in ampere mode, power output enabled), the reset register gives 0 for pin reset!&lt;/span&gt;&lt;/p&gt;[/quote]
&lt;p&gt;with bootloader , disabled NRF_LOG_ENABLED, and RTT defines, release mode, and connected to battery it works as expected. The register gives 0x01 when pin-reset is pressed.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;When I connect it with another battery - and PPK2 in series to measure the consumption, it gives 0x00 when I press pin-reset.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;I really cannot understand why. But since the normal use with battery works, I keep it.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Reset reason to safely delete bonds of nRF52832</title><link>https://devzone.nordicsemi.com/thread/497722?ContentTypeID=1</link><pubDate>Mon, 12 Aug 2024 06:09:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a8d70102-5eda-45e4-9fd1-e0687e127ff2</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;Hi Dimitra,&amp;nbsp;&lt;/p&gt;
[quote user="DimitraN"]So is it the bootloader&amp;#39;s fault that the behaviour has been changed?&amp;nbsp;[/quote]
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Yes, the bootloader clears the resetreason at&amp;nbsp;nRF5_SDK_17.1.0_ddde560\components\libraries\bootloader\nrf_bootloader.c:crc_on_valid_app_required:nrf_power_resetreas_clear&lt;/p&gt;
&lt;p&gt;Put a breakpoint here and see if your execution hits here. If it does, comment this clear function so that your application can read the RESETREAS and then the application should clear this register.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Reset reason to safely delete bonds of nRF52832</title><link>https://devzone.nordicsemi.com/thread/497154?ContentTypeID=1</link><pubDate>Tue, 06 Aug 2024 12:29:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9b9c9258-79ac-48ab-ba76-e3119df144c2</guid><dc:creator>DimitraN</dc:creator><description>[quote userid="75734" url="~/f/nordic-q-a/113341/reset-reason-to-safely-delete-bonds-of-nrf52832/495935"]1. I don&amp;#39;t think it&amp;#39;s a good idea to change&amp;nbsp;&lt;span&gt;app_error.h with custom features.&lt;/span&gt;[/quote]
&lt;p&gt;But, all we do is calling the function app_error_handler() and not app_error_handler_bare() when in release mode, so that we have access to information such as line and file of an error that might occur.&amp;nbsp;&lt;br /&gt;So far, we haven&amp;#39;t noticed any strange behaviour regarding this, do you think we should undo it?&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
[quote userid="75734" url="~/f/nordic-q-a/113341/reset-reason-to-safely-delete-bonds-of-nrf52832/495935"]2. When you don&amp;#39;t initialize logging you should indeed not call logging functions like NRF_LOG_INFO() in your application.[/quote]
&lt;p&gt;We do initialize it and call NRF_LOG_INFO. We just don&amp;#39;t have NRF_LOG_ENABLED enable (it is 0) in the production version. This I believe works fine, and the these calls are just empty when the NRF_LOG_ENABLED define is zero. Please confirm that this is true, otherwise we must comment any print we have in the code (print such as NRF_LOG_INFO) for debugging purposes..&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;#define NRF_LOG_INTERNAL_MODULE(level, level_id, ...)                                    \
    if (NRF_LOG_ENABLED &amp;amp;&amp;amp; (NRF_LOG_LEVEL &amp;gt;= level) &amp;amp;&amp;amp;                                   \
        (level &amp;lt;= NRF_LOG_DEFAULT_LEVEL))                                                \
    {                                                                                    \
        if (NRF_LOG_FILTER &amp;gt;= level)                                                     \
        {                                                                                \
            LOG_INTERNAL(LOG_SEVERITY_MOD_ID(level_id), __VA_ARGS__);                    \
        }                                                                                \
    }&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;as i see in the file nrf_log_internal.h , if the NRF_LOG_ENABLED is zero, then the call of the function does nothing.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;So, to turn back to our problem, we still cannot find out why the register RESETREAS doesn&amp;#39;t have the expected values when the external debugger (from DK) is not connected.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;I will explain again, that, after a button reset on our custom board, we expect that this register will have the value 0x01.&amp;nbsp;&lt;br /&gt;When we check this with our board connected to the DK to use the external debugger, it does have this value. The button is connected to p0.21 (pin reset) and this &amp;quot;CONFIG_GPIO_AS_PINRESET&amp;quot; is included in the preprocessor&amp;#39;s definitions.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;When a soft-reset happens, for example from a function that returns an error code other than NRF_SUCCESS, the reset reason from the register is 0x4 as expected. When the button is pressed, however, 0x1 is the value with the debugger, and 0x0 is the value without the debugger.&amp;nbsp;&lt;br /&gt;Also, after some more tests, I see that the reason might be 0x1 after double press or more of the button. We cannot understand why this strange behaviour happens.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Finally, this is very important to us, because we want to use the reset reason in order to delete bonds. (when reset reason is 0x1 we will call delete_bonds function) . But we do not want this to happen any other time in case that the register does not work without the debugger.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Hope my description helps, and I really look forward for your assistance.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Best regards,&amp;nbsp;&lt;br /&gt;Dimitra&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;h3 id="mcetoc_1i4m05t9f0"&gt;&lt;strong&gt;Edit&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;I tested many times trying to find what is going on and I want to make something clear, that maybe will help you understand what I am doing wrong or what is going on...&lt;br /&gt;&lt;br /&gt;1. When I connect my custom board with the devkit to use it as an external debugger, I also enable NRF_LOG_ENABLED&amp;nbsp;and NRF_LOG_BACKEND_RTT_ENABLED and also I comment the call of the function&amp;nbsp;dfu_async_svci_init() in main in order to see the debugging messages in Segger Embedded Studio.&amp;nbsp;&lt;br /&gt;In this case, the reset reasons I read from the register are correct, and the RED led I have on the board blinks when reason is 0x1, which is when I press the pin-reset button.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;2. When I disable&amp;nbsp;&lt;span&gt;NRF_LOG_ENABLED&lt;/span&gt;&lt;span&gt;&amp;nbsp;and NRF_LOG_BACKEND_RTT_ENABLED and uncomment the&amp;nbsp;dfu_async_svci_init(), and download the application through segger, it also works when the board is connected to the debugger (devkit) and when it is not ! (red led blilnks which indicates to me that the reason is 0x1).&amp;nbsp;&lt;br /&gt;&lt;br /&gt;3. When I keep the logs disabled and create the hex file, which includes softdevice and bootloader, and download this on the board through the nRF Connect App, then the reset reason doesnot work as expected and when I press the button when the board &lt;strong&gt;is not&lt;/strong&gt; connected to the devkit debugger!&amp;nbsp; the RED led doesnot turn on to indicate to me that the reason is 0x01 and the another led blinks which means that the reason is 0x00.&amp;nbsp;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;So is it the bootloader&amp;#39;s fault that the behaviour has been changed?&amp;nbsp;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Or is the debugger? In all cases, it works as expected when the board is connected to the debugger of the devkit.... But it doesn&amp;#39;t when I have bootloader+application and no debugger, which is the real case..&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;EDIT 2&lt;/strong&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;After more tests, I find out that when my board is powered by a battery, it works as expected!! (reset register gives 1 for pin reset)&lt;br /&gt;When it is powered by the Power Profiler Kit II (in ampere mode, power output enabled), the reset register gives 0 for pin reset!&amp;nbsp;&lt;br /&gt;All the previous tests were executed with the PPK2, so probably this was the problem from the beginning. But why? How can this be the cause ?&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Reset reason to safely delete bonds of nRF52832</title><link>https://devzone.nordicsemi.com/thread/495935?ContentTypeID=1</link><pubDate>Mon, 29 Jul 2024 07:12:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cc2b3178-1849-4b76-9c5c-949825dde64d</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;1. I don&amp;#39;t think it&amp;#39;s a good idea to change&amp;nbsp;&lt;span&gt;app_error.h with custom features.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;2. When you don&amp;#39;t initialize logging you should indeed not call logging functions like NRF_LOG_INFO() in your application.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;3. If logs aren&amp;#39;t deferred, then this call has no use and will be empty, but I don&amp;#39;t think it will be a problem calling it before a reset, since that is what it&amp;#39;s used for (macro for flushing log data before a reset).&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Best regards,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Simon&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Reset reason to safely delete bonds of nRF52832</title><link>https://devzone.nordicsemi.com/thread/495747?ContentTypeID=1</link><pubDate>Fri, 26 Jul 2024 07:43:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:33327dd5-1e8f-4781-a65e-2470eefa4d52</guid><dc:creator>DimitraN</dc:creator><description>&lt;p&gt;Okay, I will describe what I do for logging:&lt;/p&gt;
&lt;p&gt;First, main function starts with these lines:&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;//Initialization
  log_init();                             //Initialize logs.
  int32_t reset_reason = NRF_POWER-&amp;gt;RESETREAS;
  NRF_LOG_INFO(&amp;quot;Reset reason = 0x%x.\n&amp;quot;, reset_reason);
  NRF_POWER-&amp;gt;RESETREAS = NRF_POWER-&amp;gt;RESETREAS;

  fds_module_init();                      //Initialize Flash Storage Module.

  gpio_init();                            //Initialize general purpose input/output.

  gpiote_init();                          //Initialize general purpose input/output task and events.

  dfu_async_svci_init();                  //Initialize async svci for device firmware update bootloader.
  
  .... // more initializations 
}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Then, in the main file, I use a custom function that works like APP_ERROR_CHECK, and what it does is that it takes the error code that is the return value from almost all of the functions from libraries softdevice etc, and save it in flash along with timestamp and some other information.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;I have also redefined the weak&amp;nbsp;&amp;nbsp;function app_error_fault_handler , which does the same, takes error code, line and file info saves them in flash and then performs soft-reset, which is done by calling this function:&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;void hardfault_handler(void)
{
  __disable_irq();

  NRF_LOG_FINAL_FLUSH();
  
  NVIC_SystemReset();
}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;I have also changed something in app_error.h file.&amp;nbsp;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;/**@brief Macro for calling error handler function.
 *
 * @param[in] ERR_CODE Error code supplied to the error handler.
 */
#ifndef DEBUG   //NOTE changed here ifdef to ifndef 
#define APP_ERROR_HANDLER(ERR_CODE)                                    \
    do                                                                 \
    {                                                                  \
        app_error_handler((ERR_CODE), __LINE__, (uint8_t*) __FILE__);  \
    } while (0)
#else
#define APP_ERROR_HANDLER(ERR_CODE)                                    \
    do                                                                 \
    {                                                                  \
        app_error_handler_bare((ERR_CODE));                            \
    } while (0)
#endif&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;see the NOTE. I changed it so that when in Release mode, I can still get line and file information of the error to save them in flash.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Finally, I call NRF_LOG_INFO in many lines in my code, which I don&amp;#39;t comment them out when I create the hex file and operate the device without debugger.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;1) Could the functionality I made with app_error.h, and fault handlers cause the fault ?&amp;nbsp;&lt;br /&gt;2) Should I not use NRF_LOG_INFO (should I comment these lines) when I make release code to work without debugger, and not even initiliaze logging with log_init() function in main function?&lt;br /&gt;3) Should I don&amp;#39;t call&amp;nbsp;NRF_LOG_FINAL_FLUSH(); in handler that starts the reset ?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;Thank you very much for your help in advance,&lt;br /&gt;Best regards,&lt;br /&gt;Dimitra&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Reset reason to safely delete bonds of nRF52832</title><link>https://devzone.nordicsemi.com/thread/495551?ContentTypeID=1</link><pubDate>Thu, 25 Jul 2024 07:42:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1278cf58-0205-46a8-b725-15b08538bdec</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi Dimitra&lt;/p&gt;
&lt;p&gt;Disabling the debugger shouldn&amp;#39;t change the reset reasons if the application is running as it should, so I&amp;#39;m guessing that when you disable the logging, something is failing in your application causing this soft-reset you&amp;#39;re seeing. Maybe something in your application is trying to use logging, and that the application crashes when you disable it. Have you also commented out the calls to the logging after disabling the logs on your end.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>