<?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>Problems with uart in both bootloader and application</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/38917/problems-with-uart-in-both-bootloader-and-application</link><description>Hi, 
 I am developing a bootloader for a custom board with the nRF52840 (nRF5 SDK v15.0.0 and SEGGER Embedded Studio V3.30) where we have no other option but to engage DFU using the uart. The uart is also used in the actual application and we are planning</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 01 Oct 2018 13:32:30 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/38917/problems-with-uart-in-both-bootloader-and-application" /><item><title>RE: Problems with uart in both bootloader and application</title><link>https://devzone.nordicsemi.com/thread/150988?ContentTypeID=1</link><pubDate>Mon, 01 Oct 2018 13:32:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:aa0d0e9d-df73-44fd-84f5-8fa54181c252</guid><dc:creator>AndersLundqvist</dc:creator><description>&lt;p&gt;Hi Einar,&lt;/p&gt;
&lt;p&gt;It actually works! In retrospektive it was actually there in the blinky example as well. If you know where to look that could have been a giveaway but in this (and many other cases) there were quite a lot of places to look.&lt;/p&gt;
&lt;p&gt;However, in my defence, the symptoms were very hard to analyze and the fact that the application actually worked as long as the uart was not engaged, it was far from obvious. Come to think of it, there is likely some interrupt that ends up in the MBR instead of inside an ISR.&lt;/p&gt;
&lt;p&gt;In this project we will not use any Soft Device at all, so why should I look for information there? This should be covered in at least some DFU page.&lt;/p&gt;
&lt;p&gt;But many thanks! I had almost given up hope on this and was starting to consider writing my own bootloader...&lt;/p&gt;
&lt;p&gt;Best regards&lt;/p&gt;
&lt;p&gt;Anders&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problems with uart in both bootloader and application</title><link>https://devzone.nordicsemi.com/thread/150976?ContentTypeID=1</link><pubDate>Mon, 01 Oct 2018 13:00:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9b61f063-4816-434b-89f7-70a4929deae7</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi Anders,&lt;/p&gt;
&lt;p&gt;Now I see the problem. The MBR needs 8 bytes of RAM, so you have to adjust the RAM start address of your application to&amp;nbsp;0x20000008 (and reduce the RAM size by 8). This is not documented for the stand-alone MBR as far as I can see, &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.s140.sds/dita/softdevices/s130/mem_usage/mem_resource_reqs.html?cp=2_3_2_0_13_0_0"&gt;but it is documented for the SoftDevice&lt;/a&gt;. (I have reported this lack of documentation internally.)&lt;/p&gt;
&lt;p&gt;Br,&lt;/p&gt;
&lt;p&gt;Einar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problems with uart in both bootloader and application</title><link>https://devzone.nordicsemi.com/thread/150642?ContentTypeID=1</link><pubDate>Thu, 27 Sep 2018 09:04:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f9996e48-0e73-4f59-a028-28ec93906682</guid><dc:creator>AndersLundqvist</dc:creator><description>&lt;p&gt;Now I have tried the same setup (this time without any alterations at all in the bootloader, except FC disabling which is needed in my case) and it does not work! I have tried debugging and it works exactly like on our custom board...&lt;/p&gt;
&lt;p&gt;Could you please verify this on your side, i.e. Compile a&amp;nbsp;&lt;span&gt;secure_bootloader_uart_mbr_pca10056_debug, download it to the board:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;nrfjprog --eraseall&lt;br /&gt;nrfjprog --program secure_bootloader_uart_mbr_pca10056_debug.hex --chiperase&lt;br /&gt;nrfjprog --program mbr.hex&lt;br /&gt;nrfjprog --reset&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Compile the&amp;nbsp;examples\peripheral\uart\pca10056\blank\ses with FLASH_START 0x1000., create a package with the same key used with the bootloader and finally program it using:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;nrfutil dfu serial -pkg uart_pca10056.zip -b 115200 -p COM3 -fc 0&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Does it work as expected?&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;Anders&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problems with uart in both bootloader and application</title><link>https://devzone.nordicsemi.com/thread/150622?ContentTypeID=1</link><pubDate>Thu, 27 Sep 2018 08:24:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:449eba95-eab6-4376-8109-57754e12db13</guid><dc:creator>AndersLundqvist</dc:creator><description>&lt;p&gt;OK.&lt;/p&gt;
&lt;p&gt;I have tried debugging while disabling optimization in SES. The results are unclear and the stepping loses control after the&amp;nbsp;app_uart_put. If I put a breakpoint on the next instruction in main it hits that breakpoint but after that it loses control. My guess is that the transmission causes an interrupt when the data has been written and that ISR (which and where?) fucks up everything. Is this your opinion as well?&lt;/p&gt;
&lt;p&gt;I&amp;#39;d like to point out that, apart from very modest changes of the bootloader and the uart app, I have not written any of the code that is running. I have disabled flow control but apart from that no changes has been made to the sdk_config.&lt;/p&gt;
&lt;p&gt;There is no point in me continuing the project until this issue is solved because we do need a working uart in our real application.&lt;/p&gt;
&lt;p&gt;I just had a look at the secure_bootloader_uart_mbr_pca10056_debug and it has &amp;quot;Optimization&amp;quot; to &amp;quot;Optimize For Size&amp;quot;. What exactly have you altered in your debug projects for SES?&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1538036655859v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;Best regards&lt;/p&gt;
&lt;p&gt;Anders&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problems with uart in both bootloader and application</title><link>https://devzone.nordicsemi.com/thread/150583?ContentTypeID=1</link><pubDate>Thu, 27 Sep 2018 06:20:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1b4fe1f0-7d2b-415b-ac79-66778973a7f5</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi Anders,&lt;/p&gt;
[quote user="AndersLundqvist"]Believe me, it IS working flawlessly if no bootloader has started the application. Why? Well perhaps because the code is correct to the point where it actually executes [/quote]
&lt;p&gt;If that is the case then it might be that the bootloader does not clean-up properly before starting the application (e.g. some UART registers might not have their default value assumed by the UART driver in the application), but the SDK bootloader should clean-up properly. I any case&amp;nbsp;I think you need to debug a bit more to see exactly what happens in your application to find this.&amp;nbsp;&lt;/p&gt;
[quote user="AndersLundqvist"]I have no clue as to what you are referring to. If I look into the options for the project I can see that the &amp;quot;Optimization Level&amp;quot; is set to &amp;quot;Optimize For Size&amp;quot;. Compilation has (as always?) been carried out using [Build][Rebuild Solution].[/quote]
&lt;p&gt;Breaking and stepping through code when you optimize (particularly for size) is not easy as the resulting machine code can be quite different from the C code you are looking at. Therefor disabling optimization is always a good idea in such cases. In the SES projects we deliver in our SDK there is both a &amp;quot;Release&amp;quot; and &amp;quot;Debug&amp;quot; build configuration. Using &amp;quot;Debug&amp;quot; disables optimization (among other things) to make debugging easier. Please use that and try again.&lt;/p&gt;
[quote user="AndersLundqvist"]If the program counter (PC) leaves the program area it either means that someone has set a function pointer to a not so good location or it means that some memory location has been overwritten (hey it&amp;#39;s C-code we are talking about).[/quote]
&lt;p&gt;I agree that it is a likely explanation. As you have such a simple application you should be able to track down where this happens using a debugger quite easily.&lt;/p&gt;
[quote user="AndersLundqvist"]You also say that there is no difference if the bootloader is present or not. Could you explain that in more detail to me, because I do not follow you in that respect. [/quote]
&lt;p&gt;You are right that the bootloader does a few things as you have described, but it should clean-up properly after itself. It might be some issue here, but in any case, I think the proper way to handle this is to debug the application a bit further to see what actually goes wrong. If the problem is that some register or similar is not as expected, then you can go back to the bootloader code and see if it can be to blame.&lt;/p&gt;
[quote user="AndersLundqvist"]Data already loaded into RAM does not magically disappear when changing PC to a different location (app), or...?[/quote]
&lt;p&gt;Of course. But if your application uses uninitialized RAM (previously used by the bootloader as you suggest or not), then that is a bug in your application. You cannot blame the bootloader for that. (I am not suggesting this necessarily is the case here, though).&lt;/p&gt;
&lt;p&gt;So to sum up I still think you need to debug the application to see where and how things go wrong. (That does not mean that I am certain that the bootloader does not have anything to do with it.)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problems with uart in both bootloader and application</title><link>https://devzone.nordicsemi.com/thread/150509?ContentTypeID=1</link><pubDate>Wed, 26 Sep 2018 14:00:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f7edfdc8-3c2a-4426-a516-806f48f63fb3</guid><dc:creator>AndersLundqvist</dc:creator><description>&lt;p&gt;Believe me, it IS working flawlessly if no bootloader has started the application. Why? Well perhaps because the code is correct to the point where it actually executes (no code in the real world is flawless). :-)&lt;/p&gt;
&lt;p&gt;I have no clue as to what you are referring to. If I look into the options for the project I can see that the &amp;quot;Optimization Level&amp;quot; is set to &amp;quot;Optimize For Size&amp;quot;. Compilation has (as always?) been carried out using [Build][Rebuild Solution].&lt;/p&gt;
&lt;p&gt;If the program counter (PC) leaves the program area it either means that someone has set a function pointer to a not so good location or it means that some memory location has been overwritten (hey it&amp;#39;s C-code we are talking about).&lt;/p&gt;
&lt;p&gt;You also say that there is no difference if the bootloader is present or not. Could you explain that in more detail to me, because I do not follow you in that respect. Data already loaded into RAM does not magically disappear when changing PC to a different location (app), or...? Not speaking of alterations to hardware registers done using the bootloader... Are you implying that you can load an address into the processor memory and then wipe the entire processor blank (except for the adress mentioned) before a reboot and that the processor sees this after the reboot and continues execution from the adress pointed out? Nice feature but is that really the case?&lt;/p&gt;
&lt;p&gt;Best regards&lt;/p&gt;
&lt;p&gt;Anders&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problems with uart in both bootloader and application</title><link>https://devzone.nordicsemi.com/thread/150501?ContentTypeID=1</link><pubDate>Wed, 26 Sep 2018 13:37:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a3777858-a017-43ab-99ad-65957ade629f</guid><dc:creator>Einar Thorsrud</dc:creator><description>[quote user="AndersLundqvist"]Debugging the application without the bootloader is pointless, since the application then runs exactly as expected.[/quote]
&lt;p&gt;I fail to see why. The presence of the bootloader should not have any effect on the application whatsoever. So if it makes debugging more difficult, just skip the bootloader until you have found the issue, then introduce it again.&lt;/p&gt;
[quote user="AndersLundqvist"]I stepped the code and the PC was last seen at line 310 in nrfx_uarte.c (a fairly uninteresting piece of code). Pausing the debugger results in a helt in an &amp;quot;Unknown function at 0x00000686&amp;quot; or thereabouts which clearly is something outside the application (according to the documentation this should be in the MBR).[/quote]
&lt;p&gt;&amp;nbsp;That&amp;#39;s odd. Have you built without optimization (selected Debug in the dropdown in SES)?&lt;/p&gt;
[quote user="AndersLundqvist"]Is this a BUG in the SDK? A BUG in the SES? Or...?[/quote]
&lt;p&gt;&amp;nbsp;There is not enough information here to draw any conclusion at this point. More debugging needed &lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f642.svg" title="Slight smile"&gt;&amp;#x1f642;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problems with uart in both bootloader and application</title><link>https://devzone.nordicsemi.com/thread/150497?ContentTypeID=1</link><pubDate>Wed, 26 Sep 2018 13:29:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1846a223-4661-43c6-81e1-0b9b21f41c7b</guid><dc:creator>AndersLundqvist</dc:creator><description>&lt;p&gt;Considering the fact that the original code for the uart example is (excerpt):&lt;/p&gt;
&lt;p&gt;while (app_uart_put(cr) != NRF_SUCCESS);&lt;br /&gt; while (app_uart_get(&amp;amp;cr) != NRF_SUCCESS);&lt;/p&gt;
&lt;p&gt;I can only pity your example coder/designer...&lt;/p&gt;
&lt;p&gt;And yes, I am quite certain that the led is not toggled. I am currently running the example without any call to app_uart_put and the led is blinking steadily at the desired frequency.&lt;/p&gt;
&lt;p&gt;Debugging the application without the bootloader is pointless, since the application then runs exactly as expected.&lt;/p&gt;
&lt;p&gt;I finally managed to get debugging while using the bootloader working. Tricky, very tricky... Should really be documentet somewhere.&lt;/p&gt;
&lt;p&gt;I stepped the code and the PC was last seen at line 310 in nrfx_uarte.c (a fairly uninteresting piece of code). Pausing the debugger results in a helt in an &amp;quot;Unknown function at 0x00000686&amp;quot; or thereabouts which clearly is something outside the application (according to the documentation this should be in the MBR).&lt;/p&gt;
&lt;p&gt;Is this a BUG in the SDK? A BUG in the SES? Or...?&lt;/p&gt;
&lt;p&gt;Best regards&lt;/p&gt;
&lt;p&gt;Anders&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problems with uart in both bootloader and application</title><link>https://devzone.nordicsemi.com/thread/150486?ContentTypeID=1</link><pubDate>Wed, 26 Sep 2018 12:41:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3e2b503b-aabe-4279-b25e-e1673aa4e995</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;You do not need to do anything in particular to debug when you have the bootloader (see for instance &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/27426/debug-application-with-bootloader-installed"&gt;this thread&lt;/a&gt;). However, it is quite tedious as every time you make a change in the application you have to update the bootloader settings, if not the bootloader will not start the application. Therefore, I generally recommend to debug without the bootloader installed (you can still use the exact same application without any adjustments).&lt;/p&gt;
&lt;p&gt;You should always check return values using&amp;nbsp;APP_ERROR_CHECK() so that things does not fail silently, which you do not do for the call to&amp;nbsp;app_uart_put(). It does not seem relevant in this case though. Are you sure the GPIO (LED_2) is not toggled? How have you verified? I expect you will see where the problem is quite fast when you start using the debugger.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problems with uart in both bootloader and application</title><link>https://devzone.nordicsemi.com/thread/150474?ContentTypeID=1</link><pubDate>Wed, 26 Sep 2018 12:16:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5217a4ba-2891-438d-89db-3607e5be72eb</guid><dc:creator>AndersLundqvist</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;The code is as follows:&lt;/p&gt;
&lt;p&gt;uint8_t cr = &amp;#39;A&amp;#39;;&lt;br /&gt;while (true)&lt;br /&gt; {&lt;br /&gt;app_uart_put(cr);&lt;/p&gt;
&lt;p&gt;nrf_delay_ms(300);&lt;br /&gt; nrf_gpio_pin_toggle(LED_2);&lt;/p&gt;
&lt;p&gt;if (cr == &amp;#39;q&amp;#39; || cr == &amp;#39;Q&amp;#39;)&lt;br /&gt; {&lt;br /&gt; printf(&amp;quot; \r\nExit!\r\n&amp;quot;);&lt;/p&gt;
&lt;p&gt;while (true)&lt;br /&gt; {&lt;br /&gt; // Do nothing.&lt;br /&gt; }&lt;br /&gt; }&lt;br /&gt; }&lt;/p&gt;
&lt;p&gt;If app_uart_put(cr); is executed but not the pin toggling (and supposedly the delay). I consider the code not running anymore. I see no call to APP_ERROR_CHECK() in app_uart_put(). The &amp;#39;A&amp;#39; is received &amp;quot;on the other side&amp;quot; of the uart i.e. my terminal program.&lt;/p&gt;
&lt;p&gt;Just curious, how do I use the debugger when the code that is running is started by the bootloader? That would indeed solve most of my problems...&lt;/p&gt;
&lt;p&gt;Best regards&lt;/p&gt;
&lt;p&gt;Anders&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problems with uart in both bootloader and application</title><link>https://devzone.nordicsemi.com/thread/150467?ContentTypeID=1</link><pubDate>Wed, 26 Sep 2018 12:04:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5f542a23-d0fb-45d4-8eab-d72928bea028</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;What do you mean when you say that the application &amp;quot;hangs&amp;quot;? The most common reason for seeing a unresponsive application (or an unintended reset) is that an error has been caught by an&amp;nbsp;APP_ERROR_CHECK(). In that case the device will enter a eternal loop in de debug handler for debug builds (DEBUG defined) or reset for release builds (DEBUG not defined). I recommend you start by checking if that is the case (using the debugger).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>