<?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>switch UART pins at runtime</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/106788/switch-uart-pins-at-runtime</link><description>Hi, 
 I have rs232 and rs485 connected at my board to different pins. 
 Is there a example how to switch UART configuration at runtime? ( I want to swith active UART via BLE NUS command) 
 What is recommended devicetree for this configuration?</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 21 Dec 2023 10:08:24 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/106788/switch-uart-pins-at-runtime" /><item><title>RE: switch UART pins at runtime</title><link>https://devzone.nordicsemi.com/thread/461402?ContentTypeID=1</link><pubDate>Thu, 21 Dec 2023 10:08:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:807311fe-7efc-4f57-88df-3194fd76ac03</guid><dc:creator>Jared</dc:creator><description>&lt;p&gt;Great,&lt;/p&gt;
&lt;p&gt;Thanks for sharing your implementation,&lt;/p&gt;
&lt;p&gt;regards&lt;/p&gt;
&lt;p&gt;Jared&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: switch UART pins at runtime</title><link>https://devzone.nordicsemi.com/thread/461366?ContentTypeID=1</link><pubDate>Thu, 21 Dec 2023 07:41:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:39cf3c8f-9b35-401f-94e0-1b7b277d68dc</guid><dc:creator>mkoniarz</dc:creator><description>&lt;p&gt;I managed to do this way:&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;#define&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;UARTE_MODE_RS232&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;0&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;#define&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;UARTE_MODE_RS485&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;1&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;#define&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;UARTE_RS232_RX_PIN&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;23&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;#define&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;UARTE_RS232_TX_PIN&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;22&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;#define&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;UARTE_RS485_RX_PIN&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;25&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;#define&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;UARTE_RS485_TX_PIN&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;27&lt;/span&gt;&lt;/div&gt;
&lt;pre&gt;&lt;span&gt;#define&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;UARTE_RS485_RXTX_PIN&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;26&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;
void uarte_init(uint8_t mode) {
	nrfx_uarte_config_t uarte_config = NRFX_UARTE_DEFAULT_CONFIG(UARTE_RS232_TX_PIN,UARTE_RS232_RX_PIN);
	if(uarte_initialized) {
		nrfx_uarte_uninit(&amp;amp;uarte_instance);		
		uarte_initialized=0;
	}
	uarte_config.cts_pin = NRF_UARTE_PSEL_DISCONNECTED;
	uarte_config.rts_pin = NRF_UARTE_PSEL_DISCONNECTED;	
	uarte_mode = mode;
	uarte_config.baudrate = UARTE_BAUDRATE_BAUDRATE_Baud115200;
	uarte_config.p_context = &amp;amp;uarte_instance;
	if(mode == UARTE_MODE_RS232) {
		uarte_config.rxd_pin = UARTE_RS232_RX_PIN;
		uarte_config.txd_pin = UARTE_RS232_TX_PIN;
	} else if(mode == UARTE_MODE_RS485) {
		uarte_config.rxd_pin = UARTE_RS485_RX_PIN;
		uarte_config.txd_pin = UARTE_RS485_TX_PIN;
		nrf_gpio_cfg_output(UARTE_RS485_RXTX_PIN);
		nrf_gpio_pin_clear(UARTE_RS485_RXTX_PIN);
	} else {
		return;
	}
	#if defined(__ZEPHYR__)
    	IRQ_DIRECT_CONNECT(NRFX_IRQ_NUMBER_GET(NRF_UARTE_INST_GET(UARTE_INST_IDX)), IRQ_PRIO_LOWEST,
        	               NRFX_UARTE_INST_HANDLER_GET(UARTE_INST_IDX), 0);
	#endif
	if(nrfx_uarte_init(&amp;amp;uarte_instance, &amp;amp;uarte_config, uarte_callback) == NRFX_SUCCESS) {
		uarte_initialized=1;
	}
	nrfx_uarte_rx(&amp;amp;uarte_instance,uarte_rx_buffer, UART_RXTX_BUFFER_SIZE);
	rx_in_progress = 1;
}&lt;/pre&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: switch UART pins at runtime</title><link>https://devzone.nordicsemi.com/thread/461078?ContentTypeID=1</link><pubDate>Tue, 19 Dec 2023 13:52:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:612d11b0-911b-48da-aacf-a94fd0b2b0fa</guid><dc:creator>Jared</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;This is a bit tricky but I think you need to use the nrfx driver correctly for this to work.&lt;/p&gt;
&lt;p&gt;For example try to call the &lt;a href="https://github.com/NordicSemiconductor/nrfx/blob/f147ea557d5e2a04cb95ab8328204bcf36d8f410/drivers/include/nrfx_uart.h#L221C12-L221C33"&gt;nrfx_uart_reconfigure&lt;/a&gt;() with the new configuration struct.&lt;/p&gt;
&lt;p&gt;See &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/78379/changing-uart-tx-and-rx-pins-during-zephyr-runtime-with-nrfx/324220"&gt;this &lt;/a&gt;answer for more,&lt;/p&gt;
&lt;p&gt;I see that Zephyr has &lt;a href="https://zephyrproject.org/zephyr-weekly-update-multiplexing-all-the-things/"&gt;introduced &lt;/a&gt;device multiplexing, but I couldn&amp;#39;t find any example on it.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;regards&lt;/p&gt;
&lt;p&gt;Jared&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>