<?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>NRFConnect printk() an uart not conflicting?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/99031/nrfconnect-printk-an-uart-not-conflicting</link><description>Hi, 
 I am following the fundamental NRF course, and the UART exercise (lesson 5 ex 1) works as expected. 
 Adding printk() to the program like this( for example): 
 
 Works also as expected, even thought printk() is using the same UART as the main program</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 25 Apr 2023 09:03:23 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/99031/nrfconnect-printk-an-uart-not-conflicting" /><item><title>RE: NRFConnect printk() an uart not conflicting?</title><link>https://devzone.nordicsemi.com/thread/422222?ContentTypeID=1</link><pubDate>Tue, 25 Apr 2023 09:03:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1747fb67-589f-429b-9679-b48ea7ffe9e6</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user="Johan.h"]&lt;p&gt;FYI, lesson 8 ex. 2 (Mutex)&amp;nbsp; does not build out of the box as&amp;nbsp;&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_TEST_RANDOM_GENERATOR&lt;/span&gt;&lt;span&gt;=y&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;is missing from .prj file. (once added all is OK)&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;[/quote]
&lt;p&gt;Thanks for letting us know. We actually fixed this&amp;nbsp;issue yesterday, with this commit:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/NordicDeveloperAcademy/ncs-fund/commit/665f30e56b00798205bbbd218af4259b62c0102a"&gt;https://github.com/NordicDeveloperAcademy/ncs-fund/commit/665f30e56b00798205bbbd218af4259b62c0102a&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user="Johan.h"]&lt;p&gt;Understood, it is clear that changing UART prams like baud rate in the app will change printk() as well.&lt;/p&gt;
&lt;p&gt;If I disable interrupts for uart, will prink(0 stop working?&amp;nbsp;&lt;/p&gt;[/quote]
&lt;p&gt;The console uses poll_out, which does not use any interrupts, so you should be able to disable the UART interrupts.&lt;/p&gt;
&lt;p&gt;I tested this quick by disabling uart interrupts (NRF_UARTE0-&amp;gt;INTEN = 0) in hello_world, and it still prints the expected text.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRFConnect printk() an uart not conflicting?</title><link>https://devzone.nordicsemi.com/thread/422195?ContentTypeID=1</link><pubDate>Tue, 25 Apr 2023 07:41:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8b601f19-093c-46ad-9dab-a7279f37cfa1</guid><dc:creator>Johan.h</dc:creator><description>&lt;p&gt;Understood, it is clear that changing UART prams like baud rate in the app will change printk() as well.&lt;/p&gt;
&lt;p&gt;If I disable interrupts for uart, will prink(0 stop working?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Anyway I will play a bit with this to get deeper understating from a viewpoint of an old-school embedded programmer.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;FYI, lesson 8 ex. 2 (Mutex)&amp;nbsp; does not build out of the box as&amp;nbsp;&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_TEST_RANDOM_GENERATOR&lt;/span&gt;&lt;span&gt;=y&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;is missing from .prj file. (once added all is OK)&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;BR&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;Johanan&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRFConnect printk() an uart not conflicting?</title><link>https://devzone.nordicsemi.com/thread/422104?ContentTypeID=1</link><pubDate>Mon, 24 Apr 2023 14:45:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:abff6bd7-c4fb-4114-a0b5-a17122c6eb68</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hello Johanan,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I&amp;#39;m usually used to handling questions that are related to something not working, which makes me glad to hear that everything is working as you want it.&lt;/p&gt;
[quote user=""]Can you explain what is going on under the hood? how does this work without conflicts?[/quote]
&lt;p&gt;I&amp;#39;ll try my best.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;printk() can be routed to either &amp;quot;console&amp;quot; or &amp;quot;log&amp;quot;. Let us assume that you&amp;#39;re using the console (hint: setting CONFIG_LOG_PRINTK routes printk() through the logging module instead).&lt;/p&gt;
&lt;p&gt;CONFIG_PRINTK kconfig reference lists this:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.3.0/kconfig/index.html#CONFIG_PRINTK"&gt;https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.3.0/kconfig/index.html#CONFIG_PRINTK&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The first sentence is:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;Send printk() to console&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;To route printk() to the uart, as you have at this time, you need to set the backend of the console to the corresponding uart device in device-tree.&lt;/p&gt;
&lt;p&gt;Most (if not all) define this in the board dts file:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/v3.2.99-ncs2/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840.dts#L16"&gt;https://github.com/nrfconnect/sdk-zephyr/blob/v3.2.99-ncs2/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840.dts#L16&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Both &amp;quot;uart&amp;quot; driver and the &amp;quot;console&amp;quot;&amp;nbsp;subsys use the exact same peripheral here.&lt;/p&gt;
&lt;p&gt;Here&amp;#39;s the generic uart_console.c file, which will be equal for all devices that conforms to the zephyr &amp;quot;uart&amp;quot; API, by including zephyr/drivers/uart.h:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/v3.2.99-ncs2/drivers/console/uart_console.c"&gt;https://github.com/nrfconnect/sdk-zephyr/blob/v3.2.99-ncs2/drivers/console/uart_console.c&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The exact same thing is done in the sample that you&amp;#39;re using:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/NordicDeveloperAcademy/ncs-fund/blob/main/v2.x.x/lesson5/fund_less5_exer1_solution/src/main.c#L17"&gt;https://github.com/NordicDeveloperAcademy/ncs-fund/blob/main/v2.x.x/lesson5/fund_less5_exer1_solution/src/main.c#L17&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;So, both your application and the console goes to the uart API, which again goes to the underlying nrf driver:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/v3.2.99-ncs2/drivers/serial/uart_nrfx_uarte.c#L1760-L1792"&gt;https://github.com/nrfconnect/sdk-zephyr/blob/v3.2.99-ncs2/drivers/serial/uart_nrfx_uarte.c#L1760-L1792&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;example, uart.h::uart_tx() goes to uart_nrfx_uarte.c::uarte_nrfx_tx().&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;How does this work without any conflict?&amp;nbsp;In this particular use-case, the&amp;nbsp;API is blocking, so first come, first serve.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>