<?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>How can I properly debug my custom Buttonless DFU application?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/68052/how-can-i-properly-debug-my-custom-buttonless-dfu-application</link><description>I am attempting to create a custom Buttonless DFU application by building on top of the default example from the SDK. Specifically, I am merging the Buttonless DFU app with the BLE UART app and the TWI sensor reading app. Among those 2 other apps, I have</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 12 Nov 2020 04:41:01 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/68052/how-can-i-properly-debug-my-custom-buttonless-dfu-application" /><item><title>RE: How can I properly debug my custom Buttonless DFU application?</title><link>https://devzone.nordicsemi.com/thread/279614?ContentTypeID=1</link><pubDate>Thu, 12 Nov 2020 04:41:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4197f140-14c4-4c3e-88e8-47d18b48049f</guid><dc:creator>cor10</dc:creator><description>&lt;p&gt;Hi there Einar, thanks for your help with this. I finally was able to Debug and found the point at which my program is breaking! THANK YOU! In general, should I keep the changes made to&amp;nbsp;&lt;strong&gt;&lt;span&gt;nrf_bootloader.c&lt;/span&gt;&lt;/strong&gt; for future development/debugging? Or should that quick fix be undone moving forward?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I know that this following information is not really appropriate&amp;nbsp;on this ticket, but for reference I will include a summary of my bug (I can make a new ticket, or research previous tickets, so no need to provide a solution, unless its an easy one for you). The error I get is&amp;nbsp;ERROR 7 [NRF_ERROR_INVALID_PARAM]&lt;span&gt;&amp;nbsp;and it comes from calling&amp;nbsp;&lt;strong&gt;ble_advertising_init()&lt;/strong&gt;. Following the Debugger through this call to&amp;nbsp;&lt;strong&gt;ble_advertising_init()&lt;/strong&gt;, I am taken to&amp;nbsp;&lt;strong&gt;ble_advdata_encode()&lt;/strong&gt;. In this function, there is the&amp;nbsp;&lt;em&gt;if-statement:&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;em&gt;&lt;pre class="ui-code" data-mode="text"&gt;    // Encode &amp;#39;complete&amp;#39; uuid list.
    if (p_advdata-&amp;gt;uuids_complete.uuid_cnt &amp;gt; 0)
    {
        err_code = uuid_list_encode(&amp;amp;p_advdata-&amp;gt;uuids_complete,
                                    BLE_GAP_AD_TYPE_16BIT_SERVICE_UUID_COMPLETE,
                                    BLE_GAP_AD_TYPE_128BIT_SERVICE_UUID_COMPLETE,
                                    p_encoded_data,
                                    p_len,
                                    max_size);
        VERIFY_SUCCESS(err_code);
    }&lt;/pre&gt;&lt;br /&gt;&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;The SES Debugger then steps into&amp;nbsp;&lt;strong&gt;&lt;/strong&gt;the above execution of&amp;nbsp;&lt;strong&gt;uuid_list_encode()&lt;/strong&gt; and then again it steps into&amp;nbsp;&lt;strong&gt;uuid_list_sized_encode()&lt;/strong&gt; (for 16bit UUIDs). In&amp;nbsp;&lt;strong&gt;uuid_list_sized_encode()&lt;/strong&gt;, there is a for-loop that iterates through the UUIDs provided by the application, and my app successfully handles the first UUID, which is the default Buttonless DFU UUID provided by the NRF SDK Buttonless DFU example (this is expected since I got the default example to work perfectly). During the second iteration of this for-loop, aka during the processing of my newly added NUS UUID (which I believe I have added erroneously), the whole system breaks when it tries to run&amp;nbsp;&lt;strong&gt;VERIFY_SUCCESS()&lt;/strong&gt; on the output of&amp;nbsp;&lt;strong&gt;sd_ble_uuid_encode()&lt;/strong&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;It seems to me that there is some issue with the way I am adding the NUS Service UUID to the default Buttonless DFU app. For reference, here is the code that introduces this UUID in my application:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;static ble_uuid_t m_adv_uuids[]         = 
{
    {BLE_UUID_DEVICE_INFORMATION_SERVICE, BLE_UUID_TYPE_BLE},
    {BLE_UUID_NUS_SERVICE, 0x02} //NUS_SERVICE_UUID_TYPE}
};&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I wonder if there is something obviously incorrect with this array, or if there are other crucial steps I need to take to add this UUID properly. For reference, I made sure&amp;nbsp;&lt;span style="font-weight:400;"&gt;NRF_SDH_BLE_VS_UUID_COUNT is set to 2 for each UUID in this app.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;span style="font-weight:400;"&gt;Following other posts online, I made an edit to my code to call&amp;nbsp;&lt;strong&gt;services_init()&lt;/strong&gt; before calling&amp;nbsp;&lt;strong&gt;advertising_init()&lt;/strong&gt; and this produced a different error. This time the errors produced&amp;nbsp;&lt;/span&gt;&lt;/span&gt;when I follow the same Debugging path as above switch between&amp;nbsp;&lt;strong&gt;SOFTDEVICE: INVALID MEMORY ACCESS&lt;/strong&gt;&amp;nbsp;and &lt;strong&gt;NRF_ERROR_INVALID_ADDR &lt;/strong&gt;(Invalid pointer supplied) when trying to execute &lt;strong&gt;sd_ble_uuid_encode()&lt;/strong&gt;. And this time around, the error occurs on the first iteration of the for-loop&amp;nbsp;&lt;strong&gt;&lt;/strong&gt;in&lt;strong&gt;&amp;nbsp;&lt;/strong&gt;&lt;strong&gt;uuid_list_sized_encode()&lt;/strong&gt;, meaning its breaking with the default UUID.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How can I properly debug my custom Buttonless DFU application?</title><link>https://devzone.nordicsemi.com/thread/279573?ContentTypeID=1</link><pubDate>Wed, 11 Nov 2020 16:28:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1d23402a-fee7-407e-ab6d-ddf5df842f5b</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote user="cor10"]I did what you mentioned and I cannot get the device to reach the Breakpoint at the beginning of &lt;strong&gt;main.c&lt;/strong&gt;[/quote]
&lt;p&gt;This may be because of a small but important detail when debugging with a bootloader. The bootloader will check the integrity of the application, and only start it if it is&amp;nbsp;valid&amp;nbsp;&amp;nbsp;(hash remains the same). So if you want to keep the bootloader in place but debug while modifying the application code, you need to change the bootloader so that it does not check the application hash. I recommend you simply modify crc_on_valid_app_required() in&amp;nbsp;&amp;lt;SDK&amp;gt;/components/libraries/bootloader/nrf_bootloader.c so that it always returns false and flash that bootloader. Then you can debug your application as expected even though the bootloader is present and runs first. Note that you still need to flash a bootloader settings page initially or do an initial DFU update to flag that a valid app is present, though.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How can I properly debug my custom Buttonless DFU application?</title><link>https://devzone.nordicsemi.com/thread/278874?ContentTypeID=1</link><pubDate>Sat, 07 Nov 2020 04:09:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:86ff21fd-df2c-4d28-a3bf-d3a0e87e0e03</guid><dc:creator>cor10</dc:creator><description>&lt;p&gt;Hey Edvin,&lt;/p&gt;
&lt;p&gt;I did what you mentioned and I cannot get the device to reach the Breakpoint at the beginning of &lt;strong&gt;main.c&lt;/strong&gt;. I have included my code that programs the device for reference.&lt;/p&gt;
&lt;p&gt;Regardless of which &lt;strong&gt;nrfutil settings generate&lt;/strong&gt; function I use (between the commented and uncommented options in the code snippet below), whenever I &lt;strong&gt;Attach Debugger&amp;nbsp;&lt;/strong&gt;in&amp;nbsp;&lt;strong&gt;&lt;/strong&gt;SES, I am brought to the&amp;nbsp;file &amp;#39;&lt;strong&gt;nrf_log_frontend.c&lt;/strong&gt;&amp;#39;, specifically to the func:&lt;strong&gt; int32_t nrf_log_backend_add(nrf_log_backend_t const * p_backend, nrf_log_severity_t severity)&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;When I click the RESTART button to restart the Debugger, it never goes to the Breakpoints that I set in&amp;nbsp;&lt;strong&gt;main.c&lt;/strong&gt; and just goes straight to&amp;nbsp;&lt;strong&gt;nrf_log_backend_add()&lt;/strong&gt;. Nothing is printed to the Debug Terminal.&lt;/p&gt;
&lt;p&gt;Setting&amp;nbsp;&lt;strong&gt;NRF_FPRINTF_FLAG_AUTOMATIC_CR_ON_LF_ENABLED = 0&lt;/strong&gt; didnt make any difference that I was able to detect.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#! /bin/bash

## Compile bootloader and application:
#boot_make=&amp;#39;../nrf-sdk/examples/dfu/secure_bootloader/pca10040_s132_ble/armgcc/&amp;#39;
boot_make=&amp;#39;../nrf-sdk/examples/dfu/secure_bootloader/pca10040_s132_ble_debug/armgcc/&amp;#39;
boot=${boot_make}_build/nrf52832_xxaa_s132.hex
softdevice=&amp;#39;../nrf-sdk/components/softdevice/s132/hex/s132_nrf52_7.0.1_softdevice.hex&amp;#39;
app_make=&amp;#39;../nrf-sdk/examples/ble_peripheral/ble_app_buttonless_dfu/pca10040/s132/armgcc/&amp;#39;
app=${app_make}_build/nrf52832_xxaa.hex

make -C &amp;quot;$boot_make&amp;quot;
make -C &amp;quot;$app_make&amp;quot;

nrfutil settings generate --family NRF52 --application &amp;quot;$app&amp;quot; --application-version 1 --bootloader-ve    rsion 1 --bl-settings-version 2 settings.hex

#nrfutil settings generate --family NRF52 --application &amp;quot;$app&amp;quot; --application-version 1 --bootloader-v    ersion 1 --bl-settings-version 2 --softdevice &amp;quot;$softdevice&amp;quot; --key-file private.key settings.hex

nrfjprog -e
nrfjprog --program &amp;quot;$softdevice&amp;quot; --verify
nrfjprog --program &amp;quot;$boot&amp;quot; --verify
nrfjprog --program &amp;quot;$app&amp;quot; --verify
nrfjprog --program settings.hex --verify

nrfjprog --reset   &lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Any advice?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How can I properly debug my custom Buttonless DFU application?</title><link>https://devzone.nordicsemi.com/thread/278745?ContentTypeID=1</link><pubDate>Fri, 06 Nov 2020 10:14:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:30c831fd-cf3b-4497-aeef-2c598ee31e97</guid><dc:creator>Edvin</dc:creator><description>[quote user=""], the new application code is never able to start and so it never advertises. On the nRF Connect app, everything works as it should: the .zip package is written and it even&amp;nbsp;prints a&amp;nbsp; &amp;quot;Successful DFU!&amp;quot; notification when its done. But the code on the device never starts.[/quote]
&lt;p&gt;&amp;nbsp;This we don&amp;#39;t know. Probably, the application starts, but it doesn&amp;#39;t start advertising because of an error, My guess is an APP_ERROR_CHECK(err_code); receiving an err_code != 0 before it starts advertising. This will cause a reset, and it will run into the same error, and hence you never see the advertisements.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Regarding your approach 2:&lt;/p&gt;
&lt;p&gt;Can you please try to run your commands (nrfjprog) first, and then attach the SES project, set a breakpoint in the start of main.c, and then reset the device using the UI:&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/5125.pastedimage1604657569651v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Is the breakpoint reached then?&lt;/p&gt;
&lt;p&gt;If so, what happens when you press resume again?&lt;/p&gt;
&lt;p&gt;Do you see anything in the debug terminal? If not, what is your&amp;nbsp;NRF_FPRINTF_FLAG_AUTOMATIC_CR_ON_LF_ENABLED in your application&amp;#39;s sdk_config.h? Can you try to set it to 0? If you need to perform this change, remember to generate the bootloader settings file again after you have compiled.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>