<?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>Best aproach to share/switch a UART?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/116147/best-aproach-to-share-switch-a-uart</link><description>Hi there, right now I&amp;#39;m working with an application that allows me to collect data via UART from several sensors (two), and I also I have a SIM module that allows me to communicate via UART. 
 
 But I&amp;#39;m facing the problem that I&amp;#39;m just using a single</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 12 Nov 2024 11:18:45 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/116147/best-aproach-to-share-switch-a-uart" /><item><title>RE: Best aproach to share/switch a UART?</title><link>https://devzone.nordicsemi.com/thread/510077?ContentTypeID=1</link><pubDate>Tue, 12 Nov 2024 11:18:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8e5489de-e06a-4ea4-a0b3-02b0e34d3b75</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/4034.old.c"&gt;devzone.nordicsemi.com/.../4034.old.c&lt;/a&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/5100.new.c"&gt;devzone.nordicsemi.com/.../5100.new.c&lt;/a&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/0724.diff.patch"&gt;devzone.nordicsemi.com/.../0724.diff.patch&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Files attached&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Best aproach to share/switch a UART?</title><link>https://devzone.nordicsemi.com/thread/510076?ContentTypeID=1</link><pubDate>Tue, 12 Nov 2024 11:14:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7fe2a564-df50-4c73-ab82-13c425b9e617</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;Try this new fixed code where I tried to add the mutex like I suggested to your code. It also makes the logic simpler. I have not compiled it but want to show you the logic how it is done. You are very capable of fixing the compiler issues.&lt;/p&gt;
&lt;p&gt;For some reason, I am unable to upload files,&amp;nbsp;So I will try to upload files in a different comment&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Best aproach to share/switch a UART?</title><link>https://devzone.nordicsemi.com/thread/510074?ContentTypeID=1</link><pubDate>Tue, 12 Nov 2024 11:07:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b62421cb-3ee4-438b-aed1-b164de6e205a</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;Let me write down my thoughts. A simple solution is to introduce a mutex for UART access. This allows only one task to control UART at any given time, ensuring smoother task coordination without blocking or interrupting each other’s communication.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Start by setting up a FreeRTOS mutex around the UART. Whenever a task needs to access UART, it locks the mutex, completes its operation, then releases it. This ensures only one task is using UART at any time, which keeps things from clashing.&lt;/p&gt;
&lt;p&gt;If one task has tighter timing needs, consider adjusting its priority or giving it a shorter wait on the mutex. This way, urgent UART access isn’t held up unnecessarily.&lt;/p&gt;
&lt;p&gt;Adding a timeout to the mutex acquisition is also a good idea. If a task can’t get access to UART within the set time, you can log the issue or handle it some other way to avoid blocking everything else.&lt;/p&gt;
&lt;p&gt;If there are frequent UART requests from multiple tasks, you might also think about using a queue. With a queue, tasks can queue up their UART requests, and a single handler can take these one by one. This setup simplifies retries and error handling, making the overall code a bit easier to manage.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Best aproach to share/switch a UART?</title><link>https://devzone.nordicsemi.com/thread/509958?ContentTypeID=1</link><pubDate>Mon, 11 Nov 2024 16:34:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0356e087-1235-4cce-8fac-ad31bfaf1ee7</guid><dc:creator>Fernando Mercado</dc:creator><description>&lt;p&gt;&lt;span style="font-size:150%;"&gt;Yes, I&amp;#39;m using FreeRTOS and&amp;nbsp;nrf5_sdk_17.1.0.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Best aproach to share/switch a UART?</title><link>https://devzone.nordicsemi.com/thread/509865?ContentTypeID=1</link><pubDate>Mon, 11 Nov 2024 11:53:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5ec7b699-ed9f-41db-a5f7-b8507aba11f5</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;I assumed you were using the nRF Connect SDK, but from the snippet you posted it appears you are using Freertos. Please confirm your setup (SDK version, RTOS, etc).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Best aproach to share/switch a UART?</title><link>https://devzone.nordicsemi.com/thread/509746?ContentTypeID=1</link><pubDate>Fri, 08 Nov 2024 23:18:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:53311035-3d00-47d3-8f6d-0b49dd1f1958</guid><dc:creator>Fernando Mercado</dc:creator><description>&lt;p&gt;&lt;span style="font-size:150%;"&gt;Hi,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:150%;"&gt;Actually no, it was my bad, let me explain more in deep my case.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:150%;"&gt;I have two tasks, and one of them I need to help me to ask via UART the current displayed window of an HMI, then into the task, call the Tx to send the command, and after that, call the RX with a timeout to wait for the response of that command from the HMI (inside of DISPLAY_MODULE_UART_getCurrentDisplayedWindow there is the call of Tx and Rx).&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:150%;"&gt;&lt;strong&gt;I&amp;#39;ll let down the snippet code:&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;static void rx_tx_function(void *pvParameter){ &lt;/code&gt;&lt;br /&gt;&lt;code&gt; while(1){ &lt;/code&gt;&lt;br /&gt;&lt;code&gt;DISPLAY_MODULE_UART_getCurrentDisplayedWindow(pCurrentWindow, pNumberCurrentWindow, pAll_OK);&lt;/code&gt;&lt;br /&gt;&lt;code&gt; if(all_OK){&lt;/code&gt;&lt;br /&gt;&lt;code&gt; SEGGER_RTT_printf(0, &amp;quot;[INFO] - from-&amp;gt;[%s()]-&amp;gt;Current_Window = [%s]\n&amp;quot;, __FUNCTION__, currentWindow);&lt;/code&gt;&lt;br /&gt;&lt;code&gt; if(numberCurrentWindow != SKIPPED_WINDOW){&lt;/code&gt;&lt;br /&gt;&lt;code&gt; SEGGER_RTT_printf(0, &amp;quot;[INFO] - from-&amp;gt;[%s()]-&amp;gt;NumberCurrentWindow = [%d]\n&amp;quot;, __FUNCTION__, numberCurrentWindow);&lt;/code&gt;&lt;br /&gt;&lt;code&gt; } &lt;/code&gt;&lt;br /&gt;&lt;code&gt; else{&lt;/code&gt;&lt;br /&gt;&lt;code&gt; SEGGER_RTT_printf(0, &amp;quot;[INFO] - from-&amp;gt;[%s()]-&amp;gt;Skipped: [%s]\n&amp;quot;, currentWindow); &lt;/code&gt;&lt;br /&gt;&lt;code&gt; } &lt;/code&gt;&lt;br /&gt;&lt;code&gt; }&lt;/code&gt;&lt;br /&gt;&lt;code&gt; else{&lt;/code&gt;&lt;br /&gt;&lt;code&gt; SEGGER_RTT_printf(0, &amp;quot;[INFO] - from-&amp;gt;[%s()]-&amp;gt;Handle timeoutTicks OR Failed to extract Current Window.\n&amp;quot;, __FUNCTION__);&lt;/code&gt;&lt;br /&gt;&lt;code&gt; } &lt;/code&gt;&lt;br /&gt;&lt;code&gt; vTaskDelay(pdMS_TO_TICKS(10));&lt;/code&gt;&lt;br /&gt;&lt;code&gt; }&lt;/code&gt;&lt;br /&gt;&lt;code&gt;}&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:150%;"&gt;The other task helps me to switch from one window to another, sending a command through UART Tx, and put the Rx to wait if I press a button.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:150%;"&gt;from the HMI.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:150%;"&gt;&lt;strong&gt;I&amp;#39;ll let down the snippet code:&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;static void rx_task_function(void *pvParameter){&lt;/code&gt;&lt;br /&gt;&lt;code&gt; DISPLAY_MODULE_UART_printCurrentState(currentState.currentState); &lt;/code&gt;&lt;br /&gt;&lt;code&gt; if(currentState.currentState == STATE_WHICH_BUTTON_WAS_PRESS){ &lt;/code&gt;&lt;br /&gt;&lt;code&gt; DISPLAY_MODULE_UART_processSTATE_WHICH_BUTTON_WAS_PRESS(ptrCurrentState, ptrCountWindows);&lt;/code&gt;&lt;br /&gt;&lt;code&gt; if(countWindows.countTimeWait_WIN_8 == 3 || countWindows.countTimeWait_WIN_10 == 3){ &lt;/code&gt;&lt;br /&gt;&lt;code&gt; SEGGER_RTT_printf(0, &amp;quot;[INFO] - from-&amp;gt;[%s()]-&amp;gt;countWindows.countTimeWait_WIN_8 = [%d]\n&amp;quot;, __FUNCTION__, countWindows.countTimeWait_WIN_8);&lt;/code&gt;&lt;br /&gt;&lt;code&gt; SEGGER_RTT_printf(0, &amp;quot;[INFO] - from-&amp;gt;[%s()]-&amp;gt;countWindows.countTimeWait_WIN_10 = [%d]\n&amp;quot;, __FUNCTION__, countWindows.countTimeWait_WIN_10);&lt;/code&gt;&lt;br /&gt;&lt;code&gt; currentState.currentState = STATE_GOTO_HOME_PAGE; &lt;/code&gt;&lt;br /&gt; &lt;br /&gt;&lt;code&gt; countWindows.countTimeWait_WIN_8 = 0;&lt;/code&gt;&lt;br /&gt;&lt;code&gt; countWindows.countTimeWait_WIN_10 = 0; &lt;/code&gt;&lt;br /&gt;&lt;code&gt; }&lt;/code&gt;&lt;br /&gt;&lt;code&gt; } &lt;/code&gt;&lt;br /&gt;&lt;code&gt; else{&lt;/code&gt;&lt;br /&gt;&lt;code&gt; DISPLAY_MODULE_UART_callFSM(ptrCurrentState); &lt;/code&gt;&lt;br /&gt;&lt;code&gt; } &lt;/code&gt;&lt;br /&gt;&lt;code&gt; SEGGER_RTT_printf(0, &amp;quot;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; [INFO] - from-&amp;gt;[%s()]-&amp;gt;EXIT\n&amp;quot;, __FUNCTION__); &lt;/code&gt;&lt;br /&gt;&lt;code&gt; vTaskDelay(pdMS_TO_TICKS(10)); &lt;/code&gt;&lt;br /&gt;&lt;code&gt;}&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:150%;"&gt;The main problem of this, is that I can&amp;#39;t find a good way to share between these two task the single UART.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:150%;"&gt;Then, I&amp;#39;d appreciate it if you could help me to understand a possible solution to my issue.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:150%;"&gt;Thanks in advance,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:150%;"&gt;Fer Mercado.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Best aproach to share/switch a UART?</title><link>https://devzone.nordicsemi.com/thread/509438?ContentTypeID=1</link><pubDate>Thu, 07 Nov 2024 12:03:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5eba33aa-5512-4098-b8ed-1aff22bd394f</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Do you plan to use a multiplexer or update the PSEL registers to update the UART pinout before accessing each device? Also, is the communication always initiated by the nRF?&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Vidar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>